blob: 3d6c1dd671a1ac46f929344820f11bb69951f350 [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
Slawek Kaplonskie137cd02018-09-25 14:28:22 +0200176 @common_utils.unstable_test("bug 1789434")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200177 @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
Slawek Kaplonskie137cd02018-09-25 14:28:22 +0200182 @common_utils.unstable_test("bug 1789434")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200183 @decorators.idempotent_id('42260eea-5d56-4d30-b62a-a62694dfe4d5')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000184 @testtools.skipUnless(
185 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
186 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200187 def test_from_ha_to_dvr(self):
188 self._test_migration(before_dvr=False, before_ha=True,
189 after_dvr=True, after_ha=False)
190
Slawek Kaplonskie137cd02018-09-25 14:28:22 +0200191 @common_utils.unstable_test("bug 1789434")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200192 @decorators.idempotent_id('e4149576-248b-43fa-9d0b-a5c2f51967ce')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000193 @testtools.skipUnless(
194 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
195 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200196 def test_from_ha_to_dvr_ha(self):
197 self._test_migration(before_dvr=False, before_ha=True,
198 after_dvr=True, after_ha=True)
199
200
201class NetworkMigrationFromDVR(NetworkMigrationTestBase):
202
203 @decorators.idempotent_id('e5cac02c-248d-4aac-bd5e-9d47c5197307')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000204 @testtools.skipUnless(
205 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
206 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200207 def test_from_dvr_to_legacy(self):
208 self._test_migration(before_dvr=True, before_ha=False,
209 after_dvr=False, after_ha=False)
210
211 @decorators.idempotent_id('a00d5ad7-8509-4bb0-bdd2-7f1ee052d1cd')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000212 @testtools.skipUnless(
213 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
214 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200215 def test_from_dvr_to_ha(self):
216 self._test_migration(before_dvr=True, before_ha=False,
217 after_dvr=False, after_ha=True)
218
219 @decorators.idempotent_id('25304a51-93a8-4cf3-9523-bce8b4eaecf8')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000220 @testtools.skipUnless(
221 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
222 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200223 def test_from_dvr_to_dvr_ha(self):
224 self._test_migration(before_dvr=True, before_ha=False,
225 after_dvr=True, after_ha=True)
226
227
228class NetworkMigrationFromDVRHA(NetworkMigrationTestBase):
229
Brian Haleyeb80cc32018-04-13 16:00:49 -0400230 @common_utils.unstable_test("bug 1756301")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200231 @decorators.idempotent_id('1be9b2e2-379c-40a4-a269-6687b81df691')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000232 @testtools.skipUnless(
233 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
234 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200235 def test_from_dvr_ha_to_legacy(self):
236 self._test_migration(before_dvr=True, before_ha=True,
237 after_dvr=False, after_ha=False)
238
Brian Haleyeb80cc32018-04-13 16:00:49 -0400239 @common_utils.unstable_test("bug 1756301")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200240 @decorators.idempotent_id('55957267-4e84-4314-a2f7-7cd36a2df04b')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000241 @testtools.skipUnless(
242 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
243 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200244 def test_from_dvr_ha_to_ha(self):
245 self._test_migration(before_dvr=True, before_ha=True,
246 after_dvr=False, after_ha=True)
247
Brian Haleyeb80cc32018-04-13 16:00:49 -0400248 @common_utils.unstable_test("bug 1756301")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200249 @decorators.idempotent_id('d6bedff1-72be-4a9a-8ea2-dc037cd838e0')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000250 @testtools.skipUnless(
251 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
252 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200253 def test_from_dvr_ha_to_dvr(self):
254 self._test_migration(before_dvr=True, before_ha=True,
255 after_dvr=True, after_ha=False)