Refactor neutron constraints
This changes: 1. remove the implemention of NetworkConstraint, just inherit from the super class NeutronConstraint; 2. remove the attribute 'cmd_resource' for neutron constraints, and resolve the 'cmd_resource' in find_resourceid_by_name_or_id() Change-Id: I53ec9382a2e42c1a2742735bf15040c9db00f0cc
This commit is contained in:
parent
455ef4b48c
commit
eac3d39b75
|
@ -28,6 +28,14 @@ class NeutronClientPlugin(client_plugin.ClientPlugin):
|
|||
|
||||
service_types = [NETWORK] = ['network']
|
||||
|
||||
res_cmdres_mapping = {
|
||||
# resource: cmd_resource
|
||||
'policy': 'qos_policy',
|
||||
'loadbalancer': 'lbaas_loadbalancer',
|
||||
'pool': 'lbaas_pool',
|
||||
'l7policy': 'lbaas_l7policy'
|
||||
}
|
||||
|
||||
def _create(self):
|
||||
|
||||
con = self.context
|
||||
|
@ -67,6 +75,8 @@ class NeutronClientPlugin(client_plugin.ClientPlugin):
|
|||
|
||||
def find_resourceid_by_name_or_id(self, resource, name_or_id,
|
||||
cmd_resource=None):
|
||||
cmd_resource = (cmd_resource or
|
||||
self.res_cmdres_mapping.get(resource))
|
||||
return self._find_resource_id(self.context.tenant_id,
|
||||
resource, name_or_id,
|
||||
cmd_resource)
|
||||
|
@ -97,7 +107,7 @@ class NeutronClientPlugin(client_plugin.ClientPlugin):
|
|||
def resolve_pool(self, props, pool_key, pool_id_key):
|
||||
if props.get(pool_key):
|
||||
props[pool_id_key] = self.find_resourceid_by_name_or_id(
|
||||
'pool', props.get(pool_key), cmd_resource='lbaas_pool')
|
||||
'pool', props.get(pool_key))
|
||||
props.pop(pool_key)
|
||||
return props[pool_id_key]
|
||||
|
||||
|
@ -122,7 +132,7 @@ class NeutronClientPlugin(client_plugin.ClientPlugin):
|
|||
policy: ID or name of the policy.
|
||||
"""
|
||||
return self.find_resourceid_by_name_or_id(
|
||||
'policy', policy, cmd_resource='qos_policy')
|
||||
'policy', policy)
|
||||
|
||||
def get_secgroup_uuids(self, security_groups):
|
||||
'''Returns a list of security group UUIDs.
|
||||
|
|
|
@ -21,7 +21,6 @@ CLIENT_NAME = 'neutron'
|
|||
|
||||
class LoadbalancerConstraint(nc.NeutronConstraint):
|
||||
resource_name = 'loadbalancer'
|
||||
cmd_resource = 'lbaas_loadbalancer'
|
||||
extension = 'lbaasv2'
|
||||
|
||||
|
||||
|
@ -33,7 +32,6 @@ class ListenerConstraint(nc.NeutronConstraint):
|
|||
class PoolConstraint(nc.NeutronConstraint):
|
||||
# Pool constraint for lbaas v2
|
||||
resource_name = 'pool'
|
||||
cmd_resource = 'lbaas_pool'
|
||||
extension = 'lbaasv2'
|
||||
|
||||
|
||||
|
|
|
@ -22,24 +22,11 @@ from heat.engine import constraints
|
|||
CLIENT_NAME = 'neutron'
|
||||
|
||||
|
||||
class NetworkConstraint(constraints.BaseCustomConstraint):
|
||||
|
||||
expected_exceptions = (qe.NeutronClientException,
|
||||
exception.EntityNotFound,
|
||||
exception.PhysicalResourceNameAmbiguity)
|
||||
|
||||
def validate_with_client(self, client, value):
|
||||
neutron_plugin = client.client_plugin(CLIENT_NAME)
|
||||
neutron_plugin.find_resourceid_by_name_or_id(
|
||||
'network', value, cmd_resource=None)
|
||||
|
||||
|
||||
class NeutronConstraint(constraints.BaseCustomConstraint):
|
||||
|
||||
expected_exceptions = (qe.NeutronClientException,
|
||||
exception.EntityNotFound)
|
||||
resource_name = None
|
||||
cmd_resource = None
|
||||
extension = None
|
||||
|
||||
def validate_with_client(self, client, value):
|
||||
|
@ -49,7 +36,7 @@ class NeutronConstraint(constraints.BaseCustomConstraint):
|
|||
raise exception.EntityNotFound(entity='neutron extension',
|
||||
name=self.extension)
|
||||
neutron_plugin.find_resourceid_by_name_or_id(
|
||||
self.resource_name, value, cmd_resource=self.cmd_resource)
|
||||
self.resource_name, value)
|
||||
|
||||
|
||||
class NeutronExtConstraint(NeutronConstraint):
|
||||
|
@ -63,6 +50,10 @@ class NeutronExtConstraint(NeutronConstraint):
|
|||
neutron_plugin.resolve_ext_resource(self.resource_name, value)
|
||||
|
||||
|
||||
class NetworkConstraint(NeutronConstraint):
|
||||
resource_name = 'network'
|
||||
|
||||
|
||||
class PortConstraint(NeutronConstraint):
|
||||
resource_name = 'port'
|
||||
|
||||
|
@ -90,7 +81,6 @@ class AddressScopeConstraint(NeutronConstraint):
|
|||
|
||||
class QoSPolicyConstraint(NeutronConstraint):
|
||||
resource_name = 'policy'
|
||||
cmd_resource = 'qos_policy'
|
||||
extension = 'qos'
|
||||
|
||||
|
||||
|
|
|
@ -152,8 +152,7 @@ class HealthMonitor(neutron.NeutronResource):
|
|||
if self._lb_id is None:
|
||||
pool_id = self.client_plugin().find_resourceid_by_name_or_id(
|
||||
self.POOL,
|
||||
self.properties[self.POOL],
|
||||
cmd_resource='lbaas_pool')
|
||||
self.properties[self.POOL])
|
||||
pool = self.client().show_lbaas_pool(pool_id)['pool']
|
||||
|
||||
listener_id = pool['listeners'][0]['id']
|
||||
|
|
|
@ -110,8 +110,7 @@ class L7Rule(neutron.NeutronResource):
|
|||
if self._l7p_id is None:
|
||||
self._l7p_id = self.client_plugin().find_resourceid_by_name_or_id(
|
||||
self.L7POLICY,
|
||||
self.properties[self.L7POLICY],
|
||||
cmd_resource='lbaas_l7policy')
|
||||
self.properties[self.L7POLICY])
|
||||
return self._l7p_id
|
||||
|
||||
@property
|
||||
|
|
|
@ -136,8 +136,7 @@ class PoolMember(neutron.NeutronResource):
|
|||
if self._pool_id is None:
|
||||
self._pool_id = self.client_plugin().find_resourceid_by_name_or_id(
|
||||
self.POOL,
|
||||
self.properties[self.POOL],
|
||||
cmd_resource='lbaas_pool')
|
||||
self.properties[self.POOL])
|
||||
return self._pool_id
|
||||
|
||||
@property
|
||||
|
|
|
@ -131,48 +131,37 @@ class NeutronConstraintsValidate(common.HeatTestCase):
|
|||
scenarios = [
|
||||
('validate_network',
|
||||
dict(constraint_class=nc.NetworkConstraint,
|
||||
resource_type='network',
|
||||
cmd_resource=None)),
|
||||
resource_type='network')),
|
||||
('validate_port',
|
||||
dict(constraint_class=nc.PortConstraint,
|
||||
resource_type='port',
|
||||
cmd_resource=None)),
|
||||
resource_type='port')),
|
||||
('validate_router',
|
||||
dict(constraint_class=nc.RouterConstraint,
|
||||
resource_type='router',
|
||||
cmd_resource=None)),
|
||||
resource_type='router')),
|
||||
('validate_subnet',
|
||||
dict(constraint_class=nc.SubnetConstraint,
|
||||
resource_type='subnet',
|
||||
cmd_resource=None)),
|
||||
resource_type='subnet')),
|
||||
('validate_subnetpool',
|
||||
dict(constraint_class=nc.SubnetPoolConstraint,
|
||||
resource_type='subnetpool',
|
||||
cmd_resource=None)),
|
||||
resource_type='subnetpool')),
|
||||
('validate_address_scope',
|
||||
dict(constraint_class=nc.AddressScopeConstraint,
|
||||
resource_type='address_scope',
|
||||
cmd_resource=None)),
|
||||
resource_type='address_scope')),
|
||||
('validate_loadbalancer',
|
||||
dict(constraint_class=lc.LoadbalancerConstraint,
|
||||
resource_type='loadbalancer',
|
||||
cmd_resource='lbaas_loadbalancer')),
|
||||
resource_type='loadbalancer')),
|
||||
('validate_listener',
|
||||
dict(constraint_class=lc.ListenerConstraint,
|
||||
resource_type='listener',
|
||||
cmd_resource=None)),
|
||||
resource_type='listener')),
|
||||
('validate_pool',
|
||||
dict(constraint_class=lc.PoolConstraint,
|
||||
resource_type='pool',
|
||||
cmd_resource='lbaas_pool')),
|
||||
resource_type='pool')),
|
||||
('validate_qos_policy',
|
||||
dict(constraint_class=nc.QoSPolicyConstraint,
|
||||
resource_type='policy',
|
||||
cmd_resource='qos_policy')),
|
||||
resource_type='policy')),
|
||||
('validate_security_group',
|
||||
dict(constraint_class=nc.SecurityGroupConstraint,
|
||||
resource_type='security_group',
|
||||
cmd_resource=None))
|
||||
resource_type='security_group'))
|
||||
]
|
||||
|
||||
def test_validate(self):
|
||||
|
@ -206,10 +195,8 @@ class NeutronConstraintsValidate(common.HeatTestCase):
|
|||
self.assertTrue(constraint.validate("foo", ctx))
|
||||
self.assertFalse(constraint.validate("bar", ctx))
|
||||
mock_find.assert_has_calls(
|
||||
[mock.call(self.resource_type, 'foo',
|
||||
cmd_resource=self.cmd_resource),
|
||||
mock.call(self.resource_type, 'bar',
|
||||
cmd_resource=self.cmd_resource)])
|
||||
[mock.call(self.resource_type, 'foo'),
|
||||
mock.call(self.resource_type, 'bar')])
|
||||
|
||||
|
||||
class NeutronProviderConstraintsValidate(common.HeatTestCase):
|
||||
|
|
Loading…
Reference in New Issue