Mark endpoints in zone as property attribute
Change-Id: I2974c47eebd82bb551c2c01c699ab6c69b28b754
This commit is contained in:
parent
8b46825c09
commit
e16a2af697
@ -63,13 +63,23 @@ class Zone(base.ResourceBase):
|
|||||||
super(Zone, self).__init__(connector, identity,
|
super(Zone, self).__init__(connector, identity,
|
||||||
redfish_version)
|
redfish_version)
|
||||||
|
|
||||||
def get_endpoints(self):
|
@property
|
||||||
|
def endpoints(self):
|
||||||
"""Return a list of Endpoints present in the Zone
|
"""Return a list of Endpoints present in the Zone
|
||||||
|
|
||||||
:returns: A list of Endpoint objects
|
It is calculated once when it is queried for the first time. On
|
||||||
|
refresh, this property is reset.
|
||||||
"""
|
"""
|
||||||
return [endpoint.Endpoint(self._conn, id_, self.redfish_version) for
|
if self._endpoints is None:
|
||||||
id_ in self.links.endpoint_identities]
|
self._endpoints = [
|
||||||
|
endpoint.Endpoint(self._conn, id_, self.redfish_version)
|
||||||
|
for id_ in self.links.endpoint_identities]
|
||||||
|
|
||||||
|
return self._endpoints
|
||||||
|
|
||||||
|
def refresh(self):
|
||||||
|
super(Zone, self).refresh()
|
||||||
|
self._endpoints = None
|
||||||
|
|
||||||
def update(self, endpoints):
|
def update(self, endpoints):
|
||||||
"""Add or remove Endpoints from a Zone
|
"""Add or remove Endpoints from a Zone
|
||||||
|
@ -48,14 +48,54 @@ class ZoneTestCase(testtools.TestCase):
|
|||||||
self.assertEqual('Enabled', self.zone_inst.status.state)
|
self.assertEqual('Enabled', self.zone_inst.status.state)
|
||||||
self.assertEqual('OK', self.zone_inst.status.health)
|
self.assertEqual('OK', self.zone_inst.status.health)
|
||||||
|
|
||||||
def test_get_endpoints(self):
|
def test_endpoints(self):
|
||||||
|
# check for the underneath variable value
|
||||||
|
self.assertIsNone(self.zone_inst._endpoints)
|
||||||
|
# | GIVEN |
|
||||||
self.conn.get.return_value.json.reset_mock()
|
self.conn.get.return_value.json.reset_mock()
|
||||||
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
||||||
'endpoint.json', 'r') as f:
|
'endpoint.json', 'r') as f:
|
||||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
endpoints = self.zone_inst.get_endpoints()
|
# | WHEN |
|
||||||
self.assertEqual('NVMeDrivePF1', endpoints[0].identity)
|
actual_endpoints = self.zone_inst.endpoints
|
||||||
self.assertEqual(2, len(endpoints))
|
# | THEN |
|
||||||
|
self.assertEqual('NVMeDrivePF1', actual_endpoints[0].identity)
|
||||||
|
self.assertEqual(2, len(actual_endpoints))
|
||||||
|
self.conn.get.return_value.json.assert_called_with()
|
||||||
|
|
||||||
|
# reset mock
|
||||||
|
self.conn.get.return_value.json.reset_mock()
|
||||||
|
# | WHEN & THEN |
|
||||||
|
# tests for same object on invoking subsequently
|
||||||
|
self.assertIs(actual_endpoints,
|
||||||
|
self.zone_inst.endpoints)
|
||||||
|
self.conn.get.return_value.json.assert_not_called()
|
||||||
|
|
||||||
|
def test_endpoints_on_refresh(self):
|
||||||
|
# | GIVEN |
|
||||||
|
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
||||||
|
'endpoint.json', 'r') as f:
|
||||||
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
|
# | WHEN & THEN |
|
||||||
|
self.assertEqual('NVMeDrivePF1', self.zone_inst.endpoints[0].identity)
|
||||||
|
self.assertEqual(2, len(self.zone_inst.endpoints))
|
||||||
|
|
||||||
|
# On refreshing the fabric instance...
|
||||||
|
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
||||||
|
'zone.json', 'r') as f:
|
||||||
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
|
self.zone_inst.refresh()
|
||||||
|
|
||||||
|
# | WHEN & THEN |
|
||||||
|
self.assertIsNone(self.zone_inst._endpoints)
|
||||||
|
|
||||||
|
# | GIVEN |
|
||||||
|
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
||||||
|
'endpoint.json', 'r') as f:
|
||||||
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
|
# | WHEN & THEN |
|
||||||
|
self.assertEqual('NVMeDrivePF1', self.zone_inst.endpoints[0].identity)
|
||||||
|
self.assertEqual(2, len(self.zone_inst.endpoints))
|
||||||
|
|
||||||
def test_update(self):
|
def test_update(self):
|
||||||
self.zone_inst.update(
|
self.zone_inst.update(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user