blob: 5e081f168df6f18d106ad41d87b2de91b3625ba4 [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
70 def _is_port_active(self, router_id, device_owner):
71 ports = self.os_admin.network_client.list_ports(
72 device_id=router_id,
73 device_owner=device_owner,
74 status=const.ACTIVE).get('ports')
75 if ports:
76 if ports[0][pb.VIF_TYPE] not in [pb.VIF_TYPE_UNBOUND,
77 pb.VIF_TYPE_BINDING_FAILED]:
78 return True
79 return False
80
81 def _wait_until_router_ports_ready(self, router_id, dvr, ha):
82 if dvr:
83 self._wait_until_port_ready(
84 router_id, const.DEVICE_OWNER_DVR_INTERFACE)
85 if ha:
86 self._wait_until_port_ready(
87 router_id, const.DEVICE_OWNER_ROUTER_HA_INTF)
88 if dvr:
89 self._wait_until_port_ready(
90 router_id, const.DEVICE_OWNER_ROUTER_SNAT)
91 else:
92 self._wait_until_port_ready(
93 router_id, const.DEVICE_OWNER_HA_REPLICATED_INT)
94 self._wait_until_port_ready(
95 router_id, const.DEVICE_OWNER_ROUTER_GW)
96
97 def _wait_until_router_ports_migrated(
98 self, router_id, before_dvr, before_ha, after_dvr, after_ha):
99 if before_ha and not after_ha:
100 self._wait_until_port_deleted(
101 router_id, const.DEVICE_OWNER_ROUTER_HA_INTF)
102 self._wait_until_port_deleted(
103 router_id, const.DEVICE_OWNER_HA_REPLICATED_INT)
104 if before_dvr and not after_dvr:
105 self._wait_until_port_deleted(
106 router_id, const.DEVICE_OWNER_DVR_INTERFACE)
107 self._wait_until_port_deleted(
108 router_id, const.DEVICE_OWNER_ROUTER_SNAT)
109 self._wait_until_router_ports_ready(router_id, after_dvr, after_ha)
110
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200111 def _test_migration(self, before_dvr, before_ha, after_dvr, after_ha):
112 router = self.create_router_by_client(
113 distributed=before_dvr, ha=before_ha,
114 tenant_id=self.client.tenant_id, is_admin=True)
115
116 self.setup_network_and_server(router=router)
Chandan Kumarc125fd12017-11-15 19:41:01 +0530117 self._wait_until_router_ports_ready(
118 router['id'], before_dvr, before_ha)
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200119 self._check_connectivity()
120
rajat294495c042017-06-28 15:37:16 +0530121 self.os_admin.network_client.update_router(
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200122 router_id=router['id'], admin_state_up=False)
rajat294495c042017-06-28 15:37:16 +0530123 self.os_admin.network_client.update_router(
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200124 router_id=router['id'], distributed=after_dvr, ha=after_ha)
125 self._check_update(router, after_dvr, after_ha)
126
rajat294495c042017-06-28 15:37:16 +0530127 self.os_admin.network_client.update_router(
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200128 router_id=router['id'], admin_state_up=True)
Chandan Kumarc125fd12017-11-15 19:41:01 +0530129
130 self._wait_until_router_ports_migrated(
131 router['id'], before_dvr, before_ha, after_dvr, after_ha)
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200132 self._check_connectivity()
133
134
135class NetworkMigrationFromLegacy(NetworkMigrationTestBase):
136
137 @decorators.idempotent_id('23724222-483a-4129-bc15-7a9278f3828b')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000138 @testtools.skipUnless(
139 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
140 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200141 def test_from_legacy_to_dvr(self):
142 self._test_migration(before_dvr=False, before_ha=False,
143 after_dvr=True, after_ha=False)
144
145 @decorators.idempotent_id('09d85102-994f-4ff9-bf3e-17051145ca12')
146 def test_from_legacy_to_ha(self):
147 self._test_migration(before_dvr=False, before_ha=False,
148 after_dvr=False, after_ha=True)
149
150 @decorators.idempotent_id('fe169f2c-6ed3-4eb0-8afe-2d540c4b49e2')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000151 @testtools.skipUnless(
152 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
153 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200154 def test_from_legacy_to_dvr_ha(self):
155 self._test_migration(before_dvr=False, before_ha=False,
156 after_dvr=True, after_ha=True)
157
158
159class NetworkMigrationFromHA(NetworkMigrationTestBase):
160
161 @decorators.idempotent_id('b4e68ac0-3b76-4306-ae8a-51cf4d363b22')
162 def test_from_ha_to_legacy(self):
163 self._test_migration(before_dvr=False, before_ha=True,
164 after_dvr=False, after_ha=False)
165
166 @decorators.idempotent_id('42260eea-5d56-4d30-b62a-a62694dfe4d5')
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_ha_to_dvr(self):
171 self._test_migration(before_dvr=False, before_ha=True,
172 after_dvr=True, after_ha=False)
173
174 @decorators.idempotent_id('e4149576-248b-43fa-9d0b-a5c2f51967ce')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000175 @testtools.skipUnless(
176 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
177 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200178 def test_from_ha_to_dvr_ha(self):
179 self._test_migration(before_dvr=False, before_ha=True,
180 after_dvr=True, after_ha=True)
181
182
183class NetworkMigrationFromDVR(NetworkMigrationTestBase):
184
185 @decorators.idempotent_id('e5cac02c-248d-4aac-bd5e-9d47c5197307')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000186 @testtools.skipUnless(
187 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
188 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200189 def test_from_dvr_to_legacy(self):
190 self._test_migration(before_dvr=True, before_ha=False,
191 after_dvr=False, after_ha=False)
192
193 @decorators.idempotent_id('a00d5ad7-8509-4bb0-bdd2-7f1ee052d1cd')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000194 @testtools.skipUnless(
195 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
196 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200197 def test_from_dvr_to_ha(self):
198 self._test_migration(before_dvr=True, before_ha=False,
199 after_dvr=False, after_ha=True)
200
201 @decorators.idempotent_id('25304a51-93a8-4cf3-9523-bce8b4eaecf8')
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_dvr_ha(self):
206 self._test_migration(before_dvr=True, before_ha=False,
207 after_dvr=True, after_ha=True)
208
209
210class NetworkMigrationFromDVRHA(NetworkMigrationTestBase):
211
Brian Haleyeb80cc32018-04-13 16:00:49 -0400212 @common_utils.unstable_test("bug 1756301")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200213 @decorators.idempotent_id('1be9b2e2-379c-40a4-a269-6687b81df691')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000214 @testtools.skipUnless(
215 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
216 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200217 def test_from_dvr_ha_to_legacy(self):
218 self._test_migration(before_dvr=True, before_ha=True,
219 after_dvr=False, after_ha=False)
220
Brian Haleyeb80cc32018-04-13 16:00:49 -0400221 @common_utils.unstable_test("bug 1756301")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200222 @decorators.idempotent_id('55957267-4e84-4314-a2f7-7cd36a2df04b')
Dongcan Ye91017ca2018-02-11 10:46:03 +0000223 @testtools.skipUnless(
224 CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat',
225 "Need dvr_snat agent mode assumption.")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200226 def test_from_dvr_ha_to_ha(self):
227 self._test_migration(before_dvr=True, before_ha=True,
228 after_dvr=False, after_ha=True)
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('d6bedff1-72be-4a9a-8ea2-dc037cd838e0')
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_dvr(self):
236 self._test_migration(before_dvr=True, before_ha=True,
237 after_dvr=True, after_ha=False)