Merge "Abstract a driver API for triggering crash dump"

This commit is contained in:
Jenkins 2016-03-03 11:42:00 +00:00 committed by Gerrit Code Review
commit a3cf38a3ec
11 changed files with 28 additions and 28 deletions

View File

@ -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())

View File

@ -2589,20 +2589,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")

View File

@ -1059,7 +1059,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)

View File

@ -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):

View File

@ -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,

View File

@ -554,7 +554,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')

View File

@ -15553,15 +15553,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',
@ -15574,9 +15574,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,
'',
@ -15588,10 +15588,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',
@ -15604,7 +15604,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):

View File

@ -395,9 +395,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):

View File

@ -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
"""

View File

@ -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):

View File

@ -2609,16 +2609,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)