blob: f4b918c2f5af8fe20f2aa66cbe364242241838ae [file] [log] [blame]
Genadi Chereshnya57173bd2017-01-10 11:17:07 +02001# Copyright 2017 Red Hat, Inc.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
Chandan Kumarc125fd12017-11-15 19:41:01 +053016import functools
Genadi Chereshnya57173bd2017-01-10 11:17:07 +020017
Chandan Kumarc125fd12017-11-15 19:41:01 +053018from neutron_lib.api.definitions import portbindings as pb
19from neutron_lib import constants as const
20from tempest.common import utils
21from tempest.lib import decorators
Dongcan Ye91017ca2018-02-11 10:46:03 +000022import testtools
Chandan Kumarc125fd12017-11-15 19:41:01 +053023
24from neutron_tempest_plugin.common import utils as common_utils
Dongcan Ye91017ca2018-02-11 10:46:03 +000025from neutron_tempest_plugin import config
Chandan Kumar667d3d32017-09-22 12:24:06 +053026from neutron_tempest_plugin.scenario import base
27from neutron_tempest_plugin.scenario import test_dvr
Genadi Chereshnya57173bd2017-01-10 11:17:07 +020028
Dongcan Ye91017ca2018-02-11 10:46:03 +000029CONF = config.CONF
30
Genadi Chereshnya57173bd2017-01-10 11:17:07 +020031
32class NetworkMigrationTestBase(base.BaseTempestTestCase,
33 test_dvr.NetworkTestMixin):
34 credentials = ['primary', 'admin']
35 force_tenant_isolation = False
36
37 @classmethod
Chandan Kumarc125fd12017-11-15 19:41:01 +053038 @utils.requires_ext(extension="dvr", service="network")
39 @utils.requires_ext(extension="l3-ha", service="network")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +020040 def skip_checks(cls):
41 super(NetworkMigrationTestBase, cls).skip_checks()
42
43 def _check_update(self, router, is_dvr, is_ha):
rajat294495c042017-06-28 15:37:16 +053044 router = self.os_admin.network_client.show_router(router['id'])
Genadi Chereshnya57173bd2017-01-10 11:17:07 +020045 self.assertEqual(is_dvr, router['router']['distributed'])
46 self.assertEqual(is_ha, router['router']['ha'])
47
Chandan Kumarc125fd12017-11-15 19:41:01 +053048 def _wait_until_port_deleted(self, router_id, device_owner):
49 common_utils.wait_until_true(
50 functools.partial(
51 self._is_port_deleted,
52 router_id,
53 device_owner),
54 timeout=300, sleep=5)
55
56 def _is_port_deleted(self, router_id, device_owner):
57 ports = self.os_admin.network_client.list_ports(
58 device_id=router_id,
59 device_owner=device_owner)
60 return not ports.get('ports')
61
62 def _wait_until_port_ready(self, router_id, device_owner):
63 common_utils.wait_until_true(
64 functools.partial(
65 self._is_port_active,
66 router_id,
67 device_owner),
68 timeout=300, sleep=5)
69
Slawek Kaplonski096b6a82018-08-07 11:28:41 +020070 def _wait_until_router_ports_down(self, router_id):
71
72 def _is_port_down(port_id):
73 port = self.os_admin.network_client.show_port(port_id).get('port')
74 return port['status'] == const.DOWN
75
76 ports = self.os_admin.network_client.list_ports(
77 device_id=router_id).get('ports')
78 for port in ports:
79 common_utils.wait_until_true(
80 functools.partial(_is_port_down, port['id']),
81 timeout=300, sleep=5)
82
Chandan Kumarc125fd12017-11-15 19:41:01 +053083 def _is_port_active(self, router_id, device_owner):
84 ports = self.os_admin.network_client.list_ports(
85 device_id=router_id,
86 device_owner=device_owner,
87 status=const.ACTIVE).get('ports')
88 if ports:
89 if ports[0][pb.VIF_TYPE] not in [pb.VIF_TYPE_UNBOUND,
90 pb.VIF_TYPE_BINDING_FAILED]:
91 return True
92 return False
93
94 def _wait_until_router_ports_ready(self, router_id, dvr, ha):
95 if dvr:
96 self._wait_until_port_ready(
97 router_id, const.DEVICE_OWNER_DVR_INTERFACE)
98 if ha:
99 self._wait_until_port_ready(
100 router_id, const.DEVICE_OWNER_ROUTER_HA_INTF)
101 if dvr:
102 self._wait_until_port_ready(
103 router_id, const.DEVICE_OWNER_ROUTER_SNAT)
104 else:
105 self._wait_until_port_ready(
106 router_id, const.DEVICE_OWNER_HA_REPLICATED_INT)
107 self._wait_until_port_ready(
108 router_id, const.DEVICE_OWNER_ROUTER_GW)
109
110 def _wait_until_router_ports_migrated(
111 self, router_id, before_dvr, before_ha, after_dvr, after_ha):
112 if before_ha and not after_ha:
113 self._wait_until_port_deleted(
114 router_id, const.DEVICE_OWNER_ROUTER_HA_INTF)
115 self._wait_until_port_deleted(
116 router_id, const.DEVICE_OWNER_HA_REPLICATED_INT)
117 if before_dvr and not after_dvr:
118 self._wait_until_port_deleted(
119 router_id, const.DEVICE_OWNER_DVR_INTERFACE)
120 self._wait_until_port_deleted(
121 router_id, const.DEVICE_OWNER_ROUTER_SNAT)
122 self._wait_until_router_ports_ready(router_id, after_dvr, after_ha)
123
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200124 def _test_migration(self, before_dvr, before_ha, after_dvr, after_ha):
125 router = self.create_router_by_client(
126 distributed=before_dvr, ha=before_ha,
127 tenant_id=self.client.tenant_id, is_admin=True)
128
129 self.setup_network_and_server(router=router)
Chandan Kumarc125fd12017-11-15 19:41:01 +0530130 self._wait_until_router_ports_ready(
131 router['id'], before_dvr, before_ha)
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200132 self._check_connectivity()
133
rajat294495c042017-06-28 15:37:16 +0530134 self.os_admin.network_client.update_router(
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200135 router_id=router['id'], admin_state_up=False)
Slawek Kaplonski096b6a82018-08-07 11:28:41 +0200136 self._wait_until_router_ports_down(router['id'])
137
rajat294495c042017-06-28 15:37:16 +0530138 self.os_admin.network_client.update_router(
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200139 router_id=router['id'], distributed=after_dvr, ha=after_ha)
140 self._check_update(router, after_dvr, after_ha)
141
rajat294495c042017-06-28 15:37:16 +0530142 self.os_admin.network_client.update_router(
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200143 router_id=router['id'], admin_state_up=True)
Chandan Kumarc125fd12017-11-15 19:41:01 +0530144
145 self._wait_until_router_ports_migrated(
146 router['id'], before_dvr, before_ha, after_dvr, after_ha)
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200147 self._check_connectivity()
148
149
150class NetworkMigrationFromLegacy(NetworkMigrationTestBase):
151
152 @decorators.idempotent_id('23724222-483a-4129-bc15-7a9278f3828b')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000153 @testtools.skipUnless(
154 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
155 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200156 def test_from_legacy_to_dvr(self):
157 self._test_migration(before_dvr=False, before_ha=False,
158 after_dvr=True, after_ha=False)
159
160 @decorators.idempotent_id('09d85102-994f-4ff9-bf3e-17051145ca12')
161 def test_from_legacy_to_ha(self):
162 self._test_migration(before_dvr=False, before_ha=False,
163 after_dvr=False, after_ha=True)
164
165 @decorators.idempotent_id('fe169f2c-6ed3-4eb0-8afe-2d540c4b49e2')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000166 @testtools.skipUnless(
167 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
168 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200169 def test_from_legacy_to_dvr_ha(self):
170 self._test_migration(before_dvr=False, before_ha=False,
171 after_dvr=True, after_ha=True)
172
173
174class NetworkMigrationFromHA(NetworkMigrationTestBase):
175
176 @decorators.idempotent_id('b4e68ac0-3b76-4306-ae8a-51cf4d363b22')
177 def test_from_ha_to_legacy(self):
178 self._test_migration(before_dvr=False, before_ha=True,
179 after_dvr=False, after_ha=False)
180
181 @decorators.idempotent_id('42260eea-5d56-4d30-b62a-a62694dfe4d5')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000182 @testtools.skipUnless(
183 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
184 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200185 def test_from_ha_to_dvr(self):
186 self._test_migration(before_dvr=False, before_ha=True,
187 after_dvr=True, after_ha=False)
188
189 @decorators.idempotent_id('e4149576-248b-43fa-9d0b-a5c2f51967ce')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000190 @testtools.skipUnless(
191 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
192 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200193 def test_from_ha_to_dvr_ha(self):
194 self._test_migration(before_dvr=False, before_ha=True,
195 after_dvr=True, after_ha=True)
196
197
198class NetworkMigrationFromDVR(NetworkMigrationTestBase):
199
200 @decorators.idempotent_id('e5cac02c-248d-4aac-bd5e-9d47c5197307')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000201 @testtools.skipUnless(
202 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
203 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200204 def test_from_dvr_to_legacy(self):
205 self._test_migration(before_dvr=True, before_ha=False,
206 after_dvr=False, after_ha=False)
207
208 @decorators.idempotent_id('a00d5ad7-8509-4bb0-bdd2-7f1ee052d1cd')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000209 @testtools.skipUnless(
210 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
211 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200212 def test_from_dvr_to_ha(self):
213 self._test_migration(before_dvr=True, before_ha=False,
214 after_dvr=False, after_ha=True)
215
216 @decorators.idempotent_id('25304a51-93a8-4cf3-9523-bce8b4eaecf8')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000217 @testtools.skipUnless(
218 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
219 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200220 def test_from_dvr_to_dvr_ha(self):
221 self._test_migration(before_dvr=True, before_ha=False,
222 after_dvr=True, after_ha=True)
223
224
225class NetworkMigrationFromDVRHA(NetworkMigrationTestBase):
226
Brian Haleyeb80cc32018-04-13 16:00:49 -0400227 @common_utils.unstable_test("bug 1756301")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200228 @decorators.idempotent_id('1be9b2e2-379c-40a4-a269-6687b81df691')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000229 @testtools.skipUnless(
230 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
231 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200232 def test_from_dvr_ha_to_legacy(self):
233 self._test_migration(before_dvr=True, before_ha=True,
234 after_dvr=False, after_ha=False)
235
Brian Haleyeb80cc32018-04-13 16:00:49 -0400236 @common_utils.unstable_test("bug 1756301")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200237 @decorators.idempotent_id('55957267-4e84-4314-a2f7-7cd36a2df04b')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000238 @testtools.skipUnless(
239 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
240 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200241 def test_from_dvr_ha_to_ha(self):
242 self._test_migration(before_dvr=True, before_ha=True,
243 after_dvr=False, after_ha=True)
244
Brian Haleyeb80cc32018-04-13 16:00:49 -0400245 @common_utils.unstable_test("bug 1756301")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200246 @decorators.idempotent_id('d6bedff1-72be-4a9a-8ea2-dc037cd838e0')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000247 @testtools.skipUnless(
248 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
249 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200250 def test_from_dvr_ha_to_dvr(self):
251 self._test_migration(before_dvr=True, before_ha=True,
252 after_dvr=True, after_ha=False)