From d34ece37cd34911d3a55a351de9833ef6f263471 Mon Sep 17 00:00:00 2001 From: Lin Yang Date: Tue, 11 Jun 2019 16:02:20 -0700 Subject: [PATCH] Change "ProvidingPools" to list in Volume Capacity Change-Id: I4c89ef8cf78b8269bb1658e7b8c054e9b6e10d63 --- .../v2_4/storage_service/capacity.py | 40 ++++++++++++------- .../json_samples/v2_4/capacity_sources.json | 24 ++++++----- .../v2_4/storage_service/test_capacity.py | 39 +++++++++++++----- 3 files changed, 70 insertions(+), 33 deletions(-) diff --git a/rsd_lib/resources/v2_4/storage_service/capacity.py b/rsd_lib/resources/v2_4/storage_service/capacity.py index 5a9de67..d6d7717 100644 --- a/rsd_lib/resources/v2_4/storage_service/capacity.py +++ b/rsd_lib/resources/v2_4/storage_service/capacity.py @@ -97,11 +97,15 @@ class CapacitySource(rsd_lib_base.ResourceBase): refresh, this property is reset. """ from rsd_lib.resources.v2_4.storage_service import volume - return volume.VolumeCollection( - self._conn, - utils.get_sub_resource_path_by(self, "ProvidingVolumes"), - redfish_version=self.redfish_version, - ) + + return [ + volume.VolumeCollection( + self._conn, path, redfish_version=self.redfish_version + ) + for path in utils.get_sub_resource_path_by( + self, "ProvidingVolumes", is_collection=True + ) + ] @property @utils.cache_it @@ -111,11 +115,14 @@ class CapacitySource(rsd_lib_base.ResourceBase): It is calculated once when it is queried for the first time. On refresh, this property is reset. """ - return storage_pool.StoragePoolCollection( - self._conn, - utils.get_sub_resource_path_by(self, "ProvidingPools"), - redfish_version=self.redfish_version, - ) + return [ + storage_pool.StoragePoolCollection( + self._conn, path, redfish_version=self.redfish_version + ) + for path in utils.get_sub_resource_path_by( + self, "ProvidingPools", is_collection=True + ) + ] @property @utils.cache_it @@ -125,8 +132,11 @@ class CapacitySource(rsd_lib_base.ResourceBase): It is calculated once when it is queried for the first time. On refresh, this property is reset. """ - return drive.DriveCollection( - self._conn, - utils.get_sub_resource_path_by(self, "ProvidingDrives"), - redfish_version=self.redfish_version, - ) + return [ + drive.DriveCollection( + self._conn, path, redfish_version=self.redfish_version + ) + for path in utils.get_sub_resource_path_by( + self, "ProvidingDrives", is_collection=True + ) + ] diff --git a/rsd_lib/tests/unit/json_samples/v2_4/capacity_sources.json b/rsd_lib/tests/unit/json_samples/v2_4/capacity_sources.json index 6acc7bf..3d96ea4 100644 --- a/rsd_lib/tests/unit/json_samples/v2_4/capacity_sources.json +++ b/rsd_lib/tests/unit/json_samples/v2_4/capacity_sources.json @@ -5,15 +5,21 @@ "Description": "Volume capacity source", "Id": "1", "Name": "CapacitySource", - "ProvidingPools": { - "@odata.id": "/redfish/v1/StorageServices/1/Volumes/1/CapacitySources/1/ProvidingPools" - }, - "ProvidingVolumes": { - "@odata.id": "/redfish/v1/StorageServices/1/Volumes/1/CapacitySources/1/ProvidingVolumes" - }, - "ProvidingDrives": { - "@odata.id": "/redfish/v1/StorageServices/1/Volumes/1/CapacitySources/1/ProvidingDrives" - }, + "ProvidingPools": [ + { + "@odata.id": "/redfish/v1/StorageServices/1/Volumes/1/CapacitySources/1/ProvidingPools" + } + ], + "ProvidingVolumes": [ + { + "@odata.id": "/redfish/v1/StorageServices/1/Volumes/1/CapacitySources/1/ProvidingVolumes" + } + ], + "ProvidingDrives": [ + { + "@odata.id": "/redfish/v1/StorageServices/1/Volumes/1/CapacitySources/1/ProvidingDrives" + } + ], "ProvidedCapacity": { "Data": { "AllocatedBytes": 3071983104 diff --git a/rsd_lib/tests/unit/resources/v2_4/storage_service/test_capacity.py b/rsd_lib/tests/unit/resources/v2_4/storage_service/test_capacity.py index 0d419d9..aac329f 100644 --- a/rsd_lib/tests/unit/resources/v2_4/storage_service/test_capacity.py +++ b/rsd_lib/tests/unit/resources/v2_4/storage_service/test_capacity.py @@ -61,8 +61,9 @@ class CapacitySourceTestCase(testtools.TestCase): # | WHEN | actual_providing_volumes = self.capacity_sources_inst.providing_volumes # | THEN | + self.assertIsInstance(actual_providing_volumes, list) self.assertIsInstance( - actual_providing_volumes, volume.VolumeCollection + actual_providing_volumes[0], volume.VolumeCollection ) self.conn.get.return_value.json.assert_called_once_with() @@ -84,7 +85,10 @@ class CapacitySourceTestCase(testtools.TestCase): self.conn.get.return_value.json.return_value = json.loads(f.read()) # | WHEN & THEN | self.assertIsInstance( - self.capacity_sources_inst.providing_volumes, + self.capacity_sources_inst.providing_volumes, list + ) + self.assertIsInstance( + self.capacity_sources_inst.providing_volumes[0], volume.VolumeCollection, ) @@ -104,7 +108,10 @@ class CapacitySourceTestCase(testtools.TestCase): self.conn.get.return_value.json.return_value = json.loads(f.read()) # | WHEN & THEN | self.assertIsInstance( - self.capacity_sources_inst.providing_volumes, + self.capacity_sources_inst.providing_volumes, list + ) + self.assertIsInstance( + self.capacity_sources_inst.providing_volumes[0], volume.VolumeCollection, ) @@ -120,8 +127,9 @@ class CapacitySourceTestCase(testtools.TestCase): # | WHEN | actual_providing_pools = self.capacity_sources_inst.providing_pools # | THEN | + self.assertIsInstance(actual_providing_pools, list) self.assertIsInstance( - actual_providing_pools, storage_pool.StoragePoolCollection + actual_providing_pools[0], storage_pool.StoragePoolCollection ) self.conn.get.return_value.json.assert_called_once_with() @@ -143,8 +151,9 @@ class CapacitySourceTestCase(testtools.TestCase): ) as f: self.conn.get.return_value.json.return_value = json.loads(f.read()) # | WHEN & THEN | + self.assertIsInstance(self.capacity_sources_inst.providing_pools, list) self.assertIsInstance( - self.capacity_sources_inst.providing_pools, + self.capacity_sources_inst.providing_pools[0], storage_pool.StoragePoolCollection, ) @@ -165,8 +174,9 @@ class CapacitySourceTestCase(testtools.TestCase): ) as f: self.conn.get.return_value.json.return_value = json.loads(f.read()) # | WHEN & THEN | + self.assertIsInstance(self.capacity_sources_inst.providing_pools, list) self.assertIsInstance( - self.capacity_sources_inst.providing_pools, + self.capacity_sources_inst.providing_pools[0], storage_pool.StoragePoolCollection, ) @@ -180,7 +190,10 @@ class CapacitySourceTestCase(testtools.TestCase): # | WHEN | actual_providing_drives = self.capacity_sources_inst.providing_drives # | THEN | - self.assertIsInstance(actual_providing_drives, drive.DriveCollection) + self.assertIsInstance(actual_providing_drives, list) + self.assertIsInstance( + actual_providing_drives[0], drive.DriveCollection + ) self.conn.get.return_value.json.assert_called_once_with() # reset mock @@ -201,7 +214,11 @@ class CapacitySourceTestCase(testtools.TestCase): self.conn.get.return_value.json.return_value = json.loads(f.read()) # | WHEN & THEN | self.assertIsInstance( - self.capacity_sources_inst.providing_drives, drive.DriveCollection + self.capacity_sources_inst.providing_drives, list + ) + self.assertIsInstance( + self.capacity_sources_inst.providing_drives[0], + drive.DriveCollection, ) # On refreshing the chassis instance... @@ -220,5 +237,9 @@ class CapacitySourceTestCase(testtools.TestCase): self.conn.get.return_value.json.return_value = json.loads(f.read()) # | WHEN & THEN | self.assertIsInstance( - self.capacity_sources_inst.providing_drives, drive.DriveCollection + self.capacity_sources_inst.providing_drives, list + ) + self.assertIsInstance( + self.capacity_sources_inst.providing_drives[0], + drive.DriveCollection, )