ChetanGaonker | 901727c | 2016-11-29 14:05:03 -0800 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2016-present Ciena Corporation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain 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, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | import unittest |
| 17 | import os,sys |
ChetanGaonker | 901727c | 2016-11-29 14:05:03 -0800 | [diff] [blame] | 18 | import keystoneclient.v2_0.client as ksclient |
| 19 | import keystoneclient.apiclient.exceptions |
| 20 | import neutronclient.v2_0.client as nclient |
| 21 | import neutronclient.common.exceptions |
| 22 | import novaclient.v1_1.client as novaclient |
| 23 | from multiprocessing import Pool |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 24 | from neutronclient.v2_0 import client as neutron_client |
ChetanGaonker | 901727c | 2016-11-29 14:05:03 -0800 | [diff] [blame] | 25 | from nose.tools import assert_equal |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 26 | from OnosCtrl import OnosCtrl, get_mac |
ChetanGaonker | 901727c | 2016-11-29 14:05:03 -0800 | [diff] [blame] | 27 | from CordLogger import CordLogger |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 28 | import time |
ChetanGaonker | 901727c | 2016-11-29 14:05:03 -0800 | [diff] [blame] | 29 | |
ChetanGaonker | 71fe030 | 2016-12-19 17:45:44 -0800 | [diff] [blame] | 30 | PROTO_NAME_TCP = 'tcp' |
| 31 | PROTO_NAME_ICMP = 'icmp' |
| 32 | IPv4 = 'IPv4' |
| 33 | |
| 34 | OS_USERNAME = 'admin' |
Chetan Gaonker | 0fb91c9 | 2017-02-07 01:52:18 +0000 | [diff] [blame] | 35 | OS_PASSWORD = 'VeryLongKeystoneAdminPassword' |
ChetanGaonker | 71fe030 | 2016-12-19 17:45:44 -0800 | [diff] [blame] | 36 | OS_TENANT = 'admin' |
Chetan Gaonker | 0fb91c9 | 2017-02-07 01:52:18 +0000 | [diff] [blame] | 37 | OS_AUTH_URL = 'https://keystone.cord.lab:5000/v2.0' |
| 38 | OS_SERVICE_ENDPOINT = 'https://keystone.cord.lab:5000/v2.0/' |
Chetan Gaonker | 1f422af | 2017-01-13 21:59:16 +0000 | [diff] [blame] | 39 | VM_BOOT_TIMEOUT = 100 |
| 40 | VM_DELETE_TIMEOUT = 100 |
| 41 | |
ChetanGaonker | 71fe030 | 2016-12-19 17:45:44 -0800 | [diff] [blame] | 42 | |
| 43 | #VM SSH CREDENTIALS |
| 44 | VM_USERNAME = 'ubuntu' |
| 45 | VM_PASSWORD = 'ubuntu' |
| 46 | |
| 47 | TENANT_PREFIX = 'test-' |
| 48 | VM_PREFIX = 'test-' |
| 49 | NETWORK_PREFIX = 'test-' |
| 50 | CIDR_PREFIX = '192.168' |
| 51 | |
ChetanGaonker | 901727c | 2016-11-29 14:05:03 -0800 | [diff] [blame] | 52 | class cordvtn_exchange(CordLogger): |
| 53 | |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 54 | app_cordvtn = 'org.opencord.vtn' |
| 55 | test_path = os.path.dirname(os.path.realpath(__file__)) |
| 56 | cordvtn_dir = os.path.join(test_path, '..', 'setup') |
| 57 | cordvtn_conf_file = os.path.join(test_path, '..', '../cordvtn/network_cfg.json') |
ChetanGaonker | 901727c | 2016-11-29 14:05:03 -0800 | [diff] [blame] | 58 | |
| 59 | @classmethod |
| 60 | def setUpClass(cls): |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 61 | ''' Activate the cordvtn app''' |
ChetanGaonker | 901727c | 2016-11-29 14:05:03 -0800 | [diff] [blame] | 62 | time.sleep(3) |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 63 | cls.onos_ctrl = OnosCtrl(cls.app_cordvtn) |
| 64 | status, _ = cls.onos_ctrl.activate() |
| 65 | assert_equal(status, False) |
| 66 | time.sleep(3) |
| 67 | cls.cordvtn_setup() |
ChetanGaonker | 901727c | 2016-11-29 14:05:03 -0800 | [diff] [blame] | 68 | |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 69 | @classmethod |
| 70 | def tearDownClass(cls): |
ChetanGaonker | 901727c | 2016-11-29 14:05:03 -0800 | [diff] [blame] | 71 | '''Deactivate the cord vtn app''' |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 72 | cls.onos_ctrl.deactivate() |
| 73 | cls.cord_vtn_cleanup() |
ChetanGaonker | 901727c | 2016-11-29 14:05:03 -0800 | [diff] [blame] | 74 | |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 75 | @classmethod |
| 76 | def cordvtn_setup(cls): |
| 77 | pass |
| 78 | |
| 79 | @classmethod |
| 80 | def cord_vtn_cleanup(cls): |
| 81 | ##reset the ONOS port configuration back to default |
| 82 | for config in cls.configs.items(): |
| 83 | OnosCtrl.delete(config) |
| 84 | |
| 85 | @classmethod |
| 86 | def onos_load_config(cls, cordvtn_conf_file): |
| 87 | status, code = OnosCtrl.config(cordvtn_conf_file) |
ChetanGaonker | 901727c | 2016-11-29 14:05:03 -0800 | [diff] [blame] | 88 | if status is False: |
| 89 | log.info('JSON request returned status %d' %code) |
| 90 | assert_equal(status, True) |
| 91 | time.sleep(3) |
| 92 | |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 93 | @classmethod |
| 94 | def get_neutron_credentials(): |
| 95 | n = {} |
| 96 | n['username'] = os.environ['OS_USERNAME'] |
| 97 | n['password'] = os.environ['OS_PASSWORD'] |
| 98 | n['auth_url'] = os.environ['OS_AUTH_URL'] |
| 99 | n['tenant_name'] = os.environ['OS_TENANT_NAME'] |
| 100 | return n |
| 101 | |
| 102 | @classmethod |
ChetanGaonker | 71fe030 | 2016-12-19 17:45:44 -0800 | [diff] [blame] | 103 | def create_net(tenant_id, name, shared="", external=""): |
| 104 | cmd = "neutron net-create %s %s %s --tenant-id=%s"%(name, shared, external, tenant_id) |
| 105 | os.system(cmd) |
| 106 | time.sleep(1) |
| 107 | |
| 108 | @classmethod |
| 109 | def create_subnet(tenant_id, name, subnet, dhcp=""): |
| 110 | cmd = "neutron subnet-create %s %s --name %s %s --tenant-id=%s"%(net, subnet, name, dhcp, tenant_id) |
| 111 | os.system(cmd) |
| 112 | time.sleep(1) |
| 113 | |
| 114 | @classmethod |
| 115 | def del_net( tenant_id, name): |
| 116 | cmd = "neutron net-delete %s --tenant-id=%s"%(name, tenant_id) |
| 117 | os.system(cmd) |
| 118 | time.sleep(1) |
| 119 | |
| 120 | @classmethod |
| 121 | def del_subnet( tenant_id, name): |
| 122 | cmd = "neutron subnet-create %s %s --name %s %s --tenant-id=%s"%(net,subnet,name, dhcp, tenant_id) |
| 123 | os.system(cmd) |
| 124 | time.sleep(1) |
| 125 | |
| 126 | @classmethod |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 127 | def create_net_and_subnet(): |
| 128 | network_name = "Subscriber-1" |
| 129 | |
| 130 | creds = get_neutron_credentials() |
| 131 | neutron = client.Client(**creds) |
| 132 | |
| 133 | body_example = { |
| 134 | "network": |
| 135 | { |
| 136 | "name": network_name, |
| 137 | "admin_state_up":True |
| 138 | } |
| 139 | } |
| 140 | net = neutron.create_network(body=body_example) |
| 141 | net_dict = net['network'] |
| 142 | network_id = net_dict['id'] |
| 143 | print "Network %s created" %network_id |
| 144 | |
| 145 | create_subnet = { |
| 146 | "subnets": [ |
| 147 | { |
| 148 | "cidr":"10.10.0.0/24", |
| 149 | "ip_version":4, |
| 150 | "network_id":network_id |
| 151 | } |
| 152 | ] |
| 153 | } |
| 154 | subnet = neutron.create_subnet(body = create_subnet) |
| 155 | print "Created Subnet %s"%subnet |
| 156 | |
| 157 | @classmethod |
| 158 | def create_network(i): |
| 159 | neutron_credentials = get_neutron_credentials() |
| 160 | neutron = neutron_client.Client(**neutron_credentials) |
| 161 | json = {'network': {'name': 'network-' + str(i), |
| 162 | 'admin_state_up': True}} |
| 163 | while True: |
| 164 | try: |
| 165 | neutron.create_network(body=json) |
| 166 | print '\nnetwork-' + str(i) + ' created' |
| 167 | break |
| 168 | except Exception as e: |
| 169 | print e |
| 170 | continue |
| 171 | |
ChetanGaonker | 901727c | 2016-11-29 14:05:03 -0800 | [diff] [blame] | 172 | def create_tenant(tenant_name): |
| 173 | new_tenant = keystone.tenants.create(tenant_name=tenant_name, |
| 174 | description="CORD Tenant \ |
| 175 | created", |
| 176 | enabled=True) |
| 177 | tenant_id = new_tenant.id |
| 178 | tenant_status = True |
| 179 | user_data = [] |
| 180 | for j in range(2): |
| 181 | j += 1 |
| 182 | user_name = tenant_name + '-user-' + str(j) |
| 183 | user_data.append(create_user(user_name, tenant_id)) |
| 184 | |
| 185 | print " Tenant and User Created" |
| 186 | |
| 187 | tenant_data = {'tenant_name': tenant_name, |
| 188 | 'tenant_id': tenant_id, |
| 189 | 'status': tenant_status} |
| 190 | return tenant_data |
| 191 | |
| 192 | def create_user(user_name, tenant_id): |
| 193 | new_user = keystone.users.create(name=user_name, |
| 194 | password="ubuntu", |
| 195 | tenant_id=tenant_id) |
| 196 | print(' - Created User %s' % user_name) |
| 197 | keystone.roles.add_user_role(new_user, member_role, tenant_id) |
| 198 | if assign_admin: |
| 199 | admin_user = keystone.users.find(name='admin') |
| 200 | admin_role = keystone.roles.find(name='admin') |
| 201 | keystone.roles.add_user_role(admin_user, admin_role, tenant_id) |
| 202 | user_data = {'name': new_user.name, |
| 203 | 'id': new_user.id} |
| 204 | return user_data |
| 205 | |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 206 | def create_port( router_id, network_id): |
| 207 | credentials = get_credentials() |
| 208 | neutron = client.Client(**credentials) |
| 209 | router = neutron.show_router(router_id) |
| 210 | |
| 211 | value = {'port':{ |
| 212 | 'admin_state_up':True, |
| 213 | 'device_id': router_id, |
| 214 | 'name': 'port1', |
| 215 | 'network_id':network_id, |
| 216 | }} |
| 217 | response = neutron.create_port(body=value) |
| 218 | |
ChetanGaonker | 71fe030 | 2016-12-19 17:45:44 -0800 | [diff] [blame] | 219 | def router_create(self, name): |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 220 | external_network = None |
| 221 | for network in self.neutron.list_networks()["networks"]: |
| 222 | if network.get("router:external"): |
| 223 | external_network = network |
| 224 | break |
| 225 | |
| 226 | if not external_network: |
| 227 | raise Exception("Alarm! Can not to find external network") |
| 228 | |
| 229 | gw_info = { |
| 230 | "network_id": external_network["id"], |
| 231 | "enable_snat": True |
| 232 | } |
| 233 | router_info = { |
| 234 | "router": { |
| 235 | "name": name, |
| 236 | "external_gateway_info": gw_info, |
| 237 | "tenant_id": self.tenant_id |
| 238 | } |
| 239 | } |
ChetanGaonker | 71fe030 | 2016-12-19 17:45:44 -0800 | [diff] [blame] | 240 | router = self.neutron.router_create(router_info)['router'] |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 241 | return router |
| 242 | |
ChetanGaonker | 901727c | 2016-11-29 14:05:03 -0800 | [diff] [blame] | 243 | def delete_tenant(tenant_name): |
| 244 | tenant = keystone.tenants.find(name=tenant_name) |
| 245 | for j in range(2): |
| 246 | j += 1 |
| 247 | user_name = tenant_name + '-user-' + str(j) |
| 248 | delete_user(user_name, tenant.id) |
| 249 | tenant.delete() |
| 250 | print(' - Deleted Tenant %s ' % tenant_name) |
| 251 | return True |
| 252 | |
| 253 | def delete_user(user_name, tenant_id): |
| 254 | user = keystone.users.find(name=user_name) |
| 255 | user.delete() |
| 256 | |
| 257 | print(' - Deleted User %s' % user_name) |
| 258 | return True |
| 259 | |
ChetanGaonker | 71fe030 | 2016-12-19 17:45:44 -0800 | [diff] [blame] | 260 | def set_environment(tenants_num=0, networks_per_tenant=1, vms_per_network=2): |
| 261 | octet = 115 |
| 262 | vm_inc = 11 |
| 263 | image = nova_connection.images.get(IMAGE_ID) |
| 264 | flavor = nova_connection.flavors.get(FLAVOR_ID) |
| 265 | |
| 266 | admin_user_id = keystone_connection.users.find(name=OS_USERNAME).id |
| 267 | member_role_id = keystone_connection.roles.find(name='Member').id |
| 268 | for num_tenant in range(1, tenants_num+1): |
| 269 | tenant = keystone_connection.tenants.create('%stenant%s' % (TENANT_PREFIX, num_tenant)) |
| 270 | keystone_connection.roles.add_user_role(admin_user_id, member_role_id, tenant=tenant.id) |
| 271 | for num_network in range(networks_per_tenant): |
| 272 | network_json = {'name': '%snet%s' % (NETWORK_PREFIX, num_tenant*10+num_network), |
| 273 | 'admin_state_up': True, |
| 274 | 'tenant_id': tenant.id} |
| 275 | network = neutron_connection.create_network({'network': network_json}) |
| 276 | subnet_json = {'name': '%ssubnet%s' % (NETWORK_PREFIX, num_tenant*10+num_network), |
| 277 | 'network_id': network['network']['id'], |
| 278 | 'tenant_id': tenant.id, |
| 279 | 'enable_dhcp': True, |
| 280 | 'cidr': '%s.%s.0/24' % (CIDR_PREFIX, octet), 'ip_version': 4} |
| 281 | octet += 1 |
| 282 | subnet = neutron_connection.create_subnet({'subnet': subnet_json}) |
| 283 | router_json = {'name': '%srouter%s' % (NETWORK_PREFIX, num_tenant*10+num_network), |
| 284 | 'tenant_id': tenant.id} |
| 285 | router = neutron_connection.router_create({'router': router_json}) |
| 286 | port = neutron_connection.add_interface_router(router['router']['id'], {'subnet_id': subnet['subnet']['id']}) |
| 287 | for num_vm in range(vms_per_network): |
| 288 | tenant_nova_connection = novacli.Client(OS_USERNAME, OS_PASSWORD, tenant.name, OS_AUTH_URL) |
| 289 | m = tenant_nova_connection.servers.create('%svm%s' % (VM_PREFIX, vm_inc), image, flavor, nics=[{'net-id': network['network']['id']}, {'net-id': MGMT_NET}]) |
| 290 | vm_inc += 1 |
| 291 | |
| 292 | @classmethod |
| 293 | def get_id(tenant_id, name): |
| 294 | cmd = "neutron %s-list --tenant-id=%s"%(objname,sdn_tenant_id) |
| 295 | output = os.system(cmd) |
| 296 | lis = output.split("\n") |
| 297 | for i in lis: |
| 298 | tokens = i.split() |
Chetan Gaonker | 29e4984 | 2017-01-09 22:55:04 +0000 | [diff] [blame] | 299 | if len(tokens)>3 and tokens[3] == name: |
ChetanGaonker | 71fe030 | 2016-12-19 17:45:44 -0800 | [diff] [blame] | 300 | return tokens[1] |
| 301 | return none |
| 302 | |
| 303 | @classmethod |
| 304 | def nova_boot(tenant_id, name, netid=None, portid=None): |
| 305 | if netid: |
Chetan Gaonker | 29e4984 | 2017-01-09 22:55:04 +0000 | [diff] [blame] | 306 | cmd = "nova --os-tenant-id %s boot --flavor 1 --image %s --nic net-id=%s %s"%(tenant_id, vm_image_id,netid,name) |
ChetanGaonker | 71fe030 | 2016-12-19 17:45:44 -0800 | [diff] [blame] | 307 | if portid: |
| 308 | cmd = "nova --os-tenant-is %s boot --flavor 1 --image %s --nic port-id=%s %s"%(tenant_id,vm_image_id,portid,name) |
| 309 | os.system(cmd) |
| 310 | |
| 311 | @classmethod |
| 312 | def port_create(sdn_tenant_id,name, net, fixedip, subnetid): |
| 313 | cmd = "neutron port-create --name %s --fixed-ip subnet_id=%s,ip_address=%s --tenant-id=%s %s" %(name,subnetid,fixedip,sdn_tenant_id,net) |
| 314 | os.system(cmd) |
| 315 | time.sleep(1) |
| 316 | |
| 317 | @classmethod |
| 318 | def nova_wait_boot(sdn_tenant_id,name, state, retries=10): |
| 319 | global errno |
| 320 | cmd = "nova --os-tenant-id %s list" %(sdn_tenant_id) |
| 321 | for i in range(retries): |
| 322 | out = os.system(cmd) |
| 323 | lis = out.split("\n") |
| 324 | for line in lis: |
| 325 | toks = line.split() |
| 326 | if len(toks) >= 5 and toks[3] == name and toks[5] == state: |
| 327 | return |
| 328 | time.sleep(5) |
Chetan Gaonker | 29e4984 | 2017-01-09 22:55:04 +0000 | [diff] [blame] | 329 | errno=1 |
ChetanGaonker | 71fe030 | 2016-12-19 17:45:44 -0800 | [diff] [blame] | 330 | |
| 331 | @classmethod |
| 332 | def port_delete(sdn_tenant_id,name): |
| 333 | cmd = "neutron port-delete %s" %(name) |
| 334 | os.system(cmd) |
| 335 | time.sleep(1) |
| 336 | |
| 337 | @classmethod |
| 338 | def tenant_delete(name): |
| 339 | cmd = "keystone tenant-delete %s"%(name) |
| 340 | os.system(cmd) |
| 341 | time.sleep(1) |
| 342 | |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 343 | @classmethod |
| 344 | def verify_neutron_crud(): |
| 345 | x = os.system("neutron_test.sh") |
| 346 | return x |
ChetanGaonker | 901727c | 2016-11-29 14:05:03 -0800 | [diff] [blame] | 347 | |
Author Name | 91eaeba | 2017-01-05 13:41:45 -0800 | [diff] [blame] | 348 | def list_floatingips( **kwargs): |
| 349 | creds = get_neutron_credentials() |
| 350 | neutron = client.Client(**creds) |
| 351 | return neutron.list_floatingips(**kwargs)['floatingips'] |
| 352 | |
| 353 | def list_security_groups( **kwargs): |
| 354 | creds = get_neutron_credentials() |
| 355 | neutron = client.Client(**creds) |
| 356 | return neutron.list_security_groups(**kwargs)['security_groups'] |
| 357 | |
| 358 | def list_subnets( **kwargs): |
| 359 | creds = get_neutron_credentials() |
| 360 | neutron = client.Client(**creds) |
| 361 | return neutron.list_subnets(**kwargs)['subnets'] |
| 362 | |
| 363 | def list_networks( **kwargs): |
| 364 | creds = get_neutron_credentials() |
| 365 | neutron = client.Client(**creds) |
| 366 | return neutron.list_networks(**kwargs)['networks'] |
| 367 | |
| 368 | def list_ports( **kwargs): |
| 369 | creds = get_neutron_credentials() |
| 370 | neutron = client.Client(**creds) |
| 371 | return neutron.list_ports(**kwargs)['ports'] |
| 372 | |
| 373 | def list_routers( **kwargs): |
| 374 | creds = get_neutron_credentials() |
| 375 | neutron = client.Client(**creds) |
| 376 | return neutron.list_routers(**kwargs)['routers'] |
| 377 | |
| 378 | def update_floatingip( fip, port_id=None): |
| 379 | creds = get_neutron_credentials() |
| 380 | neutron = client.Client(**creds) |
| 381 | neutron.update_floatingip(fip, {"floatingip": |
| 382 | {"port_id": port_id}}) |
| 383 | |
| 384 | def update_subnet( subnet_id, **subnet_params): |
| 385 | creds = get_neutron_credentials() |
| 386 | neutron = client.Client(**creds) |
| 387 | neutron.update_subnet(subnet_id, {'subnet': subnet_params}) |
| 388 | |
| 389 | def update_router( router_id, **router_params): |
| 390 | creds = get_neutron_credentials() |
| 391 | neutron = client.Client(**creds) |
| 392 | neutron.update_router(router_id, {'router': router_params}) |
| 393 | |
| 394 | def router_gateway_set( router_id, external_gateway): |
| 395 | creds = get_neutron_credentials() |
| 396 | neutron = client.Client(**creds) |
| 397 | neutron.update_router( |
| 398 | router_id, {'router': {'external_gateway_info': |
| 399 | {'network_id': external_gateway}}}) |
| 400 | |
| 401 | def router_gateway_clear( router_id): |
| 402 | creds = get_neutron_credentials() |
| 403 | neutron = client.Client(**creds) |
| 404 | neutron.update_router( |
| 405 | router_id, {'router': {'external_gateway_info': None}}) |
| 406 | |
| 407 | def router_add_interface( router_id, subnet_id): |
| 408 | creds = get_neutron_credentials() |
| 409 | neutron = client.Client(**creds) |
| 410 | neutron.add_interface_router(router_id, {'subnet_id': subnet_id}) |
| 411 | |
| 412 | def router_rem_interface( router_id, subnet_id): |
| 413 | creds = get_neutron_credentials() |
| 414 | neutron = client.Client(**creds) |
| 415 | neutron.remove_interface_router( |
| 416 | router_id, {'subnet_id': subnet_id}) |
| 417 | |
| 418 | def create_floatingip( **floatingip_params): |
| 419 | creds = get_neutron_credentials() |
| 420 | neutron = client.Client(**creds) |
| 421 | response = neutron.create_floatingip( |
| 422 | {'floatingip': floatingip_params}) |
| 423 | if 'floatingip' in response and 'id' in response['floatingip']: |
| 424 | return response['floatingip']['id'] |
| 425 | |
Chetan Gaonker | 1f422af | 2017-01-13 21:59:16 +0000 | [diff] [blame] | 426 | def make_iperf_pair(server, client, **kwargs): |
| 427 | ssh = SSHClient() |
| 428 | ssh.set_missing_host_key_policy(MissingHostKeyPolicy()) |
| 429 | |
| 430 | ssh.connect(server, username=VM_USERNAME, password=VM_PASSWORD) |
| 431 | ssh.exec_command('/usr/local/bin/iperf3 -s -D') |
| 432 | |
| 433 | ssh.connect(client, username=VM_USERNAME, password=VM_PASSWORD) |
| 434 | stdin, stdout, stderr = ssh.exec_command('/usr/local/bin/iperf3 -c %s -J' % server) |
| 435 | |
| 436 | rawdata = stdout.read() |
| 437 | data = json.loads(rawdata.translate(None,'\t').translate(None,'\n')) |
| 438 | |
| 439 | return data |
| 440 | |
Chetan Gaonker | 0fb91c9 | 2017-02-07 01:52:18 +0000 | [diff] [blame] | 441 | def connect_ssh(os_ip, private_key_file=None, user='ubuntu'): |
| 442 | key = ssh.RSAKey.from_private_key_file(private_key_file) |
| 443 | client = ssh.SSHClient() |
| 444 | client.set_missing_host_key_policy(ssh.WarningPolicy()) |
| 445 | client.connect(ip, username=user, pkey=key, timeout=5) |
| 446 | return client |
Chetan Gaonker | 1f422af | 2017-01-13 21:59:16 +0000 | [diff] [blame] | 447 | |
Chetan Gaonker | 0fb91c9 | 2017-02-07 01:52:18 +0000 | [diff] [blame] | 448 | def validate_vtn_flows(switch): |
| 449 | egress = 1 |
| 450 | ingress = 2 |
| 451 | egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' } |
| 452 | ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' } |
| 453 | device_id = 'of:{}'.format(get_mac(switch)) |
| 454 | flow_id = flow.findFlow(device_id, IN_PORT = ('port', ingress), |
| 455 | ETH_TYPE = ('ethType','0x800'), IPV4_SRC = ('ip', ingress_map['ip']+'/32'), |
| 456 | IPV4_DST = ('ip', egress_map['ip']+'/32')) |
| 457 | if flow_id: |
| 458 | return True |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 459 | |
| 460 | def test_cordvtn_basic_tenant(self): |
| 461 | onos_load_config() |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 462 | |
ChetanGaonker | 71fe030 | 2016-12-19 17:45:44 -0800 | [diff] [blame] | 463 | tenant_1= create_tenant("CORD_Subscriber_Test_Tenant_1") |
Chetan Gaonker | 0fb91c9 | 2017-02-07 01:52:18 +0000 | [diff] [blame] | 464 | if tenant1 != 0: |
ChetanGaonker | 71fe030 | 2016-12-19 17:45:44 -0800 | [diff] [blame] | 465 | print "Creation of CORD Subscriber Test Tenant 1" |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 466 | |
ChetanGaonker | 71fe030 | 2016-12-19 17:45:44 -0800 | [diff] [blame] | 467 | tenant_2 = create_tenant("CORD_Subscriber_Test_Tenant_2") |
Chetan Gaonker | 0fb91c9 | 2017-02-07 01:52:18 +0000 | [diff] [blame] | 468 | if tenant2 != 0: |
ChetanGaonker | 71fe030 | 2016-12-19 17:45:44 -0800 | [diff] [blame] | 469 | print "Creation of CORD Subscriber Test Tenant 2" |
| 470 | |
| 471 | create_net(tenant_1,"a1") |
| 472 | create_subnet(tenant_1,"a1","as1","10.0.1.0/24") |
| 473 | |
| 474 | create_net(tenant_2,"a2") |
| 475 | create_subnet(tenant_2,"a2","as1","10.0.2.0/24") |
| 476 | |
| 477 | netid_1 = get_id(tenant_1,"net","a1") |
| 478 | netid_2 = get_id(tenant_2,"net","a2") |
| 479 | |
| 480 | nova_boot(tenant_1,"vm1",netid=netid) |
| 481 | nova_boot(tenant_2,"vm1",netid=netid) |
| 482 | |
| 483 | nova_wait_boot(tenant_1,"vm1", "ACTIVE") |
| 484 | nova_wait_boot(tenant_2,"vm1", "ACTIVE") |
| 485 | |
| 486 | router_create(tenant_1,"r1") |
| 487 | router_interface_add(tenant_1,"r1","as1") |
| 488 | router_create(tenant_2,"r1") |
| 489 | router_interface_add(tenant_2,"r1","as1") |
| 490 | |
| 491 | create_net(tenant_1,"x1","","--router:external=True") |
| 492 | create_net(tenant_2,"x1","","--router:external=True") |
| 493 | |
| 494 | router_gateway_set(tenant_1,"r1","x1") |
| 495 | router_gateway_set(tenant_2,"r1","x1") |
| 496 | |
| 497 | subnetid_1 = get_id(tenant_1,"subnet","as1") |
| 498 | subnetid_2 = get_id(tenant_2,"subnet","as1") |
| 499 | port_create(tenant_1,"p1","a1","10.0.1.100",subnetid_1) |
| 500 | port_create(tenant_2,"p1","a1","10.0.1.100",subnetid_2) |
| 501 | |
| 502 | port_id_1 = get_id(tenant_1,"port","p1") |
| 503 | port_id_2 = get_id(tenant_2,"port","p1") |
Chetan Gaonker | 0fb91c9 | 2017-02-07 01:52:18 +0000 | [diff] [blame] | 504 | status = validate_vtn_flows() |
| 505 | assert_equal(status, True) |
ChetanGaonker | 71fe030 | 2016-12-19 17:45:44 -0800 | [diff] [blame] | 506 | |
Chetan Gaonker | 0fb91c9 | 2017-02-07 01:52:18 +0000 | [diff] [blame] | 507 | def test_cordvtn_for_creation_of_network(self): |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 508 | onos_load_config() |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 509 | |
| 510 | ret1 = create_tenant(netA) |
| 511 | if ret1 != 0: |
| 512 | print "Creation of Tenant netA Failed" |
| 513 | |
| 514 | ret2 = create_tenant(netB) |
| 515 | if ret2 != 0: |
| 516 | print "Creation of Tenant netB Failed" |
ChetanGaonker | d65b761 | 2016-12-07 01:01:20 -0800 | [diff] [blame] | 517 | network = {'name': self.network_name, 'admin_state_up': True} |
| 518 | self.neutron.create_network({'network':network}) |
| 519 | log.info("Created network:{0}".format(self.network_name)) |
Chetan Gaonker | 0fb91c9 | 2017-02-07 01:52:18 +0000 | [diff] [blame] | 520 | status = validate_vtn_flows() |
| 521 | assert_equal(status, True) |
ChetanGaonker | d65b761 | 2016-12-07 01:01:20 -0800 | [diff] [blame] | 522 | |
| 523 | def test_cordvtn_to_create_net_work_with_subnet(self): |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 524 | onos_load_config() |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 525 | |
| 526 | ret1 = create_tenant(netA) |
| 527 | if ret1 != 0: |
| 528 | print "Creation of Tenant netA Failed" |
| 529 | |
| 530 | ret2 = create_tenant(netB) |
| 531 | if ret2 != 0: |
| 532 | print "Creation of Tenant netB Failed" |
ChetanGaonker | d65b761 | 2016-12-07 01:01:20 -0800 | [diff] [blame] | 533 | network_name = self.network_name |
| 534 | network = {'name': network_name, 'admin_state_up': True} |
| 535 | network_info = self.neutron.create_network({'network':network}) |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 536 | network_id = network_info['network']['id'] |
ChetanGaonker | d65b761 | 2016-12-07 01:01:20 -0800 | [diff] [blame] | 537 | |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 538 | log.info("Created network:{0}".format(network_id)) |
ChetanGaonker | d65b761 | 2016-12-07 01:01:20 -0800 | [diff] [blame] | 539 | self.network_ids.append(network_id) |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 540 | subnet_count = 1 |
| 541 | for cidr in self.subnet_cidrs: |
ChetanGaonker | d65b761 | 2016-12-07 01:01:20 -0800 | [diff] [blame] | 542 | gateway_ip = str(list(cidr)[1]) |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 543 | subnet = {"network_id": network_id, "ip_version":4, |
| 544 | "cidr":str(cidr), "enable_dhcp":True, |
| 545 | "host_routes":[{"destination":"0.0.0.0/0", "nexthop":gateway_ip}] |
| 546 | } |
ChetanGaonker | d65b761 | 2016-12-07 01:01:20 -0800 | [diff] [blame] | 547 | subnet = {"name":"subnet-"+str(subnet_count), "network_id": network_id, "ip_version":4, "cidr":str(cidr), "enable_dhcp":True} |
| 548 | print subnet |
| 549 | self.neutron.create_subnet({'subnet':subnet}) |
| 550 | log.info("Created subnet:{0}".format(str(cidr))) |
| 551 | if not self.number_of_subnet - 1: |
| 552 | break |
| 553 | self.number_of_subnet -= 1 |
| 554 | subnet_count += 1 |
Chetan Gaonker | 0fb91c9 | 2017-02-07 01:52:18 +0000 | [diff] [blame] | 555 | status = validate_vtn_flows() |
| 556 | assert_equal(status, True) |
ChetanGaonker | d65b761 | 2016-12-07 01:01:20 -0800 | [diff] [blame] | 557 | |
| 558 | def test_cordvtn_subnet_limit(self): |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 559 | onos_load_config() |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 560 | |
| 561 | ret1 = create_tenant(netA) |
| 562 | if ret1 != 0: |
| 563 | print "Creation of Tenant netA Failed" |
| 564 | |
| 565 | ret2 = create_tenant(netB) |
| 566 | if ret2 != 0: |
| 567 | print "Creation of Tenant netB Failed" |
ChetanGaonker | d65b761 | 2016-12-07 01:01:20 -0800 | [diff] [blame] | 568 | network_name = uuid.uuid4().get_hex() |
| 569 | network = {'name': network_name, 'admin_state_up': True} |
| 570 | network_info = self.neutron.create_network({'network':network}) |
| 571 | log.info("Created network:{0}".format(network_name)) |
| 572 | network_id = network_info['network']['id'] |
| 573 | self.network_ids.append(network_id) |
| 574 | subnet_cidrs = ['11.2.2.0/29', '11.2.2.8/29'] |
| 575 | for cidr in subnet_cidrs: |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 576 | subnet = {"network_id": network_id, "ip_version":4, "cidr": cidr} |
| 577 | subnet_info = self.neutron.create_subnet({'subnet':subnet}) |
| 578 | subnet_id = subnet_info['subnet']['id'] |
| 579 | log.info("Created subnet:{0}".format(cidr)) |
ChetanGaonker | d65b761 | 2016-12-07 01:01:20 -0800 | [diff] [blame] | 580 | while True: |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 581 | port = {"network_id": network_id, "admin_state_up": True} |
| 582 | port_info = self.neutron.create_port({'port':port}) |
| 583 | port_id = port_info['port']['id'] |
| 584 | self.port_ids.append(port_id) |
| 585 | log.info("Created Port:{0}".format(port_info['port']['id'])) |
| 586 | if not self.quota_limit: |
ChetanGaonker | d65b761 | 2016-12-07 01:01:20 -0800 | [diff] [blame] | 587 | break |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 588 | self.quota_limit -= 1 |
Chetan Gaonker | 0fb91c9 | 2017-02-07 01:52:18 +0000 | [diff] [blame] | 589 | status = validate_vtn_flows() |
| 590 | assert_equal(status, True) |
ChetanGaonker | d65b761 | 2016-12-07 01:01:20 -0800 | [diff] [blame] | 591 | |
| 592 | def test_cordvtn_floatingip_limit(self): |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 593 | onos_load_config() |
ChetanGaonker | d65b761 | 2016-12-07 01:01:20 -0800 | [diff] [blame] | 594 | |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 595 | ret1 = create_tenant(netA) |
| 596 | if ret1 != 0: |
| 597 | print "Creation of Tenant netA Failed" |
| 598 | |
| 599 | ret2 = create_tenant(netB) |
| 600 | if ret2 != 0: |
| 601 | print "Creation of Tenant netB Failed" |
| 602 | while True: |
| 603 | floatingip = {"floating_network_id": self.floating_nw_id} |
| 604 | fip_info = self.neutron.create_floatingip({'floatingip':floatingip}) |
| 605 | fip_id = fip_info['floatingip']['id'] |
| 606 | log.info("Created Floating IP:{0}".format(fip_id)) |
| 607 | self.fip_ids.append(fip_id) |
| 608 | if not self.quota_limit: |
| 609 | break |
| 610 | self.quota_limit -= 1 |
Chetan Gaonker | 0fb91c9 | 2017-02-07 01:52:18 +0000 | [diff] [blame] | 611 | status = validate_vtn_flows() |
| 612 | assert_equal(status, True) |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 613 | |
Chetan Gaonker | 0fb91c9 | 2017-02-07 01:52:18 +0000 | [diff] [blame] | 614 | def test_cordvtn_for_10_neutron_networks(self): |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 615 | onos_load_config() |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 616 | |
| 617 | ret1 = create_tenant(netA) |
| 618 | if ret1 != 0: |
| 619 | print "Creation of Tenant netA Failed" |
| 620 | |
| 621 | ret2 = create_tenant(netB) |
| 622 | if ret2 != 0: |
| 623 | print "Creation of Tenant netB Failed" |
| 624 | pool = Pool(processes=10) |
| 625 | ret = os.system("neutron quote-update --network 15") |
| 626 | if ret1 != 0: |
| 627 | print "Neutron network install failed" |
| 628 | for i in range(1, 11): |
| 629 | pool.apply_asynch(create_network, (i, )) |
| 630 | |
| 631 | pool.close() |
| 632 | pool.join() |
Chetan Gaonker | 0fb91c9 | 2017-02-07 01:52:18 +0000 | [diff] [blame] | 633 | status = validate_vtn_flows() |
| 634 | assert_equal(status, True) |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 635 | |
Chetan Gaonker | 0fb91c9 | 2017-02-07 01:52:18 +0000 | [diff] [blame] | 636 | def test_cordvtn_for_100_neutron_networks(self): |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 637 | onos_load_config() |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 638 | |
| 639 | ret1 = create_tenant(netA) |
| 640 | if ret1 != 0: |
| 641 | print "Creation of Tenant netA Failed" |
| 642 | |
| 643 | ret2 = create_tenant(netB) |
| 644 | if ret2 != 0: |
| 645 | print "Creation of Tenant netB Failed" |
| 646 | pool = Pool(processes=10) |
| 647 | |
| 648 | ret = os.system("neutron quote-update --network 105") |
| 649 | if ret1 != 0: |
| 650 | print "Neutron network install failed" |
| 651 | for i in range(1, 101): |
| 652 | pool.apply_asynch(create_network, (i, )) |
| 653 | |
| 654 | pool.close() |
| 655 | pool.join() |
Chetan Gaonker | 0fb91c9 | 2017-02-07 01:52:18 +0000 | [diff] [blame] | 656 | status = validate_vtn_flows() |
| 657 | assert_equal(status, True) |
| 658 | |
| 659 | def test_cordvtn_nodes(self): |
| 660 | pass |
| 661 | |
| 662 | def test_cordvtn_networks(self): |
| 663 | pass |
| 664 | |
| 665 | def test_cordvtn_for_range_of_networks(self): |
| 666 | pass |
| 667 | |
| 668 | def test_cordvtn_node_check(self): |
| 669 | pass |
| 670 | |
| 671 | def test_cordvtn_init(self): |
| 672 | pass |
| 673 | |
| 674 | def test_cordvtn_ports(self): |
| 675 | pass |
| 676 | |
| 677 | def test_cordvtn_synching_neutron_states(self): |
| 678 | pass |
| 679 | |
| 680 | def test_cordvtn_synching_xos_states(self): |
| 681 | pass |
| 682 | |
| 683 | def test_cordvtn_config_on_restart(self): |
| 684 | pass |
| 685 | |
| 686 | def test_cordvtn_arp_proxy(self): |
| 687 | pass |
| 688 | |
| 689 | def test_cordvtn_gateway(self): |
| 690 | pass |
| 691 | |
| 692 | def test_cordvtn_openstack_access(self): |
| 693 | pass |
| 694 | |
| 695 | def test_cordvtn_xos_access(self): |
| 696 | pass |
| 697 | |
| 698 | def test_cordvtn_ssh_access(self): |
| 699 | pass |
| 700 | |
| 701 | def test_cordvtn_ovsdbport(self): |
| 702 | pass |
| 703 | |
| 704 | def test_cordvtn_local_management_ip(self): |
| 705 | pass |
| 706 | |
| 707 | def test_cordvtn_compute_nodes(self): |
| 708 | pass |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 709 | |
| 710 | def test_cordvtn_service_dependency_for_two_subnets(self): |
| 711 | pass |
| 712 | |
| 713 | def test_cordvtn_service_dependency_for_three_subnets(self): |
| 714 | pass |
| 715 | |
| 716 | def test_cordvtn_service_dependency_for_four_subnets(self): |
| 717 | pass |
| 718 | |
| 719 | def test_cordvtn_service_dependency_for_five_subnets(self): |
| 720 | pass |
| 721 | |
| 722 | def test_cordvtn_for_biderectional_connections(self): |
| 723 | pass |
| 724 | |
| 725 | def test_cordvtn_authentication_from_openstack(self): |
| 726 | pass |
| 727 | |
| 728 | def test_cordvtn_with_gateway(self): |
| 729 | pass |
| 730 | |
| 731 | def test_cordvtn_without_gateway(self): |
| 732 | pass |
| 733 | |
| 734 | def test_cordvtn_for_service_instance(self): |
| 735 | pass |
| 736 | |
| 737 | def test_cordvtn_for_instance_to_network(self): |
| 738 | pass |
| 739 | |
| 740 | def test_cordvtn_for_network_to_instance(self): |
| 741 | pass |
| 742 | |
| 743 | def test_cordvtn_for_instance_to_instance(self): |
| 744 | pass |
| 745 | |
| 746 | def test_cordvtn_for_network_to_network(self): |
| 747 | pass |
| 748 | |
| 749 | def test_cordvtn_without_neutron_ml2_plugin(self): |
| 750 | pass |
| 751 | |
| 752 | def test_cordvtn_with_neutron_ml2_plugin(self): |
| 753 | pass |
| 754 | |
| 755 | def test_cordvtn_service_network_type_private(self): |
| 756 | pass |
| 757 | |
| 758 | def test_cordvtn_service_network_type_management_local(self): |
| 759 | pass |
| 760 | |
| 761 | def test_cordvtn_service_network_type_management_host(self): |
| 762 | pass |
| 763 | |
| 764 | def test_cordvtn_service_network_type_vsg(self): |
| 765 | pass |
| 766 | |
| 767 | def test_cordvtn_service_network_type_access_agent(self): |
ChetanGaonker | 901727c | 2016-11-29 14:05:03 -0800 | [diff] [blame] | 768 | pass |
| 769 | |
| 770 | def test_cordvtn_mgmt_network(self): |
| 771 | pass |
| 772 | |
| 773 | def test_cordvtn_data_network(self): |
| 774 | pass |
| 775 | |
| 776 | def test_cordvtn_public_network(self): |
| 777 | pass |
| 778 | |
| 779 | def test_cordvtn_in_same_network(self): |
| 780 | pass |
| 781 | |
| 782 | def test_cordvtn_local_mgmt_network(self): |
| 783 | pass |
| 784 | |
| 785 | def test_cordvtn_service_dependency(self): |
| 786 | pass |
| 787 | |
| 788 | def test_cordvtn_service_dependency_with_xos(self): |
| 789 | pass |
| 790 | |
| 791 | def test_cordvtn_vsg_xos_service_profile(self): |
| 792 | pass |
| 793 | |
| 794 | def test_cordvtn_access_agent(self): |
| 795 | pass |
| 796 | |
| 797 | def test_cordvtn_network_creation(self): |
| 798 | pass |
| 799 | |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 800 | def test_cordvtn_network_deletion(self): |
| 801 | pass |
| 802 | |
ChetanGaonker | 901727c | 2016-11-29 14:05:03 -0800 | [diff] [blame] | 803 | def test_cordvtn_removing_service_network(self): |
| 804 | pass |
| 805 | |
| 806 | def test_cordvtn_web_application(self): |
| 807 | pass |
| 808 | |
| 809 | def test_cordvtn_service_port(self): |
| 810 | pass |
ChetanGaonker | aaea6b6 | 2016-12-16 17:06:39 -0800 | [diff] [blame] | 811 | |
| 812 | def test_cordvtn_inetgration_bridge(self): |
| 813 | pass |
| 814 | |