Assaf Muller has uploaded a new change for review. Change subject: Work in progress: First commit for custom device properties. ......................................................................
Work in progress: First commit for custom device properties. 1) All methods related to nic and disk hot plug and unplug in hooks.py and libvirtvm.py now pass the params dictionary onwards. 2) Added unit test 'deviceCustomProperties' under hooksTests.py, that verifies that a custom property sent to a hook is indeed available in that hook. Change-Id: Id1684c3bcf8838b43c7856f3794f1bffd8c4b28c Signed-off-by: Assaf Muller <[email protected]> --- M tests/hooksTests.py M vdsm/hooks.py M vdsm/libvirtvm.py 3 files changed, 70 insertions(+), 31 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/24/13124/1 diff --git a/tests/hooksTests.py b/tests/hooksTests.py index f80f271..e32862d 100644 --- a/tests/hooksTests.py +++ b/tests/hooksTests.py @@ -103,3 +103,24 @@ os.unlink(sName) expectedRes = dict([(os.path.basename(sName), {'md5': md5})]) self.assertEqual(expectedRes, info) + + def test_deviceCustomProperties(self): + dirName = tempfile.mkdtemp() + script = tempfile.NamedTemporaryFile(dir=dirName, delete=False) + code = """#!/usr/bin/python + +import os +import hooking + +domXMLFile = file(os.environ['_hook_domxml'], 'a') +customProperty = os.environ['customProperty'] +domXMLFile.write(customProperty) + """ + + script.write(code) + os.chmod(script.name, 0775) + script.close() + + result = hooks._runHooksDir("oVirt", dirName, + params={'customProperty': ' rocks!'}) + self.assertEqual(result, "oVirt rocks!") diff --git a/vdsm/hooks.py b/vdsm/hooks.py index 95516a8..33faa6e 100644 --- a/vdsm/hooks.py +++ b/vdsm/hooks.py @@ -174,47 +174,54 @@ raiseError=False, params=params) -def before_nic_hotplug(nicxml, vmconf={}): - return _runHooksDir(nicxml, 'before_nic_hotplug', vmconf=vmconf) +def before_nic_hotplug(nicxml, vmconf={}, params={}): + return _runHooksDir(nicxml, 'before_nic_hotplug', vmconf=vmconf, + params=params) -def after_nic_hotplug(nicxml, vmconf={}): - return _runHooksDir(nicxml, 'after_nic_hotplug', vmconf=vmconf) +def after_nic_hotplug(nicxml, vmconf={}, params={}): + return _runHooksDir(nicxml, 'after_nic_hotplug', vmconf=vmconf, + params=params) -def before_nic_hotunplug(nicxml, vmconf={}): - return _runHooksDir(nicxml, 'before_nic_hotunplug', vmconf=vmconf) +def before_nic_hotunplug(nicxml, vmconf={}, params={}): + return _runHooksDir(nicxml, 'before_nic_hotunplug', vmconf=vmconf, + params=params) -def after_nic_hotunplug(nicxml, vmconf={}): +def after_nic_hotunplug(nicxml, vmconf={}, params={}): return _runHooksDir(nicxml, 'after_nic_hotunplug', vmconf=vmconf, - raiseError=False) + params=params, raiseError=False) -def after_nic_hotplug_fail(nicxml, vmconf={}): +def after_nic_hotplug_fail(nicxml, vmconf={}, params={}): return _runHooksDir(nicxml, 'after_nic_hotplug_fail', vmconf=vmconf, - raiseError=False) + params=params, raiseError=False) -def after_nic_hotunplug_fail(nicxml, vmconf={}): +def after_nic_hotunplug_fail(nicxml, vmconf={}, params={}): return _runHooksDir(nicxml, 'after_nic_hotunplug_fail', vmconf=vmconf, - raiseError=False) + params=params, raiseError=False) -def before_disk_hotplug(domxml, vmconf={}): - return _runHooksDir(domxml, 'before_disk_hotplug', vmconf=vmconf) +def before_disk_hotplug(domxml, vmconf={}, params={}): + return _runHooksDir(domxml, 'before_disk_hotplug', vmconf=vmconf, + params=params) -def after_disk_hotplug(domxml, vmconf={}): - return _runHooksDir(domxml, 'after_disk_hotplug', vmconf=vmconf) +def after_disk_hotplug(domxml, vmconf={}, params={}): + return _runHooksDir(domxml, 'after_disk_hotplug', vmconf=vmconf, + params=params) -def before_disk_hotunplug(domxml, vmconf={}): - return _runHooksDir(domxml, 'before_disk_hotunplug', vmconf=vmconf) +def before_disk_hotunplug(domxml, vmconf={}, params={}): + return _runHooksDir(domxml, 'before_disk_hotunplug', vmconf=vmconf, + params=params) -def after_disk_hotunplug(domxml, vmconf={}): - return _runHooksDir(domxml, 'after_disk_hotunplug', vmconf=vmconf) +def after_disk_hotunplug(domxml, vmconf={}, params={}): + return _runHooksDir(domxml, 'after_disk_hotunplug', vmconf=vmconf, + params=params) def before_vdsm_start(): diff --git a/vdsm/libvirtvm.py b/vdsm/libvirtvm.py index 39d1b5b..f42e8b7 100644 --- a/vdsm/libvirtvm.py +++ b/vdsm/libvirtvm.py @@ -1501,14 +1501,16 @@ nicParams = params['nic'] nic = NetworkInterfaceDevice(self.conf, self.log, **nicParams) nicXml = nic.getXML().toprettyxml(encoding='utf-8') - nicXml = hooks.before_nic_hotplug(nicXml, self.conf) + nicXml = hooks.before_nic_hotplug(nicXml, self.conf, + params=params.get('custom', {})) self.log.debug("Hotplug NIC xml: %s", nicXml) try: self._dom.attachDevice(nicXml) except libvirt.libvirtError as e: self.log.error("Hotplug failed", exc_info=True) - nicXml = hooks.after_nic_hotplug_fail(nicXml, self.conf) + nicXml = hooks.after_nic_hotplug_fail( + nicXml, self.conf, params=params.get('custom', {})) if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN: return errCode['noVM'] return {'status': {'code': errCode['hotplugNic']['status']['code'], @@ -1522,7 +1524,8 @@ self.conf['devices'].append(nicParams) self.saveState() self._getUnderlyingNetworkInterfaceInfo() - hooks.after_nic_hotplug(nicXml, self.conf) + hooks.after_nic_hotplug(nicXml, self.conf, + params=params.get('custom', {})) if hasattr(nic, 'portMirroring'): mirroredNetworks = [] @@ -1538,7 +1541,8 @@ self.log.error("setPortMirroring for network %s failed", network, exc_info=True) nicParams['portMirroring'] = mirroredNetworks - self.hotunplugNic({'nic': nicParams}) + self.hotunplugNic({'nic': nicParams}, + params=params.get('custom', {})) return {'status': {'code': errCode['hotplugNic']['status']['code'], 'message': e.message}} @@ -1679,7 +1683,8 @@ supervdsm.getProxy().unsetPortMirroring(network, nic.name) nicXml = nic.getXML().toprettyxml(encoding='utf-8') - hooks.before_nic_hotunplug(nicXml, self.conf) + hooks.before_nic_hotunplug(nicXml, self.conf, + params=params.get('custom', {})) self.log.debug("Hotunplug NIC xml: %s", nicXml) else: self.log.error("Hotunplug NIC failed - NIC not found: %s", @@ -1715,12 +1720,14 @@ if nic: self._devices[vm.NIC_DEVICES].append(nic) self.saveState() - hooks.after_nic_hotunplug_fail(nicXml, self.conf) + hooks.after_nic_hotunplug_fail(nicXml, self.conf, + params=params.get('custom', {})) return { 'status': {'code': errCode['hotunplugNic']['status']['code'], 'message': e.message}} - hooks.after_nic_hotunplug(nicXml, self.conf) + hooks.after_nic_hotunplug(nicXml, self.conf, + params=params.get('custom', {})) return {'status': doneCode, 'vmList': self.status()} def hotplugDisk(self, params): @@ -1738,7 +1745,8 @@ driveXml = drive.getXML().toprettyxml(encoding='utf-8') self.log.debug("Hotplug disk xml: %s" % (driveXml)) - hooks.before_disk_hotplug(driveXml, self.conf) + hooks.before_disk_hotplug(driveXml, self.conf, + params=params.get('custom', {})) try: self._dom.attachDevice(driveXml) except libvirt.libvirtError as e: @@ -1758,7 +1766,8 @@ self.conf['devices'].append(diskParams) self.saveState() self._getUnderlyingDriveInfo() - hooks.after_disk_hotplug(driveXml, self.conf) + hooks.after_disk_hotplug(driveXml, self.conf, + params=params.get('custom', {})) return {'status': doneCode, 'vmList': self.status()} @@ -1800,7 +1809,8 @@ self.saveState() - hooks.before_disk_hotunplug(driveXml, self.conf) + hooks.before_disk_hotunplug(driveXml, self.conf, + params=params.get('custom', {})) try: self._dom.detachDevice(driveXml) except libvirt.libvirtError as e: @@ -1817,7 +1827,8 @@ 'status': {'code': errCode['hotunplugDisk']['status']['code'], 'message': e.message}} else: - hooks.after_disk_hotunplug(driveXml, self.conf) + hooks.after_disk_hotunplug(driveXml, self.conf, + params=params.get('custom', {})) self._cleanup() return {'status': doneCode, 'vmList': self.status()} -- To view, visit http://gerrit.ovirt.org/13124 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id1684c3bcf8838b43c7856f3794f1bffd8c4b28c Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Assaf Muller <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
