Add new RSD 2.4 module

Inherit 2.3 module for RSD 2.4 dummy module right now. Should
add 2.4 new functionalities into this module later.

Change-Id: I7902108fdb87dd69c6711bac75a8af7a67ac70a2
This commit is contained in:
Lin Yang 2018-12-05 12:31:29 -08:00
parent 898d2be08a
commit 0d6cd233b3
6 changed files with 248 additions and 2 deletions
rsd_lib
main.py
resources/v2_4
tests/unit

@ -21,6 +21,7 @@ from sushy.resources import base
from rsd_lib.resources import v2_1
from rsd_lib.resources import v2_2
from rsd_lib.resources import v2_3
from rsd_lib.resources import v2_4
class RSDLib(base.ResourceBase):
@ -74,9 +75,14 @@ class RSDLib(base.ResourceBase):
redfish_version=self._redfish_version)
elif version.StrictVersion("2.3.0") <= rsd_version \
and rsd_version < version.StrictVersion("2.4.0"):
# Specific interface for RSD 2.2 version
# Specific interface for RSD 2.3 version
return v2_3.RSDLibV2_3(self._conn, self._root_prefix,
redfish_version=self._redfish_version)
elif version.StrictVersion("2.4.0") <= rsd_version \
and rsd_version < version.StrictVersion("2.5.0"):
# Specific interface for RSD 2.4 version
return v2_4.RSDLibV2_4(self._conn, self._root_prefix,
redfish_version=self._redfish_version)
else:
raise NotImplementedError(
"The rsd-lib library doesn't support RSD API "

@ -0,0 +1,23 @@
# 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.
from rsd_lib.resources import v2_3
class RSDLibV2_4(v2_3.RSDLibV2_3):
# TODO(lin.yang): Inherit 2.3 module for RSD 2.4 dummy module,
# should add 2.4 new functionalities into this module.
pass

@ -0,0 +1,44 @@
{
"@odata.context": "/redfish/v1/$metadata#ServiceRoot.ServiceRoot",
"@odata.id": "/redfish/v1/",
"@odata.type": "#ServiceRoot.v1_1_1.ServiceRoot",
"Id": "RootService",
"Name": "Root Service",
"Description": "description-as-string",
"RedfishVersion": "1.1.0",
"UUID": "92384634-2938-2342-8820-489239905423",
"Systems": {
"@odata.id": "/redfish/v1/Systems"
},
"Chassis": {
"@odata.id": "/redfish/v1/Chassis"
},
"Managers": {
"@odata.id": "/redfish/v1/Managers"
},
"EventService": {
"@odata.id": "/redfish/v1/EventService"
},
"Fabrics": {
"@odata.id": "/redfish/v1/Fabrics"
},
"EthernetSwitches": {
"@odata.id": "/redfish/v1/EthernetSwitches"
},
"StorageServices": {
"@odata.id": "/redfish/v1/StorageServices"
},
"Oem": {
"Intel_RackScale": {
"@odata.type": "#Intel.Oem.ServiceRoot",
"ApiVersion": "2.4.0",
"Nodes": {
"@odata.id": "/redfish/v1/Nodes"
},
"EthernetSwitches": {
"@odata.id": "/redfish/v1/EthernetSwitches"
}
}
},
"Links": {}
}

@ -0,0 +1,163 @@
# 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.v2_1.chassis import chassis as v2_1_chassis
from rsd_lib.resources.v2_1.manager import manager as v2_1_manager
from rsd_lib.resources.v2_2.ethernet_switch import ethernet_switch \
as v2_2_ethernet_switch
from rsd_lib.resources.v2_2.system import system as v2_2_system
from rsd_lib.resources.v2_3.fabric import fabric as v2_3_fabric
from rsd_lib.resources.v2_3.node import node as v2_3_node
from rsd_lib.resources.v2_3.storage_service import storage_service \
as v2_3_storage_service
from rsd_lib.resources import v2_4
class RSDLibV2_3TestCase(testtools.TestCase):
def setUp(self):
super(RSDLibV2_3TestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_4/root.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.rsd = v2_4.RSDLibV2_4(self.conn)
def test__parse_attributes(self):
self.rsd._parse_attributes()
self.assertEqual("2.4.0", self.rsd._rsd_api_version)
self.assertEqual("1.1.0", self.rsd._redfish_version)
self.assertEqual("/redfish/v1/Systems", self.rsd._systems_path)
self.assertEqual("/redfish/v1/Nodes", self.rsd._nodes_path)
self.assertEqual("/redfish/v1/Chassis", self.rsd._chassis_path)
self.assertEqual("/redfish/v1/Fabrics", self.rsd._fabrics_path)
self.assertEqual("/redfish/v1/StorageServices",
self.rsd._storage_service_path)
self.assertEqual(None, self.rsd._telemetry_service_path)
@mock.patch.object(v2_2_system, 'SystemCollection', autospec=True)
def test_get_system_collection(self, mock_system_collection):
self.rsd.get_system_collection()
mock_system_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Systems',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_2_system, 'System', autospec=True)
def test_get_system(self, mock_system):
self.rsd.get_system('fake-system-id')
mock_system.assert_called_once_with(
self.rsd._conn, 'fake-system-id',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_3_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_3_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(v2_3_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(v2_3_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)
@mock.patch.object(v2_1_chassis, 'ChassisCollection', autospec=True)
def test_get_chassis_collection(self, mock_chassis_collection):
self.rsd.get_chassis_collection()
mock_chassis_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Chassis',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_1_chassis, 'Chassis', autospec=True)
def test_get_chassis(self, mock_chassis):
self.rsd.get_chassis('fake-chassis-id')
mock_chassis.assert_called_once_with(
self.rsd._conn, 'fake-chassis-id',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_3_storage_service, 'StorageServiceCollection',
autospec=True)
def test_get_storage_service_collection(self,
mock_storage_service_collection):
self.rsd.get_storage_service_collection()
mock_storage_service_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/StorageServices',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_3_storage_service, 'StorageService', autospec=True)
def test_get_storage_service(self, mock_storage_service):
self.rsd.get_storage_service('fake-storage-service-id')
mock_storage_service.assert_called_once_with(
self.rsd._conn, 'fake-storage-service-id',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_1_manager, 'ManagerCollection', autospec=True)
def test_get_manager_collection(self, mock_manager_collection):
self.rsd.get_manager_collection()
mock_manager_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Managers',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_1_manager, 'Manager', autospec=True)
def test_get_manager(self, mock_manager_service):
self.rsd.get_manager('fake-manager-id')
mock_manager_service.assert_called_once_with(
self.rsd._conn, 'fake-manager-id',
redfish_version=self.rsd.redfish_version
)
@mock.patch.object(v2_2_ethernet_switch,
'EthernetSwitchCollection',
autospec=True)
def test_get_ethernet_switch_collection(self,
mock_ethernet_switch_collection):
self.rsd.get_ethernet_switch_collection()
mock_ethernet_switch_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/EthernetSwitches',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_2_ethernet_switch, 'EthernetSwitch', autospec=True)
def test_get_ethernet_switch(self, mock_ethernet_switch_service):
self.rsd.get_ethernet_switch('fake-ethernet-switch-id')
mock_ethernet_switch_service.assert_called_once_with(
self.rsd._conn, 'fake-ethernet-switch-id',
redfish_version=self.rsd.redfish_version
)
# @mock.patch.object(v2_2_telemetry, 'Telemetry', autospec=True)
# def test_get_telemetry_service(self, mock_telemetry_service):
# self.rsd.get_telemetry_service()
# mock_telemetry_service.assert_called_once_with(
# self.rsd._conn, '/redfish/v1/TelemetryService',
# redfish_version=self.rsd.redfish_version)

@ -23,6 +23,7 @@ from rsd_lib import main
from rsd_lib.resources import v2_1
from rsd_lib.resources import v2_2
from rsd_lib.resources import v2_3
from rsd_lib.resources import v2_4
class RSDLibTestCase(testtools.TestCase):
@ -42,10 +43,12 @@ class RSDLibTestCase(testtools.TestCase):
self.assertEqual("2.1.0", self.rsd._rsd_api_version)
self.assertEqual("1.0.2", self.rsd._redfish_version)
@mock.patch.object(v2_4, 'RSDLibV2_4', autospec=True)
@mock.patch.object(v2_3, 'RSDLibV2_3', autospec=True)
@mock.patch.object(v2_2, 'RSDLibV2_2', autospec=True)
@mock.patch.object(v2_1, 'RSDLibV2_1', autospec=True)
def test_factory(self, mock_rsdlibv2_1, mock_rsdlibv2_2, mock_rsdlibv2_3):
def test_factory(self, mock_rsdlibv2_1, mock_rsdlibv2_2, mock_rsdlibv2_3,
mock_rsdlibv2_4):
self.rsd.factory()
mock_rsdlibv2_1.assert_called_once_with(
self.rsd._conn,
@ -66,6 +69,13 @@ class RSDLibTestCase(testtools.TestCase):
self.rsd._root_prefix,
redfish_version=self.rsd._redfish_version)
self.rsd._rsd_api_version = "2.4.0"
self.rsd.factory()
mock_rsdlibv2_4.assert_called_once_with(
self.rsd._conn,
self.rsd._root_prefix,
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 "\