Add Thermal reference instance in chassis
Change-Id: I42309659e12c3f27a5e516cfcf0e16035fc93374
This commit is contained in:
parent
9135c6615c
commit
91774d44e2
@ -18,6 +18,7 @@ from sushy import utils
|
||||
|
||||
from rsd_lib.resources.v2_1.chassis import power
|
||||
from rsd_lib.resources.v2_1.chassis import power_zone
|
||||
from rsd_lib.resources.v2_1.chassis import thermal
|
||||
from rsd_lib.resources.v2_1.chassis import thermal_zone
|
||||
from rsd_lib import utils as rsd_lib_utils
|
||||
|
||||
@ -183,6 +184,22 @@ class Chassis(base.ResourceBase):
|
||||
self._conn, self._get_thermal_zone_collection_path(),
|
||||
redfish_version=self.redfish_version)
|
||||
|
||||
def _get_thermal_path(self):
|
||||
"""Helper function to find the Thermal path"""
|
||||
return utils.get_sub_resource_path_by(self, 'Thermal')
|
||||
|
||||
@property
|
||||
@utils.cache_it
|
||||
def thermal(self):
|
||||
"""Property to provide reference to `Thermal` instance
|
||||
|
||||
It is calculated once when it is queried for the first time. On
|
||||
refresh, this property is reset.
|
||||
"""
|
||||
return thermal.Thermal(
|
||||
self._conn, self._get_thermal_path(),
|
||||
redfish_version=self.redfish_version)
|
||||
|
||||
def update(self, asset_tag=None, location_id=None):
|
||||
"""Update AssetTag and Location->Id properties
|
||||
|
||||
|
@ -19,6 +19,7 @@ from sushy.tests.unit import base
|
||||
from rsd_lib.resources.v2_1.chassis import chassis
|
||||
from rsd_lib.resources.v2_1.chassis import power
|
||||
from rsd_lib.resources.v2_1.chassis import power_zone
|
||||
from rsd_lib.resources.v2_1.chassis import thermal
|
||||
from rsd_lib.resources.v2_1.chassis import thermal_zone
|
||||
|
||||
|
||||
@ -248,6 +249,59 @@ class TestChassis(base.TestCase):
|
||||
self.assertIsInstance(self.chassis_inst.thermal_zones,
|
||||
thermal_zone.ThermalZoneCollection)
|
||||
|
||||
def test__get_thermal_path(self):
|
||||
expected = '/redfish/v1/Chassis/Rack1/Thermal'
|
||||
result = self.chassis_inst._get_thermal_path()
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
def test__get_thermal_path_missing_thermal_attr(self):
|
||||
self.chassis_inst._json.pop('Thermal')
|
||||
self.assertRaisesRegex(
|
||||
exceptions.MissingAttributeError, 'attribute Thermal',
|
||||
self.chassis_inst._get_thermal_path)
|
||||
|
||||
def test_thermal(self):
|
||||
# | GIVEN |
|
||||
self.conn.get.return_value.json.reset_mock()
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
||||
'thermal.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
# | WHEN |
|
||||
actual_thermal = self.chassis_inst.thermal
|
||||
# | THEN |
|
||||
self.assertIsInstance(actual_thermal, thermal.Thermal)
|
||||
self.conn.get.return_value.json.assert_called_once_with()
|
||||
|
||||
# reset mock
|
||||
self.conn.get.return_value.json.reset_mock()
|
||||
# | WHEN & THEN |
|
||||
# tests for same object on invoking subsequently
|
||||
self.assertIsInstance(actual_thermal, thermal.Thermal)
|
||||
self.conn.get.return_value.json.assert_not_called()
|
||||
|
||||
def test_thermal_on_refresh(self):
|
||||
# | GIVEN |
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
||||
'thermal.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
# | WHEN & THEN |
|
||||
self.assertIsInstance(self.chassis_inst.thermal, thermal.Thermal)
|
||||
|
||||
# On refreshing the chassis instance...
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
||||
'chassis.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.chassis_inst.invalidate()
|
||||
self.chassis_inst.refresh(force=False)
|
||||
|
||||
# | GIVEN |
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
||||
'thermal.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
# | WHEN & THEN |
|
||||
self.assertIsInstance(self.chassis_inst.thermal, thermal.Thermal)
|
||||
|
||||
def test_update(self):
|
||||
self.chassis_inst.update(asset_tag='Rack#1', location_id='1234')
|
||||
self.chassis_inst._conn.patch.assert_called_once_with(
|
||||
|
Loading…
x
Reference in New Issue
Block a user