From d9c59bba766fa73328cad83348ebda5a2956cc48 Mon Sep 17 00:00:00 2001 From: Lin Yang Date: Fri, 14 Dec 2018 14:47:01 -0800 Subject: [PATCH] Add method to update chassis properties Change-Id: Ibb07235b93c003e58e63dc6f6679bfbc92f43a81 --- rsd_lib/resources/v2_1/chassis/chassis.py | 24 ++++++++++++++++ .../resources/v2_1/chassis/test_chassis.py | 28 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/rsd_lib/resources/v2_1/chassis/chassis.py b/rsd_lib/resources/v2_1/chassis/chassis.py index 9a40d1a..81e5bc7 100644 --- a/rsd_lib/resources/v2_1/chassis/chassis.py +++ b/rsd_lib/resources/v2_1/chassis/chassis.py @@ -132,6 +132,30 @@ class Chassis(base.ResourceBase): """ super(Chassis, self).__init__(connector, identity, redfish_version) + def update(self, asset_tag=None, location_id=None): + """Update AssetTag and Location->Id properties + + :param asset_tag: The user assigned asset tag for this chassis + :param location_id: The user assigned location id for this chassis. + It can be changed only for a Rack Chassis + """ + + data = {} + + if asset_tag is not None: + data['AssetTag'] = asset_tag + + if location_id is not None: + data['Oem'] = { + "Intel_RackScale": { + "Location": { + "Id": location_id + } + } + } + + self._conn.patch(self.path, data=data) + class ChassisCollection(base.ResourceCollectionBase): @property diff --git a/rsd_lib/tests/unit/resources/v2_1/chassis/test_chassis.py b/rsd_lib/tests/unit/resources/v2_1/chassis/test_chassis.py index 5072db6..650f76d 100644 --- a/rsd_lib/tests/unit/resources/v2_1/chassis/test_chassis.py +++ b/rsd_lib/tests/unit/resources/v2_1/chassis/test_chassis.py @@ -77,6 +77,34 @@ class TestChassis(base.TestCase): self.assertEqual('Unique ID', self.chassis_inst.oem.uuid) self.assertEqual('54.348103, 18.645172', self.chassis_inst.oem.geo_tag) + def test_update(self): + self.chassis_inst.update(asset_tag='Rack#1', location_id='1234') + self.chassis_inst._conn.patch.assert_called_once_with( + '/redfish/v1/Chassis/chassis1', + data={ + "AssetTag": "Rack#1", + "Oem": { + "Intel_RackScale": { + "Location": { + "Id": "1234"}}}}) + + self.chassis_inst._conn.patch.reset_mock() + self.chassis_inst.update(asset_tag='Rack#1') + self.chassis_inst._conn.patch.assert_called_once_with( + '/redfish/v1/Chassis/chassis1', + data={ + "AssetTag": "Rack#1"}) + + self.chassis_inst._conn.patch.reset_mock() + self.chassis_inst.update(location_id='1234') + self.chassis_inst._conn.patch.assert_called_once_with( + '/redfish/v1/Chassis/chassis1', + data={ + "Oem": { + "Intel_RackScale": { + "Location": { + "Id": "1234"}}}}) + class TestChassisCollection(base.TestCase):