From 3a0e5f985fdd4b067d68450360cf62d57e82ecb2 Mon Sep 17 00:00:00 2001 From: Hironori Shiina Date: Fri, 19 Feb 2016 16:32:21 +0900 Subject: [PATCH] Abstract a driver API for triggering crash dump An implementation to trigger crash dump depends on hypervisors. Inject_nmi is just a libvirt implementation. The driver API name should be "trigger_crash_dump" for the abstraction. This patch only changes names of the driver API and an Exception. It has no functional changes. Change-Id: Icef57d346fac7f92132bc14e22d5b2652397a64a Closes-Bug: 1547362 --- nova/api/openstack/compute/servers.py | 2 +- nova/compute/manager.py | 8 ++++---- nova/compute/rpcapi.py | 2 +- nova/exception.py | 4 ++-- .../api/openstack/compute/test_serversV21.py | 2 +- nova/tests/unit/compute/test_rpcapi.py | 2 +- nova/tests/unit/virt/libvirt/test_driver.py | 18 +++++++++--------- nova/tests/unit/virt/test_virt_drivers.py | 4 ++-- nova/virt/driver.py | 6 +++--- nova/virt/fake.py | 2 +- nova/virt/libvirt/driver.py | 6 +++--- 11 files changed, 28 insertions(+), 28 deletions(-) diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index 68cf726d26de..d48ab8d0890b 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -1207,7 +1207,7 @@ class ServersController(wsgi.Controller): 'trigger_crash_dump', id) except (exception.InstanceNotReady, exception.InstanceIsLocked) as e: raise webob.exc.HTTPConflict(explanation=e.format_message()) - except exception.NMINotSupported as e: + except exception.TriggerCrashDumpNotSupported as e: raise webob.exc.HTTPBadRequest(explanation=e.format_message()) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 604583c53043..e1ca07c90938 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -2585,20 +2585,20 @@ class ComputeManager(manager.Manager): self._notify_about_instance_usage(context, instance, "power_on.end") @messaging.expected_exceptions(NotImplementedError, - exception.NMINotSupported, + exception.TriggerCrashDumpNotSupported, exception.InstanceNotRunning) @wrap_exception() @wrap_instance_event @wrap_instance_fault def trigger_crash_dump(self, context, instance): - """Trigger crash dump in an instance by injecting NMI.""" + """Trigger crash dump in an instance.""" self._notify_about_instance_usage(context, instance, "trigger_crash_dump.start") # This method does not change task_state and power_state because the - # effect of an NMI depends on user's configuration. - self.driver.inject_nmi(instance) + # effect of a trigger depends on user's configuration. + self.driver.trigger_crash_dump(instance) self._notify_about_instance_usage(context, instance, "trigger_crash_dump.end") diff --git a/nova/compute/rpcapi.py b/nova/compute/rpcapi.py index c9b33c6b3a52..6d1ec23b3827 100644 --- a/nova/compute/rpcapi.py +++ b/nova/compute/rpcapi.py @@ -1039,7 +1039,7 @@ class ComputeAPI(object): version = '4.6' if not self.client.can_send_version(version): - raise exception.NMINotSupported() + raise exception.TriggerCrashDumpNotSupported() cctxt = self.client.prepare(server=_compute_host(None, instance), version=version) diff --git a/nova/exception.py b/nova/exception.py index 978747f1162a..a39c6fc87848 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -2077,8 +2077,8 @@ class UEFINotSupported(Invalid): msg_fmt = _("UEFI is not supported") -class NMINotSupported(Invalid): - msg_fmt = _("Injecting NMI is not supported") +class TriggerCrashDumpNotSupported(Invalid): + msg_fmt = _("Triggering crash dump is not supported") class UnsupportedHostCPUControlPolicy(Invalid): diff --git a/nova/tests/unit/api/openstack/compute/test_serversV21.py b/nova/tests/unit/api/openstack/compute/test_serversV21.py index f4318588cd96..b85d1ea263fe 100644 --- a/nova/tests/unit/api/openstack/compute/test_serversV21.py +++ b/nova/tests/unit/api/openstack/compute/test_serversV21.py @@ -2136,7 +2136,7 @@ class ServersControllerTriggerCrashDumpTest(ControllerTest): self.req, FAKE_UUID, body=self.body) @mock.patch.object(compute_api.API, 'trigger_crash_dump', - side_effect=exception.NMINotSupported) + side_effect=exception.TriggerCrashDumpNotSupported) def test_trigger_crash_dump_not_supported(self, mock_trigger_crash_dump): self.assertRaises(webob.exc.HTTPBadRequest, self.controller._action_trigger_crash_dump, diff --git a/nova/tests/unit/compute/test_rpcapi.py b/nova/tests/unit/compute/test_rpcapi.py index 8396adef924b..5a57a895863b 100644 --- a/nova/tests/unit/compute/test_rpcapi.py +++ b/nova/tests/unit/compute/test_rpcapi.py @@ -549,7 +549,7 @@ class ComputeRpcAPITestCase(test.NoDBTestCase): def test_trigger_crash_dump_incompatible(self): self.flags(compute='4.0', group='upgrade_levels') - self.assertRaises(exception.NMINotSupported, + self.assertRaises(exception.TriggerCrashDumpNotSupported, self._test_compute_api, 'trigger_crash_dump', 'cast', instance=self.fake_instance_obj, version='4.6') diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index 22d6d871a968..65c7052859f8 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -15398,15 +15398,15 @@ class LibvirtDriverTestCase(test.NoDBTestCase): cpumodel.POLICY_FORBID]), set([f.policy for f in cpu.features])) - def test_inject_nmi(self): + def test_trigger_crash_dump(self): mock_guest = mock.Mock(libvirt_guest.Guest, id=1) instance = objects.Instance(uuid='fake-uuid', id=1) with mock.patch.object(self.drvr._host, 'get_guest', return_value=mock_guest): - self.drvr.inject_nmi(instance) + self.drvr.trigger_crash_dump(instance) - def test_inject_nmi_not_running(self): + def test_trigger_crash_dump_not_running(self): ex = fakelibvirt.make_libvirtError( fakelibvirt.libvirtError, 'Requested operation is not valid: domain is not running', @@ -15419,9 +15419,9 @@ class LibvirtDriverTestCase(test.NoDBTestCase): with mock.patch.object(self.drvr._host, 'get_guest', return_value=mock_guest): self.assertRaises(exception.InstanceNotRunning, - self.drvr.inject_nmi, instance) + self.drvr.trigger_crash_dump, instance) - def test_inject_nmi_not_supported(self): + def test_trigger_crash_dump_not_supported(self): ex = fakelibvirt.make_libvirtError( fakelibvirt.libvirtError, '', @@ -15433,10 +15433,10 @@ class LibvirtDriverTestCase(test.NoDBTestCase): with mock.patch.object(self.drvr._host, 'get_guest', return_value=mock_guest): - self.assertRaises(exception.NMINotSupported, - self.drvr.inject_nmi, instance) + self.assertRaises(exception.TriggerCrashDumpNotSupported, + self.drvr.trigger_crash_dump, instance) - def test_inject_nmi_unexpected_error(self): + def test_trigger_crash_dump_unexpected_error(self): ex = fakelibvirt.make_libvirtError( fakelibvirt.libvirtError, 'UnexpectedError', @@ -15449,7 +15449,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase): with mock.patch.object(self.drvr._host, 'get_guest', return_value=mock_guest): self.assertRaises(fakelibvirt.libvirtError, - self.drvr.inject_nmi, instance) + self.drvr.trigger_crash_dump, instance) class LibvirtVolumeUsageTestCase(test.NoDBTestCase): diff --git a/nova/tests/unit/virt/test_virt_drivers.py b/nova/tests/unit/virt/test_virt_drivers.py index 79d134735315..7ae65ed54f63 100644 --- a/nova/tests/unit/virt/test_virt_drivers.py +++ b/nova/tests/unit/virt/test_virt_drivers.py @@ -393,9 +393,9 @@ class _VirtDriverTestCase(_FakeDriverBackendTestCase): self.connection.power_on(self.ctxt, instance_ref, network_info, None) @catch_notimplementederror - def test_inject_nmi(self): + def test_trigger_crash_dump(self): instance_ref, network_info = self._get_running_instance() - self.connection.inject_nmi(instance_ref) + self.connection.trigger_crash_dump(instance_ref) @catch_notimplementederror def test_soft_delete(self): diff --git a/nova/virt/driver.py b/nova/virt/driver.py index 624b01490741..0ff5e088b8f0 100644 --- a/nova/virt/driver.py +++ b/nova/virt/driver.py @@ -740,14 +740,14 @@ class ComputeDriver(object): """ raise NotImplementedError() - def inject_nmi(self, instance): - """Inject an non-maskable interruption (NMI) into the given instance. + def trigger_crash_dump(self, instance): + """Trigger crash dump mechanism on the given instance. Stalling instances can be triggered to dump the crash data. How the guest OS reacts in details, depends on the configuration of it. :param nova.objects.instance.Instance instance: - The instance where the NMI should be injected to. + The instance where the crash dump should be triggered. :return: None """ diff --git a/nova/virt/fake.py b/nova/virt/fake.py index 1c0e9cfe42dc..685c734b74d6 100644 --- a/nova/virt/fake.py +++ b/nova/virt/fake.py @@ -240,7 +240,7 @@ class FakeDriver(driver.ComputeDriver): block_device_info=None): pass - def inject_nmi(self, instance): + def trigger_crash_dump(self, instance): pass def soft_delete(self, instance): diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 59c536c6668a..55c2f4bd22d3 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -2590,16 +2590,16 @@ class LibvirtDriver(driver.ComputeDriver): # and available before we attempt to start the instance. self._hard_reboot(context, instance, network_info, block_device_info) - def inject_nmi(self, instance): + def trigger_crash_dump(self, instance): - """Inject an NMI to the specified instance.""" + """Trigger crash dump by injecting an NMI to the specified instance.""" try: self._host.get_guest(instance).inject_nmi() except libvirt.libvirtError as ex: error_code = ex.get_error_code() if error_code == libvirt.VIR_ERR_NO_SUPPORT: - raise exception.NMINotSupported() + raise exception.TriggerCrashDumpNotSupported() elif error_code == libvirt.VIR_ERR_OPERATION_INVALID: raise exception.InstanceNotRunning(instance_id=instance.uuid)