summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-03 22:28:34 +0000
committerGerrit Code Review <review@openstack.org>2017-06-03 22:28:34 +0000
commitf5643e1982583a43a5bdae8a7d45bf4d7f1179ca (patch)
tree7923e116a4b7e9a6b094617df80bdf3b1c0ffd0d
parent6c6173c578b3545dbfdd427b37887043bb41723e (diff)
parent48747eacdcf48574c284120f08ef8bc03bb9d252 (diff)
Merge "api: work around Routes cutting off suffix from resource id" into stable/newton
-rw-r--r--neutron/api/v2/resource.py16
-rw-r--r--neutron/tests/tempest/api/test_tag.py4
2 files changed, 19 insertions, 1 deletions
diff --git a/neutron/api/v2/resource.py b/neutron/api/v2/resource.py
index f01cced..b2cdd8e 100644
--- a/neutron/api/v2/resource.py
+++ b/neutron/api/v2/resource.py
@@ -74,8 +74,22 @@ def Resource(controller, faults=None, deserializers=None, serializers=None,
74 if request.body: 74 if request.body:
75 args['body'] = deserializer.deserialize(request.body)['body'] 75 args['body'] = deserializer.deserialize(request.body)['body']
76 76
77 method = getattr(controller, action) 77 # Routes library is dumb and cuts off everything after last dot (.)
78 # as format. At the same time, it doesn't enforce format suffix,
79 # which combined makes it impossible to pass a 'id' with dots
80 # included (the last section after the last dot is lost). This is
81 # important for some API extensions like tags where the id is
82 # really a tag name that can contain special characters.
83 #
84 # To work around the Routes behaviour, we will attach the suffix
85 # back to id if it's not one of supported formats (atm json only).
86 # This of course won't work for the corner case of a tag name that
87 # actually ends with '.json', but there seems to be no better way
88 # to tackle it without breaking API backwards compatibility.
89 if fmt is not None and fmt not in format_types:
90 args['id'] = '.'.join([args['id'], fmt])
78 91
92 method = getattr(controller, action)
79 result = method(request=request, **args) 93 result = method(request=request, **args)
80 except Exception as e: 94 except Exception as e:
81 mapped_exc = api_common.convert_exception_to_http_exc(e, faults, 95 mapped_exc = api_common.convert_exception_to_http_exc(e, faults,
diff --git a/neutron/tests/tempest/api/test_tag.py b/neutron/tests/tempest/api/test_tag.py
index 5cf6e23..97e5343 100644
--- a/neutron/tests/tempest/api/test_tag.py
+++ b/neutron/tests/tempest/api/test_tag.py
@@ -43,6 +43,10 @@ class TagTestJSON(base.BaseAdminNetworkTest):
43 self.client.update_tag(self.resource, self.res_id, 'red') 43 self.client.update_tag(self.resource, self.res_id, 'red')
44 self._get_and_compare_tags(['red', 'blue', 'green']) 44 self._get_and_compare_tags(['red', 'blue', 'green'])
45 45
46 # add a tag with a dot
47 self.client.update_tag(self.resource, self.res_id, 'black.or.white')
48 self._get_and_compare_tags(['red', 'blue', 'green', 'black.or.white'])
49
46 # replace tags 50 # replace tags
47 tags = ['red', 'yellow', 'purple'] 51 tags = ['red', 'yellow', 'purple']
48 res_body = self.client.update_tags(self.resource, self.res_id, tags) 52 res_body = self.client.update_tags(self.resource, self.res_id, tags)