Mark Wu has uploaded a new change for review.
Change subject: PEP8 cleanup for *.py under vdsm_hooks ......................................................................
PEP8 cleanup for *.py under vdsm_hooks
Change-Id: Ifc798bb4598291d52e2cebce1ed65228f657ebbd Signed-off-by: Mark Wu wudxw@linux.vnet.ibm.com --- M Makefile.am M vdsm_hooks/directlun/after_vm_destroy.py M vdsm_hooks/directlun/before_vm_migrate_destination.py M vdsm_hooks/directlun/before_vm_start.py M vdsm_hooks/faqemu/before_vm_start.py M vdsm_hooks/floppy/before_vm_migrate_source.py M vdsm_hooks/floppy/before_vm_start.py M vdsm_hooks/hostusb/after_vm_destroy.py M vdsm_hooks/hostusb/before_vm_start.py M vdsm_hooks/hugepages/after_vm_destroy.py M vdsm_hooks/hugepages/before_vm_migrate_destination.py M vdsm_hooks/hugepages/before_vm_start.py M vdsm_hooks/isolatedprivatevlan/before_vm_start.py M vdsm_hooks/nestedvt/before_vm_start.py M vdsm_hooks/numa/before_vm_start.py M vdsm_hooks/pincpu/before_vm_start.py M vdsm_hooks/promisc/before_vm_destroy.py M vdsm_hooks/qos/before_vm_start.py M vdsm_hooks/smartcard/before_vm_start.py M vdsm_hooks/smbios/before_vm_start.py M vdsm_hooks/sriov/after_vm_destroy.py M vdsm_hooks/vmdisk/before_vm_start.py 22 files changed, 150 insertions(+), 71 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/34/9734/1
diff --git a/Makefile.am b/Makefile.am index 99e1a4f..f6f97bd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -89,11 +89,7 @@ vdsm/vdsm \ vdsm_api \ vdsm_cli \ - vdsm_hooks/fileinject \ - vdsm_hooks/promisc/after_vm_start.py \ - vdsm_hooks/scratchpad \ - vdsm_hooks/sriov/before_vm_start.py \ - vdsm_hooks/vhostmd \ + vdsm_hooks \ vdsm_reg/createDaemon.py \ vdsm_reg/define.py \ $(NULL) diff --git a/vdsm_hooks/directlun/after_vm_destroy.py b/vdsm_hooks/directlun/after_vm_destroy.py index 8b0a9c2..e88588a 100755 --- a/vdsm_hooks/directlun/after_vm_destroy.py +++ b/vdsm_hooks/directlun/after_vm_destroy.py @@ -13,13 +13,15 @@
DEV_DIRECTLUN_PATH = '/dev/directlun'
+ def removeDeviceNode(devpath):
# we don't use os.unlink because we need sudo command = ['/bin/rm', '-f', devpath] retcode, out, err = hooking.execCmd(command, sudo=True, raw=True) if retcode != 0: - sys.stderr.write('directlun after_vm_destroy: error rm -f %s, err = %s\n' % (devpath, err)) + sys.stderr.write('directlun after_vm_destroy: ' + 'error rm -f %s, err = %s\n' % (devpath, err)) sys.exit(2)
if 'directlun' in os.environ: @@ -41,5 +43,6 @@
hooking.write_domxml(domxml) except: - sys.stderr.write('directlun after_vm_destroy: [unexpected error]: %s\n' % traceback.format_exc()) + sys.stderr.write('directlun after_vm_destroy: [unexpected error]: %s\n' + % traceback.format_exc()) sys.exit(2) diff --git a/vdsm_hooks/directlun/before_vm_migrate_destination.py b/vdsm_hooks/directlun/before_vm_migrate_destination.py index ee57020..b80e60d 100755 --- a/vdsm_hooks/directlun/before_vm_migrate_destination.py +++ b/vdsm_hooks/directlun/before_vm_migrate_destination.py @@ -11,19 +11,22 @@ DEV_MAPPER_PATH = "/dev/mapper" DEV_DIRECTLUN_PATH = '/dev/directlun'
+ def createDirectory(dirpath):
# we don't use os.mkdir/chown because we need sudo command = ['/bin/mkdir', '-p', dirpath] retcode, out, err = hooking.execCmd(command, sudo=True, raw=True) if retcode != 0: - sys.stderr.write('directlun: error mkdir %s, err = %s\n' % (dirpath, err)) + sys.stderr.write('directlun: error mkdir %s, err = %s\n' % + (dirpath, err)) sys.exit(2)
mode = '755' command = ['/bin/chmod', mode, dirpath] if retcode != 0: - sys.stderr.write('directlun: error chmod %s %s, err = %s\n' % (dirpath, mode, err)) + sys.stderr.write('directlun: error chmod %s %s, err = %s\n' % + (dirpath, mode, err)) sys.exit(2)
@@ -34,7 +37,8 @@ command = ['/bin/rm', '-f', devpath] retcode, out, err = hooking.execCmd(command, sudo=True, raw=True) if retcode != 0: - sys.stderr.write('directlun: error rm -f %s, err = %s\n' % (devpath, err)) + sys.stderr.write('directlun: error rm -f %s, err = %s\n' % + (devpath, err)) sys.exit(2)
stat = os.stat(srcpath) @@ -43,14 +47,16 @@ command = ['/bin/mknod', devpath, 'b', str(major), str(minor)] retcode, out, err = hooking.execCmd(command, sudo=True, raw=True) if retcode != 0: - sys.stderr.write('directlun: error mknod %s, err = %s\n' % (devpath, err)) + sys.stderr.write('directlun: error mknod %s, err = %s\n' % + (devpath, err)) sys.exit(2)
mode = '660' command = ['/bin/chmod', mode, devpath] retcode, out, err = hooking.execCmd(command, sudo=True, raw=True) if retcode != 0: - sys.stderr.write('directlun: error chmod %s to %s, err = %s\n' % (devpath, mode, err)) + sys.stderr.write('directlun: error chmod %s to %s, err = %s\n' % + (devpath, mode, err)) sys.exit(2)
group = grp.getgrnam('qemu') @@ -61,7 +67,8 @@ command = ['/bin/chown', owner, devpath] retcode, out, err = hooking.execCmd(command, sudo=True, raw=True) if retcode != 0: - sys.stderr.write('directlun: error chown %s to %s, err = %s\n' % (devpath, owner, err)) + sys.stderr.write('directlun: error chown %s to %s, err = %s\n' % + (devpath, owner, err)) sys.exit(2)
if 'directlun' in os.environ: @@ -81,7 +88,8 @@
srcpath = DEV_MAPPER_PATH + '/' + lun if not os.path.exists(srcpath): - sys.stderr.write('directlun before_vm_migration_destination: device not found %s\n' % srcpath) + sys.stderr.write('directlun before_vm_migration_destination: ' + 'device not found %s\n' % srcpath) sys.exit(2)
uuid = domxml.getElementsByTagName('uuid')[0] @@ -92,5 +100,6 @@
hooking.write_domxml(domxml) except: - sys.stderr.write('directlun before_vm_migration_destination: [unexpected error]: %s\n' % traceback.format_exc()) + sys.stderr.write('directlun before_vm_migration_destination: ' + '[unexpected error]: %s\n' % traceback.format_exc()) sys.exit(2) diff --git a/vdsm_hooks/directlun/before_vm_start.py b/vdsm_hooks/directlun/before_vm_start.py index 0fff56a..bde62a2 100755 --- a/vdsm_hooks/directlun/before_vm_start.py +++ b/vdsm_hooks/directlun/before_vm_start.py @@ -12,6 +12,7 @@ DEV_DIRECTLUN_PATH = '/dev/directlun' NUM_OF_PCI = 27
+ def indexToDiskName(i): s = '' while True: @@ -20,6 +21,7 @@ if i == 0: break return 'vd' + (s or 'a') +
def createDiskElement(domxml, devpath, lunid, options): ''' @@ -72,13 +74,15 @@ command = ['/bin/mkdir', '-p', dirpath] retcode, out, err = hooking.execCmd(command, sudo=True, raw=True) if retcode != 0: - sys.stderr.write('directlun: error mkdir %s, err = %s\n' % (dirpath, err)) + sys.stderr.write('directlun: error mkdir %s, err = %s\n' % + (dirpath, err)) sys.exit(2)
mode = '755' command = ['/bin/chmod', mode, dirpath] if retcode != 0: - sys.stderr.write('directlun: error chmod %s %s, err = %s\n' % (dirpath, mode, err)) + sys.stderr.write('directlun: error chmod %s %s, err = %s\n' % + (dirpath, mode, err)) sys.exit(2)
@@ -89,7 +93,8 @@ command = ['/bin/rm', '-f', devpath] retcode, out, err = hooking.execCmd(command, sudo=True, raw=True) if retcode != 0: - sys.stderr.write('directlun: error rm -f %s, err = %s\n' % (devpath, err)) + sys.stderr.write('directlun: error rm -f %s, err = %s\n' % + (devpath, err)) sys.exit(2)
stat = os.stat(srcpath) @@ -98,14 +103,16 @@ command = ['/bin/mknod', devpath, 'b', str(major), str(minor)] retcode, out, err = hooking.execCmd(command, sudo=True, raw=True) if retcode != 0: - sys.stderr.write('directlun: error mknod %s, err = %s\n' % (devpath, err)) + sys.stderr.write('directlun: error mknod %s, err = %s\n' % + (devpath, err)) sys.exit(2)
mode = '660' command = ['/bin/chmod', mode, devpath] retcode, out, err = hooking.execCmd(command, sudo=True, raw=True) if retcode != 0: - sys.stderr.write('directlun: error chmod %s to %s, err = %s\n' % (devpath, mode, err)) + sys.stderr.write('directlun: error chmod %s to %s, err = %s\n' % + (devpath, mode, err)) sys.exit(2)
group = grp.getgrnam('qemu') @@ -116,7 +123,8 @@ command = ['/bin/chown', owner, devpath] retcode, out, err = hooking.execCmd(command, sudo=True, raw=True) if retcode != 0: - sys.stderr.write('directlun: error chown %s to %s, err = %s\n' % (devpath, owner, err)) + sys.stderr.write('directlun: error chown %s to %s, err = %s\n' % + (devpath, owner, err)) sys.exit(2)
@@ -154,5 +162,6 @@
hooking.write_domxml(domxml) except: - sys.stderr.write('directlun: [unexpected error]: %s\n' % traceback.format_exc()) + sys.stderr.write('directlun: [unexpected error]: %s\n' % + traceback.format_exc()) sys.exit(2) diff --git a/vdsm_hooks/faqemu/before_vm_start.py b/vdsm_hooks/faqemu/before_vm_start.py index 18e46fe..ddc6fa7 100755 --- a/vdsm_hooks/faqemu/before_vm_start.py +++ b/vdsm_hooks/faqemu/before_vm_start.py @@ -14,7 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # Refer to the README and COPYING files for full details of the license # @@ -39,7 +39,7 @@
devices = domxml.getElementsByTagName('devices')[0] if devices.getElementsByTagName('emulator'): - pass # TODO override emulator tag + pass # TODO override emulator tag else: emulator = domxml.createElement('emulator') emulatorPath = domxml.createTextNode('/usr/libexec/vdsm/vdsm-faqemu') diff --git a/vdsm_hooks/floppy/before_vm_migrate_source.py b/vdsm_hooks/floppy/before_vm_migrate_source.py index c700055..a0b0a1b 100755 --- a/vdsm_hooks/floppy/before_vm_migrate_source.py +++ b/vdsm_hooks/floppy/before_vm_migrate_source.py @@ -4,5 +4,6 @@ import sys
if 'floppy' in os.environ: - sys.stderr.write('floppy before_vm_migrate_source: cannot migrate VM with floppy hook\n') + sys.stderr.write('floppy before_vm_migrate_source: ' + 'cannot migrate VM with floppy hook\n') sys.exit(2) diff --git a/vdsm_hooks/floppy/before_vm_start.py b/vdsm_hooks/floppy/before_vm_start.py index 4bc3e4b..351ca0b 100755 --- a/vdsm_hooks/floppy/before_vm_start.py +++ b/vdsm_hooks/floppy/before_vm_start.py @@ -28,7 +28,8 @@ floppy = os.environ['floppy']
if not os.path.isfile(floppy): - sys.stderr.write('floppy: file not exists or not enough permissions: %s\n' % floppy) + sys.stderr.write('floppy: file not exists ' + 'or not enough permissions: %s\n' % floppy) sys.exit(2)
domxml = hooking.read_domxml() @@ -50,5 +51,6 @@ hooking.write_domxml(domxml)
except: - sys.stderr.write('floppy: [unexpected error]: %s\n' % traceback.format_exc()) + sys.stderr.write('floppy: [unexpected error]: %s\n' + % traceback.format_exc()) sys.exit(2) diff --git a/vdsm_hooks/hostusb/after_vm_destroy.py b/vdsm_hooks/hostusb/after_vm_destroy.py index 3f6e8c7..8b03e90 100755 --- a/vdsm_hooks/hostusb/after_vm_destroy.py +++ b/vdsm_hooks/hostusb/after_vm_destroy.py @@ -14,6 +14,7 @@
HOOK_HOSTUSB_PATH = '/var/run/vdsm/hooks/hostusb-permissions'
+ def get_owner(devpath): uid = pid = -1 content = '' @@ -38,6 +39,7 @@
return uid, pid
+ #!TODO: # merge chown with before_vm_start.py # maybe put it in hooks.py? @@ -55,7 +57,8 @@
uid, gid = get_owner(devpath) if uid == -1: - sys.stderr.write('hostusb after_vm_destroy: cannot find devpath: %s in file: %s\n' % (devpath, HOOK_HOSTUSB_PATH)) + sys.stderr.write('hostusb after_vm_destroy: cannot find devpath: %s ' + 'in file: %s\n' % (devpath, HOOK_HOSTUSB_PATH)) return
# we don't use os.chown because we need sudo @@ -63,7 +66,8 @@ command = ['/bin/chown', owner, devpath] retcode, out, err = hooking.execCmd(command, sudo=True, raw=True) if retcode != 0: - sys.stderr.write('hostusb after_vm_destroy: error chown %s to %s, err = %s\n' % (devpath, owner, err)) + sys.stderr.write('hostusb after_vm_destroy: error chown %s to %s, ' + 'err = %s\n' % (devpath, owner, err)) sys.exit(2)
if 'hostusb' in os.environ: @@ -71,11 +75,16 @@ regex = re.compile('^0x[\d,A-F,a-f]{4}$') for usb in os.environ['hostusb'].split('&'): vendorid, productid = usb.split(':') - if len(regex.findall(vendorid)) != 1 or len(regex.findall(productid)) != 1: - sys.stderr.write('hostusb after_vm_destroy: bad input, expected 0x0000 format for vendor and product id, input: %s:%s\n' % (vendorid, productid)) + if (len(regex.findall(vendorid)) != 1 or + len(regex.findall(productid)) != 1): + sys.stderr.write('hostusb after_vm_destroy: bad input ' + 'expected 0x0000 format for vendor and ' + 'product id, input: %s:%s\n' % + (vendorid, productid)) sys.exit(2) chown(vendorid, productid)
except: - sys.stderr.write('hostusb after_vm_destroy: [unexpected error]: %s\n' % traceback.format_exc()) + sys.stderr.write('hostusb after_vm_destroy: [unexpected error]: %s\n' % + traceback.format_exc()) sys.exit(2) diff --git a/vdsm_hooks/hostusb/before_vm_start.py b/vdsm_hooks/hostusb/before_vm_start.py index 3d3bbed..2a91c9d 100755 --- a/vdsm_hooks/hostusb/before_vm_start.py +++ b/vdsm_hooks/hostusb/before_vm_start.py @@ -40,6 +40,7 @@
HOOK_HOSTUSB_PATH = '/var/run/vdsm/hooks/hostusb-permissions'
+ def log_dev_owner(devpath, user, group): entry = devpath + ":" + str(user) + ":" + str(group)
@@ -56,6 +57,7 @@ f = file(HOOK_HOSTUSB_PATH, 'a') f.writelines(entry) f.close() +
#!TODO: # merge chown with after_vm_destroy.py @@ -85,10 +87,12 @@ command = ['/bin/chown', owner, devpath] retcode, out, err = hooking.execCmd(command, sudo=True, raw=True) if retcode != 0: - sys.stderr.write('hostusb: error chown %s to %s, err = %s\n' % (devpath, owner, err)) + sys.stderr.write('hostusb: error chown %s to %s, err = %s\n' % + (devpath, owner, err)) sys.exit(2)
log_dev_owner(devpath, stat.st_uid, stat.st_gid) +
def create_usb_device(domxml, vendorid, productid): hostdev = domxml.createElement('hostdev') @@ -116,8 +120,11 @@
for usb in os.environ['hostusb'].split('&'): vendorid, productid = usb.split(':') - if len(regex.findall(vendorid)) != 1 or len(regex.findall(productid)) != 1: - sys.stderr.write('hostusb: bad input, expected 0x0000 format for vendor and product id, input: %s:%s\n' % (vendorid, productid)) + if (len(regex.findall(vendorid)) != 1 or + len(regex.findall(productid)) != 1): + sys.stderr.write('hostusb: bad input, expected 0x0000 format ' + 'for vendor and product id, input: %s:%s\n' % + (vendorid, productid)) sys.exit(2)
hostdev = create_usb_device(domxml, vendorid, productid) @@ -126,5 +133,6 @@
hooking.write_domxml(domxml) except: - sys.stderr.write('hostusb: [unexpected error]: %s\n' % traceback.format_exc()) + sys.stderr.write('hostusb: [unexpected error]: %s\n' % + traceback.format_exc()) sys.exit(2) diff --git a/vdsm_hooks/hugepages/after_vm_destroy.py b/vdsm_hooks/hugepages/after_vm_destroy.py index c28dfca..2fb5e85 100755 --- a/vdsm_hooks/hugepages/after_vm_destroy.py +++ b/vdsm_hooks/hugepages/after_vm_destroy.py @@ -6,6 +6,7 @@
NUMBER_OF_HUGETPAGES = '/sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages'
+ def removeSysHugepages(pages): f = file(NUMBER_OF_HUGETPAGES, 'r') currPages = int(f.read()) @@ -22,5 +23,6 @@
removeSysHugepages(pages) except: - sys.stderr.write('hugepages: [unexpected error]: %s\n' % traceback.format_exc()) + sys.stderr.write('hugepages: [unexpected error]: %s\n' % + traceback.format_exc()) sys.exit(2) diff --git a/vdsm_hooks/hugepages/before_vm_migrate_destination.py b/vdsm_hooks/hugepages/before_vm_migrate_destination.py index 9d28fdf..0ec0f1f 100755 --- a/vdsm_hooks/hugepages/before_vm_migrate_destination.py +++ b/vdsm_hooks/hugepages/before_vm_migrate_destination.py @@ -8,6 +8,7 @@
NUMBER_OF_HUGETPAGES = '/sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages'
+ def addSysHugepages(pages): f = file(NUMBER_OF_HUGETPAGES, 'r') currPages = int(f.read()) @@ -18,7 +19,8 @@ command = ['sysctl', 'vm.nr_hugepages=%d' % totalPages] retcode, out, err = hooking.execCmd(command, sudo=True, raw=True) if retcode != 0: - sys.stderr.write('hugepages before_vm_migraton_destination: error in command: %s, err = %s\n' % (' '.join(command), err)) + sys.stderr.write('hugepages before_vm_migraton_destination: error in ' + 'command: %s, err = %s\n' % (' '.join(command), err)) sys.exit(2)
f = file(NUMBER_OF_HUGETPAGES, 'r') @@ -26,6 +28,7 @@ f.close()
return (newCurrPages - currPages) +
def freeSysHugepages(pages): f = file(NUMBER_OF_HUGETPAGES, 'r') @@ -37,7 +40,9 @@ command = ['sysctl', 'vm.nr_hugepages=%d' % (currPages - pages)] retcode, out, err = hooking.execCmd(command, sudo=True, raw=True) if retcode != 0: - sys.stderr.write('hugepages before_vm_migraton_destination: error in command: %s, err = %s\n' % (' '.join(command), err)) + sys.stderr.write('hugepages before_vm_migraton_destination: ' + 'error in command: %s, err = %s\n' % + (' '.join(command), err)) sys.exit(2)
@@ -47,14 +52,14 @@
addSysHugepages(pages) except: - sys.stderr.write('hugepages before_vm_migraton_destination: [unexpected error]: %s\n' % traceback.format_exc()) + sys.stderr.write('hugepages before_vm_migraton_destination: ' + '[unexpected error]: %s\n' % traceback.format_exc()) sys.exit(2) - -
# Add system hugepages allocatedPages = addSysHugepages(pages) if allocatedPages != pages: freeSysHugepages(allocatedPages) - sys.stderr.write('hugepages before_vm_migraton_destination: cannot allocate enough pages\n') + sys.stderr.write('hugepages before_vm_migraton_destination: ' + 'cannot allocate enough pages\n') sys.exit(2) diff --git a/vdsm_hooks/hugepages/before_vm_start.py b/vdsm_hooks/hugepages/before_vm_start.py index 23874ed..cddf475 100755 --- a/vdsm_hooks/hugepages/before_vm_start.py +++ b/vdsm_hooks/hugepages/before_vm_start.py @@ -44,7 +44,8 @@ command = ['sysctl', 'vm.nr_hugepages=%d' % totalPages] retcode, out, err = hooking.execCmd(command, sudo=True, raw=True) if retcode != 0: - sys.stderr.write('hugepages: error in command: %s, err = %s\n' % (' '.join(command), err)) + sys.stderr.write('hugepages: error in command: %s, err = %s\n' % + (' '.join(command), err)) sys.exit(2)
f = file(NUMBER_OF_HUGETPAGES, 'r') @@ -52,6 +53,7 @@ f.close()
return (newCurrPages - currPages) +
def freeSysHugepages(pages): f = file(NUMBER_OF_HUGETPAGES, 'r') @@ -63,7 +65,8 @@ command = ['sysctl', 'vm.nr_hugepages=%d' % (currPages - pages)] retcode, out, err = hooking.execCmd(command, sudo=True, raw=True) if retcode != 0: - sys.stderr.write('hugepages: error in command: %s, err = %s\n' % (' '.join(command), err)) + sys.stderr.write('hugepages: error in command: %s, err = %s\n' % + (' '.join(command), err)) sys.exit(2)
@@ -96,5 +99,6 @@
hooking.write_domxml(domxml) except: - sys.stderr.write('hugepages: [unexpected error]: %s\n' % traceback.format_exc()) + sys.stderr.write('hugepages: [unexpected error]: %s\n' % + traceback.format_exc()) sys.exit(2) diff --git a/vdsm_hooks/isolatedprivatevlan/before_vm_start.py b/vdsm_hooks/isolatedprivatevlan/before_vm_start.py index 8332470..6f839ed 100755 --- a/vdsm_hooks/isolatedprivatevlan/before_vm_start.py +++ b/vdsm_hooks/isolatedprivatevlan/before_vm_start.py @@ -7,6 +7,7 @@
filtername = 'isolatedprivatevlan-vdsm'
+ def addInterfaceFilter(domxml, interface, gateway, ip): if not ip is None: filterref = domxml.createElement('filterref') @@ -45,5 +46,6 @@ hooking.write_domxml(domxml)
except: - sys.stderr.write('isolated-privatevlan: [unexpected error]: %s\n' % traceback.format_exc()) + sys.stderr.write('isolated-privatevlan: [unexpected error]: %s\n' % + traceback.format_exc()) sys.exit(2) diff --git a/vdsm_hooks/nestedvt/before_vm_start.py b/vdsm_hooks/nestedvt/before_vm_start.py index 446a487..656a03f 100755 --- a/vdsm_hooks/nestedvt/before_vm_start.py +++ b/vdsm_hooks/nestedvt/before_vm_start.py @@ -14,7 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # Refer to the README and COPYING files for full details of the license # diff --git a/vdsm_hooks/numa/before_vm_start.py b/vdsm_hooks/numa/before_vm_start.py index 83e1f10..cefdb6f 100755 --- a/vdsm_hooks/numa/before_vm_start.py +++ b/vdsm_hooks/numa/before_vm_start.py @@ -48,5 +48,6 @@ sys.stderr.write('numa: numa already exists in domain xml') sys.exit(2) except: - sys.stderr.write('numa: [unexpected error]: %s\n' % traceback.format_exc()) + sys.stderr.write('numa: [unexpected error]: %s\n' % + traceback.format_exc()) sys.exit(2) diff --git a/vdsm_hooks/pincpu/before_vm_start.py b/vdsm_hooks/pincpu/before_vm_start.py index 0377992..6ea4528 100755 --- a/vdsm_hooks/pincpu/before_vm_start.py +++ b/vdsm_hooks/pincpu/before_vm_start.py @@ -21,11 +21,14 @@ vcpu = domxml.getElementsByTagName('vcpu')[0]
if not vcpu.hasAttribute('cpuset'): - sys.stderr.write('pincpu: pinning cpu to: %s\n' % os.environ['pincpu']) + sys.stderr.write('pincpu: pinning cpu to: %s\n' % + os.environ['pincpu']) vcpu.setAttribute('cpuset', os.environ['pincpu']) hooking.write_domxml(domxml) else: - sys.stderr.write('pincpu: cpuset attribute is present in vcpu, doing nothing\n') + sys.stderr.write('pincpu: cpuset attribute is present in vcpu, ' + 'doing nothing\n') except: - sys.stderr.write('pincpu: [unexpected error]: %s\n' % traceback.format_exc()) + sys.stderr.write('pincpu: [unexpected error]: %s\n' % + traceback.format_exc()) sys.exit(2) diff --git a/vdsm_hooks/promisc/before_vm_destroy.py b/vdsm_hooks/promisc/before_vm_destroy.py index ee6d080..cfc5452 100755 --- a/vdsm_hooks/promisc/before_vm_destroy.py +++ b/vdsm_hooks/promisc/before_vm_destroy.py @@ -6,6 +6,7 @@
import hooking
+ def removeMirrorNetwork(networkName): ''' this commands will remove our monitored network (bridge) from the queue: @@ -17,18 +18,21 @@ command = ['/sbin/tc', 'qdisc', 'del', 'dev', networkName, 'root'] retcode, out, err = hooking.execCmd(command, sudo=True, raw=True) if retcode != 0: - sys.stderr.write('promisc: error executing command "%s" error: %s' % (command, err)) + sys.stderr.write('promisc: error executing command "%s" error: %s' % + (command, err))
command = ['/sbin/tc', 'qdisc', 'del', 'dev', networkName, 'ingress'] retcode, out, err = hooking.execCmd(command, sudo=True, raw=True) if retcode != 0: - sys.stderr.write('promisc: error executing command "%s" error: %s' % (command, err)) + sys.stderr.write('promisc: error executing command "%s" error: %s' % + (command, err))
# remove promisc mode flag from the bridge command = ['/sbin/ifconfig', networkName, '-promisc'] retcode, out, err = hooking.execCmd(command, sudo=True, raw=True) if retcode != 0: - sys.stderr.write('promisc: error executing command "%s" error: %s' % (command, err)) + sys.stderr.write('promisc: error executing command "%s" error: %s' % + (command, err))
if 'promisc' in os.environ: try: @@ -36,9 +40,11 @@
for networkmode in networks.split(','): network, mode = networkmode.split(':') - sys.stderr.write('promisc: destroying monitoring network %s in mode %s\n' % (network, mode)) + sys.stderr.write('promisc: destroying monitoring network %s ' + 'in mode %s\n' % (network, mode)) removeMirrorNetwork(network)
except: - sys.stderr.write('promisc: [unexpected error]: %s\n' % traceback.format_exc()) + sys.stderr.write('promisc: [unexpected error]: %s\n' % + traceback.format_exc()) sys.exit(2) diff --git a/vdsm_hooks/qos/before_vm_start.py b/vdsm_hooks/qos/before_vm_start.py index ecbc05f..eb559d9 100755 --- a/vdsm_hooks/qos/before_vm_start.py +++ b/vdsm_hooks/qos/before_vm_start.py @@ -27,10 +27,12 @@ inbound or outbound elements can be once but not mandatory
syntax: - 00:11:22:33:44:55=in{'average':'1','peek':'2','burst':'5'}^out{'average':'1'}&11:11:11:11:11:11=... + MAC1=in{'average':'1','peek':'2','burst':'5'}^out{'average':'1'}&MAC2=... + Please replace 'MACn' with the MAC address of the virtual nic to be edited. '''
keys = ['average', 'peek', 'burst'] +
def add_attributes(node, attributes): data = ast.literal_eval(attributes) @@ -40,6 +42,7 @@ sys.exit(2)
node.setAttribute(key, data[key]) +
def update_interface(iface, data, domxml): bandwidth = domxml.createElement('bandwidth') @@ -76,12 +79,14 @@
iface = find_interface(arr[0], interfaces) if iface is None: - sys.stderr.write('qos hook: %s interface is not exists in VM\n' % arr[0]) + sys.stderr.write('qos hook: %s interface is not exists in VM\n' + % arr[0]) sys.exit(2)
update_interface(iface, arr[1], domxml)
hooking.write_domxml(domxml) except: - sys.stderr.write('qos hook: [unexpected error]: %s\n' % traceback.format_exc()) + sys.stderr.write('qos hook: [unexpected error]: %s\n' % + traceback.format_exc()) sys.exit(2) diff --git a/vdsm_hooks/smartcard/before_vm_start.py b/vdsm_hooks/smartcard/before_vm_start.py index 1944978..2b46033 100755 --- a/vdsm_hooks/smartcard/before_vm_start.py +++ b/vdsm_hooks/smartcard/before_vm_start.py @@ -25,5 +25,6 @@
hooking.write_domxml(domxml) except: - sys.stderr.write('smartcard: [unexpected error]: %s\n' % traceback.format_exc()) + sys.stderr.write('smartcard: [unexpected error]: %s\n' % + traceback.format_exc()) sys.exit(2) diff --git a/vdsm_hooks/smbios/before_vm_start.py b/vdsm_hooks/smbios/before_vm_start.py index b272e5b..55635a9 100755 --- a/vdsm_hooks/smbios/before_vm_start.py +++ b/vdsm_hooks/smbios/before_vm_start.py @@ -18,6 +18,7 @@
bios_entries = ["vendor", "version", "date", "release"]
+ def addSystemEntry(domxml, sysinfo, entry): systems = sysinfo.getElementsByTagName('system') if systems.length == 0: @@ -43,6 +44,7 @@ txt = domxml.createTextNode(entry[name]) e.appendChild(txt) system.appendChild(e) +
def addBiosEntry(domxml, sysinfo, entry): bioses = sysinfo.getElementsByTagName('bios') @@ -101,5 +103,6 @@ hooking.write_domxml(domxml)
except: - sys.stderr.write('smbios: [unexpected error]: %s\n' % traceback.format_exc()) + sys.stderr.write('smbios: [unexpected error]: %s\n' % + traceback.format_exc()) sys.exit(2) diff --git a/vdsm_hooks/sriov/after_vm_destroy.py b/vdsm_hooks/sriov/after_vm_destroy.py index 79058e3..1e2dd5a 100755 --- a/vdsm_hooks/sriov/after_vm_destroy.py +++ b/vdsm_hooks/sriov/after_vm_destroy.py @@ -11,12 +11,14 @@ VDSM_VAR_HOOKS_DIR = '/var/run/vdsm/hooks' SRIOV_CACHE_FILENAME = 'sriov.cache'
+ def returnDeviceToHost(addr, devpath): # attach device back to host connection = libvirtconnection.get(None) nodeDevice = connection.nodeDeviceLookupByName(addr) - if nodeDevice != None: - sys.stderr.write('sriov after_vm_destroy: attaching pci device %s back to host\n' % addr) + if nodeDevice is not None: + sys.stderr.write('sriov after_vm_destroy: attaching pci device %s ' + 'back to host\n' % addr) nodeDevice.reAttach()
# return device permissions @@ -27,7 +29,8 @@ command = ['/bin/chown', owner, dev] retcode, out, err = hooking.execCmd(command, sudo=True, raw=True) if retcode != 0: - sys.stderr.write('sriov after_vm_destroy: error chown %s to %s, err = %s\n' % (dev, owner, err)) + sys.stderr.write('sriov after_vm_destroy: error chown ' + '%s to %s, err = %s\n' % (dev, owner, err)) sys.exit(2)
if 'sriov' in os.environ: @@ -42,7 +45,7 @@ line = f.readline() if not line: break - pass # do something + pass # do something nicAddr = line.split('=') if nicAddr[0] in nics: returnDeviceToHost(nicAddr[1], nicAddr[2].strip('\n')) @@ -54,8 +57,10 @@ f.writelines(lines) f.close() else: - sys.stderr.write('sriov after_vm_destroy: cannot find sriov cache file %s\n' % path) + sys.stderr.write('sriov after_vm_destroy: cannot find sriov cache ' + 'file %s\n' % path)
except: - sys.stderr.write('sriov after_vm_destroy: [unexpected error]: %s\n' % traceback.format_exc()) + sys.stderr.write('sriov after_vm_destroy: [unexpected error]: %s\n' % + traceback.format_exc()) sys.exit(2) diff --git a/vdsm_hooks/vmdisk/before_vm_start.py b/vdsm_hooks/vmdisk/before_vm_start.py index da4ee38..bae18ab 100755 --- a/vdsm_hooks/vmdisk/before_vm_start.py +++ b/vdsm_hooks/vmdisk/before_vm_start.py @@ -14,6 +14,7 @@
driver_types = ('raw', 'qcow2')
+ def indexToDiskName(i): s = '' while True: @@ -22,6 +23,7 @@ if i == 0: break return 'vd' + (s or 'a') +
def createDiskElement(domxml, devpath, drivertype): ''' @@ -74,11 +76,13 @@ try: devpath, drivertype = disk.split(':') except ValueError: - sys.stderr.write('vmdisk: input error, expected diskpath:diskformat ie /path/disk.img:qcow2\n') + sys.stderr.write('vmdisk: input error, expected diskpath:' + 'diskformat ie /path/disk.img:qcow2\n') sys.exit(2)
if not drivertype in driver_types: - sys.stderr.write('vmdisk: input error, driver type: raw or qcow2\n') + sys.stderr.write('vmdisk: input error, driver type: ' + 'raw or qcow2\n') sys.exit(2)
diskdev = createDiskElement(domxml, devpath, drivertype) @@ -86,5 +90,6 @@
hooking.write_domxml(domxml) except: - sys.stderr.write('vmdisk: [unexpected error]: %s\n' % traceback.format_exc()) + sys.stderr.write('vmdisk: [unexpected error]: %s\n' % + traceback.format_exc()) sys.exit(2)
-- To view, visit http://gerrit.ovirt.org/9734 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange Gerrit-Change-Id: Ifc798bb4598291d52e2cebce1ed65228f657ebbd Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Mark Wu wudxw@linux.vnet.ibm.com
Zhou Zheng Sheng has posted comments on this change.
Change subject: PEP8 cleanup for *.py under vdsm_hooks ......................................................................
Patch Set 1: I would prefer that you didn't submit this
Dan tries to remove the pep8 ignore option for E121, E122, E123, and the removal of E121 is merged in the latest master (commit c509c0a). There are some E121,E122,E123 in this patch, so could you rebase the patch on http://gerrit.ovirt.org/#/c/9730/ ?
-- To view, visit http://gerrit.ovirt.org/9734 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: Ifc798bb4598291d52e2cebce1ed65228f657ebbd Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Mark Wu wudxw@linux.vnet.ibm.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com
Zhou Zheng Sheng has posted comments on this change.
Change subject: PEP8 cleanup for *.py under vdsm_hooks ......................................................................
Patch Set 1: No score
-- To view, visit http://gerrit.ovirt.org/9734 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: Ifc798bb4598291d52e2cebce1ed65228f657ebbd Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Mark Wu wudxw@linux.vnet.ibm.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com
Mark Wu has posted comments on this change.
Change subject: PEP8 cleanup for *.py under vdsm_hooks ......................................................................
Patch Set 1:
I updated pep8 on my host and didn't ignore any PEP8 error when I fix it. So I doesn't need a rebase.
-- To view, visit http://gerrit.ovirt.org/9734 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: Ifc798bb4598291d52e2cebce1ed65228f657ebbd Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Mark Wu wudxw@linux.vnet.ibm.com Gerrit-Reviewer: Mark Wu wudxw@linux.vnet.ibm.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com
Zhou Zheng Sheng has posted comments on this change.
Change subject: PEP8 cleanup for *.py under vdsm_hooks ......................................................................
Patch Set 1: Verified
(1 inline comment)
Pass autobuild.sh.
pydiff find some changes.
First change:
pydiff vdsm_hooks/qos/before_vm_start.py ../diffs/vdsm_hooks/qos/before_vm_start.py 1 difference(s) first file: vdsm_hooks/qos/before_vm_start.py second file: ../diffs/vdsm_hooks/qos/before_vm_start.py
((31, "\nQoS Hook\n========\nlibvirt domain xml:\n<interface>\n ...\n <bandwidth>\n <inbound average='1' peak='2' burst='5'/>\n <outbound average='0.5'/>\n </bandwidth>\n ...\n</interface>\n\nNote:\n for average, peak, and burst explanation look at:\n # man tc tbf\n\n'average' attribute is mandatory,\ninbound or outbound elements can be once but not mandatory\n\nsyntax:\n 00:11:22:33:44:55=in{'average':'1','peek':'2','burst':'5'}^out{'average':'1'}&11:11:11:11:11:11=...\n"), (32, "\nQoS Hook\n========\nlibvirt domain xml:\n<interface>\n ...\n <bandwidth>\n <inbound average='1' peak='2' burst='5'/>\n <outbound average='0.5'/>\n </bandwidth>\n ...\n</interface>\n\nNote:\n for average, peak, and burst explanation look at:\n # man tc tbf\n\n'average' attribute is mandatory,\ninbound or outbound elements can be once but not mandatory\n\nsyntax:\n MAC1=in{'average':'1','peek':'2','burst':'5'}^out{'average':'1'}&MAC2=...\n Please replace 'MACn' with the MAC address of the virtual nic to be edited.\n"))
This change shortens the mac address 00:11:22:33:44:55 and 11:11:11:11:11:11 to MAC1 and MAC2 to fit in 80 columns in one line. I think it's OK.
The second change:
pydiff vdsm_hooks/sriov/after_vm_destroy.py ../diffs/vdsm_hooks/sriov/after_vm_destroy.py 1 difference(s) first file: vdsm_hooks/sriov/after_vm_destroy.py second file: ../diffs/vdsm_hooks/sriov/after_vm_destroy.py
((18, '!='), (19, 'is not'))
This is for using 'is' and 'is not' when compare to "None", it's OK.
.................................................... File vdsm_hooks/directlun/after_vm_destroy.py Line 43: Line 44: hooking.write_domxml(domxml) Line 45: except: Line 46: sys.stderr.write('directlun after_vm_destroy: [unexpected error]: %s\n' Line 47: % traceback.format_exc()) I think it might be better if written as
sys.stderr.write( 'directlun after_vm_destroy: [unexpected error]: %s\n' % traceback.format_exc())
-- To view, visit http://gerrit.ovirt.org/9734 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: Ifc798bb4598291d52e2cebce1ed65228f657ebbd Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Mark Wu wudxw@linux.vnet.ibm.com Gerrit-Reviewer: Mark Wu wudxw@linux.vnet.ibm.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com
Zhou Zheng Sheng has posted comments on this change.
Change subject: PEP8 cleanup for *.py under vdsm_hooks ......................................................................
Patch Set 1: (2 inline comments)
A string literal is changed.
.................................................... File vdsm_hooks/hostusb/after_vm_destroy.py Line 71 Line 72 Line 73 Line 74 Line 75 It seems you delete the "," .
Line 75: regex = re.compile('^0x[\d,A-F,a-f]{4}$') Line 76: for usb in os.environ['hostusb'].split('&'): Line 77: vendorid, productid = usb.split(':') Line 78: if (len(regex.findall(vendorid)) != 1 or Line 79: len(regex.findall(productid)) != 1): It's better if you add 4 spaces to indent this line so it can be distinguished from the following block. Like this,
if (len(regex.findall(vendorid)) != 1 or len(regex.findall(productid)) != 1): sys.stderr.write('hostusb after_vm_destroy: bad input, ' Line 80: sys.stderr.write('hostusb after_vm_destroy: bad input ' Line 81: 'expected 0x0000 format for vendor and ' Line 82: 'product id, input: %s:%s\n' % Line 83: (vendorid, productid))
-- To view, visit http://gerrit.ovirt.org/9734 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: Ifc798bb4598291d52e2cebce1ed65228f657ebbd Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Mark Wu wudxw@linux.vnet.ibm.com Gerrit-Reviewer: Mark Wu wudxw@linux.vnet.ibm.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com
Zhou Zheng Sheng has posted comments on this change.
Change subject: PEP8 cleanup for *.py under vdsm_hooks ......................................................................
Patch Set 1: No score
-- To view, visit http://gerrit.ovirt.org/9734 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: Ifc798bb4598291d52e2cebce1ed65228f657ebbd Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Mark Wu wudxw@linux.vnet.ibm.com Gerrit-Reviewer: Mark Wu wudxw@linux.vnet.ibm.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com
Mark Wu has abandoned this change.
Change subject: PEP8 cleanup for *.py under vdsm_hooks ......................................................................
Patch Set 1: Abandoned
already cleaned up.
-- To view, visit http://gerrit.ovirt.org/9734 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: abandon Gerrit-Change-Id: Ifc798bb4598291d52e2cebce1ed65228f657ebbd Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Mark Wu wudxw@linux.vnet.ibm.com Gerrit-Reviewer: Mark Wu wudxw@linux.vnet.ibm.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com
vdsm-patches@lists.fedorahosted.org