Merge "Soft power operations for OneView hardware type"

This commit is contained in:
Zuul 2018-01-31 19:54:28 +00:00 committed by Gerrit Code Review
commit b8af1cd853
3 changed files with 48 additions and 3 deletions

View File

@ -36,7 +36,7 @@ POWER_ON = {'powerState': 'On'}
POWER_OFF = {'powerState': 'Off', 'powerControl': 'PressAndHold'}
REBOOT = {'powerState': 'On', 'powerControl': 'ColdBoot'}
SOFT_REBOOT = {'powerState': 'On', 'powerControl': 'Reset'}
SOFT_POWER_OFF = {'powerState': 'Off', 'powerControl': 'PressAndHold'}
SOFT_POWER_OFF = {'powerState': 'Off', 'powerControl': 'MomentaryPress'}
GET_POWER_STATE_MAP = {
'On': states.POWER_ON,
@ -162,9 +162,14 @@ class OneViewPower(base.PowerInterface):
oneview_client.server_hardware.update_power_state(
SET_POWER_STATE_MAP.get(power_state),
server_hardware, timeout=timeout)
elif power_state == states.REBOOT:
elif (power_state == states.REBOOT or
power_state == states.SOFT_REBOOT):
power_off_mode = (states.POWER_OFF
if power_state == states.REBOOT
else states.SOFT_POWER_OFF)
oneview_client.server_hardware.update_power_state(
SET_POWER_STATE_MAP.get(states.POWER_OFF),
SET_POWER_STATE_MAP.get(power_off_mode),
server_hardware, timeout=timeout)
management.set_boot_device(task)
oneview_client.server_hardware.update_power_state(
@ -198,3 +203,15 @@ class OneViewPower(base.PowerInterface):
self.set_power_state(task, states.REBOOT, timeout=timeout)
else:
self.set_power_state(task, states.POWER_ON, timeout=timeout)
@METRICS.timer('OneViewPower.get_supported_power_states')
def get_supported_power_states(self, task):
"""Get a list of the supported power states.
:param task: A TaskManager instance containing the node to act on.
Currently not used.
:returns: A list with the supported power states defined
in :mod:`ironic.common.states`.
"""
return [states.POWER_ON, states.POWER_OFF, states.REBOOT,
states.SOFT_REBOOT, states.SOFT_POWER_OFF]

View File

@ -174,6 +174,21 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase):
update = client.server_hardware.update_power_state
update.assert_has_calls(calls)
@mock.patch.object(common, 'get_hponeview_client')
@mock.patch.object(management, 'set_boot_device')
def test_set_power_soft_reboot(
self, mock_set_boot_device, mock_get_ov_client):
client = mock_get_ov_client()
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.set_power_state(task, states.SOFT_REBOOT)
calls = [mock.call(power.SOFT_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.patch.object(common, 'get_hponeview_client')
@mock.patch.object(management, 'set_boot_device')
def test_set_power_on_fail(self, mock_set_boot_device, mock_get_ov_client):
@ -291,3 +306,11 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase):
update.assert_called_once_with(power.POWER_ON, server_hardware,
timeout=2)
mock_set_boot_device.assert_called_once_with(task)
def test_get_supported_power_states(self):
with task_manager.acquire(self.context, self.node.uuid,
shared=True) as task:
supported_power_states = (
task.driver.power.get_supported_power_states(task))
self.assertEqual(set(power.SET_POWER_STATE_MAP),
set(supported_power_states))

View File

@ -0,0 +1,5 @@
---
features:
- |
Enables support for soft power off and soft
reboot in the ``oneview`` hardware type.