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 |
| 20 | from tempest.common import utils |
| 21 | from tempest.lib import decorators |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 22 | import testtools |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 23 | |
| 24 | from neutron_tempest_plugin.common import utils as common_utils |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 25 | from neutron_tempest_plugin import config |
Chandan Kumar | 667d3d3 | 2017-09-22 12:24:06 +0530 | [diff] [blame] | 26 | from neutron_tempest_plugin.scenario import base |
| 27 | from neutron_tempest_plugin.scenario import test_dvr |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 28 | |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 29 | CONF = config.CONF |
| 30 | |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 31 | |
| 32 | class NetworkMigrationTestBase(base.BaseTempestTestCase, |
| 33 | test_dvr.NetworkTestMixin): |
| 34 | credentials = ['primary', 'admin'] |
| 35 | force_tenant_isolation = False |
| 36 | |
| 37 | @classmethod |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 38 | @utils.requires_ext(extension="dvr", service="network") |
| 39 | @utils.requires_ext(extension="l3-ha", service="network") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 40 | def skip_checks(cls): |
| 41 | super(NetworkMigrationTestBase, cls).skip_checks() |
| 42 | |
| 43 | def _check_update(self, router, is_dvr, is_ha): |
rajat29 | 4495c04 | 2017-06-28 15:37:16 +0530 | [diff] [blame] | 44 | router = self.os_admin.network_client.show_router(router['id']) |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 45 | self.assertEqual(is_dvr, router['router']['distributed']) |
| 46 | self.assertEqual(is_ha, router['router']['ha']) |
| 47 | |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 48 | 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 Kaplonski | 096b6a8 | 2018-08-07 11:28:41 +0200 | [diff] [blame] | 70 | 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 Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 83 | 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 Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 124 | 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 Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 130 | self._wait_until_router_ports_ready( |
| 131 | router['id'], before_dvr, before_ha) |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 132 | self._check_connectivity() |
| 133 | |
rajat29 | 4495c04 | 2017-06-28 15:37:16 +0530 | [diff] [blame] | 134 | self.os_admin.network_client.update_router( |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 135 | router_id=router['id'], admin_state_up=False) |
Slawek Kaplonski | 096b6a8 | 2018-08-07 11:28:41 +0200 | [diff] [blame] | 136 | self._wait_until_router_ports_down(router['id']) |
| 137 | |
rajat29 | 4495c04 | 2017-06-28 15:37:16 +0530 | [diff] [blame] | 138 | self.os_admin.network_client.update_router( |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 139 | router_id=router['id'], distributed=after_dvr, ha=after_ha) |
| 140 | self._check_update(router, after_dvr, after_ha) |
| 141 | |
rajat29 | 4495c04 | 2017-06-28 15:37:16 +0530 | [diff] [blame] | 142 | self.os_admin.network_client.update_router( |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 143 | router_id=router['id'], admin_state_up=True) |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 144 | |
| 145 | self._wait_until_router_ports_migrated( |
| 146 | router['id'], before_dvr, before_ha, after_dvr, after_ha) |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 147 | self._check_connectivity() |
| 148 | |
| 149 | |
| 150 | class NetworkMigrationFromLegacy(NetworkMigrationTestBase): |
| 151 | |
| 152 | @decorators.idempotent_id('23724222-483a-4129-bc15-7a9278f3828b') |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 153 | @testtools.skipUnless( |
| 154 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 155 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 156 | 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 Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 166 | @testtools.skipUnless( |
| 167 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 168 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 169 | 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 | |
| 174 | class NetworkMigrationFromHA(NetworkMigrationTestBase): |
| 175 | |
| 176 | @decorators.idempotent_id('b4e68ac0-3b76-4306-ae8a-51cf4d363b22') |
| 177 | def test_from_ha_to_legacy(self): |
| 178 | self._test_migration(before_dvr=False, before_ha=True, |
| 179 | after_dvr=False, after_ha=False) |
| 180 | |
| 181 | @decorators.idempotent_id('42260eea-5d56-4d30-b62a-a62694dfe4d5') |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 182 | @testtools.skipUnless( |
| 183 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 184 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 185 | def test_from_ha_to_dvr(self): |
| 186 | self._test_migration(before_dvr=False, before_ha=True, |
| 187 | after_dvr=True, after_ha=False) |
| 188 | |
| 189 | @decorators.idempotent_id('e4149576-248b-43fa-9d0b-a5c2f51967ce') |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 190 | @testtools.skipUnless( |
| 191 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 192 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 193 | def test_from_ha_to_dvr_ha(self): |
| 194 | self._test_migration(before_dvr=False, before_ha=True, |
| 195 | after_dvr=True, after_ha=True) |
| 196 | |
| 197 | |
| 198 | class NetworkMigrationFromDVR(NetworkMigrationTestBase): |
| 199 | |
| 200 | @decorators.idempotent_id('e5cac02c-248d-4aac-bd5e-9d47c5197307') |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 201 | @testtools.skipUnless( |
| 202 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 203 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 204 | def test_from_dvr_to_legacy(self): |
| 205 | self._test_migration(before_dvr=True, before_ha=False, |
| 206 | after_dvr=False, after_ha=False) |
| 207 | |
| 208 | @decorators.idempotent_id('a00d5ad7-8509-4bb0-bdd2-7f1ee052d1cd') |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 209 | @testtools.skipUnless( |
| 210 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 211 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 212 | def test_from_dvr_to_ha(self): |
| 213 | self._test_migration(before_dvr=True, before_ha=False, |
| 214 | after_dvr=False, after_ha=True) |
| 215 | |
| 216 | @decorators.idempotent_id('25304a51-93a8-4cf3-9523-bce8b4eaecf8') |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 217 | @testtools.skipUnless( |
| 218 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 219 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 220 | def test_from_dvr_to_dvr_ha(self): |
| 221 | self._test_migration(before_dvr=True, before_ha=False, |
| 222 | after_dvr=True, after_ha=True) |
| 223 | |
| 224 | |
| 225 | class NetworkMigrationFromDVRHA(NetworkMigrationTestBase): |
| 226 | |
Brian Haley | eb80cc3 | 2018-04-13 16:00:49 -0400 | [diff] [blame] | 227 | @common_utils.unstable_test("bug 1756301") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 228 | @decorators.idempotent_id('1be9b2e2-379c-40a4-a269-6687b81df691') |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 229 | @testtools.skipUnless( |
| 230 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 231 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 232 | def test_from_dvr_ha_to_legacy(self): |
| 233 | self._test_migration(before_dvr=True, before_ha=True, |
| 234 | after_dvr=False, after_ha=False) |
| 235 | |
Brian Haley | eb80cc3 | 2018-04-13 16:00:49 -0400 | [diff] [blame] | 236 | @common_utils.unstable_test("bug 1756301") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 237 | @decorators.idempotent_id('55957267-4e84-4314-a2f7-7cd36a2df04b') |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 238 | @testtools.skipUnless( |
| 239 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 240 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 241 | def test_from_dvr_ha_to_ha(self): |
| 242 | self._test_migration(before_dvr=True, before_ha=True, |
| 243 | after_dvr=False, after_ha=True) |
| 244 | |
Brian Haley | eb80cc3 | 2018-04-13 16:00:49 -0400 | [diff] [blame] | 245 | @common_utils.unstable_test("bug 1756301") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 246 | @decorators.idempotent_id('d6bedff1-72be-4a9a-8ea2-dc037cd838e0') |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 247 | @testtools.skipUnless( |
| 248 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 249 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 250 | def test_from_dvr_ha_to_dvr(self): |
| 251 | self._test_migration(before_dvr=True, before_ha=True, |
| 252 | after_dvr=True, after_ha=False) |