| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
import netaddr |
| 16 |
|
| 17 |
from tempest.common import utils |
| 18 |
from tempest.lib import decorators |
| 19 |
from tempest.lib import exceptions as lib_exc |
| 20 |
|
| 21 |
from neutron_tempest_plugin.neutron_dynamic_routing.api import\ |
| 22 |
test_bgp_speaker_extensions as test_base |
| 23 |
|
| 24 |
|
| 25 |
class BgpSpeakerTestJSONNegative(test_base.BgpSpeakerTestJSONBase): |
| 26 |
|
| 27 |
"""Negative test cases asserting proper behavior of BGP API extension""" |
| 28 |
|
| 29 |
@decorators.attr(type=['negative']) |
| 30 |
@decorators.idempotent_id('75e9ee2f-6efd-4320-bff7-ae24741c8b06') |
| 31 |
def test_create_bgp_speaker_illegal_local_asn(self): |
| 32 |
wrong_asn = 65537 |
| 33 |
if utils.is_extension_enabled('bgp_4byte_asn', 'network'): |
| 34 |
wrong_asn = 4294967296 |
| 35 |
self.assertRaises(lib_exc.BadRequest, |
| 36 |
self.create_bgp_speaker, |
| 37 |
local_as=wrong_asn) |
| 38 |
|
| 39 |
@decorators.attr(type=['negative']) |
| 40 |
@decorators.idempotent_id('6742ec2e-382a-4453-8791-13a19b47cd13') |
| 41 |
def test_create_bgp_speaker_non_admin(self): |
| 42 |
self.assertRaises(lib_exc.Forbidden, |
| 43 |
self.bgp_client.create_bgp_speaker, |
| 44 |
{'bgp_speaker': self.default_bgp_speaker_args}) |
| 45 |
|
| 46 |
@decorators.attr(type=['negative']) |
| 47 |
@decorators.idempotent_id('33f7aaf0-9786-478b-b2d1-a51086a50eb4') |
| 48 |
def test_create_bgp_peer_non_admin(self): |
| 49 |
self.assertRaises(lib_exc.Forbidden, |
| 50 |
self.bgp_client.create_bgp_peer, |
| 51 |
{'bgp_peer': self.default_bgp_peer_args}) |
| 52 |
|
| 53 |
@decorators.attr(type=['negative']) |
| 54 |
@decorators.idempotent_id('39435932-0266-4358-899b-0e9b1e53c3e9') |
| 55 |
def test_update_bgp_speaker_local_asn(self): |
| 56 |
bgp_speaker = self.create_bgp_speaker(**self.default_bgp_speaker_args) |
| 57 |
bgp_speaker_id = bgp_speaker['id'] |
| 58 |
|
| 59 |
self.assertRaises(lib_exc.BadRequest, self.update_bgp_speaker, |
| 60 |
bgp_speaker_id, local_as='4321') |
| 61 |
|
| 62 |
@decorators.idempotent_id('9cc33701-51e5-421f-a5d5-fd7b330e550f') |
| 63 |
def test_get_advertised_routes_tenant_networks(self): |
| 64 |
addr_scope1 = self.create_address_scope('my-scope1', ip_version=4) |
| 65 |
addr_scope2 = self.create_address_scope('my-scope2', ip_version=4) |
| 66 |
ext_net = self.create_shared_network(**{'router:external': True}) |
| 67 |
tenant_net1 = self.create_network() |
| 68 |
tenant_net2 = self.create_network() |
| 69 |
ext_subnetpool = self.create_subnetpool( |
| 70 |
'test-pool-ext', |
| 71 |
is_admin=True, |
| 72 |
default_prefixlen=24, |
| 73 |
address_scope_id=addr_scope1['id'], |
| 74 |
prefixes=['8.0.0.0/8']) |
| 75 |
tenant_subnetpool1 = self.create_subnetpool( |
| 76 |
'tenant-test-pool', |
| 77 |
default_prefixlen=25, |
| 78 |
address_scope_id=addr_scope1['id'], |
| 79 |
prefixes=['10.10.0.0/16']) |
| 80 |
tenant_subnetpool2 = self.create_subnetpool( |
| 81 |
'tenant-test-pool', |
| 82 |
default_prefixlen=25, |
| 83 |
address_scope_id=addr_scope2['id'], |
| 84 |
prefixes=['11.10.0.0/16']) |
| 85 |
self.create_subnet({'id': ext_net['id']}, |
| 86 |
cidr=netaddr.IPNetwork('8.0.0.0/24'), |
| 87 |
ip_version=4, |
| 88 |
client=self.admin_client, |
| 89 |
subnetpool_id=ext_subnetpool['id']) |
| 90 |
tenant_subnet1 = self.create_subnet( |
| 91 |
{'id': tenant_net1['id']}, |
| 92 |
cidr=netaddr.IPNetwork('10.10.0.0/24'), |
| 93 |
ip_version=4, |
| 94 |
subnetpool_id=tenant_subnetpool1['id']) |
| 95 |
tenant_subnet2 = self.create_subnet( |
| 96 |
{'id': tenant_net2['id']}, |
| 97 |
cidr=netaddr.IPNetwork('11.10.0.0/24'), |
| 98 |
ip_version=4, |
| 99 |
subnetpool_id=tenant_subnetpool2['id']) |
| 100 |
ext_gw_info = {'network_id': ext_net['id']} |
| 101 |
router = self.create_router(ext_gw_info) |
| 102 |
self.admin_routers.append(router) |
| 103 |
self.admin_client.add_router_interface_with_subnet_id( |
| 104 |
router['id'], |
| 105 |
tenant_subnet1['id']) |
| 106 |
self.admin_routerports.append({'router_id': router['id'], |
| 107 |
'subnet_id': tenant_subnet1['id']}) |
| 108 |
self.admin_client.add_router_interface_with_subnet_id( |
| 109 |
router['id'], |
| 110 |
tenant_subnet2['id']) |
| 111 |
self.admin_routerports.append({'router_id': router['id'], |
| 112 |
'subnet_id': tenant_subnet2['id']}) |
| 113 |
bgp_speaker = self.create_bgp_speaker(**self.default_bgp_speaker_args) |
| 114 |
bgp_speaker_id = bgp_speaker['id'] |
| 115 |
self.bgp_adm_client.add_bgp_gateway_network(bgp_speaker_id, |
| 116 |
ext_net['id']) |
| 117 |
routes = self.bgp_adm_client.get_bgp_advertised_routes(bgp_speaker_id) |
| 118 |
self.assertEqual(1, len(routes['advertised_routes'])) |
| 119 |
self.assertEqual(tenant_subnet1['cidr'], |
| 120 |
routes['advertised_routes'][0]['destination']) |
| 121 |
fixed_ip = router['external_gateway_info']['external_fixed_ips'][0] |
| 122 |
self.assertEqual(fixed_ip['ip_address'], |
| 123 |
routes['advertised_routes'][0]['next_hop']) |