Enable ethernet switch resource in RSD 2.3

Change-Id: I2d893a5b949d574a2ef1306d3641a7987d10bdd9
This commit is contained in:
Lin Yang 2018-12-05 15:26:43 -08:00
parent 0d6cd233b3
commit c73bef5a96
5 changed files with 99 additions and 12 deletions

View File

@ -16,6 +16,7 @@
from sushy.resources import base
from rsd_lib.resources import v2_2
from rsd_lib.resources.v2_3.ethernet_switch import ethernet_switch
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
@ -95,3 +96,27 @@ class RSDLibV2_3(v2_2.RSDLibV2_2):
return fabric.Fabric(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)

View File

@ -15,8 +15,8 @@
import logging
from rsd_lib.resources.v2_1.ethernet_switch import ethernet_switch\
as v2_1_ethernet_switch
from rsd_lib.resources.v2_2.ethernet_switch import ethernet_switch\
as v2_2_ethernet_switch
from sushy.resources import base
from rsd_lib import utils as rsd_lib_utils
@ -61,7 +61,7 @@ class TransmissionSelectionField(base.ListField):
'TrafficClass', adapter=rsd_lib_utils.int_or_none)
class EthernetSwitch(v2_1_ethernet_switch.EthernetSwitch):
class EthernetSwitch(v2_2_ethernet_switch.EthernetSwitch):
class_to_priority_mapping = ClassToPriorityMappingField(
'ClassToPriorityMapping')
"""The ethernet switch class to priority mapping"""
@ -95,3 +95,23 @@ class EthernetSwitch(v2_1_ethernet_switch.EthernetSwitch):
transmission_selection = TransmissionSelectionField(
'TransmissionSelection')
"""The ethernet switch transmission selection"""
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)

View File

@ -11,8 +11,8 @@
# under the License.
import json
import mock
import testtools
from sushy.tests.unit import base
@ -131,3 +131,45 @@ class TestEthernetSwtich(base.TestCase):
self.assertEqual(2,
self.ethernet_switch_inst.
transmission_selection[1].traffic_class)
class EthernetSwitchCollectionTestCase(testtools.TestCase):
def setUp(self):
super(EthernetSwitchCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'ethernet_switch_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.assertEqual(('/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.ethernet_switch_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.assertIsInstance(members, list)
self.assertEqual(1, len(members))

View File

@ -19,10 +19,10 @@ 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 import v2_3
from rsd_lib.resources.v2_3.ethernet_switch import ethernet_switch \
as v2_3_ethernet_switch
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 \
@ -137,7 +137,7 @@ class RSDLibV2_3TestCase(testtools.TestCase):
redfish_version=self.rsd.redfish_version
)
@mock.patch.object(v2_2_ethernet_switch,
@mock.patch.object(v2_3_ethernet_switch,
'EthernetSwitchCollection',
autospec=True)
def test_get_ethernet_switch_collection(self,
@ -147,7 +147,7 @@ class RSDLibV2_3TestCase(testtools.TestCase):
self.rsd._conn, '/redfish/v1/EthernetSwitches',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_2_ethernet_switch, 'EthernetSwitch', autospec=True)
@mock.patch.object(v2_3_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(

View File

@ -19,9 +19,9 @@ 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.ethernet_switch import ethernet_switch \
as v2_3_ethernet_switch
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 \
@ -137,7 +137,7 @@ class RSDLibV2_3TestCase(testtools.TestCase):
redfish_version=self.rsd.redfish_version
)
@mock.patch.object(v2_2_ethernet_switch,
@mock.patch.object(v2_3_ethernet_switch,
'EthernetSwitchCollection',
autospec=True)
def test_get_ethernet_switch_collection(self,
@ -147,7 +147,7 @@ class RSDLibV2_3TestCase(testtools.TestCase):
self.rsd._conn, '/redfish/v1/EthernetSwitches',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_2_ethernet_switch, 'EthernetSwitch', autospec=True)
@mock.patch.object(v2_3_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(