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