summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-02 23:04:41 +0000
committerGerrit Code Review <review@openstack.org>2017-06-02 23:04:41 +0000
commit6c6173c578b3545dbfdd427b37887043bb41723e (patch)
treeb144485b92cb0c645fb19817602eb582656c35f5
parent1a5b86675dc0392940b1b1043c1bdfcb56188c16 (diff)
parentd48e5c7575bc4fe786cfbdca2b88060eec905015 (diff)
Merge "Add API test for tag" into stable/newton
-rw-r--r--neutron/tests/tempest/api/test_tag.py174
-rw-r--r--neutron/tests/tempest/services/network/json/network_client.py41
2 files changed, 215 insertions, 0 deletions
diff --git a/neutron/tests/tempest/api/test_tag.py b/neutron/tests/tempest/api/test_tag.py
new file mode 100644
index 0000000..5cf6e23
--- /dev/null
+++ b/neutron/tests/tempest/api/test_tag.py
@@ -0,0 +1,174 @@
1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13from tempest.lib import exceptions as lib_exc
14from tempest import test
15
16from neutron.tests.tempest.api import base
17
18
19class TagTestJSON(base.BaseAdminNetworkTest):
20
21 @classmethod
22 @test.requires_ext(extension="tag", service="network")
23 def resource_setup(cls):
24 super(TagTestJSON, cls).resource_setup()
25 cls.res_id = cls._create_resource()
26
27 def _get_and_compare_tags(self, tags):
28 res_body = self.client.get_tags(self.resource, self.res_id)
29 self.assertItemsEqual(tags, res_body['tags'])
30
31 def _test_tag_operations(self):
32 # create and get tags
33 tags = ['red', 'blue']
34 res_body = self.client.update_tags(self.resource, self.res_id, tags)
35 self.assertItemsEqual(tags, res_body['tags'])
36 self._get_and_compare_tags(tags)
37
38 # add a tag
39 self.client.update_tag(self.resource, self.res_id, 'green')
40 self._get_and_compare_tags(['red', 'blue', 'green'])
41
42 # update tag exist
43 self.client.update_tag(self.resource, self.res_id, 'red')
44 self._get_and_compare_tags(['red', 'blue', 'green'])
45
46 # replace tags
47 tags = ['red', 'yellow', 'purple']
48 res_body = self.client.update_tags(self.resource, self.res_id, tags)
49 self.assertItemsEqual(tags, res_body['tags'])
50 self._get_and_compare_tags(tags)
51
52 # get tag
53 self.client.get_tag(self.resource, self.res_id, 'red')
54
55 # get tag not exist
56 self.assertRaises(lib_exc.NotFound, self.client.get_tag,
57 self.resource, self.res_id, 'green')
58
59 # delete tag
60 self.client.delete_tag(self.resource, self.res_id, 'red')
61 self._get_and_compare_tags(['yellow', 'purple'])
62
63 # delete tag not exist
64 self.assertRaises(lib_exc.NotFound, self.client.delete_tag,
65 self.resource, self.res_id, 'green')
66
67 # delete tags
68 self.client.delete_tags(self.resource, self.res_id)
69 self._get_and_compare_tags([])
70
71
72class TagNetworkTestJSON(TagTestJSON):
73 resource = 'networks'
74
75 @classmethod
76 def _create_resource(cls):
77 network = cls.create_network()
78 return network['id']
79
80 @test.attr(type='smoke')
81 @test.idempotent_id('5621062d-fbfb-4437-9d69-138c78ea4188')
82 def test_network_tags(self):
83 self._test_tag_operations()
84
85
86class TagFilterTestJSON(base.BaseAdminNetworkTest):
87 credentials = ['primary', 'alt', 'admin']
88 resource = 'networks'
89
90 @classmethod
91 @test.requires_ext(extension="tag", service="network")
92 def resource_setup(cls):
93 super(TagFilterTestJSON, cls).resource_setup()
94
95 res1_id = cls._create_resource('tag-res1')
96 res2_id = cls._create_resource('tag-res2')
97 res3_id = cls._create_resource('tag-res3')
98 res4_id = cls._create_resource('tag-res4')
99 # tag-res5: a resource without tags
100 cls._create_resource('tag-res5')
101
102 cls.client.update_tags(cls.resource, res1_id, ['red'])
103 cls.client.update_tags(cls.resource, res2_id, ['red', 'blue'])
104 cls.client.update_tags(cls.resource, res3_id,
105 ['red', 'blue', 'green'])
106 cls.client.update_tags(cls.resource, res4_id, ['green'])
107
108 @classmethod
109 def setup_clients(cls):
110 super(TagFilterTestJSON, cls).setup_clients()
111 cls.client = cls.alt_manager.network_client
112
113 def _assertEqualResources(self, expected, res):
114 actual = [n['name'] for n in res if n['name'].startswith('tag-res')]
115 self.assertEqual(set(expected), set(actual))
116
117 def _test_filter_tags(self):
118 # tags single
119 filters = {'tags': 'red'}
120 res = self._list_resource(filters)
121 self._assertEqualResources(['tag-res1', 'tag-res2', 'tag-res3'], res)
122
123 # tags multi
124 filters = {'tags': 'red,blue'}
125 res = self._list_resource(filters)
126 self._assertEqualResources(['tag-res2', 'tag-res3'], res)
127
128 # tags-any single
129 filters = {'tags-any': 'blue'}
130 res = self._list_resource(filters)
131 self._assertEqualResources(['tag-res2', 'tag-res3'], res)
132
133 # tags-any multi
134 filters = {'tags-any': 'red,blue'}
135 res = self._list_resource(filters)
136 self._assertEqualResources(['tag-res1', 'tag-res2', 'tag-res3'], res)
137
138 # not-tags single
139 filters = {'not-tags': 'red'}
140 res = self._list_resource(filters)
141 self._assertEqualResources(['tag-res4', 'tag-res5'], res)
142
143 # not-tags multi
144 filters = {'not-tags': 'red,blue'}
145 res = self._list_resource(filters)
146 self._assertEqualResources(['tag-res1', 'tag-res4', 'tag-res5'], res)
147
148 # not-tags-any single
149 filters = {'not-tags-any': 'blue'}
150 res = self._list_resource(filters)
151 self._assertEqualResources(['tag-res1', 'tag-res4', 'tag-res5'], res)
152
153 # not-tags-any multi
154 filters = {'not-tags-any': 'red,blue'}
155 res = self._list_resource(filters)
156 self._assertEqualResources(['tag-res4', 'tag-res5'], res)
157
158
159class TagFilterNetworkTestJSON(TagFilterTestJSON):
160 resource = 'networks'
161
162 @classmethod
163 def _create_resource(cls, name):
164 res = cls.create_network(network_name=name)
165 return res['id']
166
167 def _list_resource(self, filters):
168 res = self.client.list_networks(**filters)
169 return res['networks']
170
171 @test.attr(type='smoke')
172 @test.idempotent_id('a66b5cca-7db2-40f5-a33d-8ac9f864e53e')
173 def test_filter_network_tags(self):
174 self._test_filter_tags()
diff --git a/neutron/tests/tempest/services/network/json/network_client.py b/neutron/tests/tempest/services/network/json/network_client.py
index 93e31ea..610b049 100644
--- a/neutron/tests/tempest/services/network/json/network_client.py
+++ b/neutron/tests/tempest/services/network/json/network_client.py
@@ -907,3 +907,44 @@ class NetworkClientJSON(service_client.RestClient):
907 body = {'extensions': self.deserialize_list(body)} 907 body = {'extensions': self.deserialize_list(body)}
908 self.expected_success(200, resp.status) 908 self.expected_success(200, resp.status)
909 return service_client.ResponseBody(resp, body) 909 return service_client.ResponseBody(resp, body)
910
911 def get_tags(self, resource_type, resource_id):
912 uri = '%s/%s/%s/tags' % (
913 self.uri_prefix, resource_type, resource_id)
914 resp, body = self.get(uri)
915 self.expected_success(200, resp.status)
916 body = jsonutils.loads(body)
917 return service_client.ResponseBody(resp, body)
918
919 def get_tag(self, resource_type, resource_id, tag):
920 uri = '%s/%s/%s/tags/%s' % (
921 self.uri_prefix, resource_type, resource_id, tag)
922 resp, body = self.get(uri)
923 self.expected_success(204, resp.status)
924
925 def update_tag(self, resource_type, resource_id, tag):
926 uri = '%s/%s/%s/tags/%s' % (
927 self.uri_prefix, resource_type, resource_id, tag)
928 resp, body = self.put(uri, None)
929 self.expected_success(201, resp.status)
930
931 def update_tags(self, resource_type, resource_id, tags):
932 uri = '%s/%s/%s/tags' % (
933 self.uri_prefix, resource_type, resource_id)
934 req_body = jsonutils.dumps({'tags': tags})
935 resp, body = self.put(uri, req_body)
936 self.expected_success(200, resp.status)
937 body = jsonutils.loads(body)
938 return service_client.ResponseBody(resp, body)
939
940 def delete_tags(self, resource_type, resource_id):
941 uri = '%s/%s/%s/tags' % (
942 self.uri_prefix, resource_type, resource_id)
943 resp, body = self.delete(uri)
944 self.expected_success(204, resp.status)
945
946 def delete_tag(self, resource_type, resource_id, tag):
947 uri = '%s/%s/%s/tags/%s' % (
948 self.uri_prefix, resource_type, resource_id, tag)
949 resp, body = self.delete(uri)
950 self.expected_success(204, resp.status)