[aim-mapping] Fix PT create error in auto-ptg
The commit 6d56931196 introduced a
variation in the UUID of the "auto" PTGs implicitly created by the
apic_mapping policy driver. The API layer however was not made aware
of this variation and hence rejected this new UUID format when used
to create a policy target. This is fixed in this patch by allowing
the validation for this new UUID format with the regex:
auto[0-9a-f]{32}\Z
The auto PTG was also missing an implicit subnet for IP address allocation
to any PTs that are created in that PTG. This is also being fixed.
UTs have been added/updated to validate the above changes.
Change-Id: Idda35feb5c61587f3f014491768daecf03660ad9
Closes-bug: 1630923
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
# under the License.
|
||||
|
||||
import abc
|
||||
import re
|
||||
|
||||
from neutron.api import extensions
|
||||
from neutron.api.v2 import attributes as attr
|
||||
@@ -373,11 +374,22 @@ def _validate_gbp_resource_name(data, valid_values=None):
|
||||
# Any REST API defined GBP resource name is restricted to 128 characters
|
||||
return attr._validate_string(data, max_len=128)
|
||||
|
||||
|
||||
AUTO_PTG_REGEX = re.compile('auto[0-9a-f]{32}\Z', re.I)
|
||||
|
||||
|
||||
def _validate_gbp_uuid_or_none(data, valid_values=None):
|
||||
if data is not None:
|
||||
if not bool(AUTO_PTG_REGEX.match(data)):
|
||||
return attr._validate_uuid_or_none(data)
|
||||
|
||||
|
||||
attr.validators['type:gbp_port_range'] = _validate_gbp_port_range
|
||||
attr.validators['type:network_service_params'] = _validate_network_svc_params
|
||||
attr.validators['type:external_dict'] = _validate_external_dict
|
||||
attr.validators['type:gbproutes'] = _validate_gbproutes
|
||||
attr.validators['type:gbp_resource_name'] = _validate_gbp_resource_name
|
||||
attr.validators['type:gbp_uuid_or_none'] = _validate_gbp_uuid_or_none
|
||||
|
||||
|
||||
POLICY_TARGETS = 'policy_targets'
|
||||
@@ -412,7 +424,7 @@ RESOURCE_ATTRIBUTE_MAP = {
|
||||
'status_details': {'allow_post': False, 'allow_put': False,
|
||||
'is_visible': True},
|
||||
'policy_target_group_id': {'allow_post': True, 'allow_put': True,
|
||||
'validate': {'type:uuid_or_none': None},
|
||||
'validate': {'type:gbp_uuid_or_none': None},
|
||||
'required': True, 'is_visible': True},
|
||||
'cluster_id': {'allow_post': True, 'allow_put': True,
|
||||
'validate': {'type:string': None},
|
||||
|
||||
@@ -2749,6 +2749,9 @@ class ApicMappingDriver(api.ResourceMappingDriver,
|
||||
# we will map the id of the PTG to the APIC EPG name
|
||||
self.apic_manager.db.update_apic_name(
|
||||
auto_ptg['id'], 'policy_target_group', str(shadow_epg))
|
||||
ptg_context = group_policy_context.PolicyTargetGroupContext(
|
||||
context._plugin, context._plugin_context, auto_ptg)
|
||||
self._use_implicit_subnet(ptg_context)
|
||||
|
||||
def _associate_service_filter(self, tenant, contract, filter_name,
|
||||
entry_name, transaction=None, **attrs):
|
||||
|
||||
@@ -2226,6 +2226,8 @@ class TestL2PolicyWithAutoPTG(TestL2PolicyBase):
|
||||
expected_res_status=webob.exc.HTTPBadRequest.code)
|
||||
self.assertEqual('AutoPTGAttrsUpdateNotSupported',
|
||||
res['NeutronError']['type'])
|
||||
self.create_policy_target(name='pt',
|
||||
policy_target_group_id=ptg['id'])
|
||||
# Auto PTG cannot be deleted by user
|
||||
res = self.delete_policy_target_group(
|
||||
ptg['id'], expected_res_status=webob.exc.HTTPBadRequest.code)
|
||||
|
||||
@@ -1200,3 +1200,14 @@ class TestGroupPolicyAttributeValidators(base.BaseTestCase):
|
||||
invalid_name = 'x' * 129
|
||||
msg = "'" + invalid_name + "' exceeds maximum length of 128"
|
||||
self.assertEqual(gp._validate_gbp_resource_name(invalid_name), msg)
|
||||
|
||||
def test_validate_gbp_uuid(self):
|
||||
self.assertIsNone(gp._validate_gbp_uuid_or_none(_uuid()))
|
||||
auto_uuid = 'auto' + '9' * 32
|
||||
self.assertIsNone(gp._validate_gbp_uuid_or_none(auto_uuid))
|
||||
bad_uuid = 'autt' + '9' * 32
|
||||
self.assertEqual(gp._validate_gbp_uuid_or_none(bad_uuid),
|
||||
"'%s' is not a valid UUID" % bad_uuid)
|
||||
bad_uuid = 'auto' + 'z' * 32
|
||||
self.assertEqual(gp._validate_gbp_uuid_or_none(bad_uuid),
|
||||
"'%s' is not a valid UUID" % bad_uuid)
|
||||
|
||||
Reference in New Issue
Block a user