blob: 410c64eb4b7e78701fd852c744e9253da22525da [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
Rodolfo Alonso Hernandez4dea8062020-01-16 16:32:59 +000020from neutron_lib.utils import test
Chandan Kumarc125fd12017-11-15 19:41:01 +053021from tempest.common import utils
22from tempest.lib import decorators
Dongcan Ye91017ca2018-02-11 10:46:03 +000023import testtools
Chandan Kumarc125fd12017-11-15 19:41:01 +053024
25from neutron_tempest_plugin.common import utils as common_utils
Dongcan Ye91017ca2018-02-11 10:46:03 +000026from neutron_tempest_plugin import config
Chandan Kumar667d3d32017-09-22 12:24:06 +053027from neutron_tempest_plugin.scenario import base
28from neutron_tempest_plugin.scenario import test_dvr
Genadi Chereshnya57173bd2017-01-10 11:17:07 +020029
Dongcan Ye91017ca2018-02-11 10:46:03 +000030CONF = config.CONF
31
Genadi Chereshnya57173bd2017-01-10 11:17:07 +020032
33class NetworkMigrationTestBase(base.BaseTempestTestCase,
34 test_dvr.NetworkTestMixin):
35 credentials = ['primary', 'admin']
36 force_tenant_isolation = False
37
38 @classmethod
Chandan Kumarc125fd12017-11-15 19:41:01 +053039 @utils.requires_ext(extension="dvr", service="network")
40 @utils.requires_ext(extension="l3-ha", service="network")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +020041 def skip_checks(cls):
42 super(NetworkMigrationTestBase, cls).skip_checks()
43
44 def _check_update(self, router, is_dvr, is_ha):
rajat294495c042017-06-28 15:37:16 +053045 router = self.os_admin.network_client.show_router(router['id'])
Genadi Chereshnya57173bd2017-01-10 11:17:07 +020046 self.assertEqual(is_dvr, router['router']['distributed'])
47 self.assertEqual(is_ha, router['router']['ha'])
48
Chandan Kumarc125fd12017-11-15 19:41:01 +053049 def _wait_until_port_deleted(self, router_id, device_owner):
50 common_utils.wait_until_true(
51 functools.partial(
52 self._is_port_deleted,
53 router_id,
54 device_owner),
55 timeout=300, sleep=5)
56
57 def _is_port_deleted(self, router_id, device_owner):
58 ports = self.os_admin.network_client.list_ports(
59 device_id=router_id,
60 device_owner=device_owner)
61 return not ports.get('ports')
62
63 def _wait_until_port_ready(self, router_id, device_owner):
64 common_utils.wait_until_true(
65 functools.partial(
66 self._is_port_active,
67 router_id,
68 device_owner),
69 timeout=300, sleep=5)
70
Slawek Kaplonski096b6a82018-08-07 11:28:41 +020071 def _wait_until_router_ports_down(self, router_id):
72
73 def _is_port_down(port_id):
74 port = self.os_admin.network_client.show_port(port_id).get('port')
75 return port['status'] == const.DOWN
76
77 ports = self.os_admin.network_client.list_ports(
78 device_id=router_id).get('ports')
79 for port in ports:
80 common_utils.wait_until_true(
81 functools.partial(_is_port_down, port['id']),
82 timeout=300, sleep=5)
83
Chandan Kumarc125fd12017-11-15 19:41:01 +053084 def _is_port_active(self, router_id, device_owner):
85 ports = self.os_admin.network_client.list_ports(
86 device_id=router_id,
87 device_owner=device_owner,
88 status=const.ACTIVE).get('ports')
89 if ports:
90 if ports[0][pb.VIF_TYPE] not in [pb.VIF_TYPE_UNBOUND,
91 pb.VIF_TYPE_BINDING_FAILED]:
92 return True
93 return False
94
95 def _wait_until_router_ports_ready(self, router_id, dvr, ha):
96 if dvr:
97 self._wait_until_port_ready(
98 router_id, const.DEVICE_OWNER_DVR_INTERFACE)
99 if ha:
100 self._wait_until_port_ready(
101 router_id, const.DEVICE_OWNER_ROUTER_HA_INTF)
102 if dvr:
103 self._wait_until_port_ready(
104 router_id, const.DEVICE_OWNER_ROUTER_SNAT)
105 else:
106 self._wait_until_port_ready(
107 router_id, const.DEVICE_OWNER_HA_REPLICATED_INT)
108 self._wait_until_port_ready(
109 router_id, const.DEVICE_OWNER_ROUTER_GW)
110
111 def _wait_until_router_ports_migrated(
112 self, router_id, before_dvr, before_ha, after_dvr, after_ha):
113 if before_ha and not after_ha:
114 self._wait_until_port_deleted(
115 router_id, const.DEVICE_OWNER_ROUTER_HA_INTF)
116 self._wait_until_port_deleted(
117 router_id, const.DEVICE_OWNER_HA_REPLICATED_INT)
118 if before_dvr and not after_dvr:
119 self._wait_until_port_deleted(
120 router_id, const.DEVICE_OWNER_DVR_INTERFACE)
121 self._wait_until_port_deleted(
122 router_id, const.DEVICE_OWNER_ROUTER_SNAT)
123 self._wait_until_router_ports_ready(router_id, after_dvr, after_ha)
124
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200125 def _test_migration(self, before_dvr, before_ha, after_dvr, after_ha):
126 router = self.create_router_by_client(
127 distributed=before_dvr, ha=before_ha,
128 tenant_id=self.client.tenant_id, is_admin=True)
129
130 self.setup_network_and_server(router=router)
Chandan Kumarc125fd12017-11-15 19:41:01 +0530131 self._wait_until_router_ports_ready(
132 router['id'], before_dvr, before_ha)
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200133 self._check_connectivity()
134
rajat294495c042017-06-28 15:37:16 +0530135 self.os_admin.network_client.update_router(
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200136 router_id=router['id'], admin_state_up=False)
Slawek Kaplonski096b6a82018-08-07 11:28:41 +0200137 self._wait_until_router_ports_down(router['id'])
138
rajat294495c042017-06-28 15:37:16 +0530139 self.os_admin.network_client.update_router(
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200140 router_id=router['id'], distributed=after_dvr, ha=after_ha)
141 self._check_update(router, after_dvr, after_ha)
142
rajat294495c042017-06-28 15:37:16 +0530143 self.os_admin.network_client.update_router(
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200144 router_id=router['id'], admin_state_up=True)
Chandan Kumarc125fd12017-11-15 19:41:01 +0530145
146 self._wait_until_router_ports_migrated(
147 router['id'], before_dvr, before_ha, after_dvr, after_ha)
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200148 self._check_connectivity()
149
150
151class NetworkMigrationFromLegacy(NetworkMigrationTestBase):
152
153 @decorators.idempotent_id('23724222-483a-4129-bc15-7a9278f3828b')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000154 @testtools.skipUnless(
155 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
156 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200157 def test_from_legacy_to_dvr(self):
158 self._test_migration(before_dvr=False, before_ha=False,
159 after_dvr=True, after_ha=False)
160
161 @decorators.idempotent_id('09d85102-994f-4ff9-bf3e-17051145ca12')
162 def test_from_legacy_to_ha(self):
163 self._test_migration(before_dvr=False, before_ha=False,
164 after_dvr=False, after_ha=True)
165
166 @decorators.idempotent_id('fe169f2c-6ed3-4eb0-8afe-2d540c4b49e2')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000167 @testtools.skipUnless(
168 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
169 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200170 def test_from_legacy_to_dvr_ha(self):
171 self._test_migration(before_dvr=False, before_ha=False,
172 after_dvr=True, after_ha=True)
173
174
175class NetworkMigrationFromHA(NetworkMigrationTestBase):
176
177 @decorators.idempotent_id('b4e68ac0-3b76-4306-ae8a-51cf4d363b22')
178 def test_from_ha_to_legacy(self):
179 self._test_migration(before_dvr=False, before_ha=True,
180 after_dvr=False, after_ha=False)
181
182 @decorators.idempotent_id('42260eea-5d56-4d30-b62a-a62694dfe4d5')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000183 @testtools.skipUnless(
184 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
185 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200186 def test_from_ha_to_dvr(self):
187 self._test_migration(before_dvr=False, before_ha=True,
188 after_dvr=True, after_ha=False)
189
190 @decorators.idempotent_id('e4149576-248b-43fa-9d0b-a5c2f51967ce')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000191 @testtools.skipUnless(
192 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
193 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200194 def test_from_ha_to_dvr_ha(self):
195 self._test_migration(before_dvr=False, before_ha=True,
196 after_dvr=True, after_ha=True)
197
198
199class NetworkMigrationFromDVR(NetworkMigrationTestBase):
200
201 @decorators.idempotent_id('e5cac02c-248d-4aac-bd5e-9d47c5197307')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000202 @testtools.skipUnless(
203 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
204 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200205 def test_from_dvr_to_legacy(self):
206 self._test_migration(before_dvr=True, before_ha=False,
207 after_dvr=False, after_ha=False)
208
209 @decorators.idempotent_id('a00d5ad7-8509-4bb0-bdd2-7f1ee052d1cd')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000210 @testtools.skipUnless(
211 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
212 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200213 def test_from_dvr_to_ha(self):
214 self._test_migration(before_dvr=True, before_ha=False,
215 after_dvr=False, after_ha=True)
216
217 @decorators.idempotent_id('25304a51-93a8-4cf3-9523-bce8b4eaecf8')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000218 @testtools.skipUnless(
219 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
220 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200221 def test_from_dvr_to_dvr_ha(self):
222 self._test_migration(before_dvr=True, before_ha=False,
223 after_dvr=True, after_ha=True)
224
225
226class NetworkMigrationFromDVRHA(NetworkMigrationTestBase):
227
Rodolfo Alonso Hernandez4dea8062020-01-16 16:32:59 +0000228 @test.unstable_test("bug 1756301")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200229 @decorators.idempotent_id('1be9b2e2-379c-40a4-a269-6687b81df691')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000230 @testtools.skipUnless(
231 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
232 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200233 def test_from_dvr_ha_to_legacy(self):
234 self._test_migration(before_dvr=True, before_ha=True,
235 after_dvr=False, after_ha=False)
236
Rodolfo Alonso Hernandez4dea8062020-01-16 16:32:59 +0000237 @test.unstable_test("bug 1756301")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200238 @decorators.idempotent_id('55957267-4e84-4314-a2f7-7cd36a2df04b')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000239 @testtools.skipUnless(
240 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
241 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200242 def test_from_dvr_ha_to_ha(self):
243 self._test_migration(before_dvr=True, before_ha=True,
244 after_dvr=False, after_ha=True)
245
Rodolfo Alonso Hernandez4dea8062020-01-16 16:32:59 +0000246 @test.unstable_test("bug 1756301")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200247 @decorators.idempotent_id('d6bedff1-72be-4a9a-8ea2-dc037cd838e0')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000248 @testtools.skipUnless(
249 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
250 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200251 def test_from_dvr_ha_to_dvr(self):
252 self._test_migration(before_dvr=True, before_ha=True,
253 after_dvr=True, after_ha=False)