Add PowerZone reference instance in chassis
Change-Id: I3fe84d3f2dbbbfc112a0d3d7e6739912ead75edf
This commit is contained in:
parent
3764c4d8d0
commit
a30a6b2320
@ -16,6 +16,7 @@
|
|||||||
from sushy.resources import base
|
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 import utils as rsd_lib_utils
|
from rsd_lib import utils as rsd_lib_utils
|
||||||
|
|
||||||
|
|
||||||
@ -132,6 +133,22 @@ class Chassis(base.ResourceBase):
|
|||||||
"""
|
"""
|
||||||
super(Chassis, self).__init__(connector, identity, redfish_version)
|
super(Chassis, self).__init__(connector, identity, redfish_version)
|
||||||
|
|
||||||
|
def _get_power_zone_collection_path(self):
|
||||||
|
"""Helper function to find the PowerZoneCollection path"""
|
||||||
|
return utils.get_sub_resource_path_by(self, 'PowerZones')
|
||||||
|
|
||||||
|
@property
|
||||||
|
@utils.cache_it
|
||||||
|
def power_zones(self):
|
||||||
|
"""Property to provide reference to `PowerZoneCollection` instance
|
||||||
|
|
||||||
|
It is calculated once when it is queried for the first time. On
|
||||||
|
refresh, this property is reset.
|
||||||
|
"""
|
||||||
|
return power_zone.PowerZoneCollection(
|
||||||
|
self._conn, self._get_power_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
|
||||||
|
|
||||||
|
@ -11,12 +11,13 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
|
from sushy import exceptions
|
||||||
from sushy.tests.unit import base
|
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
|
||||||
|
|
||||||
|
|
||||||
class TestChassis(base.TestCase):
|
class TestChassis(base.TestCase):
|
||||||
@ -77,6 +78,63 @@ class TestChassis(base.TestCase):
|
|||||||
self.assertEqual('Unique ID', self.chassis_inst.oem.uuid)
|
self.assertEqual('Unique ID', self.chassis_inst.oem.uuid)
|
||||||
self.assertEqual('54.348103, 18.645172', self.chassis_inst.oem.geo_tag)
|
self.assertEqual('54.348103, 18.645172', self.chassis_inst.oem.geo_tag)
|
||||||
|
|
||||||
|
def test__get_power_zone_collection_path(self):
|
||||||
|
expected = '/redfish/v1/Chassis/Rack1/PowerZones'
|
||||||
|
result = self.chassis_inst._get_power_zone_collection_path()
|
||||||
|
self.assertEqual(expected, result)
|
||||||
|
|
||||||
|
def test__get_power_zone_collection_path_missing_processors_attr(self):
|
||||||
|
self.chassis_inst._json.pop('PowerZones')
|
||||||
|
self.assertRaisesRegex(
|
||||||
|
exceptions.MissingAttributeError, 'attribute PowerZones',
|
||||||
|
self.chassis_inst._get_power_zone_collection_path)
|
||||||
|
|
||||||
|
def test_power_zones(self):
|
||||||
|
# | GIVEN |
|
||||||
|
self.conn.get.return_value.json.reset_mock()
|
||||||
|
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
||||||
|
'power_zone_collection.json', 'r') as f:
|
||||||
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
|
# | WHEN |
|
||||||
|
actual_power_zones = self.chassis_inst.power_zones
|
||||||
|
# | THEN |
|
||||||
|
self.assertIsInstance(actual_power_zones,
|
||||||
|
power_zone.PowerZoneCollection)
|
||||||
|
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_power_zones,
|
||||||
|
self.chassis_inst.power_zones)
|
||||||
|
self.conn.get.return_value.json.assert_not_called()
|
||||||
|
|
||||||
|
def test_power_zones_on_refresh(self):
|
||||||
|
# | GIVEN |
|
||||||
|
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
||||||
|
'power_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.power_zones,
|
||||||
|
power_zone.PowerZoneCollection)
|
||||||
|
|
||||||
|
# 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/'
|
||||||
|
'power_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.power_zones,
|
||||||
|
power_zone.PowerZoneCollection)
|
||||||
|
|
||||||
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