blob: c3227a9331a219579cb3a735848c5c721b559451 [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')
Ilya Menkov319bd382020-05-22 15:16:32 +0400153 @utils.requires_ext(extension='default-subnetpools', service='network')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000154 def test_create_subnetpool_with_timestamp(self):
155 sp = self._create_subnetpool()
156 # Verifies body contains timestamp fields
157 self.assertIsNotNone(sp['created_at'])
158 self.assertIsNotNone(sp['updated_at'])
159
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000160 @decorators.idempotent_id('d48c7578-c3d2-4f9b-a7a1-be2008c770a0')
Ilya Menkov319bd382020-05-22 15:16:32 +0400161 @utils.requires_ext(extension='default-subnetpools', service='network')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000162 def test_update_subnetpool_with_timestamp(self):
163 sp = self._create_subnetpool()
164 origin_updated_at = sp['updated_at']
165 update_body = {'name': sp['name'] + 'new',
166 'min_prefixlen': self.min_prefixlen,
167 'max_prefixlen': self.max_prefixlen}
168 body = self.client.update_subnetpool(sp['id'], **update_body)
169 updated_sp = body['subnetpool']
170 new_updated_at = updated_sp['updated_at']
171 self.assertEqual(sp['created_at'], updated_sp['created_at'])
172 # Verify that origin_updated_at is not same with new_updated_at
173 self.assertIsNot(origin_updated_at, new_updated_at)
174
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000175 @decorators.idempotent_id('1d3970e6-bcf7-46cd-b7d7-0807759c73b4')
Ilya Menkov319bd382020-05-22 15:16:32 +0400176 @utils.requires_ext(extension='default-subnetpools', service='network')
Daniel Mellado3c0aeab2016-01-29 11:30:25 +0000177 def test_show_subnetpool_attribute_with_timestamp(self):
178 sp = self._create_subnetpool()
179 body = self.client.show_subnetpool(sp['id'])
180 show_sp = body['subnetpool']
181 # verify the timestamp from creation and showed is same
182 self.assertEqual(sp['created_at'], show_sp['created_at'])
183 self.assertEqual(sp['updated_at'], show_sp['updated_at'])
ZhaoBof5620692016-05-05 17:16:23 +0800184
Hongbin Lu840c03c2018-04-03 19:34:58 +0000185 @decorators.idempotent_id('396a97dc-b66c-4c46-9171-c39eefe6936c')
Hongbin Lu7681a5c2018-04-18 15:54:45 +0000186 @utils.requires_ext(extension="standard-attr-segment", service="network")
Hongbin Lu840c03c2018-04-03 19:34:58 +0000187 def test_segment_with_timestamp(self):
188 network = self.create_network()
189 segment = self.admin_client.list_segments(
190 network_id=network['id'])['segments'][0]
191 # Verifies body contains timestamp fields
192 self.assertIsNotNone(segment['created_at'])
193 self.assertIsNotNone(segment['updated_at'])
194
195 body = self.admin_client.show_segment(segment['id'])
196 show_segment = body['segment']
197 # verify the timestamp from creation and showed is same
198 self.assertEqual(segment['created_at'], show_segment['created_at'])
199 self.assertEqual(segment['updated_at'], show_segment['updated_at'])
200
201 origin_updated_at = segment['updated_at']
202 update_body = {'name': str(segment['name']) + 'new'}
203 body = self.admin_client.update_segment(segment['id'], **update_body)
204 updated_segment = body['segment']
205 new_updated_at = updated_segment['updated_at']
206 self.assertEqual(segment['created_at'], updated_segment['created_at'])
207 # Verify that origin_updated_at is not same with new_updated_at
208 self.assertIsNot(origin_updated_at, new_updated_at)
209
ZhaoBof5620692016-05-05 17:16:23 +0800210
211class TestTimeStampWithL3(base_routers.BaseRouterTest):
ZhaoBof5620692016-05-05 17:16:23 +0800212
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000213 required_extensions = ['standard-attr-timestamp']
ZhaoBof5620692016-05-05 17:16:23 +0800214
215 @classmethod
216 def resource_setup(cls):
217 super(TestTimeStampWithL3, cls).resource_setup()
218 cls.ext_net_id = CONF.network.public_network_id
219
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000220 @decorators.idempotent_id('433ba770-b310-4da9-5d42-733217a1c7b1')
ZhaoBof5620692016-05-05 17:16:23 +0800221 def test_create_router_with_timestamp(self):
222 router = self.create_router(router_name='test')
223 # Verifies body contains timestamp fields
224 self.assertIsNotNone(router['created_at'])
225 self.assertIsNotNone(router['updated_at'])
226
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000227 @decorators.idempotent_id('4a65417a-c11c-4b4d-a351-af01abcf57c6')
ZhaoBof5620692016-05-05 17:16:23 +0800228 def test_update_router_with_timestamp(self):
229 router = self.create_router(router_name='test')
230 origin_updated_at = router['updated_at']
231 update_body = {'name': router['name'] + 'new'}
232 body = self.client.update_router(router['id'], **update_body)
233 updated_router = body['router']
234 new_updated_at = updated_router['updated_at']
235 self.assertEqual(router['created_at'], updated_router['created_at'])
236 # Verify that origin_updated_at is not same with new_updated_at
237 self.assertIsNot(origin_updated_at, new_updated_at)
238
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000239 @decorators.idempotent_id('1ab50ac2-7cbd-4a17-b23e-a9e36cfa4ec2')
ZhaoBof5620692016-05-05 17:16:23 +0800240 def test_show_router_attribute_with_timestamp(self):
241 router = self.create_router(router_name='test')
242 body = self.client.show_router(router['id'])
243 show_router = body['router']
244 # verify the timestamp from creation and showed is same
245 self.assertEqual(router['created_at'],
246 show_router['created_at'])
Brian Haley060f8032017-04-04 14:10:12 -0400247 # 'updated_at' timestamp can change immediately after creation
248 # if environment is HA or DVR, so just make sure it's >=
249 self.assertGreaterEqual(show_router['updated_at'],
250 router['updated_at'])
ZhaoBof5620692016-05-05 17:16:23 +0800251
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000252 @decorators.idempotent_id('8ae55186-464f-4b87-1c9f-eb2765ee81ac')
ZhaoBof5620692016-05-05 17:16:23 +0800253 def test_create_floatingip_with_timestamp(self):
Federico Ressi3dfa94c2018-07-06 09:46:39 +0200254 fip = self.create_floatingip()
ZhaoBof5620692016-05-05 17:16:23 +0800255 # Verifies body contains timestamp fields
256 self.assertIsNotNone(fip['created_at'])
257 self.assertIsNotNone(fip['updated_at'])
258
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000259 @decorators.idempotent_id('a3ac215a-61ac-13f9-9d3c-57c51f11afa1')
ZhaoBof5620692016-05-05 17:16:23 +0800260 def test_update_floatingip_with_timestamp(self):
Federico Ressi3dfa94c2018-07-06 09:46:39 +0200261 fip = self.create_floatingip()
ZhaoBof5620692016-05-05 17:16:23 +0800262 origin_updated_at = fip['updated_at']
263 update_body = {'description': 'new'}
264 body = self.client.update_floatingip(fip['id'], **update_body)
265 updated_fip = body['floatingip']
266 new_updated_at = updated_fip['updated_at']
267 self.assertEqual(fip['created_at'], updated_fip['created_at'])
268 # Verify that origin_updated_at is not same with new_updated_at
269 self.assertIsNot(origin_updated_at, new_updated_at)
270
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000271 @decorators.idempotent_id('32a6a086-e1ef-413b-b13a-0cfe13ef051e')
ZhaoBof5620692016-05-05 17:16:23 +0800272 def test_show_floatingip_attribute_with_timestamp(self):
Federico Ressi3dfa94c2018-07-06 09:46:39 +0200273 fip = self.create_floatingip()
ZhaoBof5620692016-05-05 17:16:23 +0800274 body = self.client.show_floatingip(fip['id'])
275 show_fip = body['floatingip']
276 # verify the timestamp from creation and showed is same
277 self.assertEqual(fip['created_at'],
278 show_fip['created_at'])
279 self.assertEqual(fip['updated_at'],
280 show_fip['updated_at'])
281
282
Federico Ressie570de62018-10-10 15:33:55 +0200283class TestTimeStampWithSecurityGroup(base.BaseNetworkTest):
ZhaoBof5620692016-05-05 17:16:23 +0800284
Jakub Libosvar1982aa12017-05-30 11:15:33 +0000285 required_extensions = ['standard-attr-timestamp']
ZhaoBof5620692016-05-05 17:16:23 +0800286
287 @classmethod
288 def resource_setup(cls):
289 super(TestTimeStampWithSecurityGroup, cls).resource_setup()
290 cls.ext_net_id = CONF.network.public_network_id
291
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000292 @decorators.idempotent_id('a3150a7b-d31a-423a-abf3-45e71c97cbac')
ZhaoBof5620692016-05-05 17:16:23 +0800293 def test_create_sg_with_timestamp(self):
Federico Ressie570de62018-10-10 15:33:55 +0200294 security_group = self.create_security_group()
ZhaoBof5620692016-05-05 17:16:23 +0800295 # Verifies body contains timestamp fields
Federico Ressie570de62018-10-10 15:33:55 +0200296 self.assertIsNotNone(security_group['created_at'])
297 self.assertIsNotNone(security_group['updated_at'])
ZhaoBof5620692016-05-05 17:16:23 +0800298
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000299 @decorators.idempotent_id('432ae0d3-32b4-413e-a9b3-091ac76da31b')
ZhaoBof5620692016-05-05 17:16:23 +0800300 def test_update_sg_with_timestamp(self):
Federico Ressie570de62018-10-10 15:33:55 +0200301 security_group = self.create_security_group()
302
303 # Make sure update time will be different
304 time.sleep(2.)
305 updated_security_group = self.client.update_security_group(
306 security_group['id'], name=security_group['name'] + 'new')[
307 'security_group']
308
309 # Verify that created_at hasn't changed
310 self.assertEqual(security_group['created_at'],
311 updated_security_group['created_at'])
312 # Verify that updated_at has changed
313 self.assertNotEqual(security_group['updated_at'],
314 updated_security_group['updated_at'])
ZhaoBof5620692016-05-05 17:16:23 +0800315
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000316 @decorators.idempotent_id('521e6723-43d6-12a6-8c3d-f5042ad9fc32')
ZhaoBof5620692016-05-05 17:16:23 +0800317 def test_show_sg_attribute_with_timestamp(self):
Federico Ressie570de62018-10-10 15:33:55 +0200318 security_group = self.create_security_group()
319 observed_security_group = self.client.show_security_group(
320 security_group['id'])['security_group']
ZhaoBof5620692016-05-05 17:16:23 +0800321
Federico Ressie570de62018-10-10 15:33:55 +0200322 # Verify that created_at hasn't changed
323 self.assertEqual(security_group['created_at'],
324 observed_security_group['created_at'])
325 # Verify that updated_at hasn't changed
326 self.assertEqual(security_group['updated_at'],
327 observed_security_group['updated_at'])
328
329 def _create_security_group_rule(self):
330 security_group = self.create_security_group()
331 return self.create_security_group_rule(
332 security_group=security_group,
333 direction=constants.INGRESS_DIRECTION,
334 protocol=constants.PROTO_NAME_TCP,
335 port_range_min=77,
336 port_range_max=77)
ZhaoBof5620692016-05-05 17:16:23 +0800337
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000338 @decorators.idempotent_id('83e8bd32-43e0-a3f0-1af3-12a5733c653e')
ZhaoBof5620692016-05-05 17:16:23 +0800339 def test_create_sgrule_with_timestamp(self):
Federico Ressie570de62018-10-10 15:33:55 +0200340 security_group_rule = self._create_security_group_rule()
ZhaoBof5620692016-05-05 17:16:23 +0800341 # Verifies body contains timestamp fields
Federico Ressie570de62018-10-10 15:33:55 +0200342 self.assertIn('created_at', security_group_rule)
343 self.assertIn('updated_at', security_group_rule)
ZhaoBof5620692016-05-05 17:16:23 +0800344
Sławek Kapłońskic0caa2e2017-02-25 10:11:32 +0000345 @decorators.idempotent_id('143da0e6-ba17-43ad-b3d7-03aa759c3cb4')
ZhaoBof5620692016-05-05 17:16:23 +0800346 def test_show_sgrule_attribute_with_timestamp(self):
Federico Ressie570de62018-10-10 15:33:55 +0200347 security_group_rule = self._create_security_group_rule()
348
349 observed_security_group_rule = self.client.show_security_group_rule(
350 security_group_rule['id'])['security_group_rule']
351
352 # Verify the time stamp from creation and showed are equal
353 self.assertEqual(security_group_rule['created_at'],
354 observed_security_group_rule['created_at'])
355 self.assertEqual(security_group_rule['updated_at'],
356 observed_security_group_rule['updated_at'])