Add ThermalZone reference instance in chassis

Change-Id: Ie91278c04e4f0ea27881f01961138574a236a2cc
This commit is contained in:
Lin Yang 2018-12-17 22:37:46 -08:00
parent 4e29ceb539
commit 879ec9adbd
2 changed files with 76 additions and 1 deletions

View File

@ -17,6 +17,7 @@ from sushy.resources import base
from sushy import utils
from rsd_lib.resources.v2_1.chassis import power_zone
from rsd_lib.resources.v2_1.chassis import thermal_zone
from rsd_lib import utils as rsd_lib_utils
@ -149,6 +150,22 @@ class Chassis(base.ResourceBase):
self._conn, self._get_power_zone_collection_path(),
redfish_version=self.redfish_version)
def _get_thermal_zone_collection_path(self):
"""Helper function to find the ThermalZoneCollection path"""
return utils.get_sub_resource_path_by(self, 'ThermalZones')
@property
@utils.cache_it
def thermal_zones(self):
"""Property to provide reference to `ThermalZoneCollection` instance
It is calculated once when it is queried for the first time. On
refresh, this property is reset.
"""
return thermal_zone.ThermalZoneCollection(
self._conn, self._get_thermal_zone_collection_path(),
redfish_version=self.redfish_version)
def update(self, asset_tag=None, location_id=None):
"""Update AssetTag and Location->Id properties

View File

@ -18,6 +18,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_zone
from rsd_lib.resources.v2_1.chassis import thermal_zone
class TestChassis(base.TestCase):
@ -83,7 +84,7 @@ class TestChassis(base.TestCase):
result = self.chassis_inst._get_power_zone_collection_path()
self.assertEqual(expected, result)
def test__get_power_zone_collection_path_missing_processors_attr(self):
def test__get_power_zone_collection_path_missing_power_zone_attr(self):
self.chassis_inst._json.pop('PowerZones')
self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute PowerZones',
@ -135,6 +136,63 @@ class TestChassis(base.TestCase):
self.assertIsInstance(self.chassis_inst.power_zones,
power_zone.PowerZoneCollection)
def test__get_thermal_zone_collection_path(self):
expected = '/redfish/v1/Chassis/Rack1/ThermalZones'
result = self.chassis_inst._get_thermal_zone_collection_path()
self.assertEqual(expected, result)
def test__get_thermal_zone_collection_path_missing_thermal_zone_attr(self):
self.chassis_inst._json.pop('ThermalZones')
self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute ThermalZones',
self.chassis_inst._get_thermal_zone_collection_path)
def test_thermal_zones(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_1/'
'thermal_zone_collection.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_thermal_zones = self.chassis_inst.thermal_zones
# | THEN |
self.assertIsInstance(actual_thermal_zones,
thermal_zone.ThermalZoneCollection)
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.assertIs(actual_thermal_zones,
self.chassis_inst.thermal_zones)
self.conn.get.return_value.json.assert_not_called()
def test_thermal_zones_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_1/'
'thermal_zone_collection.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.chassis_inst.thermal_zones,
thermal_zone.ThermalZoneCollection)
# 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_zone_collection.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.chassis_inst.thermal_zones,
thermal_zone.ThermalZoneCollection)
def test_update(self):
self.chassis_inst.update(asset_tag='Rack#1', location_id='1234')
self.chassis_inst._conn.patch.assert_called_once_with(