diff --git a/rsd_lib/resources/v2_3/ethernet_switch/__init__.py b/rsd_lib/resources/v2_3/ethernet_switch/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rsd_lib/resources/v2_3/ethernet_switch/ethernet_switch.py b/rsd_lib/resources/v2_3/ethernet_switch/ethernet_switch.py new file mode 100644 index 0000000..d3b3f6a --- /dev/null +++ b/rsd_lib/resources/v2_3/ethernet_switch/ethernet_switch.py @@ -0,0 +1,92 @@ +# 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 rsd_lib.resources.v2_1.ethernet_switch import ethernet_switch\ + as v2_1_ethernet_switch +from sushy.resources import base + +from rsd_lib import utils as rsd_lib_utils + +LOG = logging.getLogger(__name__) + + +class ClassToPriorityMappingField(base.ListField): + priority = base.Field('Priority', adapter=int) + + traffic_class = base.Field('TrafficClass', adapter=int) + + +class PriorityFlowControlField(base.CompositeField): + enabled = base.Field('Enabled', adapter=bool) + + lossless_priorities = base.Field('LosslessPriorities', adapter=list) + + +class PriorityToClassMappingField(base.ListField): + priority = base.Field('Priority', adapter=int) + + traffic_class = base.Field('TrafficClass', adapter=int) + + +class TrafficClassficationField(base.ListField): + port = base.Field('Port', adapter=int) + + protocol = base.Field('Protocol') + + traffic_class = base.Field('TrafficClass', adapter=int) + + +class TransmissionSelectionField(base.ListField): + bandwidth_percent = base.Field('BandwidthPercent', adapter=int) + + traffic_class = base.Field('TrafficClass', adapter=int) + + +class EthernetSwitch(v2_1_ethernet_switch.EthernetSwitch): + class_to_priority_mapping = ClassToPriorityMappingField( + 'ClassToPriorityMapping') + """The ethernet switch class to priority mapping""" + + dcbx_enabled = base.Field('DCBXEnabled', adapter=bool) + """The boolean indicate this dcbx is enabled or not""" + + ets_enabled = base.Field('ETSEnabled', adapter=bool) + """The boolean indicate this etse is enabled or not""" + + lldp_enabled = base.Field('LLDPEnabled', adapter=bool) + """The boolean indicate this lldp is enabled or not""" + + max_acl_number = base.Field('MaxACLNumber') + """The ethernet switch max acl number""" + + metrics = base.Field('Metrics', default=(), + adapter=rsd_lib_utils.get_resource_identity) + """The ethernet switch metrics""" + + priority_flow_control = PriorityFlowControlField('PriorityFlowControl') + """The ethernet switch priority flow control""" + + priority_to_class_mapping = PriorityToClassMappingField( + 'PriorityToClassMapping') + """The ethernet switch priority to class mapping""" + + traffic_classification = TrafficClassficationField('TrafficClassification') + """The ethernet switch traffic classification""" + + transmission_selection = TransmissionSelectionField( + 'TransmissionSelection') + """The ethernet switch transmission selection""" diff --git a/rsd_lib/tests/unit/json_samples/v2_3/ethernet_switch.json b/rsd_lib/tests/unit/json_samples/v2_3/ethernet_switch.json new file mode 100644 index 0000000..0ea0fd2 --- /dev/null +++ b/rsd_lib/tests/unit/json_samples/v2_3/ethernet_switch.json @@ -0,0 +1,103 @@ +{ + "@odata.context": "/redfish/v1/$metadata#EthernetSwitch.EthernetSwitch", + "@odata.id": "/redfish/v1/EthernetSwitches/Switch1", + "@odata.type": "#EthernetSwitch.v1_1_0.EthernetSwitch", + "ACLs": { + "@odata.id": "/redfish/v1/EthernetSwitches/Switch1/ACLs" + }, + "ClassToPriorityMapping": [ + { + "Priority": 5, + "TrafficClass": 1 + }, + { + "Priority": 5, + "TrafficClass": 2 + } + ], + "DCBXEnabled": true, + "Description": "description-as-string", + "ETSEnabled": true, + "FirmwareName": "ONIE", + "FirmwareVersion": "1.1", + "Id": "Switch1", + "LLDPEnabled": true, + "Links": { + "Chassis": { + "@odata.id": "/redfish/v1/Chassis/FabricModule1" + }, + "ManagedBy": [ + { + "@odata.id": "/redfish/v1/Managers/PSME" + } + ], + "Oem": {} + }, + "Manufacturer": "Quanta", + "ManufacturingDate": "02/21/2015 00:00:00", + "MaxACLNumber": 4, + "Metrics": { + "@odata.id": "/redfish/v1/EthernetSwitches/Switch1/Metrics" + }, + "Model": "ly8_rangley", + "Name": "Switch1", + "Oem": {}, + "PartNumber": "1LY8UZZ0007", + "Ports": { + "@odata.id": "/redfish/v1/EthernetSwitches/Switch1/Ports" + }, + "PriorityFlowControl": { + "Enabled": true, + "LosslessPriorities": [ + 0, + 1, + 6, + 7 + ] + }, + "PriorityToClassMapping": [ + { + "Priority": 5, + "TrafficClass": 1 + }, + { + "Priority": 6, + "TrafficClass": 2 + } + ], + "Role": "TOR", + "SerialNumber": "2M220100SL", + "Status": { + "Health": "OK", + "HealthRollup": null, + "State": "Enabled" + }, + "SwitchId": "unique switch id", + "TrafficClassification": [ + { + "Port": 4791, + "Protocol": "UDP", + "TrafficClass": 1 + }, + { + "Port": 860, + "Protocol": "TCP", + "TrafficClass": 2 + }, + { + "Port": 3260, + "Protocol": "TCP", + "TrafficClass": 2 + } + ], + "TransmissionSelection": [ + { + "BandwidthPercent": 60, + "TrafficClass": 1 + }, + { + "BandwidthPercent": 30, + "TrafficClass": 2 + } + ] +} diff --git a/rsd_lib/tests/unit/json_samples/v2_3/ethernet_switch_collection.json b/rsd_lib/tests/unit/json_samples/v2_3/ethernet_switch_collection.json new file mode 100644 index 0000000..15b982a --- /dev/null +++ b/rsd_lib/tests/unit/json_samples/v2_3/ethernet_switch_collection.json @@ -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" + } + ] +} \ No newline at end of file diff --git a/rsd_lib/tests/unit/resources/v2_3/ethernet_switch/__init__.py b/rsd_lib/tests/unit/resources/v2_3/ethernet_switch/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rsd_lib/tests/unit/resources/v2_3/ethernet_switch/test_ethernet_switch.py b/rsd_lib/tests/unit/resources/v2_3/ethernet_switch/test_ethernet_switch.py new file mode 100644 index 0000000..03279a4 --- /dev/null +++ b/rsd_lib/tests/unit/resources/v2_3/ethernet_switch/test_ethernet_switch.py @@ -0,0 +1,136 @@ +# 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_3.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_3/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_date) + 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.assertIsNone(self.ethernet_switch_inst._ports) + self.assertEqual('/redfish/v1/Chassis/FabricModule1', + self.ethernet_switch_inst.links.chassis) + self.assertEqual(('/redfish/v1/Managers/PSME',), + self.ethernet_switch_inst.links.managed_by) + self.assertEqual(5, + self.ethernet_switch_inst. + class_to_priority_mapping[0].priority) + self.assertEqual(1, + self.ethernet_switch_inst. + class_to_priority_mapping[0].traffic_class) + self.assertEqual(5, + self.ethernet_switch_inst. + class_to_priority_mapping[1].priority) + self.assertEqual(2, + self.ethernet_switch_inst. + class_to_priority_mapping[1].traffic_class) + self.assertEqual(True, self.ethernet_switch_inst.dcbx_enabled) + self.assertEqual(True, self.ethernet_switch_inst.ets_enabled) + self.assertEqual(True, self.ethernet_switch_inst.lldp_enabled) + self.assertEqual(4, self.ethernet_switch_inst.max_acl_number) + self.assertEqual('/redfish/v1/EthernetSwitches/Switch1/Metrics', + self.ethernet_switch_inst.metrics) + self.assertEqual(True, + self.ethernet_switch_inst. + priority_flow_control.enabled) + self.assertEqual([0, 1, 6, 7], + self.ethernet_switch_inst. + priority_flow_control.lossless_priorities) + self.assertEqual(5, + self.ethernet_switch_inst. + priority_to_class_mapping[0].priority) + self.assertEqual(1, + self.ethernet_switch_inst. + priority_to_class_mapping[0].traffic_class) + self.assertEqual(6, + self.ethernet_switch_inst. + priority_to_class_mapping[1].priority) + self.assertEqual(2, + self.ethernet_switch_inst. + priority_to_class_mapping[1].traffic_class) + self.assertEqual(4791, + self.ethernet_switch_inst. + traffic_classification[0].port) + self.assertEqual('UDP', + self.ethernet_switch_inst. + traffic_classification[0].protocol) + self.assertEqual(1, + self.ethernet_switch_inst. + traffic_classification[0].traffic_class) + self.assertEqual(860, + self.ethernet_switch_inst. + traffic_classification[1].port) + self.assertEqual('TCP', + self.ethernet_switch_inst. + traffic_classification[1].protocol) + self.assertEqual(2, + self.ethernet_switch_inst. + traffic_classification[1].traffic_class) + self.assertEqual(3260, + self.ethernet_switch_inst. + traffic_classification[2].port) + self.assertEqual('TCP', + self.ethernet_switch_inst. + traffic_classification[2].protocol) + self.assertEqual(2, + self.ethernet_switch_inst. + traffic_classification[2].traffic_class) + self.assertEqual(60, + self.ethernet_switch_inst. + transmission_selection[0].bandwidth_percent) + self.assertEqual(1, + self.ethernet_switch_inst. + transmission_selection[0].traffic_class) + self.assertEqual(30, + self.ethernet_switch_inst. + transmission_selection[1].bandwidth_percent) + self.assertEqual(2, + self.ethernet_switch_inst. + transmission_selection[1].traffic_class)