Add settable `IndicatorLED` property to the `Drive` resource
Adds ``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`` class. Change-Id: Ief81d5315dee9a98d69223ca01de11ef757a348c Story: 2005342 Task: 30290
This commit is contained in:
parent
c8a63542cf
commit
4ad580bbc8
|
@ -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.
|
|
@ -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()
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue