From 79bfb1bf343484e98aa36dcc663a5370baf4cab7 Mon Sep 17 00:00:00 2001 From: pkholkin Date: Fri, 12 Sep 2014 19:31:54 +0400 Subject: [PATCH] Fix libvirt watchdog support Using the flavor extra_specs property "hw_watchdog_action" was broken. Scheduling of a new instance always failed with NoValidHostFound error because of ComputeCapabilitiesFilter, which treated this property as a host capability to be checked. Commit f0ff4d51057080e769407e873e5ed212f15b773d caused the problem. To fix this watchdog_action property is put into 'hw:' scope, so that it will be ignored by ComputeCapabilitiesFilter in scheduler and handled in libvirt driver. The doc must be fixed accordingly. Now driver accepts both 'hw_watchdog_action' and 'hw:watchdog_action', tests were edited for these cases. Were added TODO items to delete the compat code in the next release. DocImpact Closes-Bug: #1367344 Change-Id: Ic5344ec34a130ee5a0ed2c7348af0b9d79e3508e --- nova/tests/virt/libvirt/test_driver.py | 16 +++++++++++++--- nova/virt/libvirt/driver.py | 12 ++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/nova/tests/virt/libvirt/test_driver.py b/nova/tests/virt/libvirt/test_driver.py index edd6a4a8e073..7a0115f84332 100644 --- a/nova/tests/virt/libvirt/test_driver.py +++ b/nova/tests/virt/libvirt/test_driver.py @@ -2318,15 +2318,15 @@ class LibvirtConnTestCase(test.NoDBTestCase): self.assertEqual("none", cfg.devices[7].action) @mock.patch.object(objects.Flavor, 'get_by_id') - def test_get_guest_config_with_watchdog_action_flavor(self, - mock_flavor): + def _test_get_guest_config_with_watchdog_action_flavor(self, mock_flavor, + hw_watchdog_action="hw:watchdog_action"): self.flags(virt_type='kvm', group='libvirt') conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True) instance_ref = objects.Instance(**self.test_instance) flavor = instance_ref.get_flavor() - flavor.extra_specs = {'hw_watchdog_action': 'none'} + flavor.extra_specs = {hw_watchdog_action: 'none'} mock_flavor.return_value = flavor disk_info = blockinfo.get_disk_info(CONF.libvirt.virt_type, @@ -2356,6 +2356,16 @@ class LibvirtConnTestCase(test.NoDBTestCase): self.assertEqual("none", cfg.devices[7].action) + def test_get_guest_config_with_watchdog_action_through_flavor(self): + self._test_get_guest_config_with_watchdog_action_flavor() + + # TODO(pkholkin): the test accepting old property name 'hw_watchdog_action' + # should be removed in the next release + def test_get_guest_config_with_watchdog_action_through_flavor_no_scope( + self): + self._test_get_guest_config_with_watchdog_action_flavor( + hw_watchdog_action="hw_watchdog_action") + @mock.patch.object(objects.Flavor, 'get_by_id') def test_get_guest_config_with_watchdog_overrides_flavor(self, mock_flavor): diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index a2504ad4b0c0..089a9cbac940 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -4075,8 +4075,16 @@ class LibvirtDriver(driver.ComputeDriver): raise exception.PciDeviceUnsupportedHypervisor( type=CONF.libvirt.virt_type) - watchdog_action = flavor.extra_specs.get('hw_watchdog_action', - 'disabled') + if 'hw_watchdog_action' in flavor.extra_specs: + LOG.warn(_LW('Old property name "hw_watchdog_action" is now ' + 'deprecated and will be removed in the next release. ' + 'Use updated property name ' + '"hw:watchdog_action" instead')) + # TODO(pkholkin): accepting old property name 'hw_watchdog_action' + # should be removed in the next release + watchdog_action = (flavor.extra_specs.get('hw_watchdog_action') or + flavor.extra_specs.get('hw:watchdog_action') + or 'disabled') if (image_meta is not None and image_meta.get('properties', {}).get('hw_watchdog_action')): watchdog_action = image_meta['properties']['hw_watchdog_action']