diff --git a/doc/source/reference/usage.rst b/doc/source/reference/usage.rst index 369a99b..a9a181f 100644 --- a/doc/source/reference/usage.rst +++ b/doc/source/reference/usage.rst @@ -13,7 +13,7 @@ Composing and using a logical node # Get a connection with the RSD endpoint rsd = rsd_lib.RSDLib('http://localhost:8443/redfish/v1', - username='foo', password='bar') + username='foo', password='bar').factory() # Get the node collection object node_col = rsd.get_node_collection() diff --git a/requirements.txt b/requirements.txt index 709464f..09c9bbf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,5 +3,5 @@ # process, which may cause wedges in the gate later. pbr>=2.0 # Apache-2.0 -sushy<=1.2.0 # Apache-2.0 +sushy>=1.2.0 # Apache-2.0 jsonschema<3.0.0,>=2.6.0 # MIT diff --git a/rsd_lib/main.py b/rsd_lib/main.py index 5bcb451..437b28b 100644 --- a/rsd_lib/main.py +++ b/rsd_lib/main.py @@ -13,111 +13,59 @@ # License for the specific language governing permissions and limitations # under the License. -import sushy +from distutils import version + +from sushy import connector from sushy.resources import base -from rsd_lib.resources.chassis import chassis -from rsd_lib.resources.fabric import fabric -from rsd_lib.resources.node import node -from rsd_lib.resources.storage_service import storage_service +from rsd_lib.resources import v2_1 -class RSDLib(sushy.Sushy): +class RSDLib(base.ResourceBase): - _nodes_path = base.Field(['Nodes', '@odata.id'], required=True) - """NodeCollection path""" - - _chassis_path = base.Field(['Chassis', '@odata.id'], required=True) - """ChassisCollection path""" - - _storage_service_path = base.Field(['Services', - '@odata.id'], required=True) - """StorageServiceCollection path""" - - _fabrics_path = base.Field(['Fabrics', '@odata.id'], required=True) + _redfish_version = base.Field(['RedfishVersion'], required=True) """FabricCollection path""" _rsd_api_version = base.Field(['Oem', 'Intel_RackScale', 'ApiVersion'], required=True) + """RSD API version""" - def get_node_collection(self): - """Get the NodeCollection object + def __init__(self, base_url, username=None, password=None, + root_prefix='/redfish/v1/', verify=True): + """A class representing a RootService - :raises: MissingAttributeError, if the collection attribute is - not found - :returns: a NodeCollection object + :param base_url: The base URL to the Redfish controller. It + should include scheme and authority portion of the URL. For + example: https://mgmt.vendor.com + :param username: User account with admin/server-profile access + privilege + :param password: User account password + :param root_prefix: The default URL prefix. This part includes + the root service and version. Defaults to /redfish/v1 + :param verify: Either a boolean value, a path to a CA_BUNDLE + file or directory with certificates of trusted CAs. If set to + True the driver will verify the host certificates; if False + the driver will ignore verifying the SSL certificate; if it's + a path the driver will use the specified certificate or one of + the certificates in the directory. Defaults to True. """ - return node.NodeCollection(self._conn, self._nodes_path, - redfish_version=self.redfish_version) + self._root_prefix = root_prefix + super(RSDLib, self).__init__( + connector.Connector(base_url, username, password, verify), + path=self._root_prefix) - def get_node(self, identity): - """Given the identity return a Node object + def factory(self): + """Return different resource module according to RSD API Version - :param identity: The identity of the Node resource - :returns: The Node object + :returns: a resource module """ - return node.Node(self._conn, identity, - redfish_version=self.redfish_version) - - def get_storage_service_collection(self): - """Get the StorageServiceCollection object - - :raises: MissingAttributeError, if the collection attribute is - not found - :returns: a StorageServiceCollection object - """ - return storage_service.StorageServiceCollection( - self._conn, self._storage_service_path, - redfish_version=self.redfish_version) - - def get_storage_service(self, identity): - """Given the identity return a StorageService object - - :param identity: The identity of the StorageService resource - :returns: The StorageService object - """ - return storage_service.StorageService( - self._conn, identity, - redfish_version=self.redfish_version) - - def get_chassis_collection(self): - """Get the ChassisCollection object - - :raises: MissingAttributeError, if the collection attribute is - not found - :returns: a ChassisCollection object - """ - return chassis.ChassisCollection(self._conn, - self._chassis_path, - redfish_version=self.redfish_version) - - def get_chassis(self, identity): - """Given the identity return a Chassis object - - :param identity: The identity of the Chassis resource - :returns: The Chassis object - """ - return chassis.Chassis(self._conn, - identity, - redfish_version=self.redfish_version) - - def get_fabric_collection(self): - """Get the FabricCollection object - - :raises: MissingAttributeError, if the collection attribute is - not found - :returns: a FabricCollection object - """ - 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 - - :param identity: The identity of the Fabric resource - :returns: The Fabric object - """ - return fabric.Fabric(self._conn, - identity, - redfish_version=self.redfish_version) + rsd_version = version.StrictVersion(self._rsd_api_version) + if rsd_version <= version.StrictVersion("2.1.0"): + # Use the interface of RSD API 2.1.0 to interact with RSD 2.1.0 and + # all previous version. + return v2_1.RSDLibV2_1(self._conn, self._root_prefix, + redfish_version=self._redfish_version) + else: + raise NotImplementedError( + "The rsd-lib library doesn't support RSD API " + "version {0}.".format(self._rsd_api_version)) diff --git a/rsd_lib/resources/v2_1/__init__.py b/rsd_lib/resources/v2_1/__init__.py new file mode 100644 index 0000000..5790f53 --- /dev/null +++ b/rsd_lib/resources/v2_1/__init__.py @@ -0,0 +1,157 @@ +# Copyright 2017 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 sushy.resources import base +from sushy.resources.system import system + +from rsd_lib.resources.v2_1.chassis import chassis +from rsd_lib.resources.v2_1.fabric import fabric +from rsd_lib.resources.v2_1.node import node +from rsd_lib.resources.v2_1.storage_service import storage_service + + +class RSDLibV2_1(base.ResourceBase): + + _nodes_path = base.Field(['Nodes', '@odata.id'], required=True) + """NodeCollection path""" + + _chassis_path = base.Field(['Chassis', '@odata.id'], required=True) + """ChassisCollection path""" + + _storage_service_path = base.Field(['Services', + '@odata.id'], required=True) + """StorageServiceCollection path""" + + _fabrics_path = base.Field(['Fabrics', '@odata.id'], required=True) + """FabricCollection path""" + + _redfish_version = base.Field(['RedfishVersion'], required=True) + """FabricCollection path""" + + _rsd_api_version = base.Field(['Oem', 'Intel_RackScale', 'ApiVersion'], + required=True) + """RSD API version""" + + def __init__(self, connector, identity="/redfish/v1/", + redfish_version=None): + """A class representing a ComposedNode + + :param connector: A Connector instance + :param identity: The identity of the Node resource + :param redfish_version: The version of RedFish. Used to construct + the object according to schema of the given version. + """ + super(RSDLibV2_1, self).__init__(connector, identity, redfish_version) + + def get_system_collection(self): + """Get the SystemCollection object + + :raises: MissingAttributeError, if the collection attribute is + not found + :returns: a SystemCollection object + """ + return system.SystemCollection(self._conn, self._systems_path, + redfish_version=self.redfish_version) + + def get_system(self, identity): + """Given the identity return a System object + + :param identity: The identity of the System resource + :returns: The System object + """ + return system.System(self._conn, identity, + redfish_version=self.redfish_version) + + def get_node_collection(self): + """Get the NodeCollection object + + :raises: MissingAttributeError, if the collection attribute is + not found + :returns: a NodeCollection object + """ + 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 + + :param identity: The identity of the Node resource + :returns: The Node object + """ + return node.Node(self._conn, identity, + redfish_version=self.redfish_version) + + def get_storage_service_collection(self): + """Get the StorageServiceCollection object + + :raises: MissingAttributeError, if the collection attribute is + not found + :returns: a StorageServiceCollection object + """ + return storage_service.StorageServiceCollection( + self._conn, self._storage_service_path, + redfish_version=self.redfish_version) + + def get_storage_service(self, identity): + """Given the identity return a StorageService object + + :param identity: The identity of the StorageService resource + :returns: The StorageService object + """ + return storage_service.StorageService( + self._conn, identity, + redfish_version=self.redfish_version) + + def get_chassis_collection(self): + """Get the ChassisCollection object + + :raises: MissingAttributeError, if the collection attribute is + not found + :returns: a ChassisCollection object + """ + return chassis.ChassisCollection(self._conn, + self._chassis_path, + redfish_version=self.redfish_version) + + def get_chassis(self, identity): + """Given the identity return a Chassis object + + :param identity: The identity of the Chassis resource + :returns: The Chassis object + """ + return chassis.Chassis(self._conn, + identity, + redfish_version=self.redfish_version) + + def get_fabric_collection(self): + """Get the FabricCollection object + + :raises: MissingAttributeError, if the collection attribute is + not found + :returns: a FabricCollection object + """ + 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 + + :param identity: The identity of the Fabric resource + :returns: The Fabric object + """ + return fabric.Fabric(self._conn, + identity, + redfish_version=self.redfish_version) diff --git a/rsd_lib/resources/chassis/__init__.py b/rsd_lib/resources/v2_1/chassis/__init__.py similarity index 100% rename from rsd_lib/resources/chassis/__init__.py rename to rsd_lib/resources/v2_1/chassis/__init__.py diff --git a/rsd_lib/resources/chassis/chassis.py b/rsd_lib/resources/v2_1/chassis/chassis.py similarity index 100% rename from rsd_lib/resources/chassis/chassis.py rename to rsd_lib/resources/v2_1/chassis/chassis.py diff --git a/rsd_lib/resources/fabric/__init__.py b/rsd_lib/resources/v2_1/fabric/__init__.py similarity index 100% rename from rsd_lib/resources/fabric/__init__.py rename to rsd_lib/resources/v2_1/fabric/__init__.py diff --git a/rsd_lib/resources/fabric/endpoint.py b/rsd_lib/resources/v2_1/fabric/endpoint.py similarity index 100% rename from rsd_lib/resources/fabric/endpoint.py rename to rsd_lib/resources/v2_1/fabric/endpoint.py diff --git a/rsd_lib/resources/fabric/fabric.py b/rsd_lib/resources/v2_1/fabric/fabric.py similarity index 97% rename from rsd_lib/resources/fabric/fabric.py rename to rsd_lib/resources/v2_1/fabric/fabric.py index 103a88f..c0691aa 100644 --- a/rsd_lib/resources/fabric/fabric.py +++ b/rsd_lib/resources/v2_1/fabric/fabric.py @@ -18,8 +18,8 @@ import logging from sushy import exceptions from sushy.resources import base -from rsd_lib.resources.fabric import endpoint -from rsd_lib.resources.fabric import zone +from rsd_lib.resources.v2_1.fabric import endpoint +from rsd_lib.resources.v2_1.fabric import zone LOG = logging.getLogger(__name__) diff --git a/rsd_lib/resources/fabric/zone.py b/rsd_lib/resources/v2_1/fabric/zone.py similarity index 98% rename from rsd_lib/resources/fabric/zone.py rename to rsd_lib/resources/v2_1/fabric/zone.py index a08941c..29a2382 100644 --- a/rsd_lib/resources/fabric/zone.py +++ b/rsd_lib/resources/v2_1/fabric/zone.py @@ -18,7 +18,7 @@ import logging from sushy.resources import base from sushy import utils -from rsd_lib.resources.fabric import endpoint +from rsd_lib.resources.v2_1.fabric import endpoint LOG = logging.getLogger(__name__) diff --git a/rsd_lib/resources/node/__init__.py b/rsd_lib/resources/v2_1/node/__init__.py similarity index 100% rename from rsd_lib/resources/node/__init__.py rename to rsd_lib/resources/v2_1/node/__init__.py diff --git a/rsd_lib/resources/node/constants.py b/rsd_lib/resources/v2_1/node/constants.py similarity index 100% rename from rsd_lib/resources/node/constants.py rename to rsd_lib/resources/v2_1/node/constants.py diff --git a/rsd_lib/resources/node/mappings.py b/rsd_lib/resources/v2_1/node/mappings.py similarity index 97% rename from rsd_lib/resources/node/mappings.py rename to rsd_lib/resources/v2_1/node/mappings.py index 2f8e815..e0245ed 100644 --- a/rsd_lib/resources/node/mappings.py +++ b/rsd_lib/resources/v2_1/node/mappings.py @@ -15,7 +15,7 @@ from sushy import utils -from rsd_lib.resources.node import constants as node_cons +from rsd_lib.resources.v2_1.node import constants as node_cons RESET_NODE_VALUE_MAP = { 'On': node_cons.RESET_ON, diff --git a/rsd_lib/resources/node/node.py b/rsd_lib/resources/v2_1/node/node.py similarity index 98% rename from rsd_lib/resources/node/node.py rename to rsd_lib/resources/v2_1/node/node.py index d46b7c3..c3fc42e 100644 --- a/rsd_lib/resources/node/node.py +++ b/rsd_lib/resources/v2_1/node/node.py @@ -22,9 +22,9 @@ from sushy.resources import common from sushy.resources.system import system from sushy import utils -from rsd_lib.resources.node import constants as node_cons -from rsd_lib.resources.node import mappings as node_maps -from rsd_lib.resources.node import schemas as node_schemas +from rsd_lib.resources.v2_1.node import constants as node_cons +from rsd_lib.resources.v2_1.node import mappings as node_maps +from rsd_lib.resources.v2_1.node import schemas as node_schemas LOG = logging.getLogger(__name__) diff --git a/rsd_lib/resources/node/schemas.py b/rsd_lib/resources/v2_1/node/schemas.py similarity index 100% rename from rsd_lib/resources/node/schemas.py rename to rsd_lib/resources/v2_1/node/schemas.py diff --git a/rsd_lib/resources/storage_service/__init__.py b/rsd_lib/resources/v2_1/storage_service/__init__.py similarity index 100% rename from rsd_lib/resources/storage_service/__init__.py rename to rsd_lib/resources/v2_1/storage_service/__init__.py diff --git a/rsd_lib/resources/storage_service/logical_drive.py b/rsd_lib/resources/v2_1/storage_service/logical_drive.py similarity index 100% rename from rsd_lib/resources/storage_service/logical_drive.py rename to rsd_lib/resources/v2_1/storage_service/logical_drive.py diff --git a/rsd_lib/resources/storage_service/physical_drive.py b/rsd_lib/resources/v2_1/storage_service/physical_drive.py similarity index 100% rename from rsd_lib/resources/storage_service/physical_drive.py rename to rsd_lib/resources/v2_1/storage_service/physical_drive.py diff --git a/rsd_lib/resources/storage_service/remote_target.py b/rsd_lib/resources/v2_1/storage_service/remote_target.py similarity index 100% rename from rsd_lib/resources/storage_service/remote_target.py rename to rsd_lib/resources/v2_1/storage_service/remote_target.py diff --git a/rsd_lib/resources/storage_service/storage_service.py b/rsd_lib/resources/v2_1/storage_service/storage_service.py similarity index 96% rename from rsd_lib/resources/storage_service/storage_service.py rename to rsd_lib/resources/v2_1/storage_service/storage_service.py index ed50080..5cd3397 100644 --- a/rsd_lib/resources/storage_service/storage_service.py +++ b/rsd_lib/resources/v2_1/storage_service/storage_service.py @@ -18,9 +18,9 @@ import logging from sushy import exceptions from sushy.resources import base -from rsd_lib.resources.storage_service import logical_drive -from rsd_lib.resources.storage_service import physical_drive -from rsd_lib.resources.storage_service import remote_target +from rsd_lib.resources.v2_1.storage_service import logical_drive +from rsd_lib.resources.v2_1.storage_service import physical_drive +from rsd_lib.resources.v2_1.storage_service import remote_target LOG = logging.getLogger(__name__) diff --git a/rsd_lib/tests/unit/json_samples/root.json b/rsd_lib/tests/unit/json_samples/root.json index 38f648a..4bb6953 100644 --- a/rsd_lib/tests/unit/json_samples/root.json +++ b/rsd_lib/tests/unit/json_samples/root.json @@ -42,7 +42,7 @@ "Oem": { "Intel_RackScale": { "@odata.type": "#Intel.Oem.ServiceRoot", - "ApiVersion": "2.2" + "ApiVersion": "2.1.0" } }, "@odata.context": "/redfish/v1/$metadata#ServiceRoot", diff --git a/rsd_lib/tests/unit/resources/fabric/__init__.py b/rsd_lib/tests/unit/resources/v2_1/__init__.py similarity index 100% rename from rsd_lib/tests/unit/resources/fabric/__init__.py rename to rsd_lib/tests/unit/resources/v2_1/__init__.py diff --git a/rsd_lib/tests/unit/resources/chassis/test_chassis.py b/rsd_lib/tests/unit/resources/v2_1/chassis/test_chassis.py similarity index 98% rename from rsd_lib/tests/unit/resources/chassis/test_chassis.py rename to rsd_lib/tests/unit/resources/v2_1/chassis/test_chassis.py index a182b63..636a52a 100644 --- a/rsd_lib/tests/unit/resources/chassis/test_chassis.py +++ b/rsd_lib/tests/unit/resources/v2_1/chassis/test_chassis.py @@ -16,7 +16,7 @@ import mock from sushy.tests.unit import base -from rsd_lib.resources.chassis import chassis +from rsd_lib.resources.v2_1.chassis import chassis class TestChassis(base.TestCase): diff --git a/rsd_lib/tests/unit/resources/node/__init__.py b/rsd_lib/tests/unit/resources/v2_1/fabric/__init__.py similarity index 100% rename from rsd_lib/tests/unit/resources/node/__init__.py rename to rsd_lib/tests/unit/resources/v2_1/fabric/__init__.py diff --git a/rsd_lib/tests/unit/resources/fabric/test_endpoint.py b/rsd_lib/tests/unit/resources/v2_1/fabric/test_endpoint.py similarity index 98% rename from rsd_lib/tests/unit/resources/fabric/test_endpoint.py rename to rsd_lib/tests/unit/resources/v2_1/fabric/test_endpoint.py index 8825a72..857e8e9 100644 --- a/rsd_lib/tests/unit/resources/fabric/test_endpoint.py +++ b/rsd_lib/tests/unit/resources/v2_1/fabric/test_endpoint.py @@ -18,7 +18,7 @@ import json import mock import testtools -from rsd_lib.resources.fabric import endpoint +from rsd_lib.resources.v2_1.fabric import endpoint class EndpointTestCase(testtools.TestCase): diff --git a/rsd_lib/tests/unit/resources/fabric/test_fabric.py b/rsd_lib/tests/unit/resources/v2_1/fabric/test_fabric.py similarity index 98% rename from rsd_lib/tests/unit/resources/fabric/test_fabric.py rename to rsd_lib/tests/unit/resources/v2_1/fabric/test_fabric.py index 626f804..83d80f1 100644 --- a/rsd_lib/tests/unit/resources/fabric/test_fabric.py +++ b/rsd_lib/tests/unit/resources/v2_1/fabric/test_fabric.py @@ -19,9 +19,9 @@ import mock from sushy import exceptions import testtools -from rsd_lib.resources.fabric import endpoint -from rsd_lib.resources.fabric import fabric -from rsd_lib.resources.fabric import zone +from rsd_lib.resources.v2_1.fabric import endpoint +from rsd_lib.resources.v2_1.fabric import fabric +from rsd_lib.resources.v2_1.fabric import zone class FabricTestCase(testtools.TestCase): diff --git a/rsd_lib/tests/unit/resources/fabric/test_zone.py b/rsd_lib/tests/unit/resources/v2_1/fabric/test_zone.py similarity index 98% rename from rsd_lib/tests/unit/resources/fabric/test_zone.py rename to rsd_lib/tests/unit/resources/v2_1/fabric/test_zone.py index 4767827..a1d060f 100644 --- a/rsd_lib/tests/unit/resources/fabric/test_zone.py +++ b/rsd_lib/tests/unit/resources/v2_1/fabric/test_zone.py @@ -18,7 +18,7 @@ import json import mock import testtools -from rsd_lib.resources.fabric import zone +from rsd_lib.resources.v2_1.fabric import zone class ZoneTestCase(testtools.TestCase): diff --git a/rsd_lib/tests/unit/resources/storage_service/__init__.py b/rsd_lib/tests/unit/resources/v2_1/node/__init__.py similarity index 100% rename from rsd_lib/tests/unit/resources/storage_service/__init__.py rename to rsd_lib/tests/unit/resources/v2_1/node/__init__.py diff --git a/rsd_lib/tests/unit/resources/node/test_node.py b/rsd_lib/tests/unit/resources/v2_1/node/test_node.py similarity index 99% rename from rsd_lib/tests/unit/resources/node/test_node.py rename to rsd_lib/tests/unit/resources/v2_1/node/test_node.py index 7a762f2..5304a8a 100644 --- a/rsd_lib/tests/unit/resources/node/test_node.py +++ b/rsd_lib/tests/unit/resources/v2_1/node/test_node.py @@ -21,8 +21,8 @@ import testtools from sushy import exceptions from sushy.resources.system import system -from rsd_lib.resources.node import constants as node_cons -from rsd_lib.resources.node import node +from rsd_lib.resources.v2_1.node import constants as node_cons +from rsd_lib.resources.v2_1.node import node from rsd_lib.tests.unit.fakes import request_fakes diff --git a/rsd_lib/tests/unit/resources/v2_1/storage_service/__init__.py b/rsd_lib/tests/unit/resources/v2_1/storage_service/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rsd_lib/tests/unit/resources/storage_service/test_storage_service.py b/rsd_lib/tests/unit/resources/v2_1/storage_service/test_storage_service.py similarity index 97% rename from rsd_lib/tests/unit/resources/storage_service/test_storage_service.py rename to rsd_lib/tests/unit/resources/v2_1/storage_service/test_storage_service.py index 6c583d9..0bb84bc 100644 --- a/rsd_lib/tests/unit/resources/storage_service/test_storage_service.py +++ b/rsd_lib/tests/unit/resources/v2_1/storage_service/test_storage_service.py @@ -19,10 +19,10 @@ import mock from sushy import exceptions import testtools -from rsd_lib.resources.storage_service import logical_drive -from rsd_lib.resources.storage_service import physical_drive -from rsd_lib.resources.storage_service import remote_target -from rsd_lib.resources.storage_service import storage_service +from rsd_lib.resources.v2_1.storage_service import logical_drive +from rsd_lib.resources.v2_1.storage_service import physical_drive +from rsd_lib.resources.v2_1.storage_service import remote_target +from rsd_lib.resources.v2_1.storage_service import storage_service class StorageServiceTestCase(testtools.TestCase): diff --git a/rsd_lib/tests/unit/resources/v2_1/test_rsdlib_v2_1.py b/rsd_lib/tests/unit/resources/v2_1/test_rsdlib_v2_1.py new file mode 100644 index 0000000..2048387 --- /dev/null +++ b/rsd_lib/tests/unit/resources/v2_1/test_rsdlib_v2_1.py @@ -0,0 +1,66 @@ +# Copyright 2018 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. + +import json + +import mock +import testtools + +from rsd_lib.resources import v2_1 +from rsd_lib.resources.v2_1.fabric import fabric +from rsd_lib.resources.v2_1.node import node + + +class RSDLibV2_1TestCase(testtools.TestCase): + + def setUp(self): + super(RSDLibV2_1TestCase, self).setUp() + self.conn = mock.Mock() + with open('rsd_lib/tests/unit/json_samples/root.json', 'r') as f: + self.conn.get.return_value.json.return_value = json.loads(f.read()) + self.rsd = v2_1.RSDLibV2_1(self.conn) + + def test__parse_attributes(self): + self.rsd._parse_attributes() + self.assertEqual("2.1.0", self.rsd._rsd_api_version) + self.assertEqual("1.0.2", self.rsd._redfish_version) + + @mock.patch.object(node, 'NodeCollection', autospec=True) + def test_get_node_collection(self, mock_node_collection): + self.rsd.get_node_collection() + mock_node_collection.assert_called_once_with( + self.rsd._conn, '/redfish/v1/Nodes', + redfish_version=self.rsd.redfish_version) + + @mock.patch.object(node, 'Node', autospec=True) + def test_get_node(self, mock_node): + self.rsd.get_node('fake-node-id') + mock_node.assert_called_once_with( + self.rsd._conn, 'fake-node-id', + redfish_version=self.rsd.redfish_version) + + @mock.patch.object(fabric, 'FabricCollection', autospec=True) + def test_get_fabric_collection(self, mock_fabric_collection): + self.rsd.get_fabric_collection() + mock_fabric_collection.assert_called_once_with( + self.rsd._conn, '/redfish/v1/Fabrics', + redfish_version=self.rsd.redfish_version) + + @mock.patch.object(fabric, 'Fabric', autospec=True) + def test_get_fabric(self, mock_fabric): + self.rsd.get_fabric('fake-fabric-id') + mock_fabric.assert_called_once_with( + self.rsd._conn, 'fake-fabric-id', + redfish_version=self.rsd.redfish_version) diff --git a/rsd_lib/tests/unit/test_main.py b/rsd_lib/tests/unit/test_main.py index 29e4e3b..f52fe0a 100644 --- a/rsd_lib/tests/unit/test_main.py +++ b/rsd_lib/tests/unit/test_main.py @@ -20,8 +20,7 @@ from sushy import connector import testtools from rsd_lib import main -from rsd_lib.resources.fabric import fabric -from rsd_lib.resources.node import node +from rsd_lib.resources import v2_1 class RSDLibTestCase(testtools.TestCase): @@ -38,32 +37,22 @@ class RSDLibTestCase(testtools.TestCase): def test__parse_attributes(self): self.rsd._parse_attributes() - self.assertEqual("2.2", self.rsd._rsd_api_version) + self.assertEqual("2.1.0", self.rsd._rsd_api_version) + self.assertEqual("1.0.2", self.rsd._redfish_version) - @mock.patch.object(node, 'NodeCollection', autospec=True) - def test_get_node_collection(self, mock_node_collection): - self.rsd.get_node_collection() - mock_node_collection.assert_called_once_with( - self.rsd._conn, '/redfish/v1/Nodes', - redfish_version=self.rsd.redfish_version) + @mock.patch.object(v2_1, 'RSDLibV2_1', autospec=True) + def test_factory(self, mock_rsdlibv2_1): + self.rsd.factory() + mock_rsdlibv2_1.assert_called_once_with( + self.rsd._conn, + self.rsd._root_prefix, + redfish_version=self.rsd._redfish_version) - @mock.patch.object(node, 'Node', autospec=True) - def test_get_node(self, mock_node): - self.rsd.get_node('fake-node-id') - mock_node.assert_called_once_with( - self.rsd._conn, 'fake-node-id', - redfish_version=self.rsd.redfish_version) + def test_factory_unsupported_version(self): + self.rsd._rsd_api_version = "10.0.0" + expected_error_message = "The rsd-lib library doesn't support RSD "\ + "API version 10.0.0." - @mock.patch.object(fabric, 'FabricCollection', autospec=True) - def test_get_fabric_collection(self, mock_fabric_collection): - self.rsd.get_fabric_collection() - mock_fabric_collection.assert_called_once_with( - self.rsd._conn, '/redfish/v1/Fabrics', - redfish_version=self.rsd.redfish_version) - - @mock.patch.object(fabric, 'Fabric', autospec=True) - def test_get_fabric(self, mock_fabric): - self.rsd.get_fabric('fake-fabric-id') - mock_fabric.assert_called_once_with( - self.rsd._conn, 'fake-fabric-id', - redfish_version=self.rsd.redfish_version) + with self.assertRaisesRegex(NotImplementedError, + expected_error_message): + self.rsd.factory()