Add ethernet switches field
Change-Id: I4606b94c34288cfda890b68ffa8816b0c94190e0
This commit is contained in:
parent
bec53fcd2b
commit
2f5f510cee
@ -16,6 +16,7 @@
|
||||
from sushy.resources import base
|
||||
|
||||
from rsd_lib.resources.v2_1.chassis import chassis
|
||||
from rsd_lib.resources.v2_1.ethernet_switch import ethernet_switch
|
||||
from rsd_lib.resources.v2_1.fabric import fabric
|
||||
from rsd_lib.resources.v2_1.manager import manager
|
||||
from rsd_lib.resources.v2_1.node import node
|
||||
@ -44,6 +45,10 @@ class RSDLibV2_1(base.ResourceBase):
|
||||
_managers_path = base.Field(['Managers', '@odata.id'], required=True)
|
||||
"""ManagerCollection path"""
|
||||
|
||||
_ethernet_switches_path = base.Field(['EthernetSwitches', '@odata.id'],
|
||||
required=True)
|
||||
"""EthernetSwitchCollecton path"""
|
||||
|
||||
_redfish_version = base.Field(['RedfishVersion'], required=True)
|
||||
"""Redfish version"""
|
||||
|
||||
@ -183,3 +188,27 @@ class RSDLibV2_1(base.ResourceBase):
|
||||
return manager.Manager(self._conn,
|
||||
identity,
|
||||
redfish_version=self.redfish_version)
|
||||
|
||||
def get_ethernet_switch_collection(self):
|
||||
"""Get the EthernetSwitchCollection object
|
||||
|
||||
:raises: MissingAttributeError, if the collection attribute is
|
||||
not found
|
||||
:returns: a EthernetSwitchCollection object
|
||||
"""
|
||||
return ethernet_switch.EthernetSwitchCollection(
|
||||
self._conn,
|
||||
self._ethernet_switches_path,
|
||||
redfish_version=self.redfish_version
|
||||
)
|
||||
|
||||
def get_ethernet_switch(self, identity):
|
||||
"""Given the identity return a EthernetSwitch object
|
||||
|
||||
:param identity: The identity of the EthernetSwitch resource
|
||||
:returns: The EthernetSwitch object
|
||||
"""
|
||||
return ethernet_switch.EthernetSwitch(
|
||||
self._conn,
|
||||
identity,
|
||||
redfish_version=self.redfish_version)
|
||||
|
0
rsd_lib/resources/v2_1/ethernet_switch/__init__.py
Normal file
0
rsd_lib/resources/v2_1/ethernet_switch/__init__.py
Normal file
123
rsd_lib/resources/v2_1/ethernet_switch/ethernet_switch.py
Normal file
123
rsd_lib/resources/v2_1/ethernet_switch/ethernet_switch.py
Normal file
@ -0,0 +1,123 @@
|
||||
# Copyright 2018 99cloud, 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
|
||||
from sushy import utils
|
||||
|
||||
from rsd_lib import utils as rsd_lib_utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class StatusField(base.CompositeField):
|
||||
state = base.Field('State')
|
||||
|
||||
health = base.Field('Health')
|
||||
|
||||
|
||||
class LinksField(base.CompositeField):
|
||||
chassis = base.Field('Chassis', default=(),
|
||||
adapter=rsd_lib_utils.get_resource_identity)
|
||||
"""Link to chassis of this ethernet switch"""
|
||||
|
||||
managed_by = base.Field('ManagedBy', default=(),
|
||||
adapter=utils.get_members_identities)
|
||||
"""Link to manager of this ethernet switch"""
|
||||
|
||||
|
||||
class EthernetSwitch(base.ResourceBase):
|
||||
identity = base.Field('Id', required=True)
|
||||
"""The ethernet switch identity string"""
|
||||
|
||||
switch_id = base.Field('SwitchId')
|
||||
"""The ethernet switch id"""
|
||||
|
||||
name = base.Field('Name')
|
||||
"""The ethernet switch name"""
|
||||
|
||||
description = base.Field('Description')
|
||||
"""The ethernet switch description"""
|
||||
|
||||
manufacturer = base.Field('Manufacturer')
|
||||
"""The ethernet switch manufacturer"""
|
||||
|
||||
model = base.Field('Model')
|
||||
"""The ethernet switch model"""
|
||||
|
||||
manufacturing_data = base.Field('ManufacturingData')
|
||||
"""The ethernet switch manufacturing data"""
|
||||
|
||||
seria_number = base.Field('SerialNumber')
|
||||
"""The ethernet switch serial number"""
|
||||
|
||||
part_number = base.Field('PartNumber')
|
||||
"""The ethernet switch port number"""
|
||||
|
||||
firmware_name = base.Field('FirmwareName')
|
||||
"""The ethernet switch fireware name"""
|
||||
|
||||
firmware_version = base.Field('FirmwareVersion')
|
||||
"""The ethernet switch firmware version"""
|
||||
|
||||
role = base.Field('Role')
|
||||
"""The ethernet switch role"""
|
||||
|
||||
status = StatusField('Status')
|
||||
"""The ethernet switch status"""
|
||||
|
||||
acls = base.Field('ACLs', default=(),
|
||||
adapter=rsd_lib_utils.get_resource_identity)
|
||||
"""The ethernet switch ACLs"""
|
||||
|
||||
ports = base.Field('Ports', default=(),
|
||||
adapter=rsd_lib_utils.get_resource_identity)
|
||||
"""The ethernet switch ports"""
|
||||
|
||||
links = LinksField('Links')
|
||||
"""The links to ethernet switch"""
|
||||
|
||||
def __init__(self, conncetor, identity, redfish_version=None):
|
||||
"""A class representing a EthernetSwitch
|
||||
|
||||
:param connector: A Connector instance
|
||||
:param identity: The identity of the EthernetSwitch resource
|
||||
:param redfish_version: The version of RedFish. Used to construct
|
||||
the object according to schema of the given version.
|
||||
"""
|
||||
super(EthernetSwitch, self).__init__(conncetor,
|
||||
identity,
|
||||
redfish_version)
|
||||
|
||||
|
||||
class EthernetSwitchCollection(base.ResourceCollectionBase):
|
||||
|
||||
@property
|
||||
def _resource_type(self):
|
||||
return EthernetSwitch
|
||||
|
||||
def __init__(self, connector, path, redfish_version=None):
|
||||
"""A class representing a EthernetSwitch Collection
|
||||
|
||||
:param connector: A Connector instance
|
||||
:param path: The canonical path to the EthernetSwitch collection
|
||||
resource
|
||||
:param redfish_version: The version of RedFish. Used to construct
|
||||
the object according to schema of the given version.
|
||||
"""
|
||||
super(EthernetSwitchCollection, self).__init__(connector,
|
||||
path,
|
||||
redfish_version)
|
39
rsd_lib/tests/unit/json_samples/v2_1/ethernet_switch.json
Normal file
39
rsd_lib/tests/unit/json_samples/v2_1/ethernet_switch.json
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
"@odata.context": "/redfish/v1/$metadata#EthernetSwitch.EthernetSwitch",
|
||||
"@odata.id": "/redfish/v1/EthernetSwitches/Switch1",
|
||||
"@odata.type": "#EthernetSwitch.v1_0_0.EthernetSwitch",
|
||||
"Id": "Switch1",
|
||||
"SwitchId": "unique switch id",
|
||||
"Name": "Switch1",
|
||||
"Description": "description-as-string",
|
||||
"Manufacturer": "Quanta",
|
||||
"Model": "ly8_rangley",
|
||||
"ManufacturingDate": "02/21/2015 00:00:00",
|
||||
"SerialNumber": "2M220100SL",
|
||||
"PartNumber": "1LY8UZZ0007",
|
||||
"FirmwareName": "ONIE",
|
||||
"FirmwareVersion": "1.1",
|
||||
"Role": "TOR",
|
||||
"Status": {
|
||||
"State": "Enabled",
|
||||
"Health": "OK"
|
||||
},
|
||||
"ACLs": {
|
||||
"@odata.id": "/redfish/v1/EthernetSwitches/Switch1/ACLs"
|
||||
},
|
||||
"Oem": {},
|
||||
"Ports": {
|
||||
"@odata.id": "/redfish/v1/EthernetSwitches/Switch1/Ports"
|
||||
},
|
||||
"Links": {
|
||||
"Chassis": {
|
||||
"@odata.id": "/redfish/v1/Chassis/FabricModule1"
|
||||
},
|
||||
"ManagedBy": [
|
||||
{
|
||||
"@odata.id": "/redfish/v1/Managers/Manager1"
|
||||
}
|
||||
],
|
||||
"Oem": {}
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
{
|
||||
"@odata.context": "/redfish/v1/$metadata#EthernetSwitches",
|
||||
"@odata.id": "/redfish/v1/EthernetSwitches",
|
||||
"@odata.type": "#EthernetSwitchesCollection.EthernetSwitchesCollection",
|
||||
"Name": "Ethernet Switches Collection",
|
||||
"Description": "Network Switches Collection",
|
||||
"Members@odata.count": 1,
|
||||
"Members": [
|
||||
{
|
||||
"@odata.id": "/redfish/v1/EthernetSwitches/Switch1"
|
||||
}
|
||||
]
|
||||
}
|
@ -34,6 +34,9 @@
|
||||
"Fabrics" : {
|
||||
"@odata.id" : "/redfish/v1/Fabrics"
|
||||
},
|
||||
"EthernetSwitches": {
|
||||
"@odata.id": "/redfish/v1/EthernetSwitches"
|
||||
},
|
||||
"Links": {
|
||||
"Sessions": {
|
||||
"@odata.id": "/redfish/v1/SessionService/Sessions"
|
||||
|
@ -22,6 +22,9 @@
|
||||
"Fabrics": {
|
||||
"@odata.id": "/redfish/v1/Fabrics"
|
||||
},
|
||||
"EthernetSwitches": {
|
||||
"@odata.id": "/redfish/v1/EthernetSwitches"
|
||||
},
|
||||
"TelemetryService": {
|
||||
"@odata.id": "/redfish/v1/TelemetryService"
|
||||
},
|
||||
|
@ -22,6 +22,9 @@
|
||||
"Fabrics": {
|
||||
"@odata.id": "/redfish/v1/Fabrics"
|
||||
},
|
||||
"EthernetSwitches": {
|
||||
"@odata.id": "/redfish/v1/EthernetSwitches"
|
||||
},
|
||||
"StorageServices": {
|
||||
"@odata.id": "/redfish/v1/StorageServices"
|
||||
},
|
||||
|
@ -0,0 +1,103 @@
|
||||
# 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
|
||||
|
||||
from sushy.tests.unit import base
|
||||
|
||||
from rsd_lib.resources.v2_1.ethernet_switch import ethernet_switch
|
||||
|
||||
|
||||
class TestEthernetSwtich(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestEthernetSwtich, self).setUp()
|
||||
self.conn = mock.Mock()
|
||||
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_1/ethernet_switch.json',
|
||||
'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.ethernet_switch_inst = ethernet_switch.EthernetSwitch(
|
||||
self.conn,
|
||||
'/redfish/v1/EthernetSwitches/Switch1',
|
||||
redfish_version='1.0.2')
|
||||
|
||||
def test_parse_attributes(self):
|
||||
self.ethernet_switch_inst._parse_attributes()
|
||||
self.assertEqual('1.0.2', self.ethernet_switch_inst.redfish_version)
|
||||
self.assertEqual('Switch1', self.ethernet_switch_inst.identity)
|
||||
self.assertEqual('Switch1', self.ethernet_switch_inst.name)
|
||||
self.assertEqual('description-as-string',
|
||||
self.ethernet_switch_inst.description)
|
||||
self.assertEqual('Quanta', self.ethernet_switch_inst.manufacturer)
|
||||
self.assertEqual('ly8_rangley', self.ethernet_switch_inst.model)
|
||||
self.assertEqual('02/21/2015 00:00:00',
|
||||
self.ethernet_switch_inst.manufacturing_data)
|
||||
self.assertEqual('2M220100SL', self.ethernet_switch_inst.seria_number)
|
||||
self.assertEqual('1LY8UZZ0007', self.ethernet_switch_inst.part_number)
|
||||
self.assertEqual('ONIE', self.ethernet_switch_inst.firmware_name)
|
||||
self.assertEqual('1.1', self.ethernet_switch_inst.firmware_version)
|
||||
self.assertEqual('TOR', self.ethernet_switch_inst.role)
|
||||
self.assertEqual('Enabled', self.ethernet_switch_inst.status.state)
|
||||
self.assertEqual('OK', self.ethernet_switch_inst.status.health)
|
||||
self.assertEqual('/redfish/v1/EthernetSwitches/Switch1/ACLs',
|
||||
self.ethernet_switch_inst.acls)
|
||||
self.assertEqual('/redfish/v1/EthernetSwitches/Switch1/Ports',
|
||||
self.ethernet_switch_inst.ports)
|
||||
self.assertEqual('/redfish/v1/Chassis/FabricModule1',
|
||||
self.ethernet_switch_inst.links.chassis)
|
||||
self.assertEqual(('/redfish/v1/EthernetSwitches/Switch1/Ports',),
|
||||
self.ethernet_switch_inst.links.managed_by)
|
||||
|
||||
|
||||
class TestEthernetSwitchCollection(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestEthernetSwitchCollection, self).setUp()
|
||||
self.conn = mock.Mock()
|
||||
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
||||
'manager_collection.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.ethernet_switch_col = ethernet_switch.EthernetSwitchCollection(
|
||||
self.conn,
|
||||
'redfish/v1/EthernetSwitches',
|
||||
redfish_version='1.0.2')
|
||||
|
||||
def test_parse_attributes(self):
|
||||
self.ethernet_switch_col._parse_attributes()
|
||||
self.assertEqual('1.0.2', self.ethernet_switch_col.redfish_version)
|
||||
self.assertEqual('Ethernet Switches Collection',
|
||||
self.ethernet_switch_col.name)
|
||||
self.assertIn(('/redfish/v1/EthernetSwitches/Switch1',),
|
||||
self.ethernet_switch_col.members_identities)
|
||||
|
||||
@mock.patch.object(ethernet_switch, 'EthernetSwitch', autospec=True)
|
||||
def test_get_member(self, mock_ethernet_switch):
|
||||
self.manager_col.get_member('/redfish/v1/EthernetSwitches/Switch1')
|
||||
|
||||
mock_ethernet_switch.assert_called_once_with(
|
||||
self.ethernet_switch_col._conn,
|
||||
'/redfish/v1/EthernetSwitches/Switch1',
|
||||
redfish_version=self.ethernet_switch_col.redfish_version
|
||||
)
|
||||
|
||||
@mock.patch.object(ethernet_switch, 'EthernetSwitch', autospec=True)
|
||||
def test_get_members(self, mock_ethernet_switch):
|
||||
members = self.ethernet_switch_col.get_members()
|
||||
self.assertEqual(mock_ethernet_switch.call_count, 1)
|
||||
self.assertInstance(members, list)
|
||||
self.assertEqual(1, len(members))
|
@ -19,6 +19,7 @@ import testtools
|
||||
|
||||
from rsd_lib.resources import v2_1
|
||||
from rsd_lib.resources.v2_1.chassis import chassis
|
||||
from rsd_lib.resources.v2_1.ethernet_switch import ethernet_switch
|
||||
from rsd_lib.resources.v2_1.fabric import fabric
|
||||
from rsd_lib.resources.v2_1.manager import manager
|
||||
from rsd_lib.resources.v2_1.node import node
|
||||
@ -46,6 +47,8 @@ class RSDLibV2_1TestCase(testtools.TestCase):
|
||||
self.rsd._storage_service_path)
|
||||
self.assertEqual("/redfish/v1/Fabrics", self.rsd._fabrics_path)
|
||||
self.assertEqual("/redfish/v1/Managers", self.rsd._managers_path)
|
||||
self.assertEqual("/redfish/v1/EthernetSwitches",
|
||||
self.rsd._ethernet_switches_path)
|
||||
|
||||
@mock.patch.object(system, 'SystemCollection', autospec=True)
|
||||
def test_get_system_collection(self, mock_system_collection):
|
||||
@ -134,3 +137,21 @@ class RSDLibV2_1TestCase(testtools.TestCase):
|
||||
self.rsd._conn, 'fake-manager-id',
|
||||
redfish_version=self.rsd.redfish_version
|
||||
)
|
||||
|
||||
@mock.patch.object(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(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
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user