| 1 |
# Copyright 2016 Cisco Systems, 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 |
|
| 16 |
import os |
| 17 |
import random |
| 18 |
|
| 19 |
import netaddr |
| 20 |
from neutron_lib._i18n import _ |
| 21 |
from neutron_lib.utils import test |
| 22 |
from oslo_concurrency import lockutils |
| 23 |
from oslo_log import log as logging |
| 24 |
from tempest.common import compute |
| 25 |
from tempest.common import utils |
| 26 |
from tempest.common import waiters |
| 27 |
from tempest import config |
| 28 |
from tempest.lib.common.utils import data_utils |
| 29 |
from tempest.lib.common.utils import test_utils |
| 30 |
from tempest.lib import decorators |
| 31 |
|
| 32 |
from neutron_tempest_plugin.bgpvpn import base |
| 33 |
from neutron_tempest_plugin.bgpvpn.scenario import manager |
| 34 |
|
| 35 |
|
| 36 |
CONF = config.CONF |
| 37 |
LOG = logging.getLogger(__name__) |
| 38 |
NET_A = 'A' |
| 39 |
NET_A_BIS = 'A-Bis' |
| 40 |
NET_B = 'B' |
| 41 |
NET_C = 'C' |
| 42 |
|
| 43 |
if "SUBNETPOOL_PREFIX_V4" in os.environ: |
| 44 |
subnet_base = netaddr.IPNetwork(os.environ['SUBNETPOOL_PREFIX_V4']) |
| 45 |
if subnet_base.prefixlen > 21: |
| 46 |
raise Exception(_("if SUBNETPOOL_PREFIX_V4 is set, it needs to offer " |
| 47 |
"space for at least 8 /24 subnets")) |
| 48 |
else: |
| 49 |
subnet_base = netaddr.IPNetwork("10.100.0.0/16") |
| 50 |
|
| 51 |
|
| 52 |
def assign_24(idx): |
| 53 |
# how many addresses in a /24: |
| 54 |
range_size = 2 ** (32 - 24) |
| 55 |
return netaddr.cidr_merge( |
| 56 |
subnet_base[range_size * idx:range_size * (idx + 1)])[0] |
| 57 |
|
| 58 |
|
| 59 |
S1A = assign_24(1) |
| 60 |
S2A = assign_24(2) |
| 61 |
S1B = assign_24(4) |
| 62 |
S2B = assign_24(6) |
| 63 |
S1C = assign_24(6) |
| 64 |
NET_A_S1 = str(S1A) |
| 65 |
NET_A_S2 = str(S2A) |
| 66 |
NET_B_S1 = str(S1B) |
| 67 |
NET_B_S2 = str(S2B) |
| 68 |
NET_C_S1 = str(S1C) |
| 69 |
IP_A_S1_1 = str(S1A[10]) |
| 70 |
IP_B_S1_1 = str(S1B[20]) |
| 71 |
IP_C_S1_1 = str(S1C[30]) |
| 72 |
IP_A_S1_2 = str(S1A[30]) |
| 73 |
IP_B_S1_2 = str(S1B[40]) |
| 74 |
IP_A_S1_3 = str(S1A[50]) |
| 75 |
IP_B_S1_3 = str(S1B[60]) |
| 76 |
IP_A_S2_1 = str(S2A[50]) |
| 77 |
IP_B_S2_1 = str(S2B[60]) |
| 78 |
IP_A_BIS_S1_1 = IP_A_S1_1 |
| 79 |
IP_A_BIS_S1_2 = IP_A_S1_2 |
| 80 |
IP_A_BIS_S1_3 = IP_A_S1_3 |
| 81 |
IP_A_BIS_S2_1 = IP_A_S2_1 |
| 82 |
|
| 83 |
|
| 84 |
class TestBGPVPNBasic(base.BaseBgpvpnTest, manager.NetworkScenarioTest): |
| 85 |
|
| 86 |
@classmethod |
| 87 |
def setUpClass(cls): |
| 88 |
super(TestBGPVPNBasic, cls).setUpClass() |
| 89 |
cls._rt_index = 0 |
| 90 |
|
| 91 |
@classmethod |
| 92 |
@lockutils.synchronized('bgpvpn') |
| 93 |
def new_rt(cls): |
| 94 |
cls._rt_index += 1 |
| 95 |
return "64512:%d" % cls._rt_index |
| 96 |
|
| 97 |
def setUp(self): |
| 98 |
super(TestBGPVPNBasic, self).setUp() |
| 99 |
self.servers_keypairs = {} |
| 100 |
self.servers = [] |
| 101 |
self.server_fixed_ips = {} |
| 102 |
self.ports = {} |
| 103 |
self.networks = {} |
| 104 |
self.subnets = {} |
| 105 |
self.server_fips = {} |
| 106 |
self._create_security_group_for_test() |
| 107 |
self.RT1 = self.new_rt() |
| 108 |
self.RT2 = self.new_rt() |
| 109 |
self.RT3 = self.new_rt() |
| 110 |
self.RT4 = self.new_rt() |
| 111 |
|
| 112 |
@classmethod |
| 113 |
def setup_clients(cls): |
| 114 |
"""This setup the service clients for the tests""" |
| 115 |
super(TestBGPVPNBasic, cls).setup_clients() |
| 116 |
cls.admin_security_group_client = cls.os_admin.security_groups_client |
| 117 |
cls.admin_security_group_rule_client = ( |
| 118 |
cls.os_admin.security_group_rules_client) |
| 119 |
cls.admin_routers_client = cls.os_admin.routers_client |
| 120 |
cls.admin_ports_client = cls.os_admin.ports_client |
| 121 |
cls.admin_networks_client = cls.os_admin.networks_client |
| 122 |
cls.admin_subnets_client = cls.os_admin.subnets_client |
| 123 |
cls.admin_fips_client = cls.os_admin.floating_ips_client |
| 124 |
cls.admin_keys_client = cls.os_admin.keypairs_client |
| 125 |
|
| 126 |
@decorators.idempotent_id('afdd6cad-871a-4343-b97b-6319c76c815d') |
| 127 |
@utils.services('compute', 'network') |
| 128 |
def test_bgpvpn_basic(self): |
| 129 |
"""This test checks basic BGPVPN. |
| 130 |
|
| 131 |
1. Create networks A and B with their respective subnets |
| 132 |
2. Start up server 1 in network A |
| 133 |
3. Start up server 2 in network B |
| 134 |
4. Associate network A and network B to a given L3 BGPVPN |
| 135 |
5. Create router and connect it to network A |
| 136 |
6. Give a FIP to server 1 |
| 137 |
7. Check that server 1 can ping server 2 |
| 138 |
""" |
| 139 |
|
| 140 |
self._create_networks_and_subnets() |
| 141 |
self._create_servers() |
| 142 |
self._create_l3_bgpvpn() |
| 143 |
self._associate_all_nets_to_bgpvpn() |
| 144 |
self._associate_fip_and_check_l3_bgpvpn() |
| 145 |
|
| 146 |
@decorators.idempotent_id('8a5a6fac-313c-464b-9c5c-29d4e1c0a51e') |
| 147 |
@utils.services('compute', 'network') |
| 148 |
def test_bgpvpn_variant1(self): |
| 149 |
"""This test checks basic BGPVPN. |
| 150 |
|
| 151 |
1. Create networks A and B with their respective subnets |
| 152 |
2. Associate network A and network B to a given L3 BGPVPN |
| 153 |
3. Start up server 1 in network A |
| 154 |
4. Start up server 2 in network B |
| 155 |
5. Create router and connect it to network A |
| 156 |
6. Give a FIP to server 1 |
| 157 |
7. Check that server 1 can ping server 2 |
| 158 |
""" |
| 159 |
self._create_networks_and_subnets() |
| 160 |
self._create_l3_bgpvpn() |
| 161 |
self._associate_all_nets_to_bgpvpn() |
| 162 |
self._create_servers() |
| 163 |
self._associate_fip_and_check_l3_bgpvpn() |
| 164 |
|
| 165 |
@decorators.idempotent_id('e7468636-0816-4092-82ca-3590680ed00b') |
| 166 |
@utils.services('compute', 'network') |
| 167 |
def test_bgpvpn_variant2(self): |
| 168 |
"""This test checks basic BGPVPN. |
| 169 |
|
| 170 |
1. Create networks A and B with their respective subnets |
| 171 |
2. Start up server 1 in network A |
| 172 |
3. Start up server 2 in network B |
| 173 |
4. Create router and associate to network B |
| 174 |
5. Associate network A and network B to a given L3 BGPVPN |
| 175 |
6. Create router and connect it to network A |
| 176 |
7. Give a FIP to server 1 |
| 177 |
8. Check that server 1 can ping server 2 |
| 178 |
""" |
| 179 |
self._create_networks_and_subnets() |
| 180 |
self._create_servers() |
| 181 |
self.router_b = self._create_fip_router( |
| 182 |
client=self.admin_routers_client, |
| 183 |
subnet_id=self.subnets[NET_B][0]['id']) |
| 184 |
self._create_l3_bgpvpn() |
| 185 |
self._associate_all_nets_to_bgpvpn() |
| 186 |
self._associate_fip_and_check_l3_bgpvpn() |
| 187 |
|
| 188 |
@decorators.idempotent_id('7c66aa31-fb3a-4e15-8808-46eb361f153a') |
| 189 |
@utils.services('compute', 'network') |
| 190 |
def test_bgpvpn_variant3(self): |
| 191 |
"""This test checks basic BGPVPN. |
| 192 |
|
| 193 |
1. Create networks A and B with their respective subnets |
| 194 |
2. Start up server 1 in network A |
| 195 |
3. Start up server 2 in network B |
| 196 |
4. Create router and connect it to network B |
| 197 |
5. Associate network A and network B to a given L3 BGPVPN |
| 198 |
6. Delete router associated to network B |
| 199 |
7. Create router and connect it to network A |
| 200 |
8. Give a FIP to server 1 |
| 201 |
9. Check that server 1 can ping server 2 |
| 202 |
""" |
| 203 |
self._create_networks_and_subnets() |
| 204 |
self._create_servers() |
| 205 |
self.router_b = self._create_fip_router( |
| 206 |
client=self.admin_routers_client, |
| 207 |
subnet_id=self.subnets[NET_B][0]['id']) |
| 208 |
self._create_l3_bgpvpn() |
| 209 |
self._associate_all_nets_to_bgpvpn() |
| 210 |
self._delete_router(self.router_b, |
| 211 |
routers_client=self.admin_routers_client, |
| 212 |
ports_client=self.admin_ports_client) |
| 213 |
self._associate_fip_and_check_l3_bgpvpn() |
| 214 |
|
| 215 |
@decorators.idempotent_id('973ab26d-c7d8-4a32-9aa9-2d7e6f406135') |
| 216 |
@utils.services('compute', 'network') |
| 217 |
def test_bgpvpn_variant4(self): |
| 218 |
"""This test checks basic BGPVPN. |
| 219 |
|
| 220 |
1. Create networks A and B with their respective subnets |
| 221 |
2. Start up server 1 in network A |
| 222 |
3. Start up server 2 in network B |
| 223 |
4. Associate network A and network B to a given L3 BGPVPN |
| 224 |
5. Create router and connect it to network B |
| 225 |
6. Create router and connect it to network A |
| 226 |
7. Give a FIP to server 1 |
| 227 |
8. Check that server 2 can ping server 1 |
| 228 |
""" |
| 229 |
self._create_networks_and_subnets() |
| 230 |
self._create_servers() |
| 231 |
self._create_l3_bgpvpn() |
| 232 |
self._associate_all_nets_to_bgpvpn() |
| 233 |
self.router_b = self._create_fip_router( |
| 234 |
client=self.admin_routers_client, |
| 235 |
subnet_id=self.subnets[NET_B][0]['id']) |
| 236 |
self._associate_fip_and_check_l3_bgpvpn() |
| 237 |
|
| 238 |
@decorators.idempotent_id('2ac0696b-e828-4299-9e94-5f9c4988d961') |
| 239 |
@utils.services('compute', 'network') |
| 240 |
def test_bgpvpn_variant5(self): |
| 241 |
"""This test checks basic BGPVPN. |
| 242 |
|
| 243 |
1. Create networks A and B with their respective subnets |
| 244 |
2. Create router and connect it to network B |
| 245 |
3. Associate network A and network B to a given L3 BGPVPN |
| 246 |
4. Start up server 1 in network A |
| 247 |
5. Start up server 2 in network B |
| 248 |
6. Create router and connect it to network A |
| 249 |
7. Give a FIP to server 1 |
| 250 |
8. Check that server 2 can ping server 1 |
| 251 |
""" |
| 252 |
self._create_networks_and_subnets() |
| 253 |
self.router_b = self._create_fip_router( |
| 254 |
client=self.admin_routers_client, |
| 255 |
subnet_id=self.subnets[NET_B][0]['id']) |
| 256 |
self._create_l3_bgpvpn() |
| 257 |
self._associate_all_nets_to_bgpvpn() |
| 258 |
self._create_servers() |
| 259 |
self._associate_fip_and_check_l3_bgpvpn() |
| 260 |
|
| 261 |
@decorators.idempotent_id('9081338e-a52e-46bb-a40e-bda24ec4b1bd') |
| 262 |
@utils.services('compute', 'network') |
| 263 |
def test_bgpvpn_variant6(self): |
| 264 |
"""This test checks basic BGPVPN. |
| 265 |
|
| 266 |
1. Create networks A and B with their respective subnets |
| 267 |
2. Associate network A and network B to a given L3 BGPVPN |
| 268 |
3. Create router and connect it to network B |
| 269 |
4. Start up server 1 in network A |
| 270 |
5. Start up server 2 in network B |
| 271 |
6. Create router and connect it to network A |
| 272 |
7. Give a FIP to server 1 |
| 273 |
8. Check that server 2 can ping server 1 |
| 274 |
""" |
| 275 |
self._create_networks_and_subnets() |
| 276 |
self._create_l3_bgpvpn() |
| 277 |
self._associate_all_nets_to_bgpvpn() |
| 278 |
self.router_b = self._create_fip_router( |
| 279 |
client=self.admin_routers_client, |
| 280 |
subnet_id=self.subnets[NET_B][0]['id']) |
| 281 |
self._create_servers() |
| 282 |
self._associate_fip_and_check_l3_bgpvpn() |
| 283 |
|
| 284 |
@decorators.idempotent_id('133497a1-2788-40f7-be01-b3b64b5ef8cd') |
| 285 |
@utils.services('compute', 'network') |
| 286 |
def test_bgpvpn_update_route_targets_disjoint_targets(self): |
| 287 |
"""This test checks basic BGPVPN route targets update. |
| 288 |
|
| 289 |
1. Create networks A and B with their respective subnets |
| 290 |
2. Start up server 1 in network A |
| 291 |
3. Start up server 2 in network B |
| 292 |
4. Create L3 BGPVPN with only RT defined |
| 293 |
5. Associate network A to a given L3 BGPVPN |
| 294 |
6. Create router and connect it to network A |
| 295 |
7. Give a FIP to server 1 |
| 296 |
8. Check that server 1 can ping server 2 |
| 297 |
9. Update L3 BGPVPN to have eRT<>iRT and no RT what is insufficient |
| 298 |
for proper connectivity between network A and B |
| 299 |
10. Check that server 1 cannot ping server 2 |
| 300 |
11. Update L3 BGPVPN to have again only RT defined |
| 301 |
12. Check that server 1 can ping again server 2 |
| 302 |
""" |
| 303 |
self._create_networks_and_subnets() |
| 304 |
self._create_servers() |
| 305 |
self._create_l3_bgpvpn(rts=[self.RT1], import_rts=[], |
| 306 |
export_rts=[]) |
| 307 |
self._associate_all_nets_to_bgpvpn() |
| 308 |
self._associate_fip_and_check_l3_bgpvpn() |
| 309 |
self._update_l3_bgpvpn(rts=[], import_rts=[self.RT1], |
| 310 |
export_rts=[self.RT2]) |
| 311 |
self._check_l3_bgpvpn(should_succeed=False) |
| 312 |
self._update_l3_bgpvpn(rts=[self.RT1], import_rts=[], export_rts=[]) |
| 313 |
self._check_l3_bgpvpn() |
| 314 |
|
| 315 |
@decorators.idempotent_id('bf417cad-0bc4-446a-b367-850aa619ca4f') |
| 316 |
@utils.services('compute', 'network') |
| 317 |
def test_bgpvpn_update_route_targets_common_target(self): |
| 318 |
"""This test checks basic BGPVPN route targets update. |
| 319 |
|
| 320 |
1. Create networks A and B with their respective subnets |
| 321 |
2. Start up server 1 in network A |
| 322 |
3. Start up server 2 in network B |
| 323 |
4. Create L3 BGPVPN with only RT defined |
| 324 |
5. Associate network A to a given L3 BGPVPN |
| 325 |
6. Create router and connect it to network A |
| 326 |
7. Give a FIP to server 1 |
| 327 |
8. Check that server 1 can ping server 2 |
| 328 |
9. Update L3 BGPVPN to have eRT<>iRT and RT=iRT |
| 329 |
10. Check that server 1 can ping server 2 |
| 330 |
11. Update L3 BGPVPN to have again only RT defined |
| 331 |
12. Check that server 1 can ping again server 2 |
| 332 |
""" |
| 333 |
self._create_networks_and_subnets() |
| 334 |
self._create_servers() |
| 335 |
self._create_l3_bgpvpn(rts=[self.RT1], import_rts=[], export_rts=[]) |
| 336 |
self._associate_all_nets_to_bgpvpn() |
| 337 |
self._associate_fip_and_check_l3_bgpvpn() |
| 338 |
self._update_l3_bgpvpn(rts=[self.RT1], import_rts=[self.RT1], |
| 339 |
export_rts=[self.RT2]) |
| 340 |
self._check_l3_bgpvpn() |
| 341 |
self._update_l3_bgpvpn(rts=[self.RT1], import_rts=[], export_rts=[]) |
| 342 |
self._check_l3_bgpvpn() |
| 343 |
|
| 344 |
@decorators.idempotent_id('08d4f40e-3cec-485b-9da2-76e67fbd9881') |
| 345 |
@utils.services('compute', 'network') |
| 346 |
def test_bgpvpn_update_route_targets_and_unassociated_net(self): |
| 347 |
"""This test checks basic BGPVPN route targets update. |
| 348 |
|
| 349 |
1. Create networks A and B with their respective subnets |
| 350 |
2. Start up server 1 in network A |
| 351 |
3. Start up server 2 in network B |
| 352 |
4. Create invalid L3 BGPVPN with eRT<>iRT that is insufficient |
| 353 |
for proper connectivity between network A and B |
| 354 |
5. Associate network A to a given L3 BGPVPN |
| 355 |
6. Create router and connect it to network A |
| 356 |
7. Give a FIP to server 1 |
| 357 |
8. Check that server 1 cannot ping server 2 |
| 358 |
9. Associate network B to a given L3 BGPVPN |
| 359 |
10. Check that server 1 cannot ping server 2 |
| 360 |
11. Update L3 BGPVPN to have only RT defined |
| 361 |
12. Check that server 1 can ping server 2 |
| 362 |
""" |
| 363 |
self._create_networks_and_subnets() |
| 364 |
self._create_servers() |
| 365 |
self.router = self._create_router_and_associate_fip( |
| 366 |
0, self.subnets[NET_A][0]) |
| 367 |
self._create_l3_bgpvpn(rts=[], export_rts=[self.RT1], |
| 368 |
import_rts=[self.RT2]) |
| 369 |
self.bgpvpn_admin_client.create_network_association( |
| 370 |
self.bgpvpn['id'], self.networks[NET_A]['id']) |
| 371 |
self._check_l3_bgpvpn(should_succeed=False) |
| 372 |
self.bgpvpn_admin_client.create_network_association( |
| 373 |
self.bgpvpn['id'], self.networks[NET_B]['id']) |
| 374 |
self._check_l3_bgpvpn(should_succeed=False) |
| 375 |
self._update_l3_bgpvpn(rts=[self.RT1], import_rts=[], export_rts=[]) |
| 376 |
self._check_l3_bgpvpn() |
| 377 |
|
| 378 |
@test.unstable_test("bug 1897408") |
| 379 |
@decorators.idempotent_id('c8bfd695-f731-47a6-86e3-3dfa492e08e0') |
| 380 |
@utils.services('compute', 'network') |
| 381 |
def test_bgpvpn_update_rt_and_keep_local_connectivity_variant1(self): |
| 382 |
"""This test checks basic BGPVPN route targets update. |
| 383 |
|
| 384 |
1. Create networks A and B with their respective subnets |
| 385 |
2. Start up server 1 in network A |
| 386 |
3. Start up server 2 in network B |
| 387 |
4. Start up server 3 in network A |
| 388 |
5. Start up server 4 in network B |
| 389 |
6. Create invalid L3 BGPVPN with eRT<>iRT that is insufficient |
| 390 |
for proper connectivity between network A and B |
| 391 |
7. Associate network A to a given L3 BGPVPN |
| 392 |
8. Create router A and connect it to network A |
| 393 |
9. Give a FIP to server 1 |
| 394 |
10. Check that server 1 cannot ping server 2 |
| 395 |
11. Check that server 1 can ping server 3 |
| 396 |
12. Associate network B to a given L3 BGPVPN |
| 397 |
13. Create router B and connect it to network B |
| 398 |
14. Give a FIP to server 2 |
| 399 |
15. Check that server 1 still cannot ping server 2 |
| 400 |
16. Check that server 2 can ping server 4 |
| 401 |
17. Update L3 BGPVPN to have now only RT defined |
| 402 |
18. Check that server 1 can now ping server 2 |
| 403 |
19. Check that server 1 still can ping server 3 |
| 404 |
20. Check that server 2 still can ping server 4 |
| 405 |
""" |
| 406 |
self._create_networks_and_subnets() |
| 407 |
self._create_l3_bgpvpn(rts=[], import_rts=[self.RT1], |
| 408 |
export_rts=[self.RT2]) |
| 409 |
self._create_servers([[self.networks[NET_A], IP_A_S1_1], |
| 410 |
[self.networks[NET_B], IP_B_S1_1], |
| 411 |
[self.networks[NET_A], IP_A_S1_2], |
| 412 |
[self.networks[NET_B], IP_B_S1_2]]) |
| 413 |
self.bgpvpn_admin_client.create_network_association( |
| 414 |
self.bgpvpn['id'], self.networks[NET_A]['id']) |
| 415 |
self.router_a = self._create_router_and_associate_fip( |
| 416 |
0, self.subnets[NET_A][0]) |
| 417 |
self._check_l3_bgpvpn(should_succeed=False) |
| 418 |
self._check_l3_bgpvpn(self.servers[0], self.servers[2]) |
| 419 |
self.bgpvpn_admin_client.create_network_association( |
| 420 |
self.bgpvpn['id'], self.networks[NET_B]['id']) |
| 421 |
self.router_b = self._create_router_and_associate_fip( |
| 422 |
1, self.subnets[NET_B][0]) |
| 423 |
self._check_l3_bgpvpn(should_succeed=False) |
| 424 |
self._check_l3_bgpvpn(self.servers[1], self.servers[3]) |
| 425 |
self._update_l3_bgpvpn(rts=[self.RT1], import_rts=[], export_rts=[]) |
| 426 |
self._check_l3_bgpvpn() |
| 427 |
self._check_l3_bgpvpn(self.servers[0], self.servers[2]) |
| 428 |
self._check_l3_bgpvpn(self.servers[1], self.servers[3]) |
| 429 |
|
| 430 |
@test.unstable_test("bug 1897408") |
| 431 |
@decorators.idempotent_id('758a8731-5070-4b1e-9a66-d6ff05bb5be1') |
| 432 |
@utils.services('compute', 'network') |
| 433 |
def test_bgpvpn_update_rt_and_keep_local_connectivity_variant2(self): |
| 434 |
"""This test checks basic BGPVPN route targets update. |
| 435 |
|
| 436 |
1. Create networks A and B with their respective subnets |
| 437 |
2. Start up server 1 in network A |
| 438 |
3. Start up server 2 in network B |
| 439 |
4. Start up server 3 in network A |
| 440 |
5. Start up server 4 in network B |
| 441 |
6. Create invalid L3 BGPVPN with eRT<>iRT that is insufficient |
| 442 |
for proper connectivity between network A and B |
| 443 |
7. Create router A and connect it to network A |
| 444 |
8. Give a FIP to server 1 |
| 445 |
9. Create router B and connect it to network B |
| 446 |
10. Give a FIP to server 4 |
| 447 |
11. Associate network A to a given L3 BGPVPN |
| 448 |
12. Check that server 1 cannot ping server 2 |
| 449 |
13. Check that server 1 can ping server 3 |
| 450 |
14. Associate router B to a given L3 BGPVPN |
| 451 |
15. Check that server 1 still cannot ping server 2 |
| 452 |
16. Check that server 4 can ping server 2 |
| 453 |
17. Update L3 BGPVPN to have now only RT defined |
| 454 |
18. Check that server 1 can now ping server 2 |
| 455 |
19. Check that server 1 still can ping server 3 |
| 456 |
20. Check that server 4 still can ping server 2 |
| 457 |
""" |
| 458 |
self._create_networks_and_subnets() |
| 459 |
self._create_l3_bgpvpn(rts=[], import_rts=[self.RT1], |
| 460 |
export_rts=[self.RT2]) |
| 461 |
self._create_servers([[self.networks[NET_A], IP_A_S1_1], |
| 462 |
[self.networks[NET_B], IP_B_S1_1], |
| 463 |
[self.networks[NET_A], IP_A_S1_2], |
| 464 |
[self.networks[NET_B], IP_B_S1_2]]) |
| 465 |
self._create_router_and_associate_fip( |
| 466 |
0, self.subnets[NET_A][0]) |
| 467 |
router_b = self._create_router_and_associate_fip( |
| 468 |
3, self.subnets[NET_B][0]) |
| 469 |
self.bgpvpn_admin_client.create_network_association( |
| 470 |
self.bgpvpn['id'], self.networks[NET_A]['id']) |
| 471 |
self._check_l3_bgpvpn(should_succeed=False) |
| 472 |
self._check_l3_bgpvpn(self.servers[0], self.servers[2]) |
| 473 |
self.bgpvpn_admin_client.create_router_association(self.bgpvpn['id'], |
| 474 |
router_b['id']) |
| 475 |
self._check_l3_bgpvpn(should_succeed=False) |
| 476 |
self._check_l3_bgpvpn(self.servers[3], self.servers[1]) |
| 477 |
self._update_l3_bgpvpn(rts=[self.RT1], import_rts=[], export_rts=[]) |
| 478 |
self._check_l3_bgpvpn() |
| 479 |
self._check_l3_bgpvpn(self.servers[0], self.servers[2]) |
| 480 |
self._check_l3_bgpvpn(self.servers[3], self.servers[1]) |
| 481 |
|
| 482 |
@decorators.idempotent_id('876b49bc-f34a-451b-ba3c-d74295838130') |
| 483 |
@utils.services('compute', 'network') |
| 484 |
@utils.requires_ext(extension='bgpvpn-routes-control', service='network') |
| 485 |
def test_bgpvpn_port_association_local_pref(self): |
| 486 |
"""This test checks port association in BGPVPN. |
| 487 |
|
| 488 |
1. Create networks A and B with their respective subnets |
| 489 |
2. Create L3 BGPVPN |
| 490 |
3. Start up server 1 in network A |
| 491 |
4. Start up server 2 in network B |
| 492 |
5. Start up server 3 in network B |
| 493 |
6. Create router and connect it to network A |
| 494 |
7. Create router and connect it to network B |
| 495 |
8. Give a FIP to all servers |
| 496 |
9. Setup dummy HTTP service on server 2 and 3 |
| 497 |
10. Configure ip forwarding on server 2 |
| 498 |
11. Configure ip forwarding on server 3 |
| 499 |
12. Configure alternative loopback address on server 2 |
| 500 |
13. Configure alternative loopback address on server 3 |
| 501 |
14. Associate network A to a given L3 BGPVPN |
| 502 |
15. Associate port of server 2 to a given L3 BGPVPN |
| 503 |
with higher local_pref value |
| 504 |
16. Associate port of server 3 to a given L3 BGPVPN |
| 505 |
with lower local_pref value |
| 506 |
17. Check that server 1 pings server's 2 alternative ip |
| 507 |
18. Update port association of server 2 to have now |
| 508 |
lower local_pref value |
| 509 |
19. Update port association of server 3 to have now |
| 510 |
higher local_pref value |
| 511 |
20. Check that server 1 pings now server's 3 alternative ip |
| 512 |
""" |
| 513 |
self._create_networks_and_subnets(port_security=False) |
| 514 |
self._create_l3_bgpvpn() |
| 515 |
self._create_servers([[self.networks[NET_A], IP_A_S1_1], |
| 516 |
[self.networks[NET_B], IP_B_S1_1], |
| 517 |
[self.networks[NET_B], IP_B_S1_2]], |
| 518 |
port_security=False) |
| 519 |
self._create_fip_router(subnet_id=self.subnets[NET_A][0]['id']) |
| 520 |
self._create_fip_router(subnet_id=self.subnets[NET_B][0]['id']) |
| 521 |
self._associate_fip(0) |
| 522 |
self._associate_fip(1) |
| 523 |
self._associate_fip(2) |
| 524 |
self._setup_http_server(1) |
| 525 |
self._setup_http_server(2) |
| 526 |
self._setup_ip_forwarding(1) |
| 527 |
self._setup_ip_forwarding(2) |
| 528 |
self._setup_ip_address(1, IP_C_S1_1) |
| 529 |
self._setup_ip_address(2, IP_C_S1_1) |
| 530 |
|
| 531 |
primary_port_routes = [{'type': 'prefix', |
| 532 |
'local_pref': 200, |
| 533 |
'prefix': NET_C_S1}] |
| 534 |
alternate_port_routes = [{'type': 'prefix', |
| 535 |
'local_pref': 100, |
| 536 |
'prefix': NET_C_S1}] |
| 537 |
|
| 538 |
self.bgpvpn_admin_client.create_network_association( |
| 539 |
self.bgpvpn['id'], self.networks[NET_A]['id']) |
| 540 |
|
| 541 |
port_id_1 = self.ports[self.servers[1]['id']]['id'] |
| 542 |
body = self.bgpvpn_admin_client.create_port_association( |
| 543 |
self.bgpvpn['id'], port_id=port_id_1, routes=primary_port_routes) |
| 544 |
port_association_1 = body['port_association'] |
| 545 |
|
| 546 |
port_id_2 = self.ports[self.servers[2]['id']]['id'] |
| 547 |
body = self.bgpvpn_admin_client.create_port_association( |
| 548 |
self.bgpvpn['id'], port_id=port_id_2, routes=alternate_port_routes) |
| 549 |
port_association_2 = body['port_association'] |
| 550 |
|
| 551 |
destination_srv_1 = '%s:%s' % (self.servers[1]['name'], |
| 552 |
self.servers[1]['id']) |
| 553 |
destination_srv_2 = '%s:%s' % (self.servers[2]['name'], |
| 554 |
self.servers[2]['id']) |
| 555 |
|
| 556 |
self._check_l3_bgpvpn_by_specific_ip( |
| 557 |
to_server_ip=IP_C_S1_1, |
| 558 |
validate_server=destination_srv_1) |
| 559 |
|
| 560 |
self.bgpvpn_admin_client.update_port_association( |
| 561 |
self.bgpvpn['id'], port_association_1['id'], |
| 562 |
routes=alternate_port_routes) |
| 563 |
self.bgpvpn_admin_client.update_port_association( |
| 564 |
self.bgpvpn['id'], port_association_2['id'], |
| 565 |
routes=primary_port_routes) |
| 566 |
|
| 567 |
self._check_l3_bgpvpn_by_specific_ip( |
| 568 |
to_server_ip=IP_C_S1_1, |
| 569 |
validate_server=destination_srv_2) |
| 570 |
|
| 571 |
@test.unstable_test("bug 1897408") |
| 572 |
@decorators.idempotent_id('f762e6ac-920e-4d0f-aa67-02bdd4ab8433') |
| 573 |
@utils.services('compute', 'network') |
| 574 |
def test_bgpvpn_tenant_separation_and_local_connectivity(self): |
| 575 |
"""This test checks tenant separation for BGPVPN. |
| 576 |
|
| 577 |
1. Create networks A with subnet S1 and S2 |
| 578 |
2. Create networks A-Bis with subnet S1 and S2 (like for network A) |
| 579 |
3. Create L3 BGPVPN for network A with self.RT1 |
| 580 |
4. Create L3 BGPVPN for network A-Bis with self.RT2 |
| 581 |
5. Associate network A to a given L3 BGPVPN |
| 582 |
6. Associate network A-Bis to a given L3 BGPVPN |
| 583 |
7. Start up server 1 in network A and subnet S1 |
| 584 |
8. Start up server 2 in network A-Bis and subnet S1 |
| 585 |
9. Start up server 3 in network A and subnet S1 |
| 586 |
10. Start up server 4 in network A-Bis and subnet S1 |
| 587 |
11. Start up server 5 in network A and subnet S1 |
| 588 |
12. Create router A and connect it to network A |
| 589 |
13. Create router A-Bis and connect it to network A-Bis |
| 590 |
14. Give a FIP to all servers |
| 591 |
15. Setup dummy HTTP service on server 2 and 3 |
| 592 |
16. Check that server 1 pings server 3 instead of server 2 |
| 593 |
17. Check that server 1 can ping server 3 |
| 594 |
18. Check that server 2 cannot ping server 1 |
| 595 |
19. Check that server 2 pings itself instead of server 3 |
| 596 |
20. Check that server 2 can ping server 4 |
| 597 |
21. Check that server 2 pings server 4 instead of server 5 |
| 598 |
""" |
| 599 |
self._create_networks_and_subnets([NET_A, NET_A_BIS], |
| 600 |
[[NET_A_S1, NET_A_S2], |
| 601 |
[NET_A_S1, NET_A_S2]]) |
| 602 |
bgpvpn_a = self._create_l3_bgpvpn(name='test-l3-bgpvpn-a', |
| 603 |
rts=[self.RT1]) |
| 604 |
bgpvpn_a_bis = self._create_l3_bgpvpn(name='test-l3-bgpvpn-a-bis', |
| 605 |
rts=[self.RT2]) |
| 606 |
self.bgpvpn_admin_client.create_network_association( |
| 607 |
bgpvpn_a['id'], self.networks[NET_A]['id']) |
| 608 |
self.bgpvpn_admin_client.create_network_association( |
| 609 |
bgpvpn_a_bis['id'], self.networks[NET_A_BIS]['id']) |
| 610 |
self._create_servers([[self.networks[NET_A], IP_A_S1_1], |
| 611 |
[self.networks[NET_A_BIS], IP_A_BIS_S1_2], |
| 612 |
[self.networks[NET_A], IP_A_S1_2], |
| 613 |
[self.networks[NET_A_BIS], IP_A_BIS_S1_3], |
| 614 |
[self.networks[NET_A], IP_A_S1_3]]) |
| 615 |
self._create_fip_router(subnet_id=self.subnets[NET_A][0]['id']) |
| 616 |
self._create_fip_router(subnet_id=self.subnets[NET_A_BIS][0]['id']) |
| 617 |
self._associate_fip(0) |
| 618 |
self._associate_fip(1) |
| 619 |
self._associate_fip(2) |
| 620 |
self._associate_fip(3) |
| 621 |
self._associate_fip(4) |
| 622 |
self._setup_http_server(1) |
| 623 |
self._setup_http_server(2) |
| 624 |
self._setup_http_server(3) |
| 625 |
self._setup_http_server(4) |
| 626 |
self._check_l3_bgpvpn(self.servers[0], self.servers[1], |
| 627 |
should_succeed=False, validate_server=True) |
| 628 |
self._check_l3_bgpvpn(self.servers[0], self.servers[2], |
| 629 |
validate_server=True) |
| 630 |
self._check_l3_bgpvpn(self.servers[1], self.servers[0], |
| 631 |
should_succeed=False) |
| 632 |
self._check_l3_bgpvpn(self.servers[1], self.servers[2], |
| 633 |
should_succeed=False, validate_server=True) |
| 634 |
self._check_l3_bgpvpn(self.servers[1], self.servers[3], |
| 635 |
validate_server=True) |
| 636 |
self._check_l3_bgpvpn(self.servers[1], self.servers[4], |
| 637 |
should_succeed=False, validate_server=True) |
| 638 |
|
| 639 |
@decorators.idempotent_id('3b44b2f4-f514-4004-8623-2682bc46bb07') |
| 640 |
@utils.services('compute', 'network') |
| 641 |
@utils.requires_ext(extension='bgpvpn-routes-control', service='network') |
| 642 |
def test_bgpvpn_port_association_create_and_update(self): |
| 643 |
"""This test checks port association in BGPVPN. |
| 644 |
|
| 645 |
1. Create networks A and B with their respective subnets |
| 646 |
2. Create L3 BGPVPN |
| 647 |
3. Create router and connect it to network A |
| 648 |
4. Create router and connect it to network B |
| 649 |
5. Start up server 1 in network A |
| 650 |
6. Start up server 2 in network B |
| 651 |
7. Give a FIP to all servers |
| 652 |
8. Configure ip forwarding on server 2 |
| 653 |
9. Configure alternative loopback address on server 2 |
| 654 |
10. Associate network A to a given L3 BGPVPN |
| 655 |
11. Associate port of server 2 to a given L3 BGPVPN |
| 656 |
12. Check that server 1 can ping server's 2 alternative ip |
| 657 |
13. Update created before port association by routes removal |
| 658 |
14. Check that server 1 cannot ping server's 2 alternative ip |
| 659 |
""" |
| 660 |
self._create_networks_and_subnets(port_security=False) |
| 661 |
self._create_l3_bgpvpn() |
| 662 |
self._create_servers([[self.networks[NET_A], IP_A_S1_1], |
| 663 |
[self.networks[NET_B], IP_B_S1_1]], |
| 664 |
port_security=False) |
| 665 |
self._create_fip_router(subnet_id=self.subnets[NET_A][0]['id']) |
| 666 |
self._create_fip_router(subnet_id=self.subnets[NET_B][0]['id']) |
| 667 |
self._associate_fip(0) |
| 668 |
self._associate_fip(1) |
| 669 |
|
| 670 |
# preliminary check that no connectivity to 192.168.0.1 initially |
| 671 |
# exists |
| 672 |
self._check_l3_bgpvpn_by_specific_ip( |
| 673 |
should_succeed=False, to_server_ip=IP_C_S1_1) |
| 674 |
|
| 675 |
self._setup_ip_forwarding(1) |
| 676 |
self._setup_ip_address(1, IP_C_S1_1) |
| 677 |
self.bgpvpn_admin_client.create_network_association( |
| 678 |
self.bgpvpn['id'], self.networks[NET_A]['id']) |
| 679 |
port_id = self.ports[self.servers[1]['id']]['id'] |
| 680 |
port_routes = [{'type': 'prefix', |
| 681 |
'prefix': NET_C_S1}] |
| 682 |
body = self.bgpvpn_admin_client.create_port_association( |
| 683 |
self.bgpvpn['id'], port_id=port_id, routes=port_routes) |
| 684 |
port_association = body['port_association'] |
| 685 |
self._check_l3_bgpvpn_by_specific_ip( |
| 686 |
to_server_ip=IP_C_S1_1) |
| 687 |
self.bgpvpn_admin_client.update_port_association( |
| 688 |
self.bgpvpn['id'], port_association['id'], routes=[]) |
| 689 |
self._check_l3_bgpvpn_by_specific_ip( |
| 690 |
should_succeed=False, to_server_ip=IP_C_S1_1) |
| 691 |
|
| 692 |
@decorators.idempotent_id('d92a8a18-c4d0-40d5-8592-713d7dae7d25') |
| 693 |
@utils.services('compute', 'network') |
| 694 |
@utils.requires_ext(extension='bgpvpn-routes-control', service='network') |
| 695 |
@test.unstable_test("bug 1780205") |
| 696 |
def test_port_association_many_bgpvpn_routes(self): |
| 697 |
"""This test checks port association in BGPVPN. |
| 698 |
|
| 699 |
1. Create networks A and B with their respective subnets |
| 700 |
2. Create L3 BGPVPN |
| 701 |
3. Create router and connect it to network A |
| 702 |
4. Create router and connect it to network B |
| 703 |
5. Start up server 1 in network A |
| 704 |
6. Start up server 2 in network B |
| 705 |
7. Give a FIP to all servers |
| 706 |
8. Configure ip forwarding on server 2 |
| 707 |
9. Configure alternative loopback address on server 2 |
| 708 |
10. Associate network A to a given L3 BGPVPN |
| 709 |
11. Associate port of server 2 to a given L3 BGPVPN |
| 710 |
12. Check that server 1 can ping server's 2 alternative ip |
| 711 |
13. Update created before port association by routes removal |
| 712 |
14. Check that server 1 cannot ping server's 2 alternative ip |
| 713 |
""" |
| 714 |
AMOUNT_LOOPBACKS = 90 |
| 715 |
START_IP_LOOPBACKS = 31 |
| 716 |
SAMPLE_SIZE = 10 |
| 717 |
LOOPBACKS = [str(ip) for ip in |
| 718 |
S1C[START_IP_LOOPBACKS: |
| 719 |
START_IP_LOOPBACKS + AMOUNT_LOOPBACKS]] |
| 720 |
SUB_LOOPBACKS = [LOOPBACKS[0], LOOPBACKS[-1]] |
| 721 |
|
| 722 |
self._create_networks_and_subnets(port_security=False) |
| 723 |
self._create_l3_bgpvpn() |
| 724 |
self._create_servers([[self.networks[NET_A], IP_A_S1_1], |
| 725 |
[self.networks[NET_B], IP_B_S1_1]], |
| 726 |
port_security=False) |
| 727 |
self._create_fip_router(subnet_id=self.subnets[NET_A][0]['id']) |
| 728 |
self._create_fip_router(subnet_id=self.subnets[NET_B][0]['id']) |
| 729 |
self._associate_fip(0) |
| 730 |
self._associate_fip(1) |
| 731 |
|
| 732 |
for ip in SUB_LOOPBACKS: |
| 733 |
LOG.debug("Preliminary check that no connectivity exist") |
| 734 |
self._check_l3_bgpvpn_by_specific_ip( |
| 735 |
should_succeed=False, to_server_ip=ip) |
| 736 |
|
| 737 |
self._setup_ip_forwarding(1) |
| 738 |
|
| 739 |
self._setup_range_ip_address(1, LOOPBACKS) |
| 740 |
|
| 741 |
self.bgpvpn_admin_client.create_network_association( |
| 742 |
self.bgpvpn['id'], self.networks[NET_A]['id']) |
| 743 |
port_id = self.ports[self.servers[1]['id']]['id'] |
| 744 |
port_routes = [{'type': 'prefix', |
| 745 |
'prefix': ip + "/32"} |
| 746 |
for ip in LOOPBACKS] |
| 747 |
|
| 748 |
body = self.bgpvpn_admin_client.create_port_association( |
| 749 |
self.bgpvpn['id'], port_id=port_id, routes=port_routes) |
| 750 |
port_association = body['port_association'] |
| 751 |
|
| 752 |
for ip in random.sample(LOOPBACKS, SAMPLE_SIZE): |
| 753 |
LOG.debug("Check that server 1 can " |
| 754 |
"ping server 2 alternative ip %s", ip) |
| 755 |
self._check_l3_bgpvpn_by_specific_ip( |
| 756 |
to_server_ip=ip) |
| 757 |
|
| 758 |
self.bgpvpn_admin_client.update_port_association( |
| 759 |
self.bgpvpn['id'], port_association['id'], routes=[]) |
| 760 |
|
| 761 |
for ip in SUB_LOOPBACKS: |
| 762 |
LOG.debug("Check that server 1 can't " |
| 763 |
"ping server 2 alternative ip %s", ip) |
| 764 |
self._check_l3_bgpvpn_by_specific_ip( |
| 765 |
should_succeed=False, to_server_ip=ip) |
| 766 |
|
| 767 |
@decorators.idempotent_id('9c3280b5-0b32-4562-800c-0b50d9d52bfd') |
| 768 |
@utils.services('compute', 'network') |
| 769 |
@utils.requires_ext(extension='bgpvpn-routes-control', service='network') |
| 770 |
def test_bgpvpn_port_association_create_and_delete(self): |
| 771 |
"""This test checks port association in BGPVPN. |
| 772 |
|
| 773 |
1. Create networks A and B with their respective subnets |
| 774 |
2. Create L3 BGPVPN |
| 775 |
3. Create router and connect it to network A |
| 776 |
4. Create router and connect it to network B |
| 777 |
5. Start up server 1 in network A |
| 778 |
6. Start up server 2 in network B |
| 779 |
7. Give a FIP to all servers |
| 780 |
8. Configure ip forwarding on server 2 |
| 781 |
9. Configure alternative loopback address on server 2 |
| 782 |
10. Associate network A to a given L3 BGPVPN |
| 783 |
11. Associate port of server 2 to a given L3 BGPVPN |
| 784 |
12. Check that server 1 can ping server's 2 alternative ip |
| 785 |
13. Remove created before port association |
| 786 |
14. Check that server 1 cannot ping server's 2 alternative ip |
| 787 |
""" |
| 788 |
self._create_networks_and_subnets(port_security=False) |
| 789 |
self._create_l3_bgpvpn() |
| 790 |
self._create_servers([[self.networks[NET_A], IP_A_S1_1], |
| 791 |
[self.networks[NET_B], IP_B_S1_1]], |
| 792 |
port_security=False) |
| 793 |
self._create_fip_router(subnet_id=self.subnets[NET_A][0]['id']) |
| 794 |
self._create_fip_router(subnet_id=self.subnets[NET_B][0]['id']) |
| 795 |
self._associate_fip(0) |
| 796 |
self._associate_fip(1) |
| 797 |
|
| 798 |
# preliminary check that no connectivity to 192.168.0.1 initially |
| 799 |
# exists |
| 800 |
self._check_l3_bgpvpn_by_specific_ip( |
| 801 |
should_succeed=False, to_server_ip=IP_C_S1_1) |
| 802 |
|
| 803 |
self._setup_ip_forwarding(1) |
| 804 |
self._setup_ip_address(1, IP_C_S1_1) |
| 805 |
self.bgpvpn_admin_client.create_network_association( |
| 806 |
self.bgpvpn['id'], self.networks[NET_A]['id']) |
| 807 |
port_id = self.ports[self.servers[1]['id']]['id'] |
| 808 |
port_routes = [{'type': 'prefix', |
| 809 |
'prefix': NET_C_S1}] |
| 810 |
body = self.bgpvpn_admin_client.create_port_association( |
| 811 |
self.bgpvpn['id'], port_id=port_id, routes=port_routes) |
| 812 |
port_association = body['port_association'] |
| 813 |
self._check_l3_bgpvpn_by_specific_ip( |
| 814 |
to_server_ip=IP_C_S1_1) |
| 815 |
self.bgpvpn_admin_client.delete_port_association( |
| 816 |
self.bgpvpn['id'], port_association['id']) |
| 817 |
self._check_l3_bgpvpn_by_specific_ip( |
| 818 |
should_succeed=False, to_server_ip=IP_C_S1_1) |
| 819 |
|
| 820 |
@decorators.idempotent_id('73f629fa-fdae-40fc-8a7e-da3aedcf797a') |
| 821 |
@utils.services('compute', 'network') |
| 822 |
@utils.requires_ext(extension='bgpvpn-routes-control', service='network') |
| 823 |
def test_bgpvpn_port_association_bgpvpn_route(self): |
| 824 |
"""Test port association routes of type 'bgpvpn' |
| 825 |
|
| 826 |
In this test we use a Port Association with a 'bgpvpn' route |
| 827 |
to have VM 1 in network A, reach a VM 3 in network C via the Port |
| 828 |
of a VM 2 (on network B), and vice-versa. For A->C traffic, one Port |
| 829 |
Association associates the port of VM 2 to a BGPVPN, with a route of |
| 830 |
type 'bgpvpn' redistributing routes from network C. For C->A traffic, |
| 831 |
another Port Association associates the port of VM 2 to a BGPVPN, with |
| 832 |
a route of type 'bgpvpn' redistributing routes from network A. |
| 833 |
|
| 834 |
The use of RT in this test is a bit complex, and would be much |
| 835 |
simpler if we were using a VM with two interfaces. |
| 836 |
|
| 837 |
We confirm that VM 1 can join VM 3, and we confirm that the traffic |
| 838 |
actually goes through VM 2, by turning ip_forwaring off then on in VM2. |
| 839 |
""" |
| 840 |
# create networks A, B and C with their respective subnets |
| 841 |
self._create_networks_and_subnets(port_security=False) |
| 842 |
|
| 843 |
RT_to_A = self.RT1 |
| 844 |
RT_from_A = self.RT2 |
| 845 |
RT_to_C = self.RT3 |
| 846 |
RT_from_C = self.RT4 |
| 847 |
|
| 848 |
# Create L3 BGPVPN for network A |
| 849 |
bgpvpn_a = self._create_l3_bgpvpn(name="test-vpn-a", |
| 850 |
import_rts=[RT_to_A], |
| 851 |
export_rts=[RT_from_A]) |
| 852 |
|
| 853 |
# Create L3 BGPVPN for network C |
| 854 |
bgpvpn_c = self._create_l3_bgpvpn(name="test-vpn-c", |
| 855 |
import_rts=[RT_to_C], |
| 856 |
export_rts=[RT_from_C]) |
| 857 |
|
| 858 |
# Create L3 BGPVPN for network B |
| 859 |
bgpvpn_b = self._create_l3_bgpvpn(name="test-vpn-b", |
| 860 |
import_rts=[RT_from_C, RT_from_A]) |
| 861 |
|
| 862 |
# BGPVPNs to only export into A and C |
| 863 |
bgpvpn_to_a = self._create_l3_bgpvpn(name="test-vpn-to-a", |
| 864 |
export_rts=[RT_to_A]) |
| 865 |
bgpvpn_to_c = self._create_l3_bgpvpn(name="test-vpn-to-c", |
| 866 |
export_rts=[RT_to_C]) |
| 867 |
|
| 868 |
# create the three VMs |
| 869 |
self._create_servers([[self.networks[NET_A], IP_A_S1_1], |
| 870 |
[self.networks[NET_B], IP_B_S1_1], |
| 871 |
[self.networks[NET_C], IP_C_S1_1]], |
| 872 |
port_security=False) |
| 873 |
vm1, vm2, vm3 = self.servers |
| 874 |
|
| 875 |
# Create one router for each of network A, B, C and give floating |
| 876 |
# IPs to servers 1, 2, 3 |
| 877 |
self._create_fip_router(subnet_id=self.subnets[NET_A][0]['id']) |
| 878 |
self._create_fip_router(subnet_id=self.subnets[NET_B][0]['id']) |
| 879 |
self._create_fip_router(subnet_id=self.subnets[NET_C][0]['id']) |
| 880 |
self._associate_fip(0) |
| 881 |
self._associate_fip(1) |
| 882 |
self._associate_fip(2) |
| 883 |
|
| 884 |
# disable IP forwarding on VM2 |
| 885 |
self._setup_ip_forwarding(0) |
| 886 |
|
| 887 |
# connect network A to its BGPVPN |
| 888 |
self.bgpvpn_admin_client.create_network_association( |
| 889 |
bgpvpn_a['id'], self.networks[NET_A]['id']) |
| 890 |
|
| 891 |
# connect network B to its BGPVPN |
| 892 |
self.bgpvpn_admin_client.create_network_association( |
| 893 |
bgpvpn_b['id'], self.networks[NET_B]['id']) |
| 894 |
|
| 895 |
# connect network C to its BGPVPN |
| 896 |
self.bgpvpn_admin_client.create_network_association( |
| 897 |
bgpvpn_c['id'], self.networks[NET_C]['id']) |
| 898 |
|
| 899 |
# create port associations for A->C traffic |
| 900 |
# (leak routes imported by BGPVPN B -- which happen to include the |
| 901 |
# routes net C -- into net A) |
| 902 |
self.bgpvpn_admin_client.create_port_association( |
| 903 |
bgpvpn_to_a['id'], |
| 904 |
port_id=self.ports[vm2['id']]['id'], |
| 905 |
routes=[{'type': 'bgpvpn', |
| 906 |
'bgpvpn_id': bgpvpn_b['id']}, |
| 907 |
]) |
| 908 |
|
| 909 |
# create port associations for C->A traffic |
| 910 |
# (leak routes imported by BGPVPN B -- which happen to include the |
| 911 |
# routes from net A -- into net C) |
| 912 |
body = self.bgpvpn_admin_client.create_port_association( |
| 913 |
bgpvpn_to_c['id'], |
| 914 |
port_id=self.ports[vm2['id']]['id'], |
| 915 |
routes=[{'type': 'bgpvpn', |
| 916 |
'bgpvpn_id': bgpvpn_a['id']}]) |
| 917 |
|
| 918 |
port_association = body['port_association'] |
| 919 |
|
| 920 |
# check that we don't have connectivity |
| 921 |
# (because destination is supposed to be reachable via VM2, which |
| 922 |
# still has ip_forwarding disabled) |
| 923 |
self._check_l3_bgpvpn_by_specific_ip(from_server=vm1, |
| 924 |
to_server_ip=IP_C_S1_1, |
| 925 |
should_succeed=False) |
| 926 |
|
| 927 |
# enable IP forwarding on VM2 |
| 928 |
self._setup_ip_forwarding(1) |
| 929 |
|
| 930 |
# VM1 should now be able to join VM2 |
| 931 |
self._check_l3_bgpvpn_by_specific_ip(from_server=vm1, |
| 932 |
to_server_ip=IP_C_S1_1, |
| 933 |
should_succeed=True) |
| 934 |
|
| 935 |
# remove port association 1 |
| 936 |
self.bgpvpn_admin_client.delete_port_association(self.bgpvpn['id'], |
| 937 |
port_association['id']) |
| 938 |
|
| 939 |
# check that connectivity is actually interrupted |
| 940 |
self._check_l3_bgpvpn_by_specific_ip(from_server=vm1, |
| 941 |
to_server_ip=IP_C_S1_1, |
| 942 |
should_succeed=False) |
| 943 |
|
| 944 |
@decorators.idempotent_id('8478074e-22df-4234-b02b-61257b475b18') |
| 945 |
@utils.services('compute', 'network') |
| 946 |
def test_bgpvpn_negative_ping_to_unassociated_net(self): |
| 947 |
"""This test checks basic BGPVPN. |
| 948 |
|
| 949 |
1. Create networks A and B with their respective subnets |
| 950 |
2. Create L3 BGPVPN |
| 951 |
3. Associate network A to a given L3 BGPVPN |
| 952 |
4. Start up server 1 in network A |
| 953 |
5. Start up server 2 in network B |
| 954 |
6. Create router and connect it to network A |
| 955 |
7. Give a FIP to server 1 |
| 956 |
8. Check that server 1 cannot ping server 2 |
| 957 |
""" |
| 958 |
self._create_networks_and_subnets() |
| 959 |
self._create_l3_bgpvpn() |
| 960 |
self.bgpvpn_admin_client.create_network_association( |
| 961 |
self.bgpvpn['id'], self.networks[NET_A]['id']) |
| 962 |
self._create_servers() |
| 963 |
self._associate_fip_and_check_l3_bgpvpn(should_succeed=False) |
| 964 |
|
| 965 |
@decorators.idempotent_id('b6d219b2-90bb-431f-a566-bf6a780d1578') |
| 966 |
@utils.services('compute', 'network') |
| 967 |
def test_bgpvpn_negative_disjoint_import_export(self): |
| 968 |
"""This test checks basic BGPVPN. |
| 969 |
|
| 970 |
1. Create networks A and B with their respective subnets |
| 971 |
2. Create invalid L3 BGPVPN with eRT<>iRT that is insufficient |
| 972 |
for proper connectivity between network A and B |
| 973 |
3. Associate network A and B to a given L3 BGPVPN |
| 974 |
4. Start up server 1 in network A |
| 975 |
5. Start up server 2 in network B |
| 976 |
6. Create router and connect it to network A |
| 977 |
7. Give a FIP to server 1 |
| 978 |
8. Check that server 1 cannot ping server 2 |
| 979 |
""" |
| 980 |
self._create_networks_and_subnets() |
| 981 |
self._create_l3_bgpvpn(rts=[], import_rts=[self.RT1], |
| 982 |
export_rts=[self.RT2]) |
| 983 |
self._associate_all_nets_to_bgpvpn() |
| 984 |
self._create_servers() |
| 985 |
self._associate_fip_and_check_l3_bgpvpn(should_succeed=False) |
| 986 |
|
| 987 |
@decorators.idempotent_id('dc92643f-1b2c-4a3e-bc5e-ea780d721ef7') |
| 988 |
@utils.services('compute', 'network') |
| 989 |
def test_bgpvpn_negative_delete_bgpvpn(self): |
| 990 |
"""This test checks BGPVPN delete. |
| 991 |
|
| 992 |
1. Create networks A and B with their respective subnets |
| 993 |
2. Create L3 BGPVPN |
| 994 |
3. Associate network A and network B to a given L3 BGPVPN |
| 995 |
4. Start up server 1 in network A |
| 996 |
5. Start up server 2 in network B |
| 997 |
6. Create router and connect it to network A |
| 998 |
7. Give a FIP to server 1 |
| 999 |
8. Check that server 1 can ping server 2 |
| 1000 |
9. Delete L3 BGPVPN |
| 1001 |
10. Check that server 1 cannot ping server 2 |
| 1002 |
""" |
| 1003 |
self._create_networks_and_subnets() |
| 1004 |
self._create_l3_bgpvpn() |
| 1005 |
self._associate_all_nets_to_bgpvpn() |
| 1006 |
self._create_servers() |
| 1007 |
self._associate_fip_and_check_l3_bgpvpn() |
| 1008 |
self.delete_bgpvpn(self.bgpvpn_admin_client, self.bgpvpn) |
| 1009 |
self._check_l3_bgpvpn(should_succeed=False) |
| 1010 |
|
| 1011 |
@decorators.idempotent_id('2e6bf893-1410-4ef6-9948-1877f3a8f3d1') |
| 1012 |
@utils.services('compute', 'network') |
| 1013 |
def test_bgpvpn_negative_delete_net_association(self): |
| 1014 |
"""This test checks BGPVPN net association delete. |
| 1015 |
|
| 1016 |
1. Create networks A and B with their respective subnets |
| 1017 |
2. Create L3 BGPVPN |
| 1018 |
3. Associate network A and network B to a given L3 BGPVPN |
| 1019 |
4. Start up server 1 in network A |
| 1020 |
5. Start up server 2 in network B |
| 1021 |
6. Create router and connect it to network A |
| 1022 |
7. Give a FIP to server 1 |
| 1023 |
8. Check that server 1 can ping server 2 |
| 1024 |
9. Delete association of network A |
| 1025 |
10. Check that server 1 cannot ping server 2 |
| 1026 |
""" |
| 1027 |
self._create_networks_and_subnets() |
| 1028 |
self._create_l3_bgpvpn() |
| 1029 |
body = self.bgpvpn_admin_client.create_network_association( |
| 1030 |
self.bgpvpn['id'], self.networks[NET_A]['id']) |
| 1031 |
assoc_b = body['network_association'] |
| 1032 |
self.bgpvpn_admin_client.create_network_association( |
| 1033 |
self.bgpvpn['id'], self.networks[NET_B]['id']) |
| 1034 |
self._create_servers() |
| 1035 |
self._associate_fip_and_check_l3_bgpvpn() |
| 1036 |
self.bgpvpn_admin_client.delete_network_association(self.bgpvpn['id'], |
| 1037 |
assoc_b['id']) |
| 1038 |
self._check_l3_bgpvpn(should_succeed=False) |
| 1039 |
|
| 1040 |
@decorators.idempotent_id('9ebf4342-4448-4d63-98f9-44d3a606b6cf') |
| 1041 |
@utils.services('compute', 'network') |
| 1042 |
def test_bgpvpn_negative_delete_router_association(self): |
| 1043 |
"""This test checks BGPVPN router association delete. |
| 1044 |
|
| 1045 |
1. Create networks A and B with their respective subnets |
| 1046 |
2. Create router and connect it to network B |
| 1047 |
3. Create L3 BGPVPN |
| 1048 |
4. Associate network A to a given L3 BGPVPN |
| 1049 |
5. Associate router B to a given L3 BGPVPN |
| 1050 |
6. Start up server 1 in network A |
| 1051 |
7. Start up server 2 in network B |
| 1052 |
8. Create router and connect it to network A |
| 1053 |
9. Give a FIP to server 1 |
| 1054 |
10. Check that server 1 can ping server 2 |
| 1055 |
11. Delete association of router B |
| 1056 |
12. Check that server 1 cannot ping server 2 |
| 1057 |
""" |
| 1058 |
self._create_networks_and_subnets() |
| 1059 |
router_b = self._create_fip_router( |
| 1060 |
subnet_id=self.subnets[NET_B][0]['id']) |
| 1061 |
self._create_l3_bgpvpn() |
| 1062 |
self.bgpvpn_admin_client.create_network_association( |
| 1063 |
self.bgpvpn['id'], self.networks[NET_A]['id']) |
| 1064 |
body = self.bgpvpn_admin_client.create_router_association( |
| 1065 |
self.bgpvpn['id'], router_b['id']) |
| 1066 |
assoc_b = body['router_association'] |
| 1067 |
self._create_servers() |
| 1068 |
self._associate_fip_and_check_l3_bgpvpn() |
| 1069 |
self.bgpvpn_admin_client.delete_router_association(self.bgpvpn['id'], |
| 1070 |
assoc_b['id']) |
| 1071 |
self._check_l3_bgpvpn(should_succeed=False) |
| 1072 |
|
| 1073 |
@decorators.idempotent_id('be4471b3-5f57-4022-b719-b45a673a728b') |
| 1074 |
@utils.services('compute', 'network') |
| 1075 |
def test_bgpvpn_negative_update_to_disjoint_import_export(self): |
| 1076 |
"""This test checks basic BGPVPN route targets update. |
| 1077 |
|
| 1078 |
1. Create networks A and B with their respective subnets |
| 1079 |
2. Create L3 BGPVPN with only RT defined |
| 1080 |
3. Start up server 1 in network A |
| 1081 |
4. Start up server 2 in network B |
| 1082 |
5. Associate network A to a given L3 BGPVPN |
| 1083 |
6. Create router and connect it to network A |
| 1084 |
7. Give a FIP to server 1 |
| 1085 |
8. Check that server 1 can ping server 2 |
| 1086 |
9. Update L3 BGPVPN to have eRT<>iRT and no RT what is insufficient |
| 1087 |
for proper connectivity between network A and B |
| 1088 |
10. Check that server 1 cannot ping server 2 |
| 1089 |
""" |
| 1090 |
self._create_networks_and_subnets() |
| 1091 |
self._create_l3_bgpvpn(rts=[self.RT1], import_rts=[], export_rts=[]) |
| 1092 |
self._create_servers() |
| 1093 |
self._associate_all_nets_to_bgpvpn() |
| 1094 |
self._associate_fip_and_check_l3_bgpvpn() |
| 1095 |
self._update_l3_bgpvpn(rts=[], import_rts=[self.RT1], |
| 1096 |
export_rts=[self.RT2]) |
| 1097 |
self._check_l3_bgpvpn(should_succeed=False) |
| 1098 |
|
| 1099 |
@decorators.idempotent_id('fb37a546-7263-4ffe-a42c-77eca377ff1a') |
| 1100 |
@utils.services('compute', 'network') |
| 1101 |
def test_bgpvpn_negative_update_to_empty_rt_list(self): |
| 1102 |
"""This test checks basic BGPVPN route targets update. |
| 1103 |
|
| 1104 |
1. Create networks A and B with their respective subnets |
| 1105 |
2. Create L3 BGPVPN with only RT defined |
| 1106 |
3. Start up server 1 in network A |
| 1107 |
4. Start up server 2 in network B |
| 1108 |
5. Associate network A and B to a given L3 BGPVPN |
| 1109 |
6. Create router and connect it to network A |
| 1110 |
7. Give a FIP to server 1 |
| 1111 |
8. Check that server 1 can ping server 2 |
| 1112 |
9. Update L3 BGPVPN to empty RT list what is insufficient |
| 1113 |
for proper connectivity between network A and B |
| 1114 |
10. Check that server 1 cannot ping server 2 |
| 1115 |
""" |
| 1116 |
self._create_networks_and_subnets() |
| 1117 |
self._create_l3_bgpvpn(rts=[self.RT1], import_rts=[], export_rts=[]) |
| 1118 |
self._create_servers() |
| 1119 |
self._associate_all_nets_to_bgpvpn() |
| 1120 |
self._associate_fip_and_check_l3_bgpvpn() |
| 1121 |
self._update_l3_bgpvpn(rts=[], import_rts=[], export_rts=[]) |
| 1122 |
self._check_l3_bgpvpn(should_succeed=False) |
| 1123 |
|
| 1124 |
def _create_security_group_for_test(self): |
| 1125 |
self.security_group = self.create_security_group( |
| 1126 |
project_id=self.bgpvpn_admin_client.project_id, |
| 1127 |
security_groups_client=self.admin_security_group_client, |
| 1128 |
security_group_rules_client=self.admin_security_group_rule_client) |
| 1129 |
|
| 1130 |
def _create_networks_and_subnets(self, names=None, subnet_cidrs=None, |
| 1131 |
port_security=True): |
| 1132 |
if not names: |
| 1133 |
names = [NET_A, NET_B, NET_C] |
| 1134 |
if not subnet_cidrs: |
| 1135 |
subnet_cidrs = [[NET_A_S1], [NET_B_S1], [NET_C_S1]] |
| 1136 |
for (name, subnet_cidrs) in zip(names, subnet_cidrs): |
| 1137 |
network = super(manager.NetworkScenarioTest, |
| 1138 |
self).create_network(namestart=name, |
| 1139 |
port_security_enabled=port_security, |
| 1140 |
networks_client=self.admin_networks_client) |
| 1141 |
self.networks[name] = network |
| 1142 |
self.subnets[name] = [] |
| 1143 |
for (j, cidr) in enumerate(subnet_cidrs): |
| 1144 |
sub_name = "subnet-%s-%d" % (name, j + 1) |
| 1145 |
subnet = self._create_subnet_with_cidr( |
| 1146 |
network, namestart=sub_name, cidr=cidr, ip_version=4, |
| 1147 |
subnets_client=self.admin_subnets_client) |
| 1148 |
self.subnets[name].append(subnet) |
| 1149 |
|
| 1150 |
def _create_subnet_with_cidr(self, network, subnets_client=None, |
| 1151 |
namestart='subnet-smoke', **kwargs): |
| 1152 |
if not subnets_client: |
| 1153 |
subnets_client = self.subnets_client |
| 1154 |
tenant_cidr = kwargs.get('cidr') |
| 1155 |
subnet = dict( |
| 1156 |
name=data_utils.rand_name(namestart), |
| 1157 |
network_id=network['id'], |
| 1158 |
tenant_id=network['tenant_id'], |
| 1159 |
**kwargs) |
| 1160 |
result = subnets_client.create_subnet(**subnet) |
| 1161 |
self.assertIsNotNone(result, 'Unable to allocate tenant network') |
| 1162 |
subnet = result['subnet'] |
| 1163 |
self.assertEqual(subnet['cidr'], tenant_cidr) |
| 1164 |
self.addCleanup(test_utils.call_and_ignore_notfound_exc, |
| 1165 |
subnets_client.delete_subnet, subnet['id']) |
| 1166 |
return subnet |
| 1167 |
|
| 1168 |
def _create_fip_router(self, client=None, public_network_id=None, |
| 1169 |
subnet_id=None): |
| 1170 |
if not client: |
| 1171 |
client = self.admin_routers_client |
| 1172 |
router = self._create_router(client, namestart='router-') |
| 1173 |
router_id = router['id'] |
| 1174 |
if public_network_id is None: |
| 1175 |
public_network_id = CONF.network.public_network_id |
| 1176 |
if client is None: |
| 1177 |
client = self.routers_client |
| 1178 |
kwargs = {'external_gateway_info': {'network_id': public_network_id}} |
| 1179 |
router = client.update_router(router_id, **kwargs)['router'] |
| 1180 |
if subnet_id is not None: |
| 1181 |
client.add_router_interface(router_id, subnet_id=subnet_id) |
| 1182 |
self.addCleanup(test_utils.call_and_ignore_notfound_exc, |
| 1183 |
client.remove_router_interface, router_id, |
| 1184 |
subnet_id=subnet_id) |
| 1185 |
return router |
| 1186 |
|
| 1187 |
def _associate_fip(self, server_index): |
| 1188 |
server = self.servers[server_index] |
| 1189 |
fip = self.create_floating_ip( |
| 1190 |
server, external_network_id=CONF.network.public_network_id, |
| 1191 |
port_id=self.ports[server['id']]['id'], |
| 1192 |
client=self.admin_fips_client) |
| 1193 |
self.server_fips[server['id']] = fip |
| 1194 |
return fip |
| 1195 |
|
| 1196 |
def _create_router_and_associate_fip(self, server_index, subnet): |
| 1197 |
router = self._create_fip_router(client=self.admin_routers_client, |
| 1198 |
subnet_id=subnet['id']) |
| 1199 |
self._associate_fip(server_index) |
| 1200 |
return router |
| 1201 |
|
| 1202 |
def _create_server(self, name, keypair, network, ip_address, |
| 1203 |
security_group_ids, clients, port_security): |
| 1204 |
security_groups = [] |
| 1205 |
if port_security: |
| 1206 |
security_groups = security_group_ids |
| 1207 |
create_port_body = {'fixed_ips': [{'ip_address': ip_address}], |
| 1208 |
'namestart': 'port-smoke', |
| 1209 |
'security_groups': security_groups} |
| 1210 |
|
| 1211 |
port = super(manager.NetworkScenarioTest, |
| 1212 |
self).create_port(network_id=network['id'], |
| 1213 |
client=self.admin_ports_client, |
| 1214 |
**create_port_body) |
| 1215 |
|
| 1216 |
create_server_kwargs = { |
| 1217 |
'key_name': keypair['name'], |
| 1218 |
'networks': [{'uuid': network['id'], 'port': port['id']}] |
| 1219 |
} |
| 1220 |
body, servers = compute.create_test_server( |
| 1221 |
clients, wait_until='ACTIVE', name=name, **create_server_kwargs) |
| 1222 |
self.addCleanup(waiters.wait_for_server_termination, |
| 1223 |
clients.servers_client, body['id']) |
| 1224 |
self.addCleanup(test_utils.call_and_ignore_notfound_exc, |
| 1225 |
clients.servers_client.delete_server, body['id']) |
| 1226 |
server = clients.servers_client.show_server(body['id'])['server'] |
| 1227 |
LOG.debug('Created server: %s with status: %s', server['id'], |
| 1228 |
server['status']) |
| 1229 |
self.ports[server['id']] = port |
| 1230 |
return server |
| 1231 |
|
| 1232 |
def _create_servers(self, ports_config=None, port_security=True): |
| 1233 |
keypair = self.create_keypair(client=self.admin_keys_client) |
| 1234 |
security_group_ids = [self.security_group['id']] |
| 1235 |
if ports_config is None: |
| 1236 |
ports_config = [[self.networks[NET_A], IP_A_S1_1], |
| 1237 |
[self.networks[NET_B], IP_B_S1_1]] |
| 1238 |
for (i, port_config) in enumerate(ports_config): |
| 1239 |
network = port_config[0] |
| 1240 |
server = self._create_server( |
| 1241 |
'server-' + str(i + 1), keypair, network, port_config[1], |
| 1242 |
security_group_ids, self.os_admin, port_security) |
| 1243 |
self.servers.append(server) |
| 1244 |
self.servers_keypairs[server['id']] = keypair |
| 1245 |
self.server_fixed_ips[server['id']] = ( |
| 1246 |
server['addresses'][network['name']][0]['addr']) |
| 1247 |
self.assertTrue(self.servers_keypairs) |
| 1248 |
|
| 1249 |
def _create_l3_bgpvpn(self, name='test-l3-bgpvpn', rts=None, |
| 1250 |
import_rts=None, export_rts=None): |
| 1251 |
if rts is None and import_rts is None and export_rts is None: |
| 1252 |
rts = [self.RT1] |
| 1253 |
import_rts = import_rts or [] |
| 1254 |
export_rts = export_rts or [] |
| 1255 |
self.bgpvpn = self.create_bgpvpn( |
| 1256 |
self.bgpvpn_admin_client, |
| 1257 |
tenant_id=self.bgpvpn_admin_client.project_id, |
| 1258 |
name=name, route_targets=rts, export_targets=export_rts, |
| 1259 |
import_targets=import_rts) |
| 1260 |
return self.bgpvpn |
| 1261 |
|
| 1262 |
def _update_l3_bgpvpn(self, rts=None, import_rts=None, export_rts=None, |
| 1263 |
bgpvpn=None): |
| 1264 |
bgpvpn = bgpvpn or self.bgpvpn |
| 1265 |
if rts is None: |
| 1266 |
rts = [self.RT1] |
| 1267 |
import_rts = import_rts or [] |
| 1268 |
export_rts = export_rts or [] |
| 1269 |
LOG.debug('Updating targets in BGPVPN %s', bgpvpn['id']) |
| 1270 |
self.bgpvpn_admin_client.update_bgpvpn(bgpvpn['id'], |
| 1271 |
route_targets=rts, |
| 1272 |
export_targets=export_rts, |
| 1273 |
import_targets=import_rts) |
| 1274 |
|
| 1275 |
def _associate_all_nets_to_bgpvpn(self, bgpvpn=None): |
| 1276 |
bgpvpn = bgpvpn or self.bgpvpn |
| 1277 |
for network in self.networks.values(): |
| 1278 |
self.bgpvpn_admin_client.create_network_association( |
| 1279 |
bgpvpn['id'], network['id']) |
| 1280 |
LOG.debug('BGPVPN network associations completed') |
| 1281 |
|
| 1282 |
def _setup_ssh_client(self, server): |
| 1283 |
server_fip = self.server_fips[server['id']][ |
| 1284 |
'floating_ip_address'] |
| 1285 |
private_key = self.servers_keypairs[server['id']][ |
| 1286 |
'private_key'] |
| 1287 |
ssh_client = self.get_remote_client(server_fip, |
| 1288 |
private_key=private_key, |
| 1289 |
server=server) |
| 1290 |
return ssh_client |
| 1291 |
|
| 1292 |
def _setup_http_server(self, server_index): |
| 1293 |
server = self.servers[server_index] |
| 1294 |
ssh_client = self._setup_ssh_client(server) |
| 1295 |
ssh_client.exec_command("sudo nc -kl -p 80 -e echo '%s:%s' &" |
| 1296 |
% (server['name'], server['id'])) |
| 1297 |
|
| 1298 |
def _setup_ip_forwarding(self, server_index): |
| 1299 |
server = self.servers[server_index] |
| 1300 |
ssh_client = self._setup_ssh_client(server) |
| 1301 |
ssh_client.exec_command("sudo sysctl -w net.ipv4.ip_forward=1") |
| 1302 |
|
| 1303 |
def _setup_ip_address(self, server_index, cidr, device=None): |
| 1304 |
self._setup_range_ip_address(server_index, [cidr], device=None) |
| 1305 |
|
| 1306 |
def _setup_range_ip_address(self, server_index, cidrs, device=None): |
| 1307 |
MAX_CIDRS = 50 |
| 1308 |
if device is None: |
| 1309 |
device = 'lo' |
| 1310 |
server = self.servers[server_index] |
| 1311 |
ssh_client = self._setup_ssh_client(server) |
| 1312 |
for i in range(0, len(cidrs), MAX_CIDRS): |
| 1313 |
ips = ' '.join(cidrs[i:i + MAX_CIDRS]) |
| 1314 |
ssh_client.exec_command( |
| 1315 |
("for ip in {ips}; do sudo ip addr add $ip " |
| 1316 |
"dev {dev}; done").format(ips=ips, dev=device)) |
| 1317 |
|
| 1318 |
def _check_l3_bgpvpn(self, from_server=None, to_server=None, |
| 1319 |
should_succeed=True, validate_server=False): |
| 1320 |
to_server = to_server or self.servers[1] |
| 1321 |
destination_srv = None |
| 1322 |
if validate_server: |
| 1323 |
destination_srv = '%s:%s' % (to_server['name'], to_server['id']) |
| 1324 |
destination_ip = self.server_fixed_ips[to_server['id']] |
| 1325 |
self._check_l3_bgpvpn_by_specific_ip(from_server=from_server, |
| 1326 |
to_server_ip=destination_ip, |
| 1327 |
should_succeed=should_succeed, |
| 1328 |
validate_server=destination_srv) |
| 1329 |
|
| 1330 |
def _check_l3_bgpvpn_by_specific_ip(self, from_server=None, |
| 1331 |
to_server_ip=None, |
| 1332 |
should_succeed=True, |
| 1333 |
validate_server=None, |
| 1334 |
repeat_validate_server=10): |
| 1335 |
from_server = from_server or self.servers[0] |
| 1336 |
from_server_ip = self.server_fips[from_server['id']][ |
| 1337 |
'floating_ip_address'] |
| 1338 |
if to_server_ip is None: |
| 1339 |
to_server_ip = self.server_fixed_ips[self.servers[1]['id']] |
| 1340 |
ssh_client = self._setup_ssh_client(from_server) |
| 1341 |
check_reachable = should_succeed or validate_server |
| 1342 |
msg = "" |
| 1343 |
if check_reachable: |
| 1344 |
msg = "Timed out waiting for {ip} to become reachable".format( |
| 1345 |
ip=to_server_ip) |
| 1346 |
else: |
| 1347 |
msg = ("Unexpected ping response from VM with IP address " |
| 1348 |
"{dest} originated from VM with IP address " |
| 1349 |
"{src}").format(dest=to_server_ip, src=from_server_ip) |
| 1350 |
try: |
| 1351 |
result = self._check_remote_connectivity(ssh_client, |
| 1352 |
to_server_ip, |
| 1353 |
check_reachable) |
| 1354 |
# if a negative connectivity check was unsuccessful (unexpected |
| 1355 |
# ping reply) then try to know more: |
| 1356 |
if not check_reachable and not result: |
| 1357 |
try: |
| 1358 |
content = ssh_client.exec_command( |
| 1359 |
"nc %s 80" % to_server_ip).strip() |
| 1360 |
LOG.warning("Can connect to %s: %s", to_server_ip, content) |
| 1361 |
except Exception: |
| 1362 |
LOG.warning("Could ping %s, but no http", to_server_ip) |
| 1363 |
|
| 1364 |
self.assertTrue(result, msg) |
| 1365 |
|
| 1366 |
if validate_server and result: |
| 1367 |
# repeating multiple times gives increased odds of avoiding |
| 1368 |
# false positives in the case where the dataplane does |
| 1369 |
# equal-cost multipath |
| 1370 |
for i in range(0, repeat_validate_server): |
| 1371 |
real_dest = ssh_client.exec_command( |
| 1372 |
"nc %s 80" % to_server_ip).strip() |
| 1373 |
result = real_dest == validate_server |
| 1374 |
self.assertTrue( |
| 1375 |
should_succeed == result, |
| 1376 |
("Destination server name is '%s', expected is '%s'" % |
| 1377 |
(real_dest, validate_server))) |
| 1378 |
LOG.info("nc server name check %d successful", i) |
| 1379 |
except Exception: |
| 1380 |
LOG.exception("Error validating connectivity to %s " |
| 1381 |
"from VM with IP address %s: %s", |
| 1382 |
to_server_ip, from_server_ip, msg) |
| 1383 |
raise |
| 1384 |
|
| 1385 |
def _associate_fip_and_check_l3_bgpvpn(self, should_succeed=True): |
| 1386 |
subnet = self.subnets[NET_A][0] |
| 1387 |
self.router = self._create_router_and_associate_fip(0, subnet) |
| 1388 |
self._check_l3_bgpvpn(should_succeed=should_succeed) |
| 1389 |
|
| 1390 |
def _delete_router(self, router, routers_client=None, ports_client=None): |
| 1391 |
if not routers_client: |
| 1392 |
routers_client = self.routers_client |
| 1393 |
if not ports_client: |
| 1394 |
ports_client = self.ports_client |
| 1395 |
ports_rsp = ports_client.list_ports(device_id=router['id']) |
| 1396 |
interfaces = ports_rsp['ports'] |
| 1397 |
for i in interfaces: |
| 1398 |
test_utils.call_and_ignore_notfound_exc( |
| 1399 |
routers_client.remove_router_interface, router['id'], |
| 1400 |
subnet_id=i['fixed_ips'][0]['subnet_id']) |
| 1401 |
routers_client.delete_router(router['id']) |