Keystone::Project observe reality implementation
Add override parse_live_resource_data method implementation for OS::Keystone::Project resource. Also, add translation rule Resolve for correct handling domain and parent property. implements bp get-reality-for-resources Change-Id: Iaf24fbd920da7a27b497a7da7a47cedfa4c1b887
This commit is contained in:
parent
8496d98d70
commit
8065962102
|
@ -16,6 +16,7 @@ from heat.engine import constraints
|
||||||
from heat.engine import properties
|
from heat.engine import properties
|
||||||
from heat.engine import resource
|
from heat.engine import resource
|
||||||
from heat.engine import support
|
from heat.engine import support
|
||||||
|
from heat.engine import translation
|
||||||
|
|
||||||
|
|
||||||
class KeystoneProject(resource.Resource):
|
class KeystoneProject(resource.Resource):
|
||||||
|
@ -76,6 +77,24 @@ class KeystoneProject(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'
|
||||||
|
),
|
||||||
|
translation.TranslationRule(
|
||||||
|
properties,
|
||||||
|
translation.TranslationRule.RESOLVE,
|
||||||
|
[self.PARENT],
|
||||||
|
client_plugin=self.client_plugin(),
|
||||||
|
finder='get_project_id'
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
def client(self):
|
def client(self):
|
||||||
return super(KeystoneProject, self).client().client
|
return super(KeystoneProject, self).client().client
|
||||||
|
|
||||||
|
@ -83,11 +102,9 @@ class KeystoneProject(resource.Resource):
|
||||||
project_name = (self.properties[self.NAME] or
|
project_name = (self.properties[self.NAME] or
|
||||||
self.physical_resource_name())
|
self.physical_resource_name())
|
||||||
description = self.properties[self.DESCRIPTION]
|
description = self.properties[self.DESCRIPTION]
|
||||||
domain = self.client_plugin().get_domain_id(
|
domain = self.properties[self.DOMAIN]
|
||||||
self.properties[self.DOMAIN])
|
|
||||||
enabled = self.properties[self.ENABLED]
|
enabled = self.properties[self.ENABLED]
|
||||||
pp = self.properties[self.PARENT]
|
parent = self.properties[self.PARENT]
|
||||||
parent = self.client_plugin().get_project_id(pp)
|
|
||||||
|
|
||||||
project = self.client().projects.create(
|
project = self.client().projects.create(
|
||||||
name=project_name,
|
name=project_name,
|
||||||
|
@ -107,18 +124,22 @@ class KeystoneProject(resource.Resource):
|
||||||
|
|
||||||
description = prop_diff.get(self.DESCRIPTION)
|
description = prop_diff.get(self.DESCRIPTION)
|
||||||
enabled = prop_diff.get(self.ENABLED)
|
enabled = prop_diff.get(self.ENABLED)
|
||||||
domain = (prop_diff.get(self.DOMAIN) or
|
domain = prop_diff.get(self.DOMAIN, self.properties[self.DOMAIN])
|
||||||
self.properties[self.DOMAIN])
|
|
||||||
domain_id = self.client_plugin().get_domain_id(domain)
|
|
||||||
|
|
||||||
self.client().projects.update(
|
self.client().projects.update(
|
||||||
project=self.resource_id,
|
project=self.resource_id,
|
||||||
name=name,
|
name=name,
|
||||||
description=description,
|
description=description,
|
||||||
enabled=enabled,
|
enabled=enabled,
|
||||||
domain=domain_id
|
domain=domain
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def parse_live_resource_data(self, resource_properties, resource_data):
|
||||||
|
result = super(KeystoneProject, self).parse_live_resource_data(
|
||||||
|
resource_properties, resource_data)
|
||||||
|
result[self.DOMAIN] = resource_data.get('domain_id')
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def resource_mapping():
|
def resource_mapping():
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -351,3 +351,29 @@ class KeystoneProjectTest(common.HeatTestCase):
|
||||||
self.projects.get.return_value = project
|
self.projects.get.return_value = project
|
||||||
res = self.test_project._show_resource()
|
res = self.test_project._show_resource()
|
||||||
self.assertEqual({'attr': 'val'}, res)
|
self.assertEqual({'attr': 'val'}, res)
|
||||||
|
|
||||||
|
def test_get_live_state(self):
|
||||||
|
project = mock.Mock()
|
||||||
|
project.to_dict.return_value = {
|
||||||
|
"is_domain": False,
|
||||||
|
"description": "",
|
||||||
|
"links": {"self": "link"},
|
||||||
|
"enabled": True,
|
||||||
|
"id": "8cbb746917ee42f08a787e721552e738",
|
||||||
|
"parent_id": "default",
|
||||||
|
"domain_id": "default",
|
||||||
|
"name": "fake"
|
||||||
|
}
|
||||||
|
self.projects.get.return_value = project
|
||||||
|
|
||||||
|
reality = self.test_project.get_live_state(
|
||||||
|
self.test_project.properties)
|
||||||
|
expected = {
|
||||||
|
"description": "",
|
||||||
|
"enabled": True,
|
||||||
|
"domain": "default",
|
||||||
|
"name": "fake"
|
||||||
|
}
|
||||||
|
self.assertEqual(set(expected.keys()), set(reality.keys()))
|
||||||
|
for key in expected:
|
||||||
|
self.assertEqual(expected[key], reality[key])
|
||||||
|
|
Loading…
Reference in New Issue