Merge "Support power reset command"

This commit is contained in:
Zuul 2018-01-19 20:25:44 +00:00 committed by Gerrit Code Review
commit e3800fcca8
3 changed files with 40 additions and 2 deletions

View File

@ -16,8 +16,8 @@ Supported IPMI commands
.. code-block:: bash
# Power the virtual machine on, off, graceful off and NMI
ipmitool -I lanplus -U admin -P password -H 127.0.0.1 power on|off|soft|diag
# Power the virtual machine on, off, graceful off, NMI and reset
ipmitool -I lanplus -U admin -P password -H 127.0.0.1 power on|off|soft|diag|reset
# Check the power status
ipmitool -I lanplus -U admin -P password -H 127.0.0.1 power status

View File

@ -176,6 +176,30 @@ class VirtualBMCTestCase(base.TestCase):
mock_libvirt_domain.return_value.destroy.assert_not_called()
self._assert_libvirt_calls(mock_libvirt_domain, mock_libvirt_open)
def test_power_reset_is_on(self, mock_libvirt_domain, mock_libvirt_open):
domain = mock_libvirt_domain.return_value
domain.isActive.return_value = True
self.vbmc.power_reset()
domain.reset.assert_called_once_with()
self._assert_libvirt_calls(mock_libvirt_domain, mock_libvirt_open)
def test_power_reset_is_off(self, mock_libvirt_domain, mock_libvirt_open):
domain = mock_libvirt_domain.return_value
domain.isActive.return_value = False
self.vbmc.power_reset()
# power is already off, assert reset() wasn't invoked
domain.reset.assert_not_called()
self._assert_libvirt_calls(mock_libvirt_domain, mock_libvirt_open)
def test_power_reset_error(self, mock_libvirt_domain, mock_libvirt_open):
mock_libvirt_domain.side_effect = libvirt.libvirtError('boom')
ret = self.vbmc.power_reset()
self.assertEqual(0xd5, ret)
mock_libvirt_domain.return_value.reset.assert_not_called()
self._assert_libvirt_calls(mock_libvirt_domain, mock_libvirt_open)
def test_power_shutdown_is_on(self, mock_libvirt_domain,
mock_libvirt_open):
domain = mock_libvirt_domain.return_value

View File

@ -162,3 +162,17 @@ class VirtualBMC(bmc.Bmc):
'error': e})
# Command not supported in present state
return 0xd5
def power_reset(self):
LOG.debug('Power reset 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.reset()
except libvirt.libvirtError as e:
LOG.error('Error reseting the domain %(domain)s. '
'Error: %(error)s' % {'domain': self.domain_name,
'error': e})
# Command not supported in present state
return 0xd5