Adjust ipminative._reboot to comply with pyghmi contract

In most of the cases, pyghmi will raise if the expected
powerstate is not applied. In some other cases, it will
return a dict containing a key "error".

Change-Id: I1d63401a58a7d1a6de92ab482ebbcb89bf752b63
Closes-Bug: 1531981
This commit is contained in:
Jonathan Provost 2016-01-07 17:13:06 -05:00
parent 4d7f766469
commit 0b927ffc02
2 changed files with 4 additions and 5 deletions

View File

@ -221,14 +221,13 @@ def _reboot(driver_info):
LOG.error(error) LOG.error(error)
raise exception.IPMIFailure(error) raise exception.IPMIFailure(error)
state = ret.get('powerstate') if 'error' in ret:
if state == 'on':
return states.POWER_ON
else:
error = _("bad response: %s") % ret error = _("bad response: %s") % ret
LOG.error(msg, {'node_id': driver_info['uuid'], 'error': error}) LOG.error(msg, {'node_id': driver_info['uuid'], 'error': error})
raise exception.PowerStateFailure(pstate=states.REBOOT) raise exception.PowerStateFailure(pstate=states.REBOOT)
return states.POWER_ON
def _power_status(driver_info): def _power_status(driver_info):
"""Get the power status for this node. """Get the power status for this node.

View File

@ -400,7 +400,7 @@ class IPMINativeDriverTestCase(db_base.DbTestCase):
@mock.patch('pyghmi.ipmi.command.Command', autospec=True) @mock.patch('pyghmi.ipmi.command.Command', autospec=True)
def test_reboot_fail(self, ipmi_mock): def test_reboot_fail(self, ipmi_mock):
ipmicmd = ipmi_mock.return_value ipmicmd = ipmi_mock.return_value
ipmicmd.set_power.return_value = {'powerstate': 'error'} ipmicmd.set_power.return_value = {'error': 'Some IPMI error'}
self.config(retry_timeout=500, group='ipmi') self.config(retry_timeout=500, group='ipmi')
with task_manager.acquire(self.context, with task_manager.acquire(self.context,