Keystone::Endpoint observe reality implementation

Add override parse_live_resource_data method implementation for
OS::Keystone::Endpoint resource.

Also, add translation rule Resolve for correct handling
service property.

implements bp get-reality-for-resources

Change-Id: I9fba6356d57243d24593c27d81050f0821f96df7
changes/73/300973/4
Peter Razumovsky 7 years ago
parent 53aca307bf
commit f7a0cd4184

@ -92,7 +92,14 @@ class KeystoneEndpoint(resource.Resource):
[self.SERVICE],
client_plugin=self.client_plugin(),
finder='get_service_id'
)
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.REGION],
client_plugin=self.client_plugin(),
finder='get_region_id'
),
]
def client(self):
@ -138,6 +145,16 @@ class KeystoneEndpoint(resource.Resource):
name=name,
enabled=enabled)
def parse_live_resource_data(self, resource_properties, resource_data):
endpoint_reality = {}
endpoint_reality.update(
{self.SERVICE: resource_data.get('service_id'),
self.REGION: resource_data.get('region_id')})
for key in (set(self.PROPERTIES) - {self.SERVICE, self.REGION}):
endpoint_reality.update({key: resource_data.get(key)})
return endpoint_reality
def resource_mapping():
return {

@ -375,3 +375,30 @@ class KeystoneEndpointTest(common.HeatTestCase):
self.endpoints.get.return_value = mock_endpoint
attrs = rsrc._show_resource()
self.assertEqual({'attr': 'val'}, attrs)
def test_get_live_state(self):
rsrc = self._setup_endpoint_resource('test_get_live_state')
mock_endpoint = mock.Mock()
mock_endpoint.to_dict.return_value = {
'region_id': 'RegionOne',
'links': {'self': 'some_link'},
'url': 'http://127.0.0.1:8004/v1/1234',
'region': 'RegionOne',
'enabled': True,
'interface': 'admin',
'service_id': '934f10ea63c24d82a8d9370cc0a1cb3b',
'id': '7f1944ae8c524e2799119b5f2dcf9781',
'name': 'fake'}
self.endpoints.get.return_value = mock_endpoint
reality = rsrc.get_live_state(rsrc.properties)
expected = {
'region': 'RegionOne',
'enabled': True,
'interface': 'admin',
'service': '934f10ea63c24d82a8d9370cc0a1cb3b',
'name': 'fake',
'url': 'http://127.0.0.1:8004/v1/1234'
}
self.assertEqual(expected, reality)

Loading…
Cancel
Save