Browse Source

Merge "Add v2.3 support for get_resource method"

tags/1.1.0^0
Zuul 2 months ago
parent
commit
6e1ba65d28

+ 17
- 0
rsd_lib/resources/v2_3/__init__.py View File

@@ -15,6 +15,7 @@
15 15
 
16 16
 from sushy.resources import base
17 17
 
18
+from rsd_lib import exceptions as rsd_lib_exceptions
18 19
 from rsd_lib.resources import v2_2
19 20
 from rsd_lib.resources.v2_3.ethernet_switch import ethernet_switch
20 21
 from rsd_lib.resources.v2_3.fabric import fabric
@@ -22,6 +23,7 @@ from rsd_lib.resources.v2_3.manager import manager
22 23
 from rsd_lib.resources.v2_3.node import node
23 24
 from rsd_lib.resources.v2_3.storage_service import storage_service
24 25
 from rsd_lib.resources.v2_3.system import system
26
+from rsd_lib.resources.v2_3.types import RESOURCE_CLASS
25 27
 
26 28
 
27 29
 class RSDLibV2_3(v2_2.RSDLibV2_2):
@@ -157,3 +159,18 @@ class RSDLibV2_3(v2_2.RSDLibV2_2):
157 159
             self._conn,
158 160
             identity,
159 161
             redfish_version=self.redfish_version)
162
+
163
+    def get_resource(self, path):
164
+        """Return corresponding resource object from path
165
+
166
+        :param path: The path of a resource or resource collection
167
+        :returns: corresponding resource or resource collection object
168
+        """
169
+        resource_class = self._get_resource_class_from_path(
170
+            path,
171
+            RESOURCE_CLASS)
172
+        if not resource_class:
173
+            raise rsd_lib_exceptions.NoMatchingResourceError(uri=path)
174
+        return resource_class(
175
+            self._conn, path, redfish_version=self.redfish_version
176
+        )

+ 41
- 0
rsd_lib/resources/v2_3/types.py View File

@@ -0,0 +1,41 @@
1
+# Copyright 2019 Intel, Inc.
2
+# All Rights Reserved.
3
+#
4
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
5
+#    not use this file except in compliance with the License. You may obtain
6
+#    a copy of the License at
7
+#
8
+#         http://www.apache.org/licenses/LICENSE-2.0
9
+#
10
+#    Unless required by applicable law or agreed to in writing, software
11
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+#    License for the specific language governing permissions and limitations
14
+#    under the License.
15
+
16
+from copy import deepcopy
17
+
18
+from rsd_lib.resources.v2_2.types import RESOURCE_CLASS as RESOURCE_CLASS_V22
19
+from rsd_lib.resources.v2_3.storage_service import drive
20
+from rsd_lib.resources.v2_3.storage_service import drive_metrics
21
+from rsd_lib.resources.v2_3.storage_service import storage_pool
22
+from rsd_lib.resources.v2_3.storage_service import volume_metrics
23
+
24
+RESOURCE_CLASS = deepcopy(RESOURCE_CLASS_V22)
25
+RESOURCE_CLASS.update(
26
+    {
27
+        'DriveCollection': drive.DriveCollection,
28
+        'DriveMetrics': drive_metrics.DriveMetrics,
29
+        'StoragePool': storage_pool.StoragePool,
30
+        'StoragePoolCollection': storage_pool.StoragePoolCollection,
31
+        'VolumeMetrics': volume_metrics.VolumeMetrics
32
+    }
33
+)
34
+for k in (
35
+        'LogicalDrive',
36
+        'LogicalDriveCollection',
37
+        'PhysicalDrive',
38
+        'PhysicalDriveCollection',
39
+        'RemoteTarget',
40
+        'RemoteTargetCollection'):
41
+    RESOURCE_CLASS.pop(k)

+ 30
- 0
rsd_lib/tests/unit/resources/v2_3/test_rsdlib_v2_3.py View File

@@ -17,6 +17,7 @@ import json
17 17
 import mock
18 18
 import testtools
19 19
 
20
+from rsd_lib.exceptions import NoMatchingResourceError
20 21
 from rsd_lib.resources.v2_1.chassis import chassis as v2_1_chassis
21 22
 from rsd_lib.resources.v2_1.event_service import event_service \
22 23
     as v2_1_event_service
@@ -219,3 +220,32 @@ class RSDLibV2_3TestCase(testtools.TestCase):
219 220
     #     mock_telemetry_service.assert_called_once_with(
220 221
     #         self.rsd._conn, '/redfish/v1/TelemetryService',
221 222
     #         redfish_version=self.rsd.redfish_version)
223
+
224
+    def test_get_resource(self):
225
+        with mock.patch.object(
226
+            self.rsd,
227
+            "_get_resource_class_from_path",
228
+            return_value=v2_3_storage_service.storage_pool.StoragePool,
229
+        ):
230
+            with open(
231
+                "rsd_lib/tests/unit/json_samples/v2_3/storage_pool.json",
232
+                "r"
233
+            ) as f:
234
+                self.conn.get.return_value.json.return_value = json.loads(
235
+                    f.read()
236
+                )
237
+            self.assertIsInstance(
238
+                self.rsd.get_resource(
239
+                    "/redfish/v1/TelemetryService"),
240
+                v2_3_storage_service.storage_pool.StoragePool
241
+            )
242
+
243
+    def test_get_resource_with_no_class_match(self):
244
+        with mock.patch.object(
245
+            self.rsd, "_get_resource_class_from_path", return_value=None
246
+        ):
247
+            self.assertRaises(
248
+                NoMatchingResourceError,
249
+                self.rsd.get_resource,
250
+                "/redfish/v1/chassis/1",
251
+            )

Loading…
Cancel
Save