From 705bb7d4d2b41a7d8be5c9b6d2802cf9467a4964 Mon Sep 17 00:00:00 2001 From: Lin Yang Date: Wed, 11 Sep 2019 15:41:02 -0700 Subject: [PATCH] Add get_resource method in RSD 2.4 Change-Id: I9957fecd20b3b396bc0eeb8e2698679918668798 --- rsd_lib/resources/v2_1/__init__.py | 4 +- rsd_lib/resources/v2_2/__init__.py | 4 +- rsd_lib/resources/v2_3/__init__.py | 76 +++++++++++-------- rsd_lib/resources/v2_4/__init__.py | 66 +++++++++++----- .../{capacity.py => capacity_source.py} | 0 .../resources/v2_4/storage_service/volume.py | 4 +- rsd_lib/resources/v2_4/types.py | 47 ++++++++++++ ...st_capacity.py => test_capacity_source.py} | 4 +- .../v2_4/storage_service/test_volume.py | 10 ++- 9 files changed, 152 insertions(+), 63 deletions(-) rename rsd_lib/resources/v2_4/storage_service/{capacity.py => capacity_source.py} (100%) create mode 100644 rsd_lib/resources/v2_4/types.py rename rsd_lib/tests/unit/resources/v2_4/storage_service/{test_capacity.py => test_capacity_source.py} (98%) diff --git a/rsd_lib/resources/v2_1/__init__.py b/rsd_lib/resources/v2_1/__init__.py index 52d40cc..94d162e 100644 --- a/rsd_lib/resources/v2_1/__init__.py +++ b/rsd_lib/resources/v2_1/__init__.py @@ -310,8 +310,8 @@ class RSDLibV2_1(base.ResourceBase): :returns: corresponding resource or resource collection object """ resource_class = self._get_resource_class_from_path( - path, - RESOURCE_CLASS) + path, RESOURCE_CLASS + ) if not resource_class: raise rsd_lib_exceptions.NoMatchingResourceError(uri=path) return resource_class( diff --git a/rsd_lib/resources/v2_2/__init__.py b/rsd_lib/resources/v2_2/__init__.py index 910bdcd..8199d9d 100644 --- a/rsd_lib/resources/v2_2/__init__.py +++ b/rsd_lib/resources/v2_2/__init__.py @@ -183,8 +183,8 @@ class RSDLibV2_2(v2_1.RSDLibV2_1): :returns: corresponding resource or resource collection object """ resource_class = self._get_resource_class_from_path( - path, - RESOURCE_CLASS) + path, RESOURCE_CLASS + ) if not resource_class: raise rsd_lib_exceptions.NoMatchingResourceError(uri=path) return resource_class( diff --git a/rsd_lib/resources/v2_3/__init__.py b/rsd_lib/resources/v2_3/__init__.py index fe63b4d..b4836fe 100644 --- a/rsd_lib/resources/v2_3/__init__.py +++ b/rsd_lib/resources/v2_3/__init__.py @@ -30,10 +30,11 @@ from rsd_lib.resources.v2_3.types import RESOURCE_CLASS class RSDLibV2_3(v2_2.RSDLibV2_2): _ethernet_switches_path = base.Field( - ['Oem', 'Intel_RackScale', 'EthernetSwitches', '@odata.id']) + ["Oem", "Intel_RackScale", "EthernetSwitches", "@odata.id"] + ) """EthernetSwitchCollecton path""" - _storage_service_path = base.Field(['StorageServices', '@odata.id']) + _storage_service_path = base.Field(["StorageServices", "@odata.id"]) """StorageServiceCollection path""" def get_chassis_collection(self): @@ -65,8 +66,9 @@ class RSDLibV2_3(v2_2.RSDLibV2_2): :param identity: The identity of the System resource :returns: The System object """ - return system.System(self._conn, identity, - redfish_version=self.redfish_version) + return system.System( + self._conn, identity, redfish_version=self.redfish_version + ) def get_system_collection(self): """Get the SystemCollection object @@ -75,8 +77,11 @@ class RSDLibV2_3(v2_2.RSDLibV2_2): not found :returns: a SystemCollection object """ - return system.SystemCollection(self._conn, self._systems_path, - redfish_version=self.redfish_version) + return system.SystemCollection( + self._conn, + self._systems_path, + redfish_version=self.redfish_version, + ) def get_node_collection(self): """Get the NodeCollection object @@ -85,8 +90,9 @@ class RSDLibV2_3(v2_2.RSDLibV2_2): not found :returns: a NodeCollection object """ - return node.NodeCollection(self._conn, self._nodes_path, - redfish_version=self.redfish_version) + return node.NodeCollection( + self._conn, self._nodes_path, redfish_version=self.redfish_version + ) def get_node(self, identity): """Given the identity return a Node object @@ -94,8 +100,9 @@ class RSDLibV2_3(v2_2.RSDLibV2_2): :param identity: The identity of the Node resource :returns: The Node object """ - return node.Node(self._conn, identity, - redfish_version=self.redfish_version) + return node.Node( + self._conn, identity, redfish_version=self.redfish_version + ) def get_manager_collection(self): """Get the ManagerCollection object @@ -104,9 +111,11 @@ class RSDLibV2_3(v2_2.RSDLibV2_2): not found :returns: a ManagerCollection object """ - return manager.ManagerCollection(self._conn, - self._managers_path, - redfish_version=self.redfish_version) + return manager.ManagerCollection( + self._conn, + self._managers_path, + redfish_version=self.redfish_version, + ) def get_manager(self, identity): """Given the identity return a Manager object @@ -114,9 +123,9 @@ class RSDLibV2_3(v2_2.RSDLibV2_2): :param identity: The identity of the Manager resource :returns: The Manager object """ - return manager.Manager(self._conn, - identity, - redfish_version=self.redfish_version) + return manager.Manager( + self._conn, identity, redfish_version=self.redfish_version + ) def get_storage_service_collection(self): """Get the StorageServiceCollection object @@ -126,8 +135,10 @@ class RSDLibV2_3(v2_2.RSDLibV2_2): :returns: a StorageServiceCollection object """ return storage_service.StorageServiceCollection( - self._conn, self._storage_service_path, - redfish_version=self.redfish_version) + self._conn, + self._storage_service_path, + redfish_version=self.redfish_version, + ) def get_storage_service(self, identity): """Given the identity return a StorageService object @@ -136,8 +147,8 @@ class RSDLibV2_3(v2_2.RSDLibV2_2): :returns: The StorageService object """ return storage_service.StorageService( - self._conn, identity, - redfish_version=self.redfish_version) + self._conn, identity, redfish_version=self.redfish_version + ) def get_fabric_collection(self): """Get the FabricCollection object @@ -146,9 +157,11 @@ class RSDLibV2_3(v2_2.RSDLibV2_2): not found :returns: a FabricCollection object """ - return fabric.FabricCollection(self._conn, - self._fabrics_path, - redfish_version=self.redfish_version) + return fabric.FabricCollection( + self._conn, + self._fabrics_path, + redfish_version=self.redfish_version, + ) def get_fabric(self, identity): """Given the identity return a Fabric object @@ -156,9 +169,9 @@ class RSDLibV2_3(v2_2.RSDLibV2_2): :param identity: The identity of the Fabric resource :returns: The Fabric object """ - return fabric.Fabric(self._conn, - identity, - redfish_version=self.redfish_version) + return fabric.Fabric( + self._conn, identity, redfish_version=self.redfish_version + ) def get_ethernet_switch_collection(self): """Get the EthernetSwitchCollection object @@ -170,7 +183,7 @@ class RSDLibV2_3(v2_2.RSDLibV2_2): return ethernet_switch.EthernetSwitchCollection( self._conn, self._ethernet_switches_path, - redfish_version=self.redfish_version + redfish_version=self.redfish_version, ) def get_ethernet_switch(self, identity): @@ -180,9 +193,8 @@ class RSDLibV2_3(v2_2.RSDLibV2_2): :returns: The EthernetSwitch object """ return ethernet_switch.EthernetSwitch( - self._conn, - identity, - redfish_version=self.redfish_version) + self._conn, identity, redfish_version=self.redfish_version + ) def get_resource(self, path): """Return corresponding resource object from path @@ -191,8 +203,8 @@ class RSDLibV2_3(v2_2.RSDLibV2_2): :returns: corresponding resource or resource collection object """ resource_class = self._get_resource_class_from_path( - path, - RESOURCE_CLASS) + path, RESOURCE_CLASS + ) if not resource_class: raise rsd_lib_exceptions.NoMatchingResourceError(uri=path) return resource_class( diff --git a/rsd_lib/resources/v2_4/__init__.py b/rsd_lib/resources/v2_4/__init__.py index e9ab475..724345a 100644 --- a/rsd_lib/resources/v2_4/__init__.py +++ b/rsd_lib/resources/v2_4/__init__.py @@ -15,17 +15,20 @@ from sushy.resources import base +from rsd_lib import exceptions as rsd_lib_exceptions from rsd_lib.resources import v2_3 from rsd_lib.resources.v2_4.fabric import fabric from rsd_lib.resources.v2_4.node import node from rsd_lib.resources.v2_4.storage_service import storage_service from rsd_lib.resources.v2_4.system import system +from rsd_lib.resources.v2_4.types import RESOURCE_CLASS class RSDLibV2_4(v2_3.RSDLibV2_3): _telemetry_service_path = base.Field( - ['Oem', 'Intel_RackScale', 'TelemetryService', '@odata.id']) + ["Oem", "Intel_RackScale", "TelemetryService", "@odata.id"] + ) """EthernetSwitchCollecton path""" def get_system(self, identity): @@ -34,8 +37,9 @@ class RSDLibV2_4(v2_3.RSDLibV2_3): :param identity: The identity of the System resource :returns: The System object """ - return system.System(self._conn, identity, - redfish_version=self.redfish_version) + return system.System( + self._conn, identity, redfish_version=self.redfish_version + ) def get_system_collection(self): """Get the SystemCollection object @@ -44,8 +48,11 @@ class RSDLibV2_4(v2_3.RSDLibV2_3): not found :returns: a SystemCollection object """ - return system.SystemCollection(self._conn, self._systems_path, - redfish_version=self.redfish_version) + return system.SystemCollection( + self._conn, + self._systems_path, + redfish_version=self.redfish_version, + ) def get_storage_service_collection(self): """Get the StorageServiceCollection object @@ -55,8 +62,10 @@ class RSDLibV2_4(v2_3.RSDLibV2_3): :returns: a StorageServiceCollection object """ return storage_service.StorageServiceCollection( - self._conn, self._storage_service_path, - redfish_version=self.redfish_version) + self._conn, + self._storage_service_path, + redfish_version=self.redfish_version, + ) def get_storage_service(self, identity): """Given the identity return a StorageService object @@ -65,8 +74,8 @@ class RSDLibV2_4(v2_3.RSDLibV2_3): :returns: The StorageService object """ return storage_service.StorageService( - self._conn, identity, - redfish_version=self.redfish_version) + self._conn, identity, redfish_version=self.redfish_version + ) def get_node_collection(self): """Get the NodeCollection object @@ -75,8 +84,9 @@ class RSDLibV2_4(v2_3.RSDLibV2_3): not found :returns: a NodeCollection object """ - return node.NodeCollection(self._conn, self._nodes_path, - redfish_version=self.redfish_version) + return node.NodeCollection( + self._conn, self._nodes_path, redfish_version=self.redfish_version + ) def get_node(self, identity): """Given the identity return a Node object @@ -84,8 +94,9 @@ class RSDLibV2_4(v2_3.RSDLibV2_3): :param identity: The identity of the Node resource :returns: The Node object """ - return node.Node(self._conn, identity, - redfish_version=self.redfish_version) + return node.Node( + self._conn, identity, redfish_version=self.redfish_version + ) def get_fabric_collection(self): """Get the FabricCollection object @@ -94,9 +105,11 @@ class RSDLibV2_4(v2_3.RSDLibV2_3): not found :returns: a FabricCollection object """ - return fabric.FabricCollection(self._conn, - self._fabrics_path, - redfish_version=self.redfish_version) + return fabric.FabricCollection( + self._conn, + self._fabrics_path, + redfish_version=self.redfish_version, + ) def get_fabric(self, identity): """Given the identity return a Fabric object @@ -104,6 +117,21 @@ class RSDLibV2_4(v2_3.RSDLibV2_3): :param identity: The identity of the Fabric resource :returns: The Fabric object """ - return fabric.Fabric(self._conn, - identity, - redfish_version=self.redfish_version) + return fabric.Fabric( + self._conn, identity, redfish_version=self.redfish_version + ) + + def get_resource(self, path): + """Return corresponding resource object from path + + :param path: The path of a resource or resource collection + :returns: corresponding resource or resource collection object + """ + resource_class = self._get_resource_class_from_path( + path, RESOURCE_CLASS + ) + if not resource_class: + raise rsd_lib_exceptions.NoMatchingResourceError(uri=path) + return resource_class( + self._conn, path, redfish_version=self.redfish_version + ) diff --git a/rsd_lib/resources/v2_4/storage_service/capacity.py b/rsd_lib/resources/v2_4/storage_service/capacity_source.py similarity index 100% rename from rsd_lib/resources/v2_4/storage_service/capacity.py rename to rsd_lib/resources/v2_4/storage_service/capacity_source.py diff --git a/rsd_lib/resources/v2_4/storage_service/volume.py b/rsd_lib/resources/v2_4/storage_service/volume.py index bbb7736..a21bbd6 100644 --- a/rsd_lib/resources/v2_4/storage_service/volume.py +++ b/rsd_lib/resources/v2_4/storage_service/volume.py @@ -17,7 +17,7 @@ from sushy import exceptions from sushy import utils from rsd_lib.resources.v2_3.storage_service import volume -from rsd_lib.resources.v2_4.storage_service import capacity +from rsd_lib.resources.v2_4.storage_service import capacity_source class Volume(volume.Volume): @@ -30,7 +30,7 @@ class Volume(volume.Volume): refresh, this property is reset. """ return [ - capacity.CapacitySource( + capacity_source.CapacitySource( self._conn, path, redfish_version=self.redfish_version ) for path in utils.get_sub_resource_path_by( diff --git a/rsd_lib/resources/v2_4/types.py b/rsd_lib/resources/v2_4/types.py new file mode 100644 index 0000000..e23f5f1 --- /dev/null +++ b/rsd_lib/resources/v2_4/types.py @@ -0,0 +1,47 @@ +# Copyright 2019 Intel, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from copy import deepcopy + +from rsd_lib.resources.v2_3.types import RESOURCE_CLASS as RESOURCE_CLASS_V23 +from rsd_lib.resources.v2_4.fabric import endpoint +from rsd_lib.resources.v2_4.fabric import fabric +from rsd_lib.resources.v2_4.node import node +from rsd_lib.resources.v2_4.storage_service import capacity_source +from rsd_lib.resources.v2_4.storage_service import storage_service +from rsd_lib.resources.v2_4.storage_service import volume +from rsd_lib.resources.v2_4.system import processor +from rsd_lib.resources.v2_4.system import system + +RESOURCE_CLASS = deepcopy(RESOURCE_CLASS_V23) +RESOURCE_CLASS.update( + { + "CapacitySource": capacity_source.CapacitySource, + "ComposedNode": node.Node, + "ComposedNodeCollection": node.NodeCollection, + "ComputerSystem": system.System, + "ComputerSystemCollection": system.SystemCollection, + "Endpoint": endpoint.Endpoint, + "EndpointCollection": endpoint.EndpointCollection, + "Fabric": fabric.Fabric, + "FabricCollection": fabric.FabricCollection, + "Processor": processor.Processor, + "ProcessorCollection": processor.ProcessorCollection, + "StorageService": storage_service.StorageService, + "StorageServiceCollection": storage_service.StorageServiceCollection, + "Volume": volume.Volume, + "VolumeCollection": volume.VolumeCollection, + } +) 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_source.py similarity index 98% rename from rsd_lib/tests/unit/resources/v2_4/storage_service/test_capacity.py rename to rsd_lib/tests/unit/resources/v2_4/storage_service/test_capacity_source.py index 48fa018..eb8d790 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_source.py @@ -19,7 +19,7 @@ import testtools from rsd_lib.resources.v2_3.storage_service import drive from rsd_lib.resources.v2_3.storage_service import storage_pool -from rsd_lib.resources.v2_4.storage_service import capacity +from rsd_lib.resources.v2_4.storage_service import capacity_source from rsd_lib.resources.v2_4.storage_service import volume @@ -32,7 +32,7 @@ class CapacitySourceTestCase(testtools.TestCase): ) as f: self.conn.get.return_value.json.return_value = json.loads(f.read()) - self.capacity_sources_inst = capacity.CapacitySource( + self.capacity_sources_inst = capacity_source.CapacitySource( self.conn, "/redfish/v1/StorageServices/1/Volumes/1/CapacitySources/1", redfish_version="1.0.2", diff --git a/rsd_lib/tests/unit/resources/v2_4/storage_service/test_volume.py b/rsd_lib/tests/unit/resources/v2_4/storage_service/test_volume.py index 3273d03..700ce89 100644 --- a/rsd_lib/tests/unit/resources/v2_4/storage_service/test_volume.py +++ b/rsd_lib/tests/unit/resources/v2_4/storage_service/test_volume.py @@ -19,7 +19,7 @@ import testtools from sushy import exceptions -from rsd_lib.resources.v2_4.storage_service import capacity +from rsd_lib.resources.v2_4.storage_service import capacity_source from rsd_lib.resources.v2_4.storage_service import volume @@ -104,7 +104,7 @@ class StorageServiceTestCase(testtools.TestCase): # | THEN | self.assertIsInstance(actual_capacity_sources, list) self.assertIsInstance( - actual_capacity_sources[0], capacity.CapacitySource + actual_capacity_sources[0], capacity_source.CapacitySource ) self.conn.get.return_value.json.assert_called_once_with() @@ -126,7 +126,8 @@ class StorageServiceTestCase(testtools.TestCase): # | WHEN & THEN | self.assertIsInstance(self.volume_inst.capacity_sources, list) self.assertIsInstance( - self.volume_inst.capacity_sources[0], capacity.CapacitySource + self.volume_inst.capacity_sources[0], + capacity_source.CapacitySource, ) # On refreshing the telemetry service instance... @@ -146,7 +147,8 @@ class StorageServiceTestCase(testtools.TestCase): # | WHEN & THEN | self.assertIsInstance(self.volume_inst.capacity_sources, list) self.assertIsInstance( - self.volume_inst.capacity_sources[0], capacity.CapacitySource + self.volume_inst.capacity_sources[0], + capacity_source.CapacitySource, ) def test_resize_volume(self):