blob: 62c36422d8bc555501f560d7e5abfd7de19d94c4 [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
22
23from neutron_tempest_plugin.common import utils as common_utils
Chandan Kumar667d3d32017-09-22 12:24:06 +053024from neutron_tempest_plugin.scenario import base
25from neutron_tempest_plugin.scenario import test_dvr
Genadi Chereshnya57173bd2017-01-10 11:17:07 +020026
27
28class NetworkMigrationTestBase(base.BaseTempestTestCase,
29 test_dvr.NetworkTestMixin):
30 credentials = ['primary', 'admin']
31 force_tenant_isolation = False
32
33 @classmethod
Chandan Kumarc125fd12017-11-15 19:41:01 +053034 @utils.requires_ext(extension="dvr", service="network")
35 @utils.requires_ext(extension="l3-ha", service="network")
Genadi Chereshnya57173bd2017-01-10 11:17:07 +020036 def skip_checks(cls):
37 super(NetworkMigrationTestBase, cls).skip_checks()
38
39 def _check_update(self, router, is_dvr, is_ha):
rajat294495c042017-06-28 15:37:16 +053040 router = self.os_admin.network_client.show_router(router['id'])
Genadi Chereshnya57173bd2017-01-10 11:17:07 +020041 self.assertEqual(is_dvr, router['router']['distributed'])
42 self.assertEqual(is_ha, router['router']['ha'])
43
Chandan Kumarc125fd12017-11-15 19:41:01 +053044 def _wait_until_port_deleted(self, router_id, device_owner):
45 common_utils.wait_until_true(
46 functools.partial(
47 self._is_port_deleted,
48 router_id,
49 device_owner),
50 timeout=300, sleep=5)
51
52 def _is_port_deleted(self, router_id, device_owner):
53 ports = self.os_admin.network_client.list_ports(
54 device_id=router_id,
55 device_owner=device_owner)
56 return not ports.get('ports')
57
58 def _wait_until_port_ready(self, router_id, device_owner):
59 common_utils.wait_until_true(
60 functools.partial(
61 self._is_port_active,
62 router_id,
63 device_owner),
64 timeout=300, sleep=5)
65
66 def _is_port_active(self, router_id, device_owner):
67 ports = self.os_admin.network_client.list_ports(
68 device_id=router_id,
69 device_owner=device_owner,
70 status=const.ACTIVE).get('ports')
71 if ports:
72 if ports[0][pb.VIF_TYPE] not in [pb.VIF_TYPE_UNBOUND,
73 pb.VIF_TYPE_BINDING_FAILED]:
74 return True
75 return False
76
77 def _wait_until_router_ports_ready(self, router_id, dvr, ha):
78 if dvr:
79 self._wait_until_port_ready(
80 router_id, const.DEVICE_OWNER_DVR_INTERFACE)
81 if ha:
82 self._wait_until_port_ready(
83 router_id, const.DEVICE_OWNER_ROUTER_HA_INTF)
84 if dvr:
85 self._wait_until_port_ready(
86 router_id, const.DEVICE_OWNER_ROUTER_SNAT)
87 else:
88 self._wait_until_port_ready(
89 router_id, const.DEVICE_OWNER_HA_REPLICATED_INT)
90 self._wait_until_port_ready(
91 router_id, const.DEVICE_OWNER_ROUTER_GW)
92
93 def _wait_until_router_ports_migrated(
94 self, router_id, before_dvr, before_ha, after_dvr, after_ha):
95 if before_ha and not after_ha:
96 self._wait_until_port_deleted(
97 router_id, const.DEVICE_OWNER_ROUTER_HA_INTF)
98 self._wait_until_port_deleted(
99 router_id, const.DEVICE_OWNER_HA_REPLICATED_INT)
100 if before_dvr and not after_dvr:
101 self._wait_until_port_deleted(
102 router_id, const.DEVICE_OWNER_DVR_INTERFACE)
103 self._wait_until_port_deleted(
104 router_id, const.DEVICE_OWNER_ROUTER_SNAT)
105 self._wait_until_router_ports_ready(router_id, after_dvr, after_ha)
106
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200107 def _test_migration(self, before_dvr, before_ha, after_dvr, after_ha):
108 router = self.create_router_by_client(
109 distributed=before_dvr, ha=before_ha,
110 tenant_id=self.client.tenant_id, is_admin=True)
111
112 self.setup_network_and_server(router=router)
Chandan Kumarc125fd12017-11-15 19:41:01 +0530113 self._wait_until_router_ports_ready(
114 router['id'], before_dvr, before_ha)
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200115 self._check_connectivity()
116
rajat294495c042017-06-28 15:37:16 +0530117 self.os_admin.network_client.update_router(
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200118 router_id=router['id'], admin_state_up=False)
rajat294495c042017-06-28 15:37:16 +0530119 self.os_admin.network_client.update_router(
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200120 router_id=router['id'], distributed=after_dvr, ha=after_ha)
121 self._check_update(router, after_dvr, after_ha)
122
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'], admin_state_up=True)
Chandan Kumarc125fd12017-11-15 19:41:01 +0530125
126 self._wait_until_router_ports_migrated(
127 router['id'], before_dvr, before_ha, after_dvr, after_ha)
Genadi Chereshnya57173bd2017-01-10 11:17:07 +0200128 self._check_connectivity()
129
130
131class NetworkMigrationFromLegacy(NetworkMigrationTestBase):
132
133 @decorators.idempotent_id('23724222-483a-4129-bc15-7a9278f3828b')
134 def test_from_legacy_to_dvr(self):
135 self._test_migration(before_dvr=False, before_ha=False,
136 after_dvr=True, after_ha=False)
137
138 @decorators.idempotent_id('09d85102-994f-4ff9-bf3e-17051145ca12')
139 def test_from_legacy_to_ha(self):
140 self._test_migration(before_dvr=False, before_ha=False,
141 after_dvr=False, after_ha=True)
142
143 @decorators.idempotent_id('fe169f2c-6ed3-4eb0-8afe-2d540c4b49e2')
144 def test_from_legacy_to_dvr_ha(self):
145 self._test_migration(before_dvr=False, before_ha=False,
146 after_dvr=True, after_ha=True)
147
148
149class NetworkMigrationFromHA(NetworkMigrationTestBase):
150
151 @decorators.idempotent_id('b4e68ac0-3b76-4306-ae8a-51cf4d363b22')
152 def test_from_ha_to_legacy(self):
153 self._test_migration(before_dvr=False, before_ha=True,
154 after_dvr=False, after_ha=False)
155
156 @decorators.idempotent_id('42260eea-5d56-4d30-b62a-a62694dfe4d5')
157 def test_from_ha_to_dvr(self):
158 self._test_migration(before_dvr=False, before_ha=True,
159 after_dvr=True, after_ha=False)
160
161 @decorators.idempotent_id('e4149576-248b-43fa-9d0b-a5c2f51967ce')
162 def test_from_ha_to_dvr_ha(self):
163 self._test_migration(before_dvr=False, before_ha=True,
164 after_dvr=True, after_ha=True)
165
166
167class NetworkMigrationFromDVR(NetworkMigrationTestBase):
168
169 @decorators.idempotent_id('e5cac02c-248d-4aac-bd5e-9d47c5197307')
170 def test_from_dvr_to_legacy(self):
171 self._test_migration(before_dvr=True, before_ha=False,
172 after_dvr=False, after_ha=False)
173
174 @decorators.idempotent_id('a00d5ad7-8509-4bb0-bdd2-7f1ee052d1cd')
175 def test_from_dvr_to_ha(self):
176 self._test_migration(before_dvr=True, before_ha=False,
177 after_dvr=False, after_ha=True)
178
179 @decorators.idempotent_id('25304a51-93a8-4cf3-9523-bce8b4eaecf8')
180 def test_from_dvr_to_dvr_ha(self):
181 self._test_migration(before_dvr=True, before_ha=False,
182 after_dvr=True, after_ha=True)
183
184
185class NetworkMigrationFromDVRHA(NetworkMigrationTestBase):
186
187 @decorators.idempotent_id('1be9b2e2-379c-40a4-a269-6687b81df691')
188 def test_from_dvr_ha_to_legacy(self):
189 self._test_migration(before_dvr=True, before_ha=True,
190 after_dvr=False, after_ha=False)
191
192 @decorators.idempotent_id('55957267-4e84-4314-a2f7-7cd36a2df04b')
193 def test_from_dvr_ha_to_ha(self):
194 self._test_migration(before_dvr=True, before_ha=True,
195 after_dvr=False, after_ha=True)
196
197 @decorators.idempotent_id('d6bedff1-72be-4a9a-8ea2-dc037cd838e0')
198 def test_from_dvr_ha_to_dvr(self):
199 self._test_migration(before_dvr=True, before_ha=True,
200 after_dvr=True, after_ha=False)