Merge "Add v2.3 support for get_resource method"
This commit is contained in:
commit
6e1ba65d28
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
from sushy.resources import base
|
from sushy.resources import base
|
||||||
|
|
||||||
|
from rsd_lib import exceptions as rsd_lib_exceptions
|
||||||
from rsd_lib.resources import v2_2
|
from rsd_lib.resources import v2_2
|
||||||
from rsd_lib.resources.v2_3.ethernet_switch import ethernet_switch
|
from rsd_lib.resources.v2_3.ethernet_switch import ethernet_switch
|
||||||
from rsd_lib.resources.v2_3.fabric import fabric
|
from rsd_lib.resources.v2_3.fabric import fabric
|
||||||
@ -22,6 +23,7 @@ from rsd_lib.resources.v2_3.manager import manager
|
|||||||
from rsd_lib.resources.v2_3.node import node
|
from rsd_lib.resources.v2_3.node import node
|
||||||
from rsd_lib.resources.v2_3.storage_service import storage_service
|
from rsd_lib.resources.v2_3.storage_service import storage_service
|
||||||
from rsd_lib.resources.v2_3.system import system
|
from rsd_lib.resources.v2_3.system import system
|
||||||
|
from rsd_lib.resources.v2_3.types import RESOURCE_CLASS
|
||||||
|
|
||||||
|
|
||||||
class RSDLibV2_3(v2_2.RSDLibV2_2):
|
class RSDLibV2_3(v2_2.RSDLibV2_2):
|
||||||
@ -157,3 +159,18 @@ class RSDLibV2_3(v2_2.RSDLibV2_2):
|
|||||||
self._conn,
|
self._conn,
|
||||||
identity,
|
identity,
|
||||||
redfish_version=self.redfish_version)
|
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
|
||||||
|
)
|
||||||
|
41
rsd_lib/resources/v2_3/types.py
Normal file
41
rsd_lib/resources/v2_3/types.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
# 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_2.types import RESOURCE_CLASS as RESOURCE_CLASS_V22
|
||||||
|
from rsd_lib.resources.v2_3.storage_service import drive
|
||||||
|
from rsd_lib.resources.v2_3.storage_service import drive_metrics
|
||||||
|
from rsd_lib.resources.v2_3.storage_service import storage_pool
|
||||||
|
from rsd_lib.resources.v2_3.storage_service import volume_metrics
|
||||||
|
|
||||||
|
RESOURCE_CLASS = deepcopy(RESOURCE_CLASS_V22)
|
||||||
|
RESOURCE_CLASS.update(
|
||||||
|
{
|
||||||
|
'DriveCollection': drive.DriveCollection,
|
||||||
|
'DriveMetrics': drive_metrics.DriveMetrics,
|
||||||
|
'StoragePool': storage_pool.StoragePool,
|
||||||
|
'StoragePoolCollection': storage_pool.StoragePoolCollection,
|
||||||
|
'VolumeMetrics': volume_metrics.VolumeMetrics
|
||||||
|
}
|
||||||
|
)
|
||||||
|
for k in (
|
||||||
|
'LogicalDrive',
|
||||||
|
'LogicalDriveCollection',
|
||||||
|
'PhysicalDrive',
|
||||||
|
'PhysicalDriveCollection',
|
||||||
|
'RemoteTarget',
|
||||||
|
'RemoteTargetCollection'):
|
||||||
|
RESOURCE_CLASS.pop(k)
|
@ -17,6 +17,7 @@ import json
|
|||||||
import mock
|
import mock
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
|
from rsd_lib.exceptions import NoMatchingResourceError
|
||||||
from rsd_lib.resources.v2_1.chassis import chassis as v2_1_chassis
|
from rsd_lib.resources.v2_1.chassis import chassis as v2_1_chassis
|
||||||
from rsd_lib.resources.v2_1.event_service import event_service \
|
from rsd_lib.resources.v2_1.event_service import event_service \
|
||||||
as v2_1_event_service
|
as v2_1_event_service
|
||||||
@ -219,3 +220,32 @@ class RSDLibV2_3TestCase(testtools.TestCase):
|
|||||||
# mock_telemetry_service.assert_called_once_with(
|
# mock_telemetry_service.assert_called_once_with(
|
||||||
# self.rsd._conn, '/redfish/v1/TelemetryService',
|
# self.rsd._conn, '/redfish/v1/TelemetryService',
|
||||||
# redfish_version=self.rsd.redfish_version)
|
# redfish_version=self.rsd.redfish_version)
|
||||||
|
|
||||||
|
def test_get_resource(self):
|
||||||
|
with mock.patch.object(
|
||||||
|
self.rsd,
|
||||||
|
"_get_resource_class_from_path",
|
||||||
|
return_value=v2_3_storage_service.storage_pool.StoragePool,
|
||||||
|
):
|
||||||
|
with open(
|
||||||
|
"rsd_lib/tests/unit/json_samples/v2_3/storage_pool.json",
|
||||||
|
"r"
|
||||||
|
) as f:
|
||||||
|
self.conn.get.return_value.json.return_value = json.loads(
|
||||||
|
f.read()
|
||||||
|
)
|
||||||
|
self.assertIsInstance(
|
||||||
|
self.rsd.get_resource(
|
||||||
|
"/redfish/v1/TelemetryService"),
|
||||||
|
v2_3_storage_service.storage_pool.StoragePool
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_get_resource_with_no_class_match(self):
|
||||||
|
with mock.patch.object(
|
||||||
|
self.rsd, "_get_resource_class_from_path", return_value=None
|
||||||
|
):
|
||||||
|
self.assertRaises(
|
||||||
|
NoMatchingResourceError,
|
||||||
|
self.rsd.get_resource,
|
||||||
|
"/redfish/v1/chassis/1",
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user