Fix logging and exceptions messages in ipminative driver

1) Log level changed to "error" when exception is raised.
2) Full error message passed to IPMIFailure exception.
3) Target power state passed to PowerStateFailure instead of
returned state.

Change-Id: I62a78cfc330054180a8d92693e04609150c4b97b
This commit is contained in:
Yuriy Zveryanskyy 2015-08-26 12:47:25 +03:00
parent 8cd56e3e1e
commit e946ef026b

View File

@ -134,7 +134,7 @@ def _power_on(driver_info):
from ipmi.
"""
msg = _LW("IPMI power on failed for node %(node_id)s with the "
msg = _("IPMI power on failed for node %(node_id)s with the "
"following error: %(error)s")
try:
ipmicmd = ipmi_command.Command(bmc=driver_info['address'],
@ -143,15 +143,17 @@ def _power_on(driver_info):
wait = CONF.ipmi.retry_timeout
ret = ipmicmd.set_power('on', wait)
except pyghmi_exception.IpmiException as e:
LOG.warning(msg, {'node_id': driver_info['uuid'], 'error': str(e)})
raise exception.IPMIFailure(cmd=str(e))
error = msg % {'node_id': driver_info['uuid'], 'error': e}
LOG.error(error)
raise exception.IPMIFailure(error)
state = ret.get('powerstate')
if state == 'on':
return states.POWER_ON
else:
LOG.warning(msg, {'node_id': driver_info['uuid'], 'error': ret})
raise exception.PowerStateFailure(pstate=state)
error = _("bad response: %s") % ret
LOG.error(msg, {'node_id': driver_info['uuid'], 'error': error})
raise exception.PowerStateFailure(pstate=states.POWER_ON)
def _power_off(driver_info):
@ -164,7 +166,7 @@ def _power_off(driver_info):
from ipmi.
"""
msg = _LW("IPMI power off failed for node %(node_id)s with the "
msg = _("IPMI power off failed for node %(node_id)s with the "
"following error: %(error)s")
try:
ipmicmd = ipmi_command.Command(bmc=driver_info['address'],
@ -173,15 +175,17 @@ def _power_off(driver_info):
wait = CONF.ipmi.retry_timeout
ret = ipmicmd.set_power('off', wait)
except pyghmi_exception.IpmiException as e:
LOG.warning(msg, {'node_id': driver_info['uuid'], 'error': str(e)})
raise exception.IPMIFailure(cmd=str(e))
error = msg % {'node_id': driver_info['uuid'], 'error': e}
LOG.error(error)
raise exception.IPMIFailure(error)
state = ret.get('powerstate')
if state == 'off':
return states.POWER_OFF
else:
LOG.warning(msg % {'node_id': driver_info['uuid'], 'error': ret})
raise exception.PowerStateFailure(pstate=state)
error = _("bad response: %s") % ret
LOG.error(msg, {'node_id': driver_info['uuid'], 'error': error})
raise exception.PowerStateFailure(pstate=states.POWER_OFF)
def _reboot(driver_info):
@ -196,7 +200,7 @@ def _reboot(driver_info):
from ipmi.
"""
msg = _LW("IPMI power reboot failed for node %(node_id)s with the "
msg = _("IPMI power reboot failed for node %(node_id)s with the "
"following error: %(error)s")
try:
ipmicmd = ipmi_command.Command(bmc=driver_info['address'],
@ -205,15 +209,17 @@ def _reboot(driver_info):
wait = CONF.ipmi.retry_timeout
ret = ipmicmd.set_power('boot', wait)
except pyghmi_exception.IpmiException as e:
LOG.warning(msg % {'node_id': driver_info['uuid'], 'error': str(e)})
raise exception.IPMIFailure(cmd=str(e))
error = msg % {'node_id': driver_info['uuid'], 'error': e}
LOG.error(error)
raise exception.IPMIFailure(error)
state = ret.get('powerstate')
if state == 'on':
return states.POWER_ON
else:
LOG.warning(msg % {'node_id': driver_info['uuid'], 'error': ret})
raise exception.PowerStateFailure(pstate=state)
error = _("bad response: %s") % ret
LOG.error(msg, {'node_id': driver_info['uuid'], 'error': error})
raise exception.PowerStateFailure(pstate=states.REBOOT)
def _power_status(driver_info):
@ -231,10 +237,11 @@ def _power_status(driver_info):
password=driver_info['password'])
ret = ipmicmd.get_power()
except pyghmi_exception.IpmiException as e:
LOG.warning(_LW("IPMI get power state failed for node %(node_id)s "
"with the following error: %(error)s"),
{'node_id': driver_info['uuid'], 'error': str(e)})
raise exception.IPMIFailure(cmd=str(e))
msg = (_("IPMI get power state failed for node %(node_id)s "
"with the following error: %(error)s") %
{'node_id': driver_info['uuid'], 'error': e})
LOG.error(msg)
raise exception.IPMIFailure(msg)
state = ret.get('powerstate')
if state == 'on':