Merge "Add attributes schema for OS::Keystone::Project"
This commit is contained in:
commit
b360e3fcaf
@ -12,6 +12,7 @@
|
||||
# under the License.
|
||||
|
||||
from heat.common.i18n import _
|
||||
from heat.engine import attributes
|
||||
from heat.engine import constraints
|
||||
from heat.engine import properties
|
||||
from heat.engine import resource
|
||||
@ -77,6 +78,45 @@ class KeystoneProject(resource.Resource):
|
||||
),
|
||||
}
|
||||
|
||||
ATTRIBUTES = (
|
||||
NAME_ATTR, PARENT_ATTR, DOMAIN_ATTR, ENABLED_ATTR, IS_DOMAIN_ATTR
|
||||
) = (
|
||||
'name', 'parent_id', 'domain_id', 'enabled', 'is_domain'
|
||||
)
|
||||
attributes_schema = {
|
||||
NAME_ATTR: attributes.Schema(
|
||||
_('Project name.'),
|
||||
support_status=support.SupportStatus(version='10.0.0'),
|
||||
type=attributes.Schema.STRING
|
||||
),
|
||||
PARENT_ATTR: attributes.Schema(
|
||||
_('Parent project id.'),
|
||||
support_status=support.SupportStatus(version='10.0.0'),
|
||||
type=attributes.Schema.STRING
|
||||
),
|
||||
DOMAIN_ATTR: attributes.Schema(
|
||||
_('Domain id for project.'),
|
||||
support_status=support.SupportStatus(version='10.0.0'),
|
||||
type=attributes.Schema.STRING
|
||||
),
|
||||
ENABLED_ATTR: attributes.Schema(
|
||||
_('Flag of enable project.'),
|
||||
support_status=support.SupportStatus(version='10.0.0'),
|
||||
type=attributes.Schema.BOOLEAN
|
||||
),
|
||||
IS_DOMAIN_ATTR: attributes.Schema(
|
||||
_('Indicates whether the project also acts as a domain.'),
|
||||
support_status=support.SupportStatus(version='10.0.0'),
|
||||
type=attributes.Schema.BOOLEAN
|
||||
),
|
||||
}
|
||||
|
||||
def _resolve_attribute(self, name):
|
||||
if self.resource_id is None:
|
||||
return
|
||||
project = self.client().projects.get(self.resource_id)
|
||||
return getattr(project, name, None)
|
||||
|
||||
def translation_rules(self, properties):
|
||||
return [
|
||||
translation.TranslationRule(
|
||||
|
@ -106,8 +106,8 @@ class KeystoneUser(resource.Resource,
|
||||
NAME_ATTR, DEFAULT_PROJECT_ATTR, DOMAIN_ATTR, ENABLED_ATTR,
|
||||
PASSWORD_EXPIRES_AT_ATTR
|
||||
) = (
|
||||
'name', 'default_project_id', 'domain_id',
|
||||
'enabled', 'password_expires_at'
|
||||
'name', 'default_project_id', 'domain_id', 'enabled',
|
||||
'password_expires_at'
|
||||
)
|
||||
attributes_schema = {
|
||||
NAME_ATTR: attributes.Schema(
|
||||
|
@ -73,7 +73,11 @@ class KeystoneProjectTest(common.HeatTestCase):
|
||||
value = mock.MagicMock()
|
||||
project_id = '477e8273-60a7-4c41-b683-fdb0bc7cd151'
|
||||
value.id = project_id
|
||||
|
||||
value.name = 'test_project_1'
|
||||
value.domain_id = 'default'
|
||||
value.enabled = True
|
||||
value.parent_id = 'my_father'
|
||||
value.is_domain = False
|
||||
return value
|
||||
|
||||
def test_project_handle_create(self):
|
||||
@ -377,3 +381,24 @@ class KeystoneProjectTest(common.HeatTestCase):
|
||||
self.assertEqual(set(expected.keys()), set(reality.keys()))
|
||||
for key in expected:
|
||||
self.assertEqual(expected[key], reality[key])
|
||||
|
||||
def test_resolve_attributes(self):
|
||||
mock_project = self._get_mock_project()
|
||||
self.test_project.resource_id = mock_project['id']
|
||||
self.projects.get.return_value = mock_project
|
||||
self.assertEqual(
|
||||
'test_project_1',
|
||||
self.test_project._resolve_attribute(
|
||||
project.KeystoneProject.NAME_ATTR))
|
||||
self.assertEqual(
|
||||
'my_father',
|
||||
self.test_project._resolve_attribute(
|
||||
project.KeystoneProject.PARENT_ATTR))
|
||||
self.assertEqual(
|
||||
'default',
|
||||
self.test_project._resolve_attribute(
|
||||
project.KeystoneProject.DOMAIN_ATTR))
|
||||
self.assertTrue(self.test_project._resolve_attribute(
|
||||
project.KeystoneProject.ENABLED_ATTR))
|
||||
self.assertFalse(self.test_project._resolve_attribute(
|
||||
project.KeystoneProject.IS_DOMAIN_ATTR))
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
fixes:
|
||||
- Add attribute schema to `OS::Keystone::Project`. This allow get_attr
|
||||
function can work with project resource.
|
Loading…
Reference in New Issue
Block a user