Merge "Add a timeout for powering on/off a node on HPE OneView Driver"

This commit is contained in:
Zuul 2017-10-24 13:20:50 +00:00 committed by Gerrit Code Review
commit 09fae1c98f
3 changed files with 33 additions and 16 deletions

View File

@ -128,12 +128,14 @@ class OneViewPower(base.PowerInterface):
@METRICS.timer('OneViewPower.set_power_state')
@task_manager.require_exclusive_lock
def set_power_state(self, task, power_state):
def set_power_state(self, task, power_state, timeout=None):
"""Set the power state of the task's node.
:param task: a TaskManager instance.
:param power_state: The desired power state POWER_ON, POWER_OFF or
REBOOT from :mod:`ironic.common.states`.
:param timeout: timeout (in seconds) positive integer (> 0) for any
power state. ``None`` indicates to use default timeout.
:raises: InvalidParameterValue if an invalid power state was specified.
:raises: PowerStateFailure if the power couldn't be set to power_state.
:raises: OneViewError if OneView fails setting the power state.
@ -155,36 +157,43 @@ class OneViewPower(base.PowerInterface):
{'node_uuid': task.node.uuid, 'power_state': power_state})
server_hardware = task.node.driver_info.get('server_hardware_uri')
timeout = (-1 if timeout is None else timeout)
try:
if power_state == states.POWER_ON:
management.set_boot_device(task)
self.client.server_hardware.update_power_state(
SET_POWER_STATE_MAP.get(power_state), server_hardware)
SET_POWER_STATE_MAP.get(power_state),
server_hardware, timeout=timeout)
elif power_state == states.REBOOT:
self.client.server_hardware.update_power_state(
SET_POWER_STATE_MAP.get(states.POWER_OFF), server_hardware)
SET_POWER_STATE_MAP.get(states.POWER_OFF), server_hardware,
timeout=timeout)
management.set_boot_device(task)
self.client.server_hardware.update_power_state(
SET_POWER_STATE_MAP.get(states.POWER_ON), server_hardware)
SET_POWER_STATE_MAP.get(states.POWER_ON), server_hardware,
timeout=timeout)
else:
self.client.server_hardware.update_power_state(
SET_POWER_STATE_MAP.get(power_state), server_hardware)
SET_POWER_STATE_MAP.get(power_state), server_hardware,
timeout=timeout)
except client_exception.HPOneViewException as exc:
raise exception.OneViewError(
_("Error setting power state: %s") % exc)
@METRICS.timer('OneViewPower.reboot')
@task_manager.require_exclusive_lock
def reboot(self, task):
def reboot(self, task, timeout=None):
"""Reboot the node.
:param task: a TaskManager instance.
:param timeout: timeout (in seconds) positive integer (> 0) for any
power state. ``None`` indicates to use default timeout.
:raises: PowerStateFailure if the final state of the node is not
POWER_ON.
"""
current_power_state = self.get_power_state(task)
if current_power_state == states.POWER_ON:
self.set_power_state(task, states.REBOOT)
self.set_power_state(task, states.REBOOT, timeout=timeout)
else:
self.set_power_state(task, states.POWER_ON)
self.set_power_state(task, states.POWER_ON, timeout=timeout)

View File

@ -121,7 +121,8 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase):
self.driver.power.set_power_state(task, states.POWER_ON)
self.assertTrue(mock_set_boot_device.called)
update = client.server_hardware.update_power_state
update.assert_called_once_with(power.POWER_ON, server_hardware)
update.assert_called_once_with(power.POWER_ON, server_hardware,
timeout=-1)
@mock.patch.object(management, 'set_boot_device')
def test_set_power_off(self, mock_set_boot_device, mock_get_ov_client):
@ -132,7 +133,8 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase):
self.driver.power.set_power_state(task, states.POWER_OFF)
self.assertFalse(mock_set_boot_device.called)
update = client.server_hardware.update_power_state
update.assert_called_once_with(power.POWER_OFF, server_hardware)
update.assert_called_once_with(power.POWER_OFF, server_hardware,
timeout=-1)
@mock.patch.object(management, 'set_boot_device')
def test_set_power_reboot(self, mock_set_boot_device, mock_get_ov_client):
@ -141,8 +143,8 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase):
server_hardware = self.node.driver_info.get('server_hardware_uri')
with task_manager.acquire(self.context, self.node.uuid) as task:
self.driver.power.set_power_state(task, states.REBOOT)
calls = [mock.call(power.POWER_OFF, server_hardware),
mock.call(power.POWER_ON, server_hardware)]
calls = [mock.call(power.POWER_OFF, server_hardware, timeout=-1),
mock.call(power.POWER_ON, server_hardware, timeout=-1)]
update = client.server_hardware.update_power_state
update.assert_has_calls(calls)
@ -230,8 +232,8 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase):
server_hardware = self.node.driver_info.get('server_hardware_uri')
with task_manager.acquire(self.context, self.node.uuid) as task:
self.driver.power.reboot(task)
calls = [mock.call(power.POWER_OFF, server_hardware),
mock.call(power.POWER_ON, server_hardware)]
calls = [mock.call(power.POWER_OFF, server_hardware, timeout=-1),
mock.call(power.POWER_ON, server_hardware, timeout=-1)]
update = client.server_hardware.update_power_state
update.assert_has_calls(calls)
mock_set_boot_device.assert_called_once_with(task)
@ -245,7 +247,8 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase):
self.driver.power.client = client
server_hardware = self.node.driver_info.get('server_hardware_uri')
with task_manager.acquire(self.context, self.node.uuid) as task:
self.driver.power.reboot(task)
self.driver.power.reboot(task, timeout=-1)
update = client.server_hardware.update_power_state
update.assert_called_once_with(power.POWER_ON, server_hardware)
update.assert_called_once_with(power.POWER_ON, server_hardware,
timeout=-1)
mock_set_boot_device.assert_called_once_with(task)

View File

@ -0,0 +1,5 @@
---
features:
- |
Adds support for 'timeout' parameter when powering on/off an Ironic node
that is being managed using 'oneview' hardware type.