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 | |
| 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 Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 111 | 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 Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 117 | self._wait_until_router_ports_ready( |
| 118 | router['id'], before_dvr, before_ha) |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 119 | self._check_connectivity() |
| 120 | |
rajat29 | 4495c04 | 2017-06-28 15:37:16 +0530 | [diff] [blame] | 121 | self.os_admin.network_client.update_router( |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 122 | router_id=router['id'], admin_state_up=False) |
rajat29 | 4495c04 | 2017-06-28 15:37:16 +0530 | [diff] [blame] | 123 | self.os_admin.network_client.update_router( |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 124 | router_id=router['id'], distributed=after_dvr, ha=after_ha) |
| 125 | self._check_update(router, after_dvr, after_ha) |
| 126 | |
rajat29 | 4495c04 | 2017-06-28 15:37:16 +0530 | [diff] [blame] | 127 | self.os_admin.network_client.update_router( |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 128 | router_id=router['id'], admin_state_up=True) |
Chandan Kumar | c125fd1 | 2017-11-15 19:41:01 +0530 | [diff] [blame] | 129 | |
| 130 | self._wait_until_router_ports_migrated( |
| 131 | router['id'], before_dvr, before_ha, after_dvr, after_ha) |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 132 | self._check_connectivity() |
| 133 | |
| 134 | |
| 135 | class NetworkMigrationFromLegacy(NetworkMigrationTestBase): |
| 136 | |
| 137 | @decorators.idempotent_id('23724222-483a-4129-bc15-7a9278f3828b') |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 138 | @testtools.skipUnless( |
| 139 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 140 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 141 | 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 Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 151 | @testtools.skipUnless( |
| 152 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 153 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 154 | 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 | |
| 159 | class 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 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_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 Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 175 | @testtools.skipUnless( |
| 176 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 177 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 178 | 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 | |
| 183 | class NetworkMigrationFromDVR(NetworkMigrationTestBase): |
| 184 | |
| 185 | @decorators.idempotent_id('e5cac02c-248d-4aac-bd5e-9d47c5197307') |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 186 | @testtools.skipUnless( |
| 187 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 188 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 189 | 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 Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 194 | @testtools.skipUnless( |
| 195 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 196 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 197 | 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 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_dvr_ha(self): |
| 206 | self._test_migration(before_dvr=True, before_ha=False, |
| 207 | after_dvr=True, after_ha=True) |
| 208 | |
| 209 | |
| 210 | class NetworkMigrationFromDVRHA(NetworkMigrationTestBase): |
| 211 | |
Brian Haley | eb80cc3 | 2018-04-13 16:00:49 -0400 | [diff] [blame^] | 212 | @common_utils.unstable_test("bug 1756301") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 213 | @decorators.idempotent_id('1be9b2e2-379c-40a4-a269-6687b81df691') |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 214 | @testtools.skipUnless( |
| 215 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 216 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 217 | 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 Haley | eb80cc3 | 2018-04-13 16:00:49 -0400 | [diff] [blame^] | 221 | @common_utils.unstable_test("bug 1756301") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 222 | @decorators.idempotent_id('55957267-4e84-4314-a2f7-7cd36a2df04b') |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 223 | @testtools.skipUnless( |
| 224 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 225 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 226 | 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 Haley | eb80cc3 | 2018-04-13 16:00:49 -0400 | [diff] [blame^] | 230 | @common_utils.unstable_test("bug 1756301") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 231 | @decorators.idempotent_id('d6bedff1-72be-4a9a-8ea2-dc037cd838e0') |
Dongcan Ye | 91017ca | 2018-02-11 10:46:03 +0000 | [diff] [blame] | 232 | @testtools.skipUnless( |
| 233 | CONF.neutron_plugin_options.l3_agent_mode == 'dvr_snat', |
| 234 | "Need dvr_snat agent mode assumption.") |
Genadi Chereshnya | 57173bd | 2017-01-10 11:17:07 +0200 | [diff] [blame] | 235 | 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) |