Refactor get_resource method
Add param resource_class for _get_resource_class_from_path method. Change-Id: I5870e1b616b25c62fd4cddd2a914186fa029b824
This commit is contained in:
parent
d34ece37cd
commit
cc51729406
@ -27,7 +27,7 @@ from rsd_lib.resources.v2_1.registries import message_registry_file
|
||||
from rsd_lib.resources.v2_1.storage_service import storage_service
|
||||
from rsd_lib.resources.v2_1.system import system
|
||||
from rsd_lib.resources.v2_1.task import task_service
|
||||
from rsd_lib.resources.v2_1 import types
|
||||
from rsd_lib.resources.v2_1.types import RESOURCE_CLASS
|
||||
|
||||
|
||||
class RSDLibV2_1(base.ResourceBase):
|
||||
@ -283,10 +283,12 @@ class RSDLibV2_1(base.ResourceBase):
|
||||
redfish_version=self.redfish_version,
|
||||
)
|
||||
|
||||
def _get_resource_class_from_path(self, path):
|
||||
def _get_resource_class_from_path(self, path, resource_class):
|
||||
"""Get resource class from a given path
|
||||
|
||||
:param path: Path of any rsd resource
|
||||
:param resource_class: Mapping for looking up resource class by
|
||||
entity_type string
|
||||
:returns: Corresponding resource class
|
||||
"""
|
||||
body = self._conn.get(path=path).json()
|
||||
@ -299,7 +301,7 @@ class RSDLibV2_1(base.ResourceBase):
|
||||
# Here we use entity_type to find the corresponding resource class
|
||||
entity_type = body["@odata.type"].split(".")[-1]
|
||||
|
||||
return types.RESOURCE_CLASS.get(entity_type)
|
||||
return resource_class.get(entity_type)
|
||||
|
||||
def get_resource(self, path):
|
||||
"""Return corresponding resource object from path
|
||||
@ -307,7 +309,9 @@ class RSDLibV2_1(base.ResourceBase):
|
||||
: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 = self._get_resource_class_from_path(
|
||||
path,
|
||||
RESOURCE_CLASS)
|
||||
if not resource_class:
|
||||
raise rsd_lib_exceptions.NoMatchingResourceError(uri=path)
|
||||
return resource_class(
|
||||
|
@ -30,6 +30,7 @@ from rsd_lib.resources.v2_1.registries import message_registry_file
|
||||
from rsd_lib.resources.v2_1.storage_service import storage_service
|
||||
from rsd_lib.resources.v2_1.system import system
|
||||
from rsd_lib.resources.v2_1.task import task_service
|
||||
from rsd_lib.resources.v2_1.types import RESOURCE_CLASS
|
||||
|
||||
|
||||
class RSDLibV2_1TestCase(testtools.TestCase):
|
||||
@ -243,6 +244,7 @@ class RSDLibV2_1TestCase(testtools.TestCase):
|
||||
exceptions.ConnectionError,
|
||||
self.rsd._get_resource_class_from_path,
|
||||
"/redfish/v1/Chassis/1",
|
||||
RESOURCE_CLASS
|
||||
)
|
||||
self.conn.reset()
|
||||
|
||||
@ -254,6 +256,7 @@ class RSDLibV2_1TestCase(testtools.TestCase):
|
||||
"/redfish/v1/Chassis/1",
|
||||
self.rsd._get_resource_class_from_path,
|
||||
"/redfish/v1/Chassis/1",
|
||||
RESOURCE_CLASS
|
||||
)
|
||||
self.conn.reset()
|
||||
|
||||
@ -263,7 +266,9 @@ class RSDLibV2_1TestCase(testtools.TestCase):
|
||||
}
|
||||
self.assertEqual(
|
||||
chassis.Chassis,
|
||||
self.rsd._get_resource_class_from_path("/redfish/v1/Chassis/1"),
|
||||
self.rsd._get_resource_class_from_path(
|
||||
"/redfish/v1/Chassis/1",
|
||||
RESOURCE_CLASS),
|
||||
)
|
||||
self.conn.reset()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user