Keystone::Region observe reality implementation

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

Also, translation rule resolve has been added for parent_region
property.

implements bp get-reality-for-resources

Change-Id: I5f480cdacffb639e1d176ea5c8e9e13dbe24ff83
changes/25/301025/3
Peter Razumovsky 7 years ago
parent f5291d5781
commit 96cec395b9

@ -18,6 +18,7 @@ from heat.engine import constraints
from heat.engine import properties
from heat.engine import resource
from heat.engine import support
from heat.engine import translation
class KeystoneRegion(resource.Resource):
@ -68,6 +69,17 @@ class KeystoneRegion(resource.Resource):
)
}
def translation_rules(self, properties):
return [
translation.TranslationRule(
properties,
translation.TranslationRule.RESOLVE,
[self.PARENT_REGION],
client_plugin=self.client_plugin(),
finder='get_region_id'
)
]
def client(self):
return super(KeystoneRegion, self).client().client
@ -98,6 +110,13 @@ class KeystoneRegion(resource.Resource):
enabled=enabled
)
def parse_live_resource_data(self, resource_properties, resource_data):
return {
self.DESCRIPTION: resource_data.get(self.DESCRIPTION),
self.ENABLED: resource_data.get(self.ENABLED),
self.PARENT_REGION: resource_data.get('parent_region_id')
}
def resource_mapping():
return {

@ -145,3 +145,23 @@ class KeystoneRegionTest(common.HeatTestCase):
enabled=prop_diff[region.KeystoneRegion.ENABLED],
parent_region='test_parent_region'
)
def test_region_get_live_state(self):
self.test_region.resource_id = '477e8273-60a7-4c41-b683-fdb0bc7cd151'
mock_dict = mock.MagicMock()
mock_dict.to_dict.return_value = {
"parent_region_id": None,
"enabled": True,
"id": "79e4d02f8b454a7885c413d5d4297813",
"links": {"self": "link"},
"description": ""
}
self.regions.get.return_value = mock_dict
reality = self.test_region.get_live_state(self.test_region.properties)
expected = {
"parent_region": None,
"enabled": True,
"description": ""
}
self.assertEqual(expected, reality)

Loading…
Cancel
Save