Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 1 | # 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 Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 16 | import functools |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 17 | |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 18 | from neutron_lib.api.definitions import portbindings as pb |
| 19 | from neutron_lib import constants as const |
Rodolfo Alonso Hernandez | 4dea806 | 2020-01-16 16:32:59 +0000 | [diff] [blame] | 20 | from neutron_lib.utils import test |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 21 | from tempest.common import utils |
| 22 | from tempest.lib import decorators |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 23 | import testtools |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 24 | |
| 25 | from neutron_tempest_plugin.common import utils as common_utils |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 26 | from neutron_tempest_plugin import config |
Chandan Kumar | 667d3d3 | 2017-09-22 12:24:06 +0530 | [diff] [blame] | 27 | from neutron_tempest_plugin.scenario import base |
| 28 | from neutron_tempest_plugin.scenario import test_dvr |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 29 | |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 30 | CONF = config.CONF |
| 31 | |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 32 | |
| 33 | class NetworkMigrationTestBase(base.BaseTempestTestCase, |
| 34 | test_dvr.NetworkTestMixin): |
| 35 | credentials = ['primary', 'admin'] |
| 36 | force_tenant_isolation = False |
| 37 | |
| 38 | @classmethod |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 39 | @utils.requires_ext(extension="dvr", service="network") |
| 40 | @utils.requires_ext(extension="l3-ha", service="network") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 41 | def skip_checks(cls): |
| 42 | super(NetworkMigrationTestBase, cls).skip_checks() |
| 43 | |
| 44 | def _check_update(self, router, is_dvr, is_ha): |
rajat29 | 4495c04 | 2017-06-28 15:37:16 +0530 | [diff] [blame] | 45 | router = self.os_admin.network_client.show_router(router['id']) |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 46 | self.assertEqual(is_dvr, router['router']['distributed']) |
| 47 | self.assertEqual(is_ha, router['router']['ha']) |
| 48 | |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 49 | 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 Kaplonski | 096b6a8 | 2018-08-07 11:28:41 +0200 | [diff] [blame] | 71 | 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 Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 84 | 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 Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 125 | 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 Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 131 | self._wait_until_router_ports_ready( |
| 132 | router['id'], before_dvr, before_ha) |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 133 | self._check_connectivity() |
| 134 | |
rajat29 | 4495c04 | 2017-06-28 15:37:16 +0530 | [diff] [blame] | 135 | self.os_admin.network_client.update_router( |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 136 | router_id=router['id'], admin_state_up=False) |
Slawek Kaplonski | 096b6a8 | 2018-08-07 11:28:41 +0200 | [diff] [blame] | 137 | self._wait_until_router_ports_down(router['id']) |
| 138 | |
rajat29 | 4495c04 | 2017-06-28 15:37:16 +0530 | [diff] [blame] | 139 | self.os_admin.network_client.update_router( |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 140 | router_id=router['id'], distributed=after_dvr, ha=after_ha) |
| 141 | self._check_update(router, after_dvr, after_ha) |
| 142 | |
rajat29 | 4495c04 | 2017-06-28 15:37:16 +0530 | [diff] [blame] | 143 | self.os_admin.network_client.update_router( |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 144 | router_id=router['id'], admin_state_up=True) |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 145 | |
| 146 | self._wait_until_router_ports_migrated( |
| 147 | router['id'], before_dvr, before_ha, after_dvr, after_ha) |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 148 | self._check_connectivity() |
| 149 | |
| 150 | |
| 151 | class NetworkMigrationFromLegacy(NetworkMigrationTestBase): |
| 152 | |
| 153 | @decorators.idempotent_id('23724222-483a-4129-bc15-7a9278f3828b') |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 154 | @testtools.skipUnless( |
| 155 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 156 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 157 | 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 Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 167 | @testtools.skipUnless( |
| 168 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 169 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 170 | 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 | |
| 175 | class 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 Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 183 | @testtools.skipUnless( |
| 184 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 185 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 186 | 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 Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 191 | @testtools.skipUnless( |
| 192 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 193 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 194 | 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 | |
| 199 | class NetworkMigrationFromDVR(NetworkMigrationTestBase): |
| 200 | |
| 201 | @decorators.idempotent_id('e5cac02c-248d-4aac-bd5e-9d47c5197307') |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 202 | @testtools.skipUnless( |
| 203 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 204 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 205 | 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 Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 210 | @testtools.skipUnless( |
| 211 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 212 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 213 | 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 Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 218 | @testtools.skipUnless( |
| 219 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 220 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 221 | 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 | |
| 226 | class NetworkMigrationFromDVRHA(NetworkMigrationTestBase): |
| 227 | |
Rodolfo Alonso Hernandez | 4dea806 | 2020-01-16 16:32:59 +0000 | [diff] [blame] | 228 | @test.unstable_test("bug 1756301") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 229 | @decorators.idempotent_id('1be9b2e2-379c-40a4-a269-6687b81df691') |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 230 | @testtools.skipUnless( |
| 231 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 232 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 233 | 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 Hernandez | 4dea806 | 2020-01-16 16:32:59 +0000 | [diff] [blame] | 237 | @test.unstable_test("bug 1756301") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 238 | @decorators.idempotent_id('55957267-4e84-4314-a2f7-7cd36a2df04b') |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 239 | @testtools.skipUnless( |
| 240 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 241 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 242 | 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 Hernandez | 4dea806 | 2020-01-16 16:32:59 +0000 | [diff] [blame] | 246 | @test.unstable_test("bug 1756301") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 247 | @decorators.idempotent_id('d6bedff1-72be-4a9a-8ea2-dc037cd838e0') |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 248 | @testtools.skipUnless( |
| 249 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 250 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 251 | 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) |