Fix several flake8 issues in the plugins/xenserver code
Due to some issues in the gate, several flake8 errors got merged recently. This patch fixes the most recent issues found. For the H304 relative import errors, we have to skip those because they are put into /etc/xensource/scripts which is the current working directory when running the plugin. For the H231 incompatible python 3 'except x,y' construct, we have to skip those because this code is written to run on python 2.4 and 'except x as y' does not work with python 2.4. Note that in cleaning up some of the H304 failures for relative imports, I also re-arranged the imports to follow the hacking guide of doing standard library packages first, then third party packages, and finally nova-specific packages. Closes-Bug: #1229753 Change-Id: I1c2211fd6a10d43d7e65cdb4e18530397788cf2c
This commit is contained in:
parent
6163e808bd
commit
016e39734e
@ -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]
|
||||
|
@ -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'
|
||||
|
@ -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',
|
||||
|
@ -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...'))
|
||||
|
@ -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:
|
||||
|
@ -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__":
|
||||
|
Loading…
Reference in New Issue
Block a user