diff --git a/plugins/xenserver/networking/etc/xensource/scripts/ovs_configure_base_flows.py b/plugins/xenserver/networking/etc/xensource/scripts/ovs_configure_base_flows.py index 039cda172ca7..2a2cc213918b 100755 --- a/plugins/xenserver/networking/etc/xensource/scripts/ovs_configure_base_flows.py +++ b/plugins/xenserver/networking/etc/xensource/scripts/ovs_configure_base_flows.py @@ -24,7 +24,7 @@ This script is used to configure base openvswitch flows for XenServer hosts. import os import sys -import novalib +import novalib # noqa def main(command, phys_dev_name): @@ -62,11 +62,11 @@ def main(command, phys_dev_name): if __name__ == "__main__": if len(sys.argv) != 3 or sys.argv[1] not in ('online', 'offline', 'reset'): - print sys.argv + print(sys.argv) script_name = os.path.basename(sys.argv[0]) - print "This script configures base ovs flows." - print "usage: %s [online|offline|reset] phys-dev-name" % script_name - print " ex: %s online eth0" % script_name + print("This script configures base ovs flows.") + print("usage: %s [online|offline|reset] phys-dev-name" % script_name) + print(" ex: %s online eth0" % script_name) sys.exit(1) else: command, phys_dev_name = sys.argv[1:3] diff --git a/plugins/xenserver/networking/etc/xensource/scripts/ovs_configure_vif_flows.py b/plugins/xenserver/networking/etc/xensource/scripts/ovs_configure_vif_flows.py index 0aea079ffc2d..2fa86237aec9 100755 --- a/plugins/xenserver/networking/etc/xensource/scripts/ovs_configure_vif_flows.py +++ b/plugins/xenserver/networking/etc/xensource/scripts/ovs_configure_vif_flows.py @@ -21,12 +21,13 @@ This script is used to configure openvswitch flows on XenServer hosts. """ import os -import simplejson as json import sys # This is written to Python 2.4, since that is what is available on XenServer import netaddr -import novalib +import simplejson as json + +import novalib # noqa OVS_OFCTL = '/usr/bin/ovs-ofctl' diff --git a/plugins/xenserver/networking/etc/xensource/scripts/vif_rules.py b/plugins/xenserver/networking/etc/xensource/scripts/vif_rules.py index 26bcd16cec61..2f1c2f4f5215 100755 --- a/plugins/xenserver/networking/etc/xensource/scripts/vif_rules.py +++ b/plugins/xenserver/networking/etc/xensource/scripts/vif_rules.py @@ -24,11 +24,11 @@ XenServer hosts. import os import sys -import novalib - # This is written to Python 2.4, since that is what is available on XenServer import simplejson as json +import novalib # noqa + def main(dom_id, command, only_this_vif=None): xsls = novalib.execute_get_output('/usr/bin/xenstore-ls', diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/pluginlib_nova.py b/plugins/xenserver/xenapi/etc/xapi.d/plugins/pluginlib_nova.py index cc79cd86f0da..ebe0b9a98537 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/pluginlib_nova.py +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/pluginlib_nova.py @@ -112,7 +112,7 @@ def with_vdi_in_dom0(session, vdi, read_only, f): _vbd_unplug_with_retry(session, vbd) try: session.xenapi.VBD.destroy(vbd) - except XenAPI.Failure, e: + except XenAPI.Failure, e: # noqa logging.error(_('Ignoring XenAPI.Failure %s'), e) logging.debug(_('Destroying VBD for VDI %s done.'), vdi) @@ -128,7 +128,7 @@ def _vbd_unplug_with_retry(session, vbd): session.xenapi.VBD.unplug(vbd) logging.debug(_('VBD.unplug successful first time.')) return - except XenAPI.Failure, e: + except XenAPI.Failure, e: # noqa if (len(e.details) > 0 and e.details[0] == 'DEVICE_DETACH_REJECTED'): logging.debug(_('VBD.unplug rejected: retrying...')) diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/utils.py b/plugins/xenserver/xenapi/etc/xapi.d/plugins/utils.py index 62dffe248047..0d1f4a2fd942 100644 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/utils.py +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/utils.py @@ -35,7 +35,7 @@ class CommandNotFound(Exception): def delete_if_exists(path): try: os.unlink(path) - except OSError, e: + except OSError, e: # noqa if e.errno == errno.ENOENT: LOG.warning("'%s' was already deleted, skipping delete" % path) else: @@ -51,7 +51,7 @@ def _rename(src, dst): LOG.info("Renaming file '%s' -> '%s'" % (src, dst)) try: os.rename(src, dst) - except OSError, e: + except OSError, e: # noqa if e.errno == errno.EXDEV: LOG.error("Invalid cross-device link. Perhaps %s and %s should " "be symlinked on the same filesystem?" % (src, dst)) @@ -72,7 +72,7 @@ def make_subprocess(cmdline, stdout=False, stderr=False, stdin=False, kwargs['env'] = env try: proc = subprocess.Popen(cmdline, **kwargs) - except OSError, e: + except OSError, e: # noqa if e.errno == errno.ENOENT: raise CommandNotFound else: @@ -201,8 +201,7 @@ def _assert_vhd_not_hidden(path): value = line.split(':')[1].strip() if value == "1": raise Exception( - "VHD %(path)s is marked as hidden without child" % - locals()) + "VHD %s is marked as hidden without child" % path) def _validate_vhd(vdi_path): @@ -244,7 +243,8 @@ def _validate_vhd(vdi_path): raise Exception( "VDI '%(vdi_path)s' has an invalid %(part)s: '%(details)s'" - "%(extra)s" % locals()) + "%(extra)s" % {'vdi_path': vdi_path, 'part': part, + 'details': details, 'extra': extra}) def _validate_vdi_chain(vdi_path): @@ -264,11 +264,10 @@ def _validate_vdi_chain(vdi_path): elif 'has no parent' in first_line: return None elif 'query failed' in first_line: - raise Exception("VDI '%(path)s' not present which breaks" - " the VDI chain, bailing out" % locals()) + raise Exception("VDI '%s' not present which breaks" + " the VDI chain, bailing out" % path) else: - raise Exception("Unexpected output '%(out)s' from vhd-util" % - locals()) + raise Exception("Unexpected output '%s' from vhd-util" % out) cur_path = vdi_path while cur_path: diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenstore.py b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenstore.py index 05e3045abbc5..a6f1d6cd1532 100755 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenstore.py +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/xenstore.py @@ -27,11 +27,11 @@ try: except ImportError: import simplejson as json -import utils +import utils # noqa import XenAPIPlugin -import pluginlib_nova as pluginlib +import pluginlib_nova as pluginlib # noqa pluginlib.configure_logging("xenstore") @@ -70,7 +70,7 @@ def _record_exists(arg_dict): try: _run_command(cmd) return True - except XenstoreError, e: + except XenstoreError, e: # noqa if e.stderr == '': # if stderr was empty, this just means the path did not exist return False @@ -90,7 +90,7 @@ def read_record(self, arg_dict): try: result = _run_command(cmd) return result.strip() - except XenstoreError, e: + except XenstoreError, e: # noqa if not arg_dict.get("ignore_missing_path", False): raise if not _record_exists(arg_dict): @@ -128,7 +128,7 @@ def list_records(self, arg_dict): cmd = ["xenstore-ls", dirpath.rstrip("/")] try: recs = _run_command(cmd) - except XenstoreError, e: + except XenstoreError, e: # noqa if not _record_exists(arg_dict): return {} # Just try again in case the path was created in between @@ -160,7 +160,7 @@ def delete_record(self, arg_dict): cmd = ["xenstore-rm", "/local/domain/%(dom_id)s/%(path)s" % arg_dict] try: return _run_command(cmd) - except XenstoreError, e: + except XenstoreError, e: # noqa if 'could not remove path' in e.stderr: # Entry already gone. We're good to go. return '' @@ -204,7 +204,7 @@ def _run_command(cmd): """ try: return utils.run_command(cmd) - except utils.SubprocessException, e: + except utils.SubprocessException, e: # noqa raise XenstoreError(e.cmdline, e.ret, e.err, e.out) if __name__ == "__main__":