From f3d773300918c8754c5fcbdd186d1101fd10ce38 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Mon, 29 Jul 2013 08:54:37 -0700 Subject: [PATCH] Clean up unimplemented methods in the powervm driver There were several methods overridden from the base virt driver class in the powervm driver but all they did was pass which can cause problems with tempest, e.g. the tempest test for pausing an instance will timeout waiting for the instance state to change. This change raises NotImplementedError rather than passes so that tempest will fail out quickly when testing something that the powervm driver does not implement. Also removes the overridden manage_image_cache method since it didn't do anything, which is exactly what the base class does. Added unit tests to make sure that methods which should simply pass do and that tests which should raise NotImplementedError do that also. Fixes bug 1205066 Change-Id: Ieaf256a5c0f54804686318d6cbd5877a5003c9eb --- nova/tests/virt/powervm/test_powervm.py | 51 +++++++++++++++++++++++++ nova/virt/powervm/driver.py | 31 ++++++--------- 2 files changed, 62 insertions(+), 20 deletions(-) diff --git a/nova/tests/virt/powervm/test_powervm.py b/nova/tests/virt/powervm/test_powervm.py index 723c4992b5..1780f00747 100644 --- a/nova/tests/virt/powervm/test_powervm.py +++ b/nova/tests/virt/powervm/test_powervm.py @@ -809,6 +809,57 @@ class PowerVMDriverTestCase(test.TestCase): context.get_admin_context(), op=fake_operation, aggregate={'name': 'foo'}, host='fake') + def test_plug_vifs(self): + # Check to make sure the method raises NotImplementedError. + self.assertRaises(NotImplementedError, + self.powervm_connection.plug_vifs, + instance=None, network_info=None) + + def test_reboot(self): + # Check to make sure the method raises NotImplementedError. + self.assertRaises(NotImplementedError, self.powervm_connection.reboot, + context=None, instance=None, network_info=None, + reboot_type='SOFT') + + def test_manage_image_cache(self): + # Check to make sure the method passes (does nothing) since + # it's not implemented in the powervm driver and it passes + # in the driver base class. + self.powervm_connection.manage_image_cache(context.get_admin_context(), + True) + + def test_init_host(self): + # Check to make sure the method passes (does nothing) since + # it simply passes in the powervm driver but it raises a + # NotImplementedError in the base driver class. + self.powervm_connection.init_host(host='fake') + + def test_pause(self): + # Check to make sure the method raises NotImplementedError. + self.assertRaises(NotImplementedError, self.powervm_connection.pause, + instance=None) + + def test_unpause(self): + # Check to make sure the method raises NotImplementedError. + self.assertRaises(NotImplementedError, self.powervm_connection.unpause, + instance=None) + + def test_suspend(self): + # Check to make sure the method raises NotImplementedError. + self.assertRaises(NotImplementedError, self.powervm_connection.suspend, + instance=None) + + def test_resume(self): + # Check to make sure the method raises NotImplementedError. + self.assertRaises(NotImplementedError, self.powervm_connection.resume, + instance=None, network_info=None) + + def test_host_power_action(self): + # Check to make sure the method raises NotImplementedError. + self.assertRaises(NotImplementedError, + self.powervm_connection.host_power_action, + host='fake', action='die!') + class PowerVMDriverLparTestCase(test.TestCase): """Unit tests for PowerVM connection calls.""" diff --git a/nova/virt/powervm/driver.py b/nova/virt/powervm/driver.py index 13a0f3c9f4..f1f1fb3b79 100755 --- a/nova/virt/powervm/driver.py +++ b/nova/virt/powervm/driver.py @@ -62,10 +62,6 @@ class PowerVMDriver(driver.ComputeDriver): super(PowerVMDriver, self).__init__(virtapi) self._powervm = operator.PowerVMOperator() - @property - def host_state(self): - pass - def init_host(self, host): """Initialize anything that is necessary for the driver to function, including catching up with currently running VM's on the given host. @@ -94,7 +90,9 @@ class PowerVMDriver(driver.ComputeDriver): return self._powervm.get_host_uptime(host) def plug_vifs(self, instance, network_info): - pass + """Plug VIFs into networks.""" + raise NotImplementedError(_("Network injection is not supported by the" + "PowerVM driver.")) def macs_for_instance(self, instance): return self._powervm.macs_for_instance(instance) @@ -121,7 +119,8 @@ class PowerVMDriver(driver.ComputeDriver): :param bad_volumes_callback: Function to handle any bad volumes encountered """ - pass + raise NotImplementedError(_("Reboot is not supported by the" + "PowerVM driver.")) def get_host_ip_addr(self): """Retrieves the IP address of the hypervisor host.""" @@ -186,11 +185,13 @@ class PowerVMDriver(driver.ComputeDriver): def suspend(self, instance): """suspend the specified instance.""" - pass + raise NotImplementedError(_("Suspend is not supported by the" + "PowerVM driver.")) def resume(self, instance, network_info, block_device_info=None): """resume the specified instance.""" - pass + raise NotImplementedError(_("Resume is not supported by the" + "PowerVM driver.")) def power_off(self, instance): """Power off the specified instance.""" @@ -207,7 +208,8 @@ class PowerVMDriver(driver.ComputeDriver): def host_power_action(self, host, action): """Reboots, shuts down or powers up the host.""" - pass + raise NotImplementedError(_("Host power action is not supported by the" + "PowerVM driver.")) def legacy_nwinfo(self): """ @@ -215,17 +217,6 @@ class PowerVMDriver(driver.ComputeDriver): """ return False - def manage_image_cache(self, context, all_instances): - """ - Manage the driver's local image cache. - - Some drivers chose to cache images for instances on disk. This method - is an opportunity to do management of that cache which isn't directly - related to other calls into the driver. The prime example is to clean - the cache and remove images which are no longer of interest. - """ - pass - def migrate_disk_and_power_off(self, context, instance, dest, instance_type, network_info, block_device_info=None):