Add new fabric resource for RSD 2.3

Change-Id: I6feaca6c9b41728ac68413a551255d565946d740
This commit is contained in:
Lin Yang 2018-05-07 16:42:15 -07:00
parent bcd579f5bd
commit 2d81ac38d9
8 changed files with 221 additions and 3 deletions
rsd_lib

@ -16,6 +16,7 @@
from sushy.resources import base
from rsd_lib.resources import v2_2
from rsd_lib.resources.v2_3.fabric import fabric
from rsd_lib.resources.v2_3.node import node
from rsd_lib.resources.v2_3.storage_service import storage_service
@ -59,3 +60,24 @@ class RSDLibV2_3(v2_2.RSDLibV2_2):
return storage_service.StorageService(
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)

@ -0,0 +1,76 @@
# 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 logging
from sushy.resources import base
LOG = logging.getLogger(__name__)
class StatusField(base.CompositeField):
state = base.Field('State')
health = base.Field('Health')
health_rollup = base.Field('HealthRollup')
class Fabric(base.ResourceBase):
description = base.Field('Description')
"""The fabric description"""
fabric_type = base.Field('FabricType')
"""The fabric type"""
identity = base.Field('Id', required=True)
"""The fabric identity string"""
max_zones = base.Field('MaxZones')
"""Maximum number of zones for the fabric"""
name = base.Field('Name')
"""The fabric name"""
status = StatusField('Status')
def __init__(self, connector, identity, redfish_version=None):
"""A class representing a Fabric
:param connector: A Connector instance
:param identity: The identity of the Fabric resource
:param redfish_version: The version of RedFish. Used to construct
the object according to schema of the given version.
"""
super(Fabric, self).__init__(connector, identity,
redfish_version)
class FabricCollection(base.ResourceCollectionBase):
@property
def _resource_type(self):
return Fabric
def __init__(self, connector, path, redfish_version=None):
"""A class representing a FabricCollection
:param connector: A Connector instance
:param path: The canonical path to the Fabric collection
resource
:param redfish_version: The version of RedFish. Used to construct
the object according to schema of the given version.
"""
super(FabricCollection, self).__init__(connector, path,
redfish_version)

@ -0,0 +1,25 @@
{
"@odata.context": "/redfish/v1/$metadata#Fabric.Fabric",
"@odata.id": "/redfish/v1/Fabrics/NVMeoE",
"@odata.type": "#Fabric.v1_0_0.Fabric",
"Id": "NVMeoE",
"Actions": {
"Oem": null
},
"Zones": {
"@odata.id": "/redfish/v1/Fabrics/NVMeoE/Zones"
},
"Endpoints": {
"@odata.id": "/redfish/v1/Fabrics/NVMeoE/Endpoints"
},
"FabricType": "NVMeOverFabrics",
"Links": {
"Oem": {}
},
"Oem": {},
"Status": {
"Health": "OK",
"HealthRollup": "OK",
"State": "Enabled"
}
}

@ -0,0 +1,13 @@
{
"@odata.context": "/redfish/v1/$metadata#FabricCollection.FabricCollection",
"@odata.id": "/redfish/v1/Fabrics",
"@odata.type": "#FabricCollection.FabricCollection",
"Name": "Fabric Collection",
"Description": " Fabric Collection",
"Members@odata.count": 1,
"Members": [
{
"@odata.id": "/redfish/v1/Fabrics/NVMeoE"
}
]
}

@ -0,0 +1,82 @@
# 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.
import json
import mock
import testtools
from rsd_lib.resources.v2_3.fabric import fabric
class FabricTestCase(testtools.TestCase):
def setUp(self):
super(FabricTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/fabric.json',
'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.fabric_inst = fabric.Fabric(
self.conn, '/redfish/v1/Fabrics/NVMeoE',
redfish_version='1.0.2')
def test__parse_attributes(self):
self.fabric_inst._parse_attributes()
self.assertEqual('1.0.2', self.fabric_inst.redfish_version)
self.assertEqual('NVMeoE', self.fabric_inst.identity)
self.assertEqual(None, self.fabric_inst.name)
self.assertEqual('NVMeOverFabrics', self.fabric_inst.fabric_type)
self.assertEqual(None, self.fabric_inst.max_zones)
self.assertEqual('Enabled', self.fabric_inst.status.state)
self.assertEqual('OK', self.fabric_inst.status.health)
self.assertEqual('OK', self.fabric_inst.status.health_rollup)
class FabricCollectionTestCase(testtools.TestCase):
def setUp(self):
super(FabricCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'fabric_collection.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.fabric_col = fabric.FabricCollection(
self.conn, '/redfish/v1/Fabrics', redfish_version='1.0.2')
def test__parse_attributes(self):
self.fabric_col._parse_attributes()
self.assertEqual('1.0.2', self.fabric_col.redfish_version)
self.assertEqual('Fabric Collection',
self.fabric_col.name)
self.assertEqual(('/redfish/v1/Fabrics/NVMeoE',),
self.fabric_col.members_identities)
@mock.patch.object(fabric, 'Fabric', autospec=True)
def test_get_member(self, mock_fabric):
self.fabric_col.get_member('/redfish/v1/Fabrics/NVMeoE')
mock_fabric.assert_called_once_with(
self.fabric_col._conn, '/redfish/v1/Fabrics/NVMeoE',
redfish_version=self.fabric_col.redfish_version)
@mock.patch.object(fabric, 'Fabric', autospec=True)
def test_get_members(self, mock_fabric):
members = self.fabric_col.get_members()
mock_fabric.assert_called_once_with(
self.fabric_col._conn, '/redfish/v1/Fabrics/NVMeoE',
redfish_version=self.fabric_col.redfish_version)
self.assertIsInstance(members, list)
self.assertEqual(1, len(members))

@ -18,11 +18,11 @@ import mock
import testtools
from rsd_lib.resources.v2_1.chassis import chassis as v2_1_chassis
from rsd_lib.resources.v2_1.fabric import fabric as v2_1_fabric
from rsd_lib.resources.v2_1.manager import manager as v2_1_manager
from rsd_lib.resources.v2_1.node import node as v2_1_node
from rsd_lib.resources.v2_2.system import system as v2_2_system
from rsd_lib.resources import v2_3
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
@ -77,14 +77,14 @@ class RSDLibV2_3TestCase(testtools.TestCase):
self.rsd._conn, 'fake-node-id',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_1_fabric, 'FabricCollection', autospec=True)
@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_1_fabric, 'Fabric', autospec=True)
@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(