Add Drive.volumes

Change-Id: Ic836e8e99ea66199b48d9d40eb56e102bdbd498d
This commit is contained in:
Aija Jauntēva
2021-07-06 05:23:15 -04:00
parent 5b38ec591e
commit 0eaacad87f
3 changed files with 46 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
---
features:
- |
Adds ``Drive.volumes`` property for list of volumes that drive is part of.

View File

@@ -19,6 +19,7 @@ from sushy import exceptions
from sushy.resources import base
from sushy.resources import common
from sushy.resources import mappings as res_maps
from sushy.resources.system.storage import volume
from sushy import utils
LOG = logging.getLogger(__name__)
@@ -67,6 +68,24 @@ class Drive(base.ResourceBase):
status = common.StatusField('Status')
"""This type describes the status and health of the drive"""
@property
@utils.cache_it
def volumes(self):
"""A list of volumes that this drive is part of.
Volumes that this drive either wholly or only partially contains.
:raises: MissingAttributeError if '@odata.id' field is missing.
:returns: A list of `Volume` instances
"""
paths = utils.get_sub_resource_path_by(
self, ["Links", "Volumes"], is_collection=True)
return [volume.Volume(self._conn, path,
redfish_version=self.redfish_version,
registries=self.registries)
for path in paths]
def set_indicator_led(self, state):
"""Set IndicatorLED to the given state.

View File

@@ -58,6 +58,29 @@ class DriveTestCase(base.TestCase):
self.assertEqual(sushy.STATE_ENABLED, self.stor_drive.status.state)
self.assertEqual(sushy.HEALTH_OK, self.stor_drive.status.health)
def test_volumes(self):
with open('sushy/tests/unit/json_samples/drive3.json') as f:
drive_json = json.load(f)
with open('sushy/tests/unit/json_samples/volume2.json') as f:
volume2_json = json.load(f)
with open('sushy/tests/unit/json_samples/volume3.json') as f:
volume3_json = json.load(f)
self.conn.get.return_value.json.side_effect = [drive_json,
volume2_json,
volume3_json]
stor_drive = drive.Drive(
self.conn,
'/redfish/v1/Systems/437XR1138R2/Storage/1/Drives/'
'3D58ECBC375FD9F2',
redfish_version='1.0.2')
volumes = stor_drive.volumes
self.assertEqual(2, len(volumes))
self.assertEqual('2', volumes[0].identity)
self.assertEqual('3', volumes[1].identity)
def test_set_indicator_led(self):
with mock.patch.object(
self.stor_drive, 'invalidate',