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
This commit is contained in:
parent
d51c5670d8
commit
3a0e5f985f
|
@ -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())
|
||||
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
"""
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue