libvirt:Add a driver API to inject an NMI

This patch adds a new driver API to inject an NMI to an instance.
This API is implemented by libvirt driver.

NMI (Non-maskable Interruption) is used to trigger a special function such as
the kernel crash dump mechanism.

DocImpact

Change-Id: Iaf63352139c466430d3304a87a66398133541fac
Implements: blueprint inject-nmi
This commit is contained in:
Hironori Shiina 2015-07-16 13:35:04 +00:00 committed by Shiina, Hironori
parent 8a73c0430d
commit d0ee3ab01d
6 changed files with 36 additions and 0 deletions

View File

@ -751,6 +751,9 @@ class Domain(object):
def jobStats(self, flags=0):
return {}
def injectNMI(self, flags=0):
return 0
class DomainSnapshot(object):
def __init__(self, name, domain):

View File

@ -365,6 +365,11 @@ class _VirtDriverTestCase(_FakeDriverBackendTestCase):
self.connection.power_off(instance_ref)
self.connection.power_on(self.ctxt, instance_ref, network_info, None)
@catch_notimplementederror
def test_inject_nmi(self):
instance_ref, network_info = self._get_running_instance()
self.connection.inject_nmi(instance_ref)
@catch_notimplementederror
def test_soft_delete(self):
instance_ref, network_info = self._get_running_instance(obj=True)

View File

@ -673,6 +673,13 @@ class ComputeDriver(object):
"""
raise NotImplementedError()
def inject_nmi(self, instance):
"""Inject an NMI to the specified instance.
:param instance: nova objects.instance.Instance
"""
raise NotImplementedError()
def soft_delete(self, instance):
"""Soft delete the specified instance.

View File

@ -243,6 +243,9 @@ class FakeDriver(driver.ComputeDriver):
block_device_info=None):
pass
def inject_nmi(self, instance):
pass
def soft_delete(self, instance):
pass

View File

@ -2233,6 +2233,20 @@ 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):
"""Inject 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()
msg = (_('Error from libvirt while injecting an NMI to '
'%(instance_uuid)s: '
'[Error Code %(error_code)s] %(ex)s')
% {'instance_uuid': instance.uuid,
'error_code': error_code, 'ex': ex})
raise exception.NovaException(msg)
def suspend(self, context, instance):
"""Suspend the specified instance."""
guest = self._host.get_guest(instance)

View File

@ -114,6 +114,10 @@ class Guest(object):
"""Stops a running guest."""
self._domain.destroy()
def inject_nmi(self):
"""Injects an NMI to a guest."""
self._domain.injectNMI()
def resume(self):
"""Resumes a suspended guest."""
self._domain.resume()