From 81cb4f20a1f94c22adabb6840bc86c2909f1a444 Mon Sep 17 00:00:00 2001 From: monokai <2536818783@qq.com> Date: Mon, 14 Jan 2019 18:02:11 +0800 Subject: [PATCH] Complete the fabrics switch resource Change-Id: I216daedd80911cb2aade55e251a8d6219c760b64 --- rsd_lib/resources/v2_1/fabric/switch.py | 36 ++++++++++++++++++- .../unit/resources/v2_1/fabric/test_switch.py | 13 +++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/rsd_lib/resources/v2_1/fabric/switch.py b/rsd_lib/resources/v2_1/fabric/switch.py index a0ca067..bcc9521 100644 --- a/rsd_lib/resources/v2_1/fabric/switch.py +++ b/rsd_lib/resources/v2_1/fabric/switch.py @@ -16,6 +16,7 @@ import logging from sushy.resources import base +from sushy import utils from rsd_lib import utils as rsd_lib_utils @@ -32,8 +33,25 @@ class PortsField(base.CompositeField): identity = base.Field('@odata.id') -class Switch(base.ResourceBase): +class LinksField(base.CompositeField): + chassis = base.Field("Chassis", adapter=utils.get_members_identities) + +class SwitchResetField(base.CompositeField): + target = base.Field("target") + """The switch reset target""" + + reset_type_allowable_values = base.Field("ResetType@Redfish." + "AllowableValues") + """The switch reset reset type reset allowable values""" + + +class ActionsField(base.CompositeField): + switch_reset = SwitchResetField("#Switch.Reset") + """The actions switch reset""" + + +class Switch(base.ResourceBase): identity = base.Field('Id') """The switch identity""" @@ -84,6 +102,13 @@ class Switch(base.ResourceBase): """The switch power state""" ports = PortsField('Ports') + """The switch ports""" + + links = LinksField("Links") + """The switch links""" + + actions = ActionsField("Actions") + """The switch actions""" def __init__(self, connector, identity, redfish_version=None): """A class representing a Switch @@ -96,6 +121,15 @@ class Switch(base.ResourceBase): super(Switch, self).__init__(connector, identity, redfish_version) + def reset_switch(self): + """A post method to reset switch + + :returns: The uri of the acl rule + """ + data = {"ResetType": "GracefulRestart"} + target_uri = self.actions.switch_reset.target + self._conn.post(target_uri, data=data) + class SwitchCollection(base.ResourceCollectionBase): diff --git a/rsd_lib/tests/unit/resources/v2_1/fabric/test_switch.py b/rsd_lib/tests/unit/resources/v2_1/fabric/test_switch.py index d39425a..34d40ba 100644 --- a/rsd_lib/tests/unit/resources/v2_1/fabric/test_switch.py +++ b/rsd_lib/tests/unit/resources/v2_1/fabric/test_switch.py @@ -55,6 +55,19 @@ class SwitchTestCase(testtools.TestCase): self.assertEqual('On', self.switch_inst.power_state) self.assertEqual('/redfish/v1/Fabrics/PCIe/Switches/1/Ports', self.switch_inst.ports.identity) + self.assertEqual(('/redfish/v1/Chassis/PCIeSwitch1',), self. + switch_inst. + links.chassis) + self.assertEqual("/redfish/v1/Fabrics/PCIe/Switches/1/Actions/Switch." + "Reset", self.switch_inst.actions.switch_reset.target) + self.assertEqual(["GracefulRestart"], self.switch_inst.actions. + switch_reset.reset_type_allowable_values) + + def test_reset_switch(self): + self.switch_inst.reset_switch() + self.switch_inst._conn.post.assert_called_once_with( + '/redfish/v1/Fabrics/PCIe/Switches/1/Actions/Switch.Reset', + data={"ResetType": "GracefulRestart"}) class SwitchCollectionTestCase(testtools.TestCase):