blob: 9ec982d9ef8d4fe93b3fd49874427ad0e6df1531 [file] [log] [blame]
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001# 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
13import copy
Federico Ressie570de62018-10-10 15:33:55 +020014import time
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000015
Federico Ressie570de62018-10-10 15:33:55 +020016from neutron_lib import constants
Hongbin Lu7681a5c2018-04-18 15:54:45 +000017from tempest.common import utils
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000018from tempest.lib.common.utils import data_utils
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000019from tempest.lib import decorators
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000020
Chandan Kumar667d3d32017-09-22 12:24:06 +053021from neutron_tempest_plugin.api import base
22from neutron_tempest_plugin.api import base_routers
Chandan Kumar667d3d32017-09-22 12:24:06 +053023from neutron_tempest_plugin import config
ZhaoBof5620692016-05-05 17:16:23 +080024
25CONF = config.CONF
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000026
27
28class TestTimeStamp(base.BaseAdminNetworkTest):
29
Jakub Libosvar1982aa12017-05-30 11:15:33 +000030 required_extensions = ["standard-attr-timestamp"]
31
Brian Haley6767cec2018-04-10 15:30:23 -040032 # attributes for subnetpool
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000033 min_prefixlen = '28'
34 max_prefixlen = '31'
35 _ip_version = 4
36 subnet_cidr = '10.11.12.0/31'
37 new_prefix = '10.11.15.0/24'
38 larger_prefix = '10.11.0.0/16'
39
40 @classmethod
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000041 def resource_setup(cls):
42 super(TestTimeStamp, cls).resource_setup()
43 prefixes = ['10.11.12.0/24']
44 cls._subnetpool_data = {'min_prefixlen': '29', 'prefixes': prefixes}
45
46 def _create_subnetpool(self, is_admin=False, **kwargs):
Chandan Kumarc125fd12017-11-15 19:41:01 +053047 name = data_utils.rand_name('subnetpool')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000048 subnetpool_data = copy.deepcopy(self._subnetpool_data)
49 for key in subnetpool_data.keys():
50 kwargs[key] = subnetpool_data[key]
51 return self.create_subnetpool(name=name, is_admin=is_admin, **kwargs)
52
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000053 @decorators.idempotent_id('462be770-b310-4df9-9c42-773217e4c8b1')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000054 def test_create_network_with_timestamp(self):
55 network = self.create_network()
56 # Verifies body contains timestamp fields
57 self.assertIsNotNone(network['created_at'])
58 self.assertIsNotNone(network['updated_at'])
59
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000060 @decorators.idempotent_id('4db5417a-e11c-474d-a361-af00ebef57c5')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000061 def test_update_network_with_timestamp(self):
62 network = self.create_network()
63 origin_updated_at = network['updated_at']
64 update_body = {'name': network['name'] + 'new'}
65 body = self.admin_client.update_network(network['id'],
66 **update_body)
67 updated_network = body['network']
68 new_updated_at = updated_network['updated_at']
69 self.assertEqual(network['created_at'], updated_network['created_at'])
70 # Verify that origin_updated_at is not same with new_updated_at
71 self.assertIsNot(origin_updated_at, new_updated_at)
72
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000073 @decorators.idempotent_id('2ac50ab2-7ebd-4e27-b3ce-a9e399faaea2')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000074 def test_show_networks_attribute_with_timestamp(self):
75 network = self.create_network()
76 body = self.client.show_network(network['id'])
77 show_net = body['network']
78 # verify the timestamp from creation and showed is same
79 self.assertEqual(network['created_at'],
80 show_net['created_at'])
81 self.assertEqual(network['updated_at'],
82 show_net['updated_at'])
83
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000084 @decorators.idempotent_id('8ee55186-454f-4b97-9f9f-eb2772ee891c')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000085 def test_create_subnet_with_timestamp(self):
86 network = self.create_network()
87 subnet = self.create_subnet(network)
88 # Verifies body contains timestamp fields
89 self.assertIsNotNone(subnet['created_at'])
90 self.assertIsNotNone(subnet['updated_at'])
91
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +000092 @decorators.idempotent_id('a490215a-6f4c-4af9-9a4c-57c41f1c4fa1')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000093 def test_update_subnet_with_timestamp(self):
94 network = self.create_network()
95 subnet = self.create_subnet(network)
96 origin_updated_at = subnet['updated_at']
97 update_body = {'name': subnet['name'] + 'new'}
98 body = self.admin_client.update_subnet(subnet['id'],
99 **update_body)
100 updated_subnet = body['subnet']
101 new_updated_at = updated_subnet['updated_at']
102 self.assertEqual(subnet['created_at'], updated_subnet['created_at'])
103 # Verify that origin_updated_at is not same with new_updated_at
104 self.assertIsNot(origin_updated_at, new_updated_at)
105
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000106 @decorators.idempotent_id('1836a086-e7cf-4141-bf57-0cfe79e8051e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000107 def test_show_subnet_attribute_with_timestamp(self):
108 network = self.create_network()
109 subnet = self.create_subnet(network)
110 body = self.client.show_subnet(subnet['id'])
111 show_subnet = body['subnet']
112 # verify the timestamp from creation and showed is same
113 self.assertEqual(subnet['created_at'],
114 show_subnet['created_at'])
115 self.assertEqual(subnet['updated_at'],
116 show_subnet['updated_at'])
117
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000118 @decorators.idempotent_id('e2450a7b-d84f-4600-a093-45e78597bbac')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000119 def test_create_port_with_timestamp(self):
120 network = self.create_network()
121 port = self.create_port(network)
122 # Verifies body contains timestamp fields
123 self.assertIsNotNone(port['created_at'])
124 self.assertIsNotNone(port['updated_at'])
125
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000126 @decorators.idempotent_id('4241e0d3-54b4-46ce-a9a7-093fc764161b')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000127 def test_update_port_with_timestamp(self):
128 network = self.create_network()
129 port = self.create_port(network)
130 origin_updated_at = port['updated_at']
131 update_body = {'name': port['name'] + 'new'}
132 body = self.admin_client.update_port(port['id'],
133 **update_body)
134 updated_port = body['port']
135 new_updated_at = updated_port['updated_at']
136 self.assertEqual(port['created_at'], updated_port['created_at'])
137 # Verify that origin_updated_at is not same with new_updated_at
138 self.assertIsNot(origin_updated_at, new_updated_at)
139
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000140 @decorators.idempotent_id('584c6723-40b6-4f26-81dd-f508f9d9fb51')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000141 def test_show_port_attribute_with_timestamp(self):
142 network = self.create_network()
143 port = self.create_port(network)
144 body = self.client.show_port(port['id'])
145 show_port = body['port']
146 # verify the timestamp from creation and showed is same
147 self.assertEqual(port['created_at'],
148 show_port['created_at'])
149 self.assertEqual(port['updated_at'],
150 show_port['updated_at'])
151
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000152 @decorators.idempotent_id('87a8b196-4b90-44f0-b7f3-d2057d7d658e')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000153 def test_create_subnetpool_with_timestamp(self):
154 sp = self._create_subnetpool()
155 # Verifies body contains timestamp fields
156 self.assertIsNotNone(sp['created_at'])
157 self.assertIsNotNone(sp['updated_at'])
158
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000159 @decorators.idempotent_id('d48c7578-c3d2-4f9b-a7a1-be2008c770a0')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000160 def test_update_subnetpool_with_timestamp(self):
161 sp = self._create_subnetpool()
162 origin_updated_at = sp['updated_at']
163 update_body = {'name': sp['name'] + 'new',
164 'min_prefixlen': self.min_prefixlen,
165 'max_prefixlen': self.max_prefixlen}
166 body = self.client.update_subnetpool(sp['id'], **update_body)
167 updated_sp = body['subnetpool']
168 new_updated_at = updated_sp['updated_at']
169 self.assertEqual(sp['created_at'], updated_sp['created_at'])
170 # Verify that origin_updated_at is not same with new_updated_at
171 self.assertIsNot(origin_updated_at, new_updated_at)
172
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000173 @decorators.idempotent_id('1d3970e6-bcf7-46cd-b7d7-0807759c73b4')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000174 def test_show_subnetpool_attribute_with_timestamp(self):
175 sp = self._create_subnetpool()
176 body = self.client.show_subnetpool(sp['id'])
177 show_sp = body['subnetpool']
178 # verify the timestamp from creation and showed is same
179 self.assertEqual(sp['created_at'], show_sp['created_at'])
180 self.assertEqual(sp['updated_at'], show_sp['updated_at'])
ZhaoBof5620692016-05-05 17:16:23 +0800181
Hongbin Lu840c03c2018-04-03 19:34:58 +0000182 @decorators.idempotent_id('396a97dc-b66c-4c46-9171-c39eefe6936c')
Hongbin Lu7681a5c2018-04-18 15:54:45 +0000183 @utils.requires_ext(extension="standard-attr-segment", service="network")
Hongbin Lu840c03c2018-04-03 19:34:58 +0000184 def test_segment_with_timestamp(self):
185 network = self.create_network()
186 segment = self.admin_client.list_segments(
187 network_id=network['id'])['segments'][0]
188 # Verifies body contains timestamp fields
189 self.assertIsNotNone(segment['created_at'])
190 self.assertIsNotNone(segment['updated_at'])
191
192 body = self.admin_client.show_segment(segment['id'])
193 show_segment = body['segment']
194 # verify the timestamp from creation and showed is same
195 self.assertEqual(segment['created_at'], show_segment['created_at'])
196 self.assertEqual(segment['updated_at'], show_segment['updated_at'])
197
198 origin_updated_at = segment['updated_at']
199 update_body = {'name': str(segment['name']) + 'new'}
200 body = self.admin_client.update_segment(segment['id'], **update_body)
201 updated_segment = body['segment']
202 new_updated_at = updated_segment['updated_at']
203 self.assertEqual(segment['created_at'], updated_segment['created_at'])
204 # Verify that origin_updated_at is not same with new_updated_at
205 self.assertIsNot(origin_updated_at, new_updated_at)
206
ZhaoBof5620692016-05-05 17:16:23 +0800207
208class TestTimeStampWithL3(base_routers.BaseRouterTest):
ZhaoBof5620692016-05-05 17:16:23 +0800209
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000210 required_extensions = ['standard-attr-timestamp']
ZhaoBof5620692016-05-05 17:16:23 +0800211
212 @classmethod
213 def resource_setup(cls):
214 super(TestTimeStampWithL3, cls).resource_setup()
215 cls.ext_net_id = CONF.network.public_network_id
216
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000217 @decorators.idempotent_id('433ba770-b310-4da9-5d42-733217a1c7b1')
ZhaoBof5620692016-05-05 17:16:23 +0800218 def test_create_router_with_timestamp(self):
219 router = self.create_router(router_name='test')
220 # Verifies body contains timestamp fields
221 self.assertIsNotNone(router['created_at'])
222 self.assertIsNotNone(router['updated_at'])
223
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000224 @decorators.idempotent_id('4a65417a-c11c-4b4d-a351-af01abcf57c6')
ZhaoBof5620692016-05-05 17:16:23 +0800225 def test_update_router_with_timestamp(self):
226 router = self.create_router(router_name='test')
227 origin_updated_at = router['updated_at']
228 update_body = {'name': router['name'] + 'new'}
229 body = self.client.update_router(router['id'], **update_body)
230 updated_router = body['router']
231 new_updated_at = updated_router['updated_at']
232 self.assertEqual(router['created_at'], updated_router['created_at'])
233 # Verify that origin_updated_at is not same with new_updated_at
234 self.assertIsNot(origin_updated_at, new_updated_at)
235
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000236 @decorators.idempotent_id('1ab50ac2-7cbd-4a17-b23e-a9e36cfa4ec2')
ZhaoBof5620692016-05-05 17:16:23 +0800237 def test_show_router_attribute_with_timestamp(self):
238 router = self.create_router(router_name='test')
239 body = self.client.show_router(router['id'])
240 show_router = body['router']
241 # verify the timestamp from creation and showed is same
242 self.assertEqual(router['created_at'],
243 show_router['created_at'])
Brian Haley060f8032017-04-04 14:10:12 -0400244 # 'updated_at' timestamp can change immediately after creation
245 # if environment is HA or DVR, so just make sure it's >=
246 self.assertGreaterEqual(show_router['updated_at'],
247 router['updated_at'])
ZhaoBof5620692016-05-05 17:16:23 +0800248
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000249 @decorators.idempotent_id('8ae55186-464f-4b87-1c9f-eb2765ee81ac')
ZhaoBof5620692016-05-05 17:16:23 +0800250 def test_create_floatingip_with_timestamp(self):
Federico Ressi3dfa94c2018-07-06 09:46:39 +0200251 fip = self.create_floatingip()
ZhaoBof5620692016-05-05 17:16:23 +0800252 # Verifies body contains timestamp fields
253 self.assertIsNotNone(fip['created_at'])
254 self.assertIsNotNone(fip['updated_at'])
255
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000256 @decorators.idempotent_id('a3ac215a-61ac-13f9-9d3c-57c51f11afa1')
ZhaoBof5620692016-05-05 17:16:23 +0800257 def test_update_floatingip_with_timestamp(self):
Federico Ressi3dfa94c2018-07-06 09:46:39 +0200258 fip = self.create_floatingip()
ZhaoBof5620692016-05-05 17:16:23 +0800259 origin_updated_at = fip['updated_at']
260 update_body = {'description': 'new'}
261 body = self.client.update_floatingip(fip['id'], **update_body)
262 updated_fip = body['floatingip']
263 new_updated_at = updated_fip['updated_at']
264 self.assertEqual(fip['created_at'], updated_fip['created_at'])
265 # Verify that origin_updated_at is not same with new_updated_at
266 self.assertIsNot(origin_updated_at, new_updated_at)
267
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000268 @decorators.idempotent_id('32a6a086-e1ef-413b-b13a-0cfe13ef051e')
ZhaoBof5620692016-05-05 17:16:23 +0800269 def test_show_floatingip_attribute_with_timestamp(self):
Federico Ressi3dfa94c2018-07-06 09:46:39 +0200270 fip = self.create_floatingip()
ZhaoBof5620692016-05-05 17:16:23 +0800271 body = self.client.show_floatingip(fip['id'])
272 show_fip = body['floatingip']
273 # verify the timestamp from creation and showed is same
274 self.assertEqual(fip['created_at'],
275 show_fip['created_at'])
276 self.assertEqual(fip['updated_at'],
277 show_fip['updated_at'])
278
279
Federico Ressie570de62018-10-10 15:33:55 +0200280class TestTimeStampWithSecurityGroup(base.BaseNetworkTest):
ZhaoBof5620692016-05-05 17:16:23 +0800281
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000282 required_extensions = ['standard-attr-timestamp']
ZhaoBof5620692016-05-05 17:16:23 +0800283
284 @classmethod
285 def resource_setup(cls):
286 super(TestTimeStampWithSecurityGroup, cls).resource_setup()
287 cls.ext_net_id = CONF.network.public_network_id
288
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000289 @decorators.idempotent_id('a3150a7b-d31a-423a-abf3-45e71c97cbac')
ZhaoBof5620692016-05-05 17:16:23 +0800290 def test_create_sg_with_timestamp(self):
Federico Ressie570de62018-10-10 15:33:55 +0200291 security_group = self.create_security_group()
ZhaoBof5620692016-05-05 17:16:23 +0800292 # Verifies body contains timestamp fields
Federico Ressie570de62018-10-10 15:33:55 +0200293 self.assertIsNotNone(security_group['created_at'])
294 self.assertIsNotNone(security_group['updated_at'])
ZhaoBof5620692016-05-05 17:16:23 +0800295
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000296 @decorators.idempotent_id('432ae0d3-32b4-413e-a9b3-091ac76da31b')
ZhaoBof5620692016-05-05 17:16:23 +0800297 def test_update_sg_with_timestamp(self):
Federico Ressie570de62018-10-10 15:33:55 +0200298 security_group = self.create_security_group()
299
300 # Make sure update time will be different
301 time.sleep(2.)
302 updated_security_group = self.client.update_security_group(
303 security_group['id'], name=security_group['name'] + 'new')[
304 'security_group']
305
306 # Verify that created_at hasn't changed
307 self.assertEqual(security_group['created_at'],
308 updated_security_group['created_at'])
309 # Verify that updated_at has changed
310 self.assertNotEqual(security_group['updated_at'],
311 updated_security_group['updated_at'])
ZhaoBof5620692016-05-05 17:16:23 +0800312
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000313 @decorators.idempotent_id('521e6723-43d6-12a6-8c3d-f5042ad9fc32')
ZhaoBof5620692016-05-05 17:16:23 +0800314 def test_show_sg_attribute_with_timestamp(self):
Federico Ressie570de62018-10-10 15:33:55 +0200315 security_group = self.create_security_group()
316 observed_security_group = self.client.show_security_group(
317 security_group['id'])['security_group']
ZhaoBof5620692016-05-05 17:16:23 +0800318
Federico Ressie570de62018-10-10 15:33:55 +0200319 # Verify that created_at hasn't changed
320 self.assertEqual(security_group['created_at'],
321 observed_security_group['created_at'])
322 # Verify that updated_at hasn't changed
323 self.assertEqual(security_group['updated_at'],
324 observed_security_group['updated_at'])
325
326 def _create_security_group_rule(self):
327 security_group = self.create_security_group()
328 return self.create_security_group_rule(
329 security_group=security_group,
330 direction=constants.INGRESS_DIRECTION,
331 protocol=constants.PROTO_NAME_TCP,
332 port_range_min=77,
333 port_range_max=77)
ZhaoBof5620692016-05-05 17:16:23 +0800334
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000335 @decorators.idempotent_id('83e8bd32-43e0-a3f0-1af3-12a5733c653e')
ZhaoBof5620692016-05-05 17:16:23 +0800336 def test_create_sgrule_with_timestamp(self):
Federico Ressie570de62018-10-10 15:33:55 +0200337 security_group_rule = self._create_security_group_rule()
ZhaoBof5620692016-05-05 17:16:23 +0800338 # Verifies body contains timestamp fields
Federico Ressie570de62018-10-10 15:33:55 +0200339 self.assertIn('created_at', security_group_rule)
340 self.assertIn('updated_at', security_group_rule)
ZhaoBof5620692016-05-05 17:16:23 +0800341
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000342 @decorators.idempotent_id('143da0e6-ba17-43ad-b3d7-03aa759c3cb4')
ZhaoBof5620692016-05-05 17:16:23 +0800343 def test_show_sgrule_attribute_with_timestamp(self):
Federico Ressie570de62018-10-10 15:33:55 +0200344 security_group_rule = self._create_security_group_rule()
345
346 observed_security_group_rule = self.client.show_security_group_rule(
347 security_group_rule['id'])['security_group_rule']
348
349 # Verify the time stamp from creation and showed are equal
350 self.assertEqual(security_group_rule['created_at'],
351 observed_security_group_rule['created_at'])
352 self.assertEqual(security_group_rule['updated_at'],
353 observed_security_group_rule['updated_at'])