Merge "Complete the fabrics switch resource"

This commit is contained in:
Zuul 2019-01-22 02:27:29 +00:00 committed by Gerrit Code Review
commit 2eee08c0ce
2 changed files with 48 additions and 1 deletions

View File

@ -16,6 +16,7 @@
import logging import logging
from sushy.resources import base from sushy.resources import base
from sushy import utils
from rsd_lib import utils as rsd_lib_utils from rsd_lib import utils as rsd_lib_utils
@ -32,8 +33,25 @@ class PortsField(base.CompositeField):
identity = base.Field('@odata.id') 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') identity = base.Field('Id')
"""The switch identity""" """The switch identity"""
@ -84,6 +102,13 @@ class Switch(base.ResourceBase):
"""The switch power state""" """The switch power state"""
ports = PortsField('Ports') 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): def __init__(self, connector, identity, redfish_version=None):
"""A class representing a Switch """A class representing a Switch
@ -96,6 +121,15 @@ class Switch(base.ResourceBase):
super(Switch, self).__init__(connector, identity, super(Switch, self).__init__(connector, identity,
redfish_version) 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): class SwitchCollection(base.ResourceCollectionBase):

View File

@ -55,6 +55,19 @@ class SwitchTestCase(testtools.TestCase):
self.assertEqual('On', self.switch_inst.power_state) self.assertEqual('On', self.switch_inst.power_state)
self.assertEqual('/redfish/v1/Fabrics/PCIe/Switches/1/Ports', self.assertEqual('/redfish/v1/Fabrics/PCIe/Switches/1/Ports',
self.switch_inst.ports.identity) 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): class SwitchCollectionTestCase(testtools.TestCase):