blob: a70b995e3cbb8f7fe59e65f836e1835cff23bb20 [file] [log] [blame]
Kevin Benton183b7be2016-03-24 22:14:58 -07001# 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
Kevin Bentona2ceb2d2016-09-22 17:52:25 -070013import netaddr
14
Kevin Benton183b7be2016-03-24 22:14:58 -070015from tempest import test
16
17from neutron.tests.tempest.api import base
18from neutron.tests.tempest.api import base_security_groups as bsg
19from neutron.tests.tempest import config
20
21
22class TestRevisions(base.BaseAdminNetworkTest, bsg.BaseSecGroupTest):
23
24 @classmethod
Kevin Bentonb944fcb2016-09-02 00:26:42 -060025 @test.requires_ext(extension="standard-attr-revisions", service="network")
Kevin Benton183b7be2016-03-24 22:14:58 -070026 def skip_checks(cls):
27 super(TestRevisions, cls).skip_checks()
28
29 @test.idempotent_id('4a26a4be-9c53-483c-bc50-b53f1db10ac6')
30 def test_update_network_bumps_revision(self):
31 net = self.create_network()
Kevin Benton2f067902016-09-02 17:14:37 -070032 self.assertIn('revision_number', net)
Kevin Benton183b7be2016-03-24 22:14:58 -070033 updated = self.client.update_network(net['id'], name='newnet')
Kevin Benton2f067902016-09-02 17:14:37 -070034 self.assertGreater(updated['network']['revision_number'],
35 net['revision_number'])
Kevin Benton183b7be2016-03-24 22:14:58 -070036
37 @test.idempotent_id('cac7ecde-12d5-4331-9a03-420899dea077')
38 def test_update_port_bumps_revision(self):
39 net = self.create_network()
40 port = self.create_port(net)
Kevin Benton2f067902016-09-02 17:14:37 -070041 self.assertIn('revision_number', port)
Kevin Benton183b7be2016-03-24 22:14:58 -070042 updated = self.client.update_port(port['id'], name='newport')
Kevin Benton2f067902016-09-02 17:14:37 -070043 self.assertGreater(updated['port']['revision_number'],
44 port['revision_number'])
Kevin Benton183b7be2016-03-24 22:14:58 -070045
46 @test.idempotent_id('c1c4fa41-8e89-44d0-9bfc-409f3b66dc57')
47 def test_update_subnet_bumps_revision(self):
48 net = self.create_network()
49 subnet = self.create_subnet(net)
Kevin Benton2f067902016-09-02 17:14:37 -070050 self.assertIn('revision_number', subnet)
Kevin Benton183b7be2016-03-24 22:14:58 -070051 updated = self.client.update_subnet(subnet['id'], name='newsub')
Kevin Benton2f067902016-09-02 17:14:37 -070052 self.assertGreater(updated['subnet']['revision_number'],
53 subnet['revision_number'])
Kevin Benton183b7be2016-03-24 22:14:58 -070054
55 @test.idempotent_id('e8c5d7db-2b8d-4615-a476-6e537437c4f2')
56 def test_update_subnetpool_bumps_revision(self):
57 sp = self.create_subnetpool('subnetpool', default_prefixlen=24,
58 prefixes=['10.0.0.0/8'])
Kevin Benton2f067902016-09-02 17:14:37 -070059 self.assertIn('revision_number', sp)
Kevin Benton183b7be2016-03-24 22:14:58 -070060 updated = self.admin_client.update_subnetpool(sp['id'], name='sp2')
Kevin Benton2f067902016-09-02 17:14:37 -070061 self.assertGreater(updated['subnetpool']['revision_number'],
62 sp['revision_number'])
Kevin Benton183b7be2016-03-24 22:14:58 -070063
Nam Nguyen Hoai2984b6d2016-08-05 09:46:43 +070064 @test.idempotent_id('e8c5d7db-2b8d-4567-a326-6e123437c4d1')
65 def test_update_subnet_bumps_network_revision(self):
66 net = self.create_network()
67 subnet = self.create_subnet(net)
68 updated = self.client.show_network(net['id'])
Kevin Benton2f067902016-09-02 17:14:37 -070069 self.assertGreater(updated['network']['revision_number'],
70 net['revision_number'])
Nam Nguyen Hoai2984b6d2016-08-05 09:46:43 +070071 self.client.delete_subnet(subnet['id'])
72 updated2 = self.client.show_network(net['id'])
Kevin Benton2f067902016-09-02 17:14:37 -070073 self.assertGreater(updated2['network']['revision_number'],
74 updated['network']['revision_number'])
Nam Nguyen Hoai2984b6d2016-08-05 09:46:43 +070075
Kevin Benton183b7be2016-03-24 22:14:58 -070076 @test.idempotent_id('6c256f71-c929-4200-b3dc-4e1843506be5')
77 @test.requires_ext(extension="security-group", service="network")
78 def test_update_sg_group_bumps_revision(self):
79 sg, name = self._create_security_group()
Kevin Benton2f067902016-09-02 17:14:37 -070080 self.assertIn('revision_number', sg['security_group'])
Kevin Benton183b7be2016-03-24 22:14:58 -070081 update_body = self.client.update_security_group(
82 sg['security_group']['id'], name='new_sg_name')
Kevin Benton2f067902016-09-02 17:14:37 -070083 self.assertGreater(update_body['security_group']['revision_number'],
84 sg['security_group']['revision_number'])
Kevin Benton183b7be2016-03-24 22:14:58 -070085
86 @test.idempotent_id('6489632f-8550-4453-a674-c98849742967')
87 @test.requires_ext(extension="security-group", service="network")
88 def test_update_port_sg_binding_bumps_revision(self):
89 net = self.create_network()
90 port = self.create_port(net)
91 sg = self._create_security_group()[0]
92 self.client.update_port(
93 port['id'], security_groups=[sg['security_group']['id']])
94 updated = self.client.show_port(port['id'])
Kevin Bentona2bd97b2016-09-19 20:05:25 -070095 updated2 = self.client.update_port(port['id'], security_groups=[])
Kevin Benton2f067902016-09-02 17:14:37 -070096 self.assertGreater(updated['port']['revision_number'],
97 port['revision_number'])
98 self.assertGreater(updated2['port']['revision_number'],
99 updated['port']['revision_number'])
Kevin Benton183b7be2016-03-24 22:14:58 -0700100
101 @test.idempotent_id('29c7ab2b-d1d8-425d-8cec-fcf632960f22')
102 @test.requires_ext(extension="security-group", service="network")
103 def test_update_sg_rule_bumps_sg_revision(self):
104 sg, name = self._create_security_group()
105 rule = self.client.create_security_group_rule(
106 security_group_id=sg['security_group']['id'],
107 protocol='tcp', direction='ingress', ethertype=self.ethertype,
108 port_range_min=60, port_range_max=70)
109 updated = self.client.show_security_group(sg['security_group']['id'])
Kevin Benton2f067902016-09-02 17:14:37 -0700110 self.assertGreater(updated['security_group']['revision_number'],
111 sg['security_group']['revision_number'])
Kevin Benton183b7be2016-03-24 22:14:58 -0700112 self.client.delete_security_group_rule(
113 rule['security_group_rule']['id'])
114 updated2 = self.client.show_security_group(sg['security_group']['id'])
Kevin Benton2f067902016-09-02 17:14:37 -0700115 self.assertGreater(updated2['security_group']['revision_number'],
116 updated['security_group']['revision_number'])
Kevin Benton183b7be2016-03-24 22:14:58 -0700117
Kevin Bentona2ceb2d2016-09-22 17:52:25 -0700118 @test.idempotent_id('db70c285-0365-4fac-9f55-2a0ad8cf55a8')
119 @test.requires_ext(extension="allowed-address-pairs", service="network")
120 def test_update_allowed_address_pairs_bumps_revision(self):
121 net = self.create_network()
122 port = self.create_port(net)
123 updated = self.client.update_port(
124 port['id'], allowed_address_pairs=[{'ip_address': '1.1.1.1/32'}])
125 self.assertGreater(updated['port']['revision_number'],
126 port['revision_number'])
127 updated2 = self.client.update_port(
128 port['id'], allowed_address_pairs=[])
129 self.assertGreater(updated2['port']['revision_number'],
130 updated['port']['revision_number'])
131
132 @test.idempotent_id('a21ec3b4-3569-4b77-bf29-4177edaa2df5')
133 @test.requires_ext(extension="extra_dhcp_opt", service="network")
134 def test_update_extra_dhcp_opt_bumps_revision(self):
135 net = self.create_network()
136 port = self.create_port(net)
137 opts = [{'opt_value': 'pxelinux.0', 'opt_name': 'bootfile-name'}]
138 updated = self.client.update_port(port['id'], extra_dhcp_opts=opts)
139 self.assertGreater(updated['port']['revision_number'],
140 port['revision_number'])
141 opts[0]['opt_value'] = 'pxelinux.77'
142 updated2 = self.client.update_port(
143 port['id'], extra_dhcp_opts=opts)
144 self.assertGreater(updated2['port']['revision_number'],
145 updated['port']['revision_number'])
146
147 @test.idempotent_id('40ba648f-f374-4c29-a5b7-489dd5a38a4e')
148 @test.requires_ext(extension="dns-integration", service="network")
149 def test_update_dns_domain_bumps_revision(self):
150 net = self.create_network(dns_domain='example.test.')
Kevin Bentonf46e7a22016-09-24 23:07:45 -0700151 updated = self.client.update_network(net['id'], dns_domain='exa.test.')
Kevin Bentona2ceb2d2016-09-22 17:52:25 -0700152 self.assertGreater(updated['network']['revision_number'],
153 net['revision_number'])
154 port = self.create_port(net)
155 updated = self.client.update_port(port['id'], dns_name='port1')
156 if not updated['port']['dns_name']:
157 self.skipTest("Server does not have DNS domain configured.")
158 self.assertGreater(updated['port']['revision_number'],
159 port['revision_number'])
160 updated2 = self.client.update_port(port['id'], dns_name='')
161 self.assertGreater(updated2['port']['revision_number'],
162 updated['port']['revision_number'])
163
164 @test.idempotent_id('8482324f-cf59-4d73-b98e-d37119255300')
165 @test.requires_ext(extension="router", service="network")
166 @test.requires_ext(extension="extraroute", service="network")
167 def test_update_router_extra_routes_bumps_revision(self):
168 subnet = self.create_subnet(self.create_network())
169 subgateway = netaddr.IPAddress(subnet['gateway_ip'])
170 router = self.create_router(router_name='test')
171 self.create_router_interface(router['id'], subnet['id'])
172 router = self.client.show_router(router['id'])['router']
173 updated = self.client.update_router(
174 router['id'], routes=[{'destination': '2.0.0.0/24',
175 'nexthop': str(subgateway + 1)}])
176 self.assertGreater(updated['router']['revision_number'],
177 router['revision_number'])
178 updated2 = self.client.update_router(router['id'], routes=[])
179 self.assertGreater(updated2['router']['revision_number'],
180 updated['router']['revision_number'])
181
182 @test.idempotent_id('6bd18702-e25a-4b4b-8c0c-680113533511')
183 @test.requires_ext(extension="subnet-service-types", service="network")
184 def test_update_subnet_service_types_bumps_revisions(self):
185 subnet = self.create_subnet(self.create_network())
186 updated = self.client.update_subnet(
187 subnet['id'], service_types=['compute:'])
188 self.assertGreater(updated['subnet']['revision_number'],
189 subnet['revision_number'])
190 updated2 = self.client.update_subnet(
191 subnet['id'], service_types=[])
192 self.assertGreater(updated2['subnet']['revision_number'],
193 updated['subnet']['revision_number'])
194
195 @test.idempotent_id('9c83105c-9973-45ff-9ca2-e66d64700abe')
196 @test.requires_ext(extension="port-security", service="network")
197 def test_update_port_security_bumps_revisions(self):
198 net = self.create_network(port_security_enabled=False)
Kevin Bentonf46e7a22016-09-24 23:07:45 -0700199 updated = self.client.update_network(net['id'],
200 port_security_enabled=True)
Kevin Bentona2ceb2d2016-09-22 17:52:25 -0700201 self.assertGreater(updated['network']['revision_number'],
202 net['revision_number'])
Kevin Bentonf46e7a22016-09-24 23:07:45 -0700203 updated2 = self.client.update_network(net['id'],
204 port_security_enabled=False)
Kevin Bentona2ceb2d2016-09-22 17:52:25 -0700205 self.assertGreater(updated2['network']['revision_number'],
206 updated['network']['revision_number'])
207 port = self.create_port(net, port_security_enabled=False)
208 updated = self.client.update_port(port['id'],
209 port_security_enabled=True)
210 self.assertGreater(updated['port']['revision_number'],
211 port['revision_number'])
212 updated2 = self.client.update_port(port['id'],
213 port_security_enabled=False)
214 self.assertGreater(updated2['port']['revision_number'],
215 updated['port']['revision_number'])
216
217 @test.idempotent_id('68d5ac3a-11a1-4847-8e2e-5843c043d89b')
218 @test.requires_ext(extension="binding", service="network")
219 def test_portbinding_bumps_revision(self):
220 port = self.create_port(self.create_network())
221 port = self.admin_client.update_port(
222 port['id'], **{'binding:host_id': 'badhost1'})['port']
223 updated = self.admin_client.update_port(
224 port['id'], **{'binding:host_id': 'badhost2'})['port']
225 self.assertGreater(updated['revision_number'],
226 port['revision_number'])
227
Kevin Benton183b7be2016-03-24 22:14:58 -0700228 @test.idempotent_id('4a37bde9-1975-47e0-9b8c-2c9ca36415b0')
229 @test.requires_ext(extension="router", service="network")
230 def test_update_router_bumps_revision(self):
231 subnet = self.create_subnet(self.create_network())
232 router = self.create_router(router_name='test')
Kevin Benton2f067902016-09-02 17:14:37 -0700233 self.assertIn('revision_number', router)
234 rev1 = router['revision_number']
Kevin Benton183b7be2016-03-24 22:14:58 -0700235 router = self.client.update_router(router['id'],
236 name='test2')['router']
Kevin Benton2f067902016-09-02 17:14:37 -0700237 self.assertGreater(router['revision_number'], rev1)
Kevin Benton183b7be2016-03-24 22:14:58 -0700238 self.create_router_interface(router['id'], subnet['id'])
239 updated = self.client.show_router(router['id'])['router']
Kevin Benton2f067902016-09-02 17:14:37 -0700240 self.assertGreater(updated['revision_number'],
241 router['revision_number'])
Kevin Benton183b7be2016-03-24 22:14:58 -0700242
243 @test.idempotent_id('9de71ebc-f5df-4cd0-80bc-60299fce3ce9')
244 @test.requires_ext(extension="router", service="network")
245 @test.requires_ext(extension="standard-attr-description",
246 service="network")
247 def test_update_floatingip_bumps_revision(self):
248 ext_id = config.CONF.network.public_network_id
249 network = self.create_network()
250 subnet = self.create_subnet(network)
251 router = self.create_router('test', external_network_id=ext_id)
252 self.create_router_interface(router['id'], subnet['id'])
253 port = self.create_port(network)
254 body = self.client.create_floatingip(
255 floating_network_id=ext_id,
256 port_id=port['id'],
257 description='d1'
258 )['floatingip']
Kevin Benton2f067902016-09-02 17:14:37 -0700259 self.assertIn('revision_number', body)
Kevin Benton183b7be2016-03-24 22:14:58 -0700260 b2 = self.client.update_floatingip(body['id'], description='d2')
Kevin Benton2f067902016-09-02 17:14:37 -0700261 self.assertGreater(b2['floatingip']['revision_number'],
262 body['revision_number'])
LIU Yulong39e5f102016-05-05 14:52:26 +0800263 # disassociate
264 self.client.update_floatingip(b2['floatingip']['id'], port_id=None)