Add ThermalZone reference instance in chassis
Change-Id: Ie91278c04e4f0ea27881f01961138574a236a2cc
This commit is contained in:
parent
4e29ceb539
commit
879ec9adbd
@ -17,6 +17,7 @@ from sushy.resources import base
|
|||||||
from sushy import utils
|
from sushy import utils
|
||||||
|
|
||||||
from rsd_lib.resources.v2_1.chassis import power_zone
|
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
|
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(),
|
self._conn, self._get_power_zone_collection_path(),
|
||||||
redfish_version=self.redfish_version)
|
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):
|
def update(self, asset_tag=None, location_id=None):
|
||||||
"""Update AssetTag and Location->Id properties
|
"""Update AssetTag and Location->Id properties
|
||||||
|
|
||||||
|
@ -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 chassis
|
||||||
from rsd_lib.resources.v2_1.chassis import power_zone
|
from rsd_lib.resources.v2_1.chassis import power_zone
|
||||||
|
from rsd_lib.resources.v2_1.chassis import thermal_zone
|
||||||
|
|
||||||
|
|
||||||
class TestChassis(base.TestCase):
|
class TestChassis(base.TestCase):
|
||||||
@ -83,7 +84,7 @@ class TestChassis(base.TestCase):
|
|||||||
result = self.chassis_inst._get_power_zone_collection_path()
|
result = self.chassis_inst._get_power_zone_collection_path()
|
||||||
self.assertEqual(expected, result)
|
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.chassis_inst._json.pop('PowerZones')
|
||||||
self.assertRaisesRegex(
|
self.assertRaisesRegex(
|
||||||
exceptions.MissingAttributeError, 'attribute PowerZones',
|
exceptions.MissingAttributeError, 'attribute PowerZones',
|
||||||
@ -135,6 +136,63 @@ class TestChassis(base.TestCase):
|
|||||||
self.assertIsInstance(self.chassis_inst.power_zones,
|
self.assertIsInstance(self.chassis_inst.power_zones,
|
||||||
power_zone.PowerZoneCollection)
|
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):
|
def test_update(self):
|
||||||
self.chassis_inst.update(asset_tag='Rack#1', location_id='1234')
|
self.chassis_inst.update(asset_tag='Rack#1', location_id='1234')
|
||||||
self.chassis_inst._conn.patch.assert_called_once_with(
|
self.chassis_inst._conn.patch.assert_called_once_with(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user