| 1 |
# Copyright (c) 2015 Ericsson. |
| 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 |
from oslo_utils import uuidutils |
| 17 |
from tempest.lib.common.utils import data_utils |
| 18 |
from tempest.lib import decorators |
| 19 |
from tempest.lib import exceptions |
| 20 |
from testtools import ExpectedException |
| 21 |
|
| 22 |
from neutron_tempest_plugin.bgpvpn.base import BaseBgpvpnTest as base |
| 23 |
|
| 24 |
|
| 25 |
class BgpvpnTest(base): |
| 26 |
"""Tests the following operations in the Neutron API: |
| 27 |
|
| 28 |
create bgpvpn |
| 29 |
delete bgpvpn |
| 30 |
show bgpvpn |
| 31 |
list bgpvpns |
| 32 |
associate network to bgpvpn |
| 33 |
disassociate network from bgpvpn |
| 34 |
show network association |
| 35 |
list network associations |
| 36 |
update route targets |
| 37 |
|
| 38 |
v2.0 of the Neutron API is assumed. It is also assumed that the following |
| 39 |
options are defined in the [network] section of etc/tempest.conf: |
| 40 |
|
| 41 |
... |
| 42 |
""" |
| 43 |
|
| 44 |
@decorators.idempotent_id('4f90deb2-eb8e-4e7d-9d68-c5b5cc657f7e') |
| 45 |
def test_create_bgpvpn(self): |
| 46 |
self.create_bgpvpn(self.bgpvpn_admin_client) |
| 47 |
|
| 48 |
@decorators.attr(type=['negative']) |
| 49 |
@decorators.idempotent_id('0a911d61-d908-4c21-a11e-e403ac0d8e38') |
| 50 |
def test_create_bgpvpn_as_non_admin_fail(self): |
| 51 |
self.assertRaises(exceptions.Forbidden, |
| 52 |
self.create_bgpvpn, self.bgpvpn_client) |
| 53 |
|
| 54 |
@decorators.idempotent_id('709b23b0-9719-47df-9f53-b0812a5d5a48') |
| 55 |
def test_delete_bgpvpn(self): |
| 56 |
bgpvpn = self.create_bgpvpn(self.bgpvpn_admin_client, |
| 57 |
tenant_id=self.bgpvpn_client.project_id) |
| 58 |
self.delete_bgpvpn(self.bgpvpn_admin_client, bgpvpn) |
| 59 |
|
| 60 |
@decorators.attr(type=['negative']) |
| 61 |
@decorators.idempotent_id('596abfc2-fd89-491d-863d-25459db1df4b') |
| 62 |
def test_delete_bgpvpn_as_non_admin_fail(self): |
| 63 |
bgpvpn = self.create_bgpvpn(self.bgpvpn_admin_client, |
| 64 |
tenant_id=self.bgpvpn_client.project_id) |
| 65 |
self.assertRaises(exceptions.Forbidden, |
| 66 |
self.bgpvpn_client.delete_bgpvpn, bgpvpn['id']) |
| 67 |
|
| 68 |
@decorators.idempotent_id('9fa29db8-35d0-4beb-a986-23c369499ab1') |
| 69 |
def test_show_bgpvpn(self): |
| 70 |
bgpvpn = self.create_bgpvpn(self.bgpvpn_admin_client, |
| 71 |
tenant_id=self.bgpvpn_client.project_id) |
| 72 |
bgpvpn_details = self.bgpvpn_client.show_bgpvpn(bgpvpn['id'])['bgpvpn'] |
| 73 |
self.assertEqual(bgpvpn['id'], bgpvpn_details['id']) |
| 74 |
|
| 75 |
@decorators.attr(type=['negative']) |
| 76 |
@decorators.idempotent_id('b20110bb-393b-4342-8b30-6486cd2b4fc6') |
| 77 |
def test_show_bgpvpn_as_non_owner_fail(self): |
| 78 |
bgpvpn = self.create_bgpvpn(self.bgpvpn_admin_client, |
| 79 |
tenant_id=self.bgpvpn_client.project_id) |
| 80 |
self.assertRaises(exceptions.NotFound, |
| 81 |
self.bgpvpn_alt_client.show_bgpvpn, bgpvpn['id']) |
| 82 |
|
| 83 |
@decorators.idempotent_id('7a7feca2-1c24-4f5d-ad4b-b0e5a712adb1') |
| 84 |
def test_list_bgpvpn(self): |
| 85 |
bgpvpn = self.create_bgpvpn(self.bgpvpn_admin_client, |
| 86 |
tenant_id=self.bgpvpn_client.project_id) |
| 87 |
bgpvpns = self.bgpvpn_client.list_bgpvpns()['bgpvpns'] |
| 88 |
self.assertIn(bgpvpn['id'], |
| 89 |
[bgpvpn_alt['id'] for bgpvpn_alt in bgpvpns]) |
| 90 |
|
| 91 |
@decorators.attr(type=['negative']) |
| 92 |
@decorators.idempotent_id('4875e65d-0b65-40c0-9efd-309420686ab4') |
| 93 |
def test_list_bgpvpn_as_non_owner_fail(self): |
| 94 |
bgpvpn = self.create_bgpvpn(self.bgpvpn_admin_client, |
| 95 |
tenant_id=self.bgpvpn_client.project_id) |
| 96 |
bgpvpns_alt = self.bgpvpn_alt_client.list_bgpvpns()['bgpvpns'] |
| 97 |
self.assertNotIn(bgpvpn['id'], |
| 98 |
[bgpvpn_alt['id'] for bgpvpn_alt in bgpvpns_alt]) |
| 99 |
|
| 100 |
@decorators.idempotent_id('096281da-356d-4c04-bd55-784a26bb1b0c') |
| 101 |
def test_list_show_network_association(self): |
| 102 |
bgpvpn = self.create_bgpvpn(self.bgpvpn_admin_client, |
| 103 |
tenant_id=self.bgpvpn_client.project_id) |
| 104 |
network = self.networks_client.create_network()['network'] |
| 105 |
|
| 106 |
association = self.bgpvpn_client.create_network_association( |
| 107 |
bgpvpn['id'], network['id'])['network_association'] |
| 108 |
net_assocs = self.bgpvpn_client\ |
| 109 |
.list_network_associations(bgpvpn['id'])['network_associations'] |
| 110 |
self.assertIn(association['id'], |
| 111 |
[net_assoc['id'] for net_assoc in net_assocs]) |
| 112 |
net_assoc_details = self.bgpvpn_client\ |
| 113 |
.show_network_association(bgpvpn['id'], |
| 114 |
association['id'])['network_association'] |
| 115 |
self.assertEqual(association['id'], net_assoc_details['id']) |
| 116 |
|
| 117 |
@decorators.attr(type=['negative']) |
| 118 |
@decorators.idempotent_id('57b0da93-8e37-459f-9aaf-f903acc36025') |
| 119 |
def test_show_netassoc_as_non_owner_fail(self): |
| 120 |
bgpvpn = self.create_bgpvpn(self.bgpvpn_admin_client, |
| 121 |
tenant_id=self.bgpvpn_client.project_id) |
| 122 |
network = self.networks_client.create_network()['network'] |
| 123 |
|
| 124 |
net_assoc = self.bgpvpn_client.create_network_association( |
| 125 |
bgpvpn['id'], network['id'])['network_association'] |
| 126 |
|
| 127 |
self.assertRaises(exceptions.NotFound, |
| 128 |
self.bgpvpn_alt_client.show_network_association, |
| 129 |
bgpvpn['id'], net_assoc['id']) |
| 130 |
|
| 131 |
@decorators.attr(type=['negative']) |
| 132 |
@decorators.idempotent_id('2cbb10af-bf9c-4b32-b6a6-4066de783758') |
| 133 |
def test_list_netassoc_as_non_owner_fail(self): |
| 134 |
bgpvpn = self.create_bgpvpn(self.bgpvpn_admin_client, |
| 135 |
tenant_id=self.bgpvpn_client.project_id) |
| 136 |
network = self.networks_client.create_network()['network'] |
| 137 |
|
| 138 |
self.bgpvpn_client.create_network_association(bgpvpn['id'], |
| 139 |
network['id']) |
| 140 |
net_assocs_alt = self.bgpvpn_alt_client\ |
| 141 |
.list_network_associations(bgpvpn['id']) |
| 142 |
self.assertFalse(net_assocs_alt['network_associations']) |
| 143 |
|
| 144 |
@decorators.idempotent_id('51e1b079-aefa-4c37-8b1a-0567b3ef7954') |
| 145 |
def test_associate_disassociate_network(self): |
| 146 |
bgpvpn = self.create_bgpvpn(self.bgpvpn_admin_client, |
| 147 |
tenant_id=self.bgpvpn_client.project_id) |
| 148 |
network = self.networks_client.create_network() |
| 149 |
network_id = network['network']['id'] |
| 150 |
|
| 151 |
# Associate the network to the bgpvpn resource |
| 152 |
association = self.bgpvpn_client.create_network_association( |
| 153 |
bgpvpn['id'], network_id) |
| 154 |
self.assertEqual(association['network_association']['network_id'], |
| 155 |
network_id) |
| 156 |
updated_bgpvpn = self.bgpvpn_client.show_bgpvpn(bgpvpn['id']) |
| 157 |
self.assertEqual(updated_bgpvpn['bgpvpn']['networks'], [network_id]) |
| 158 |
|
| 159 |
# Disassociate the network from the bgpvpn resource |
| 160 |
self.bgpvpn_client.delete_network_association( |
| 161 |
bgpvpn['id'], |
| 162 |
association['network_association']['id']) |
| 163 |
updated_bgpvpn = self.bgpvpn_client.show_bgpvpn(bgpvpn['id']) |
| 164 |
self.assertEqual(updated_bgpvpn['bgpvpn']['networks'], []) |
| 165 |
|
| 166 |
self.networks_client.delete_network(network_id) |
| 167 |
|
| 168 |
@decorators.idempotent_id('559013fd-1e34-4fde-9599-f8aafe9ae716') |
| 169 |
def test_update_route_target(self): |
| 170 |
bgpvpn = self.create_bgpvpn( |
| 171 |
self.bgpvpn_admin_client, |
| 172 |
route_targets=['64512:1'], |
| 173 |
import_targets=['64512:2'], |
| 174 |
export_targets=['64512:3']) |
| 175 |
bgpvpn = self.bgpvpn_admin_client.update_bgpvpn( |
| 176 |
bgpvpn['id'], |
| 177 |
route_targets=['64512:4'], |
| 178 |
import_targets=['64512:5'], |
| 179 |
export_targets=['64512:6'] |
| 180 |
)['bgpvpn'] |
| 181 |
self.assertEqual(['64512:4'], bgpvpn['route_targets']) |
| 182 |
self.assertEqual(['64512:5'], bgpvpn['import_targets']) |
| 183 |
self.assertEqual(['64512:6'], bgpvpn['export_targets']) |
| 184 |
|
| 185 |
@decorators.attr(type=['negative']) |
| 186 |
@decorators.idempotent_id('e35eb9be-fe1f-406c-b36b-fc1879328313') |
| 187 |
def test_update_route_target_non_admin_fail(self): |
| 188 |
bgpvpn = self.create_bgpvpn( |
| 189 |
self.bgpvpn_admin_client, |
| 190 |
tenant_id=self.bgpvpn_client.project_id, |
| 191 |
route_targets=['64512:1']) |
| 192 |
with ExpectedException(exceptions.Forbidden): |
| 193 |
self.bgpvpn_client.update_bgpvpn( |
| 194 |
bgpvpn['id'], |
| 195 |
route_targets=['64512:2'], |
| 196 |
import_targets=['64512:3'], |
| 197 |
export_targets=['64512:4']) |
| 198 |
|
| 199 |
@decorators.attr(type=['negative']) |
| 200 |
@decorators.idempotent_id('464ca6f9-86e4-4ee3-9c65-f1edae93223d') |
| 201 |
def test_create_bgpvpn_with_invalid_routetargets(self): |
| 202 |
"""Create a bgpvpn with invalid route target |
| 203 |
|
| 204 |
This test verifies that invalid route targets,import targets, |
| 205 |
export targets are rejected by the Create API |
| 206 |
""" |
| 207 |
postdata = { |
| 208 |
"name": "testbgpvpn", |
| 209 |
"tenant_id": self.bgpvpn_client.project_id, |
| 210 |
"route_targets": ["0"] |
| 211 |
} |
| 212 |
self.assertRaises(exceptions.BadRequest, |
| 213 |
self.bgpvpn_admin_client.create_bgpvpn, **postdata) |
| 214 |
postdata = { |
| 215 |
"name": "testbgpvpn", |
| 216 |
"tenant_id": self.bgpvpn_client.project_id, |
| 217 |
"import_targets": ["test", " "] |
| 218 |
} |
| 219 |
self.assertRaises(exceptions.BadRequest, |
| 220 |
self.bgpvpn_admin_client.create_bgpvpn, **postdata) |
| 221 |
postdata = { |
| 222 |
"name": "testbgpvpn", |
| 223 |
"tenant_id": self.bgpvpn_client.project_id, |
| 224 |
"export_targets": ["64512:1000000000000", "xyz"] |
| 225 |
} |
| 226 |
self.assertRaises(exceptions.BadRequest, |
| 227 |
self.bgpvpn_admin_client.create_bgpvpn, **postdata) |
| 228 |
|
| 229 |
@decorators.attr(type=['negative']) |
| 230 |
@decorators.idempotent_id('7d4e9b87-e1ab-47a7-a8d6-9d179365556a') |
| 231 |
def test_update_bgpvpn_invalid_routetargets(self): |
| 232 |
"""Update the bgpvpn with invalid route targets |
| 233 |
|
| 234 |
This test verifies that invalid route targets,import targets |
| 235 |
and export targets are rejected by the Update API |
| 236 |
""" |
| 237 |
postdata = { |
| 238 |
"name": "testbgpvpn", |
| 239 |
"tenant_id": self.bgpvpn_client.project_id, |
| 240 |
} |
| 241 |
bgpvpn = self.bgpvpn_admin_client.create_bgpvpn(**postdata) |
| 242 |
updatedata = { |
| 243 |
"route_targets": ["0"] |
| 244 |
} |
| 245 |
self.assertRaises(exceptions.BadRequest, |
| 246 |
self.bgpvpn_admin_client.update_bgpvpn, |
| 247 |
bgpvpn['bgpvpn']['id'], **updatedata) |
| 248 |
updatedata = { |
| 249 |
"import_targets": ["test", " "] |
| 250 |
} |
| 251 |
self.assertRaises(exceptions.BadRequest, |
| 252 |
self.bgpvpn_admin_client.update_bgpvpn, |
| 253 |
bgpvpn['bgpvpn']['id'], **updatedata) |
| 254 |
updatedata = { |
| 255 |
"export_targets": ["64512:1000000000000", "xyz"], |
| 256 |
} |
| 257 |
self.assertRaises(exceptions.BadRequest, |
| 258 |
self.bgpvpn_admin_client.update_bgpvpn, |
| 259 |
bgpvpn['bgpvpn']['id'], **updatedata) |
| 260 |
|
| 261 |
@decorators.attr(type=['negative']) |
| 262 |
@decorators.idempotent_id('f049ce21-d239-47c0-b13f-fb57a2a558ce') |
| 263 |
def test_associate_invalid_network(self): |
| 264 |
"""Associate the invalid network in bgpvpn |
| 265 |
|
| 266 |
This test verifies that invalid network id,bgpvpn id |
| 267 |
are rejected by the associate API |
| 268 |
""" |
| 269 |
postdata = { |
| 270 |
"name": "testbgpvpn", |
| 271 |
"tenant_id": self.bgpvpn_client.project_id, |
| 272 |
} |
| 273 |
bgpvpn = self.bgpvpn_admin_client.create_bgpvpn(**postdata) |
| 274 |
network = self.networks_client.create_network() |
| 275 |
self.assertRaises(exceptions.NotFound, |
| 276 |
self.bgpvpn_client.create_network_association, |
| 277 |
bgpvpn['bgpvpn']['id'], uuidutils.generate_uuid()) |
| 278 |
self.assertRaises(exceptions.NotFound, |
| 279 |
self.bgpvpn_client.create_network_association, |
| 280 |
uuidutils.generate_uuid(), |
| 281 |
network['network']['id']) |
| 282 |
|
| 283 |
@decorators.attr(type=['negative']) |
| 284 |
@decorators.idempotent_id('078b2660-4adb-4c4c-abf0-b77bf0bface5') |
| 285 |
def test_disassociate_invalid_network(self): |
| 286 |
"""Disassociate the invalid network in bgpvpn |
| 287 |
|
| 288 |
This test verifies that invalid network id, |
| 289 |
bgpvpn id are rejected by the disassociate API |
| 290 |
""" |
| 291 |
postdata = { |
| 292 |
"name": "testbgpvpn", |
| 293 |
"tenant_id": self.bgpvpn_client.project_id, |
| 294 |
} |
| 295 |
bgpvpn = self.bgpvpn_admin_client.create_bgpvpn(**postdata) |
| 296 |
network = self.networks_client.create_network() |
| 297 |
association = self.bgpvpn_client.create_network_association( |
| 298 |
bgpvpn['bgpvpn']['id'], network['network']['id']) |
| 299 |
self.assertEqual(association['network_association'][ |
| 300 |
'network_id'], network['network']['id']) |
| 301 |
self.assertRaises(exceptions.NotFound, |
| 302 |
self.bgpvpn_client.delete_network_association, |
| 303 |
bgpvpn['bgpvpn']['id'], |
| 304 |
uuidutils.generate_uuid()) |
| 305 |
self.assertRaises(exceptions.NotFound, |
| 306 |
self.bgpvpn_client.delete_network_association, |
| 307 |
uuidutils.generate_uuid(), |
| 308 |
association['network_association']['id']) |
| 309 |
|
| 310 |
@decorators.idempotent_id('de8d94b0-0239-4a48-9574-c3a4a4f7cacb') |
| 311 |
def test_associate_disassociate_router(self): |
| 312 |
bgpvpn = self.create_bgpvpn(self.bgpvpn_admin_client, |
| 313 |
tenant_id=self.bgpvpn_client.project_id) |
| 314 |
router = self.routers_client.create_router() |
| 315 |
router_id = router['router']['id'] |
| 316 |
|
| 317 |
# Associate the network to the bgpvpn resource |
| 318 |
association = self.bgpvpn_client.create_router_association( |
| 319 |
bgpvpn['id'], router_id) |
| 320 |
self.assertEqual(association['router_association']['router_id'], |
| 321 |
router_id) |
| 322 |
updated_bgpvpn = self.bgpvpn_client.show_bgpvpn(bgpvpn['id']) |
| 323 |
self.assertEqual(updated_bgpvpn['bgpvpn']['routers'], [router_id]) |
| 324 |
|
| 325 |
# Disassociate the network from the bgpvpn resource |
| 326 |
self.bgpvpn_client.delete_router_association( |
| 327 |
bgpvpn['id'], |
| 328 |
association['router_association']['id']) |
| 329 |
updated_bgpvpn = self.bgpvpn_client.show_bgpvpn(bgpvpn['id']) |
| 330 |
self.assertEqual(updated_bgpvpn['bgpvpn']['routers'], []) |
| 331 |
|
| 332 |
self.routers_client.delete_router(router_id) |
| 333 |
|
| 334 |
@decorators.idempotent_id('3ae91755-b1b6-4c62-a699-a44eeb4ee522') |
| 335 |
def test_list_show_router_association(self): |
| 336 |
bgpvpn = self.create_bgpvpn(self.bgpvpn_admin_client, |
| 337 |
tenant_id=self.bgpvpn_client.project_id) |
| 338 |
router = self.routers_client.create_router() |
| 339 |
router_id = router['router']['id'] |
| 340 |
|
| 341 |
association = self.bgpvpn_client.create_router_association( |
| 342 |
bgpvpn['id'], router_id)['router_association'] |
| 343 |
rtr_assocs = self.bgpvpn_client\ |
| 344 |
.list_router_associations(bgpvpn['id'])['router_associations'] |
| 345 |
self.assertIn(association['id'], |
| 346 |
[rtr_assoc['id'] for rtr_assoc in rtr_assocs]) |
| 347 |
rtr_assoc_details = self.bgpvpn_client\ |
| 348 |
.show_router_association(bgpvpn['id'], |
| 349 |
association['id'])['router_association'] |
| 350 |
self.assertEqual(association['id'], rtr_assoc_details['id']) |
| 351 |
|
| 352 |
@decorators.attr(type=['negative']) |
| 353 |
@decorators.idempotent_id('4be1f073-fe57-4858-b7b9-9a189e90b770') |
| 354 |
def test_attach_associated_subnet_to_associated_router(self): |
| 355 |
# Create a first bgpvpn and associate a network with a subnet to it |
| 356 |
bgpvpn_net = self.create_bgpvpn( |
| 357 |
self.bgpvpn_admin_client, |
| 358 |
tenant_id=self.bgpvpn_client.project_id) |
| 359 |
network = self.create_network() |
| 360 |
subnet = self.create_subnet(network) |
| 361 |
self.bgpvpn_client.create_network_association( |
| 362 |
bgpvpn_net['id'], network['id']) |
| 363 |
|
| 364 |
# Create a second bgpvpn and associate a router to it |
| 365 |
bgpvpn_router = self.create_bgpvpn( |
| 366 |
self.bgpvpn_admin_client, |
| 367 |
tenant_id=self.bgpvpn_client.project_id) |
| 368 |
|
| 369 |
router = self.create_router( |
| 370 |
router_name=data_utils.rand_name('test-bgpvpn-')) |
| 371 |
self.bgpvpn_client.create_router_association( |
| 372 |
bgpvpn_router['id'], |
| 373 |
router['id']) |
| 374 |
|
| 375 |
# Attach the subnet of the network to the router |
| 376 |
subnet_data = {'subnet_id': subnet['id']} |
| 377 |
self.assertRaises(exceptions.Conflict, |
| 378 |
self.routers_client.add_router_interface, |
| 379 |
router['id'], |
| 380 |
**subnet_data) |