Keystone::Group observe reality implementation

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

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

implements bp get-reality-for-resources

Change-Id: I9bc239c80350fe27c92ca52158639761ba594efc
changes/82/300982/10
Peter Razumovsky 7 years ago
parent 708bda5152
commit c2cde5a286

@ -17,6 +17,7 @@ from heat.engine import properties
from heat.engine import resource
from heat.engine.resources.openstack.keystone import role_assignments
from heat.engine import support
from heat.engine import translation
class KeystoneGroup(resource.Resource,
@ -63,6 +64,17 @@ class KeystoneGroup(resource.Resource,
)
}
def translation_rules(self, properties):
return [
translation.TranslationRule(
properties,
translation.TranslationRule.RESOLVE,
[self.DOMAIN],
client_plugin=self.client_plugin(),
finder='get_domain_id'
)
]
properties_schema.update(
role_assignments.KeystoneRoleAssignmentMixin.mixin_properties_schema)
@ -77,8 +89,7 @@ class KeystoneGroup(resource.Resource,
group_name = (self.properties[self.NAME] or
self.physical_resource_name())
description = self.properties[self.DESCRIPTION]
domain = self.client_plugin().get_domain_id(
self.properties[self.DOMAIN])
domain = self.properties[self.DOMAIN]
group = self.client().groups.create(
name=group_name,
@ -99,13 +110,12 @@ class KeystoneGroup(resource.Resource,
description = prop_diff.get(self.DESCRIPTION)
domain = (prop_diff.get(self.DOMAIN) or
self.properties[self.DOMAIN])
domain_id = self.client_plugin().get_domain_id(domain)
self.client().groups.update(
group=self.resource_id,
name=name,
description=description,
domain_id=domain_id)
domain_id=domain)
self.update_assignment(prop_diff=prop_diff,
group_id=self.resource_id)
@ -115,6 +125,14 @@ class KeystoneGroup(resource.Resource,
with self.client_plugin().ignore_not_found:
self.client().groups.delete(self.resource_id)
def parse_live_resource_data(self, resource_properties, resource_data):
return {
self.NAME: resource_data.get(self.NAME),
self.DESCRIPTION: resource_data.get(self.DESCRIPTION),
self.DOMAIN: resource_data.get('domain_id'),
self.ROLES: self.parse_list_assignments(group_id=self.resource_id)
}
def resource_mapping():
return {

@ -59,6 +59,7 @@ class KeystoneGroupTest(common.HeatTestCase):
return_value=fakes.FakeKeystoneClient(
client=self.keystoneclient))
self.groups = self.keystoneclient.groups
self.role_assignments = self.keystoneclient.role_assignments
# Mock client plugin
def _side_effect(value):
@ -305,3 +306,36 @@ class KeystoneGroupTest(common.HeatTestCase):
self.groups.get.return_value = group
res = self.test_group._show_resource()
self.assertEqual({'attr': 'val'}, res)
def test_get_live_state(self):
group = mock.Mock()
group.to_dict.return_value = {
'id': '48ee1f94b77047e592de55a4934c198c',
'domain_id': 'default',
'name': 'fake',
'links': {'self': 'some_link'},
'description': ''}
roles = mock.MagicMock()
roles.to_dict.return_value = {
'scope': {
'project': {'id': 'fc0fe982401643368ff2eb11d9ca70f1'}},
'role': {'id': '3b8b253648f44256a457a5073b78021d'},
'group': {'id': '4147558a763046cfb68fb870d58ef4cf'}}
self.role_assignments.list.return_value = [roles]
self.groups.get.return_value = group
self.test_group.resource_id = '1234'
reality = self.test_group.get_live_state(self.test_group.properties)
expected = {
'domain': 'default',
'name': 'fake',
'description': '',
'roles': [{
'role': '3b8b253648f44256a457a5073b78021d',
'project': 'fc0fe982401643368ff2eb11d9ca70f1',
'domain': None
}]
}
self.assertEqual(set(expected.keys()), set(reality.keys()))
for key in expected:
self.assertEqual(expected[key], reality[key])

Loading…
Cancel
Save