Add settable `IndicatorLED` of `System` and `Chassis`

The ``IndicatorLED`` property of ``System`` and ``Chassis`` resources
made settable with the introduction of the ``.set_indicator_led()``
method to the respective sushy classes.

Change-Id: Ie4e0d3ad20f051fa0fc1d679f020d174de71bca0
Story: 2005342
Task: 30290
This commit is contained in:
Ilya Etingof 2019-04-02 19:54:16 +02:00
parent 7180a45763
commit c8a63542cf
6 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,6 @@
---
features:
- |
The ``IndicatorLED`` property of ``System`` and ``Chassis`` resources
made settable with the introduction of the ``.set_indicator_led()``
method to the respective sushy classes.

View File

@ -196,6 +196,26 @@ class Chassis(base.ResourceBase):
self._conn.post(target_uri, data={'ResetType': value})
LOG.info('The Chassis %s is being reset', self.identity)
def set_indicator_led(self, state):
"""Set IndicatorLED to the given state.
:param state: Desired LED state, lit (INDICATOR_LED_LIT), blinking
(INDICATOR_LED_BLINKING), off (INDICATOR_LED_OFF)
:raises: InvalidParameterValueError, if any information passed is
invalid.
"""
if state not in res_maps.INDICATOR_LED_VALUE_MAP_REV:
raise exceptions.InvalidParameterValueError(
parameter='state', value=state,
valid_values=list(res_maps.INDICATOR_LED_VALUE_MAP_REV))
data = {
'IndicatorLED': res_maps.INDICATOR_LED_VALUE_MAP_REV[state]
}
self._conn.patch(self.path, data=data)
self.invalidate()
@property
@utils.cache_it
def managers(self):

View File

@ -53,6 +53,8 @@ INDICATOR_LED_VALUE_MAP = {
'Unknown': res_cons.INDICATOR_LED_UNKNOWN,
}
INDICATOR_LED_VALUE_MAP_REV = utils.revert_dictionary(INDICATOR_LED_VALUE_MAP)
POWER_STATE_VALUE_MAP = {
'On': res_cons.POWER_STATE_ON,
'Off': res_cons.POWER_STATE_OFF,

View File

@ -246,6 +246,26 @@ class System(base.ResourceBase):
# Probably we should call refresh() as well.
self._conn.patch(self.path, data=data)
def set_indicator_led(self, state):
"""Set IndicatorLED to the given state.
:param state: Desired LED state, lit (INDICATOR_LED_LIT), blinking
(INDICATOR_LED_BLINKING), off (INDICATOR_LED_OFF)
:raises: InvalidParameterValueError, if any information passed is
invalid.
"""
if state not in res_maps.INDICATOR_LED_VALUE_MAP_REV:
raise exceptions.InvalidParameterValueError(
parameter='state', value=state,
valid_values=list(res_maps.INDICATOR_LED_VALUE_MAP_REV))
data = {
'IndicatorLED': res_maps.INDICATOR_LED_VALUE_MAP_REV[state]
}
self._conn.patch(self.path, data=data)
self.invalidate()
def _get_processor_collection_path(self):
"""Helper function to find the ProcessorCollection path"""
return utils.get_sub_resource_path_by(self, 'Processors')

View File

@ -120,6 +120,21 @@ class ChassisTestCase(base.TestCase):
self.assertRaises(exceptions.InvalidParameterValueError,
self.chassis.reset_chassis, 'invalid-value')
def test_set_indicator_led(self):
with mock.patch.object(
self.chassis, 'invalidate', autospec=True) as invalidate_mock:
self.chassis.set_indicator_led(sushy.INDICATOR_LED_BLINKING)
self.chassis._conn.patch.assert_called_once_with(
'/redfish/v1/Chassis/Blade1',
data={'IndicatorLED': 'Blinking'})
invalidate_mock.assert_called_once_with()
def test_set_indicator_led_invalid_state(self):
self.assertRaises(exceptions.InvalidParameterValueError,
self.chassis.set_indicator_led,
'spooky-glowing')
def test_managers(self):
# | GIVEN |
with open('sushy/tests/unit/json_samples/'

View File

@ -233,6 +233,21 @@ class SystemTestCase(base.TestCase):
sushy.BOOT_SOURCE_TARGET_HDD,
enabled='invalid-enabled')
def test_set_indicator_led(self):
with mock.patch.object(
self.sys_inst, 'invalidate', autospec=True) as invalidate_mock:
self.sys_inst.set_indicator_led(sushy.INDICATOR_LED_BLINKING)
self.sys_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Systems/437XR1138R2',
data={'IndicatorLED': 'Blinking'})
invalidate_mock.assert_called_once_with()
def test_set_indicator_led_invalid_state(self):
self.assertRaises(exceptions.InvalidParameterValueError,
self.sys_inst.set_indicator_led,
'spooky-glowing')
def test__get_processor_collection_path_missing_processors_attr(self):
self.sys_inst._json.pop('Processors')
self.assertRaisesRegex(