diff --git a/releasenotes/notes/add-drive-led-97b687013fec88c9.yaml b/releasenotes/notes/add-drive-led-97b687013fec88c9.yaml new file mode 100644 index 00000000..af31939f --- /dev/null +++ b/releasenotes/notes/add-drive-led-97b687013fec88c9.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Adds the ``IndicatorLED`` property to the ``Drive`` resource. The state of + the LED can be read and can be changed via the ``.set_indicator_led()`` + method of the ``Drive`` sushy class. diff --git a/sushy/resources/system/storage/drive.py b/sushy/resources/system/storage/drive.py index e45ca9e5..ca418ff6 100644 --- a/sushy/resources/system/storage/drive.py +++ b/sushy/resources/system/storage/drive.py @@ -15,7 +15,9 @@ import logging +from sushy import exceptions from sushy.resources import base +from sushy.resources import mappings as res_maps from sushy import utils LOG = logging.getLogger(__name__) @@ -27,8 +29,32 @@ class Drive(base.ResourceBase): identity = base.Field('Id', required=True) """The Drive identity string""" + indicator_led = base.MappedField('IndicatorLED', + res_maps.INDICATOR_LED_VALUE_MAP) + """Whether the indicator LED is lit or off""" + name = base.Field('Name') """The name of the resource""" capacity_bytes = base.Field('CapacityBytes', adapter=utils.int_or_none) """The size in bytes of this Drive""" + + 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() diff --git a/sushy/tests/unit/resources/system/storage/test_drive.py b/sushy/tests/unit/resources/system/storage/test_drive.py index 8d3edb0e..65d6e1b3 100644 --- a/sushy/tests/unit/resources/system/storage/test_drive.py +++ b/sushy/tests/unit/resources/system/storage/test_drive.py @@ -14,6 +14,8 @@ import json import mock +import sushy +from sushy import exceptions from sushy.resources.system.storage import drive from sushy.tests.unit import base @@ -37,3 +39,19 @@ class DriveTestCase(base.TestCase): self.assertEqual('32ADF365C6C1B7BD', self.stor_drive.identity) self.assertEqual('Drive Sample', self.stor_drive.name) self.assertEqual(899527000000, self.stor_drive.capacity_bytes) + + def test_set_indicator_led(self): + with mock.patch.object( + self.stor_drive, 'invalidate', + autospec=True) as invalidate_mock: + self.stor_drive.set_indicator_led(sushy.INDICATOR_LED_BLINKING) + self.stor_drive._conn.patch.assert_called_once_with( + '/redfish/v1/Systems/437XR1138/Storage/1/Drives/' + '32ADF365C6C1B7BD', data={'IndicatorLED': 'Blinking'}) + + invalidate_mock.assert_called_once_with() + + def test_set_indicator_led_invalid_state(self): + self.assertRaises(exceptions.InvalidParameterValueError, + self.stor_drive.set_indicator_led, + 'spooky-glowing')