Adds power diag support to vbmc

Also enhance vbmc to support power diag, i.e.
- Pulse a diagnostic interrupt (NMI) directly to
  the processor(s)

Change-Id: I7b1998d36fbcbbab3870085dd5a476f77853b3e4
This commit is contained in:
xiexs
2016-07-26 09:15:02 -04:00
committed by Lucas Alvares Gomes
parent dceecaf7c0
commit a2106ef58b
2 changed files with 38 additions and 0 deletions

View File

@@ -128,6 +128,30 @@ class VirtualBMCTestCase(base.TestCase):
self._assert_libvirt_calls(mock_libvirt_domain, mock_libvirt_open,
readonly=True)
def test_pulse_diag_is_on(self, mock_libvirt_domain, mock_libvirt_open):
domain = mock_libvirt_domain.return_value
domain.isActive.return_value = True
self.vbmc.pulse_diag()
domain.injectNMI.assert_called_once_with()
self._assert_libvirt_calls(mock_libvirt_domain, mock_libvirt_open)
def test_pulse_diag_is_off(self, mock_libvirt_domain, mock_libvirt_open):
domain = mock_libvirt_domain.return_value
domain.isActive.return_value = False
self.vbmc.pulse_diag()
# power is already off, assert injectNMI() wasn't invoked
domain.injectNMI.assert_not_called()
self._assert_libvirt_calls(mock_libvirt_domain, mock_libvirt_open)
def test_pulse_diag_error(self, mock_libvirt_domain, mock_libvirt_open):
mock_libvirt_domain.side_effect = libvirt.libvirtError('boom')
ret = self.vbmc.pulse_diag()
self.assertEqual(0xd5, ret)
mock_libvirt_domain.return_value.injectNMI.assert_not_called()
self._assert_libvirt_calls(mock_libvirt_domain, mock_libvirt_open)
def test_power_off_is_on(self, mock_libvirt_domain, mock_libvirt_open):
domain = mock_libvirt_domain.return_value
domain.isActive.return_value = True

View File

@@ -107,6 +107,20 @@ class VirtualBMC(bmc.Bmc):
return POWEROFF
def pulse_diag(self):
LOG.debug('Power diag called for domain %s', self.domain_name)
try:
with utils.libvirt_open(**self._conn_args) as conn:
domain = utils.get_libvirt_domain(conn, self.domain_name)
if domain.isActive():
domain.injectNMI()
except libvirt.libvirtError as e:
LOG.error('Error powering diag the domain %(domain)s. '
'Error: %(error)s' % {'domain': self.domain_name,
'error': e})
# Command not supported in present state
return 0xd5
def power_off(self):
LOG.debug('Power off called for domain %s', self.domain_name)
try: