Merge "Fix validate() of rbac resource"
This commit is contained in:
commit
00dfcd28d3
|
@ -16,8 +16,7 @@ from heat.common.i18n import _
|
|||
from heat.engine import properties
|
||||
from heat.engine.resources.openstack.neutron import neutron
|
||||
from heat.engine import support
|
||||
|
||||
from neutronclient.neutron import v2_0 as neutronV20
|
||||
from heat.engine import translation
|
||||
|
||||
|
||||
class RBACPolicy(neutron.NeutronResource):
|
||||
|
@ -72,16 +71,17 @@ class RBACPolicy(neutron.NeutronResource):
|
|||
)
|
||||
}
|
||||
|
||||
def prepare_properties(self, properties, name):
|
||||
props = super(RBACPolicy, self).prepare_properties(properties, name)
|
||||
|
||||
obj_type = props.get(self.OBJECT_TYPE)
|
||||
obj_id_or_name = props.get(self.OBJECT_ID)
|
||||
obj_id = neutronV20.find_resourceid_by_name_or_id(self.client(),
|
||||
obj_type,
|
||||
obj_id_or_name)
|
||||
props['object_id'] = obj_id
|
||||
return props
|
||||
def translation_rules(self, props):
|
||||
return [
|
||||
translation.TranslationRule(
|
||||
props,
|
||||
translation.TranslationRule.RESOLVE,
|
||||
[self.OBJECT_ID],
|
||||
client_plugin=self.client_plugin(),
|
||||
finder='find_resourceid_by_name_or_id',
|
||||
entity=props[self.OBJECT_TYPE]
|
||||
)
|
||||
]
|
||||
|
||||
def handle_create(self):
|
||||
props = self.prepare_properties(
|
||||
|
@ -107,7 +107,6 @@ class RBACPolicy(neutron.NeutronResource):
|
|||
|
||||
action = self.properties[self.ACTION]
|
||||
obj_type = self.properties[self.OBJECT_TYPE]
|
||||
obj_id_or_name = self.properties[self.OBJECT_ID]
|
||||
|
||||
# Validate obj_type and action per SUPPORTED_TYPES_ACTIONS.
|
||||
if obj_type not in self.SUPPORTED_TYPES_ACTIONS:
|
||||
|
@ -123,11 +122,6 @@ class RBACPolicy(neutron.NeutronResource):
|
|||
'value': self.SUPPORTED_TYPES_ACTIONS[obj_type]})
|
||||
raise exception.StackValidationFailed(message=msg)
|
||||
|
||||
# Make sure the value of object_id is correct.
|
||||
neutronV20.find_resourceid_by_name_or_id(self.client(),
|
||||
obj_type,
|
||||
obj_id_or_name)
|
||||
|
||||
|
||||
def resource_mapping():
|
||||
return {
|
||||
|
|
|
@ -56,6 +56,21 @@ resources:
|
|||
object_id: 9ba4c03a-dbd5-4836-b651-defa595796ba
|
||||
'''
|
||||
|
||||
RBAC_REFERENCE_TEMPLATE = '''
|
||||
heat_template_version: 2016-04-08
|
||||
description: Template to test rbac-policy Neutron resource
|
||||
resources:
|
||||
rbac:
|
||||
type: OS::Neutron::RBACPolicy
|
||||
properties:
|
||||
object_type: network
|
||||
target_tenant: d1dbbed707e5469da9cd4fdd618e9706
|
||||
action: access_as_shared
|
||||
object_id: {get_resource: my_net}
|
||||
my_net:
|
||||
type: OS::Neutron::Net
|
||||
'''
|
||||
|
||||
LB_TEMPLATE = '''
|
||||
heat_template_version: 2016-04-08
|
||||
description: Create a loadbalancer
|
||||
|
|
|
@ -37,16 +37,6 @@ class RBACPolicyTest(common.HeatTestCase):
|
|||
self.rbac.client = mock.MagicMock()
|
||||
self.rbac.client.return_value = self.neutron_client
|
||||
|
||||
self.rbac.client_plugin().find_resourceid_by_name_or_id = (
|
||||
mock.MagicMock(return_value='123'))
|
||||
props = {
|
||||
"action": "access_as_shared",
|
||||
"object_type": "network",
|
||||
"object_id": "9ba4c03a-dbd5-4836-b651-defa595796ba",
|
||||
"target_tenant": "d1dbbed707e5469da9cd4fdd618e9706"
|
||||
}
|
||||
self.rbac.prepare_properties = (mock.MagicMock(return_value=props))
|
||||
|
||||
def test_create(self):
|
||||
self._create_stack()
|
||||
expected = {
|
||||
|
@ -76,6 +66,11 @@ class RBACPolicyTest(common.HeatTestCase):
|
|||
self.assertRaisesRegex(exception.StackValidationFailed, msg,
|
||||
self.rbac.validate)
|
||||
|
||||
def test_validate_object_id_reference(self):
|
||||
self._create_stack(tmpl=inline_templates.RBAC_REFERENCE_TEMPLATE)
|
||||
# won't check the object_id, so validate() is success
|
||||
self.rbac.validate()
|
||||
|
||||
def test_update(self):
|
||||
self._create_stack()
|
||||
self.rbac.resource_id_set('bca25c0e-5937-4341-a911-53e202629269')
|
||||
|
|
Loading…
Reference in New Issue