blob: 7e00706e31b27479d8ee2a589652a6ea5877483a [file] [log] [blame]
ChetanGaonker901727c2016-11-29 14:05:03 -08001#
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#
16import unittest
17import os,sys
ChetanGaonker901727c2016-11-29 14:05:03 -080018import keystoneclient.v2_0.client as ksclient
19import keystoneclient.apiclient.exceptions
20import neutronclient.v2_0.client as nclient
21import neutronclient.common.exceptions
22import novaclient.v1_1.client as novaclient
23from multiprocessing import Pool
ChetanGaonkeraaea6b62016-12-16 17:06:39 -080024from neutronclient.v2_0 import client as neutron_client
ChetanGaonker901727c2016-11-29 14:05:03 -080025from nose.tools import assert_equal
ChetanGaonkeraaea6b62016-12-16 17:06:39 -080026from OnosCtrl import OnosCtrl, get_mac
ChetanGaonker901727c2016-11-29 14:05:03 -080027from CordLogger import CordLogger
ChetanGaonkeraaea6b62016-12-16 17:06:39 -080028import time
Chetan Gaonker3c8ae682017-02-18 00:50:45 +000029import py_compile
ChetanGaonker901727c2016-11-29 14:05:03 -080030
ChetanGaonker71fe0302016-12-19 17:45:44 -080031PROTO_NAME_TCP = 'tcp'
32PROTO_NAME_ICMP = 'icmp'
33IPv4 = 'IPv4'
34
35OS_USERNAME = 'admin'
Chetan Gaonker0fb91c92017-02-07 01:52:18 +000036OS_PASSWORD = 'VeryLongKeystoneAdminPassword'
ChetanGaonker71fe0302016-12-19 17:45:44 -080037OS_TENANT = 'admin'
Chetan Gaonker0fb91c92017-02-07 01:52:18 +000038OS_AUTH_URL = 'https://keystone.cord.lab:5000/v2.0'
39OS_SERVICE_ENDPOINT = 'https://keystone.cord.lab:5000/v2.0/'
Chetan Gaonker1f422af2017-01-13 21:59:16 +000040VM_BOOT_TIMEOUT = 100
41VM_DELETE_TIMEOUT = 100
42
ChetanGaonker71fe0302016-12-19 17:45:44 -080043
44#VM SSH CREDENTIALS
45VM_USERNAME = 'ubuntu'
46VM_PASSWORD = 'ubuntu'
47
48TENANT_PREFIX = 'test-'
49VM_PREFIX = 'test-'
50NETWORK_PREFIX = 'test-'
51CIDR_PREFIX = '192.168'
52
ChetanGaonker901727c2016-11-29 14:05:03 -080053class cordvtn_exchange(CordLogger):
54
ChetanGaonkeraaea6b62016-12-16 17:06:39 -080055 app_cordvtn = 'org.opencord.vtn'
56 test_path = os.path.dirname(os.path.realpath(__file__))
57 cordvtn_dir = os.path.join(test_path, '..', 'setup')
58 cordvtn_conf_file = os.path.join(test_path, '..', '../cordvtn/network_cfg.json')
ChetanGaonker901727c2016-11-29 14:05:03 -080059
60 @classmethod
61 def setUpClass(cls):
ChetanGaonkeraaea6b62016-12-16 17:06:39 -080062 ''' Activate the cordvtn app'''
ChetanGaonker901727c2016-11-29 14:05:03 -080063 time.sleep(3)
ChetanGaonkeraaea6b62016-12-16 17:06:39 -080064 cls.onos_ctrl = OnosCtrl(cls.app_cordvtn)
65 status, _ = cls.onos_ctrl.activate()
66 assert_equal(status, False)
67 time.sleep(3)
68 cls.cordvtn_setup()
ChetanGaonker901727c2016-11-29 14:05:03 -080069
ChetanGaonkeraaea6b62016-12-16 17:06:39 -080070 @classmethod
71 def tearDownClass(cls):
ChetanGaonker901727c2016-11-29 14:05:03 -080072 '''Deactivate the cord vtn app'''
ChetanGaonkeraaea6b62016-12-16 17:06:39 -080073 cls.onos_ctrl.deactivate()
74 cls.cord_vtn_cleanup()
ChetanGaonker901727c2016-11-29 14:05:03 -080075
ChetanGaonkeraaea6b62016-12-16 17:06:39 -080076 @classmethod
77 def cordvtn_setup(cls):
78 pass
79
80 @classmethod
81 def cord_vtn_cleanup(cls):
82 ##reset the ONOS port configuration back to default
83 for config in cls.configs.items():
84 OnosCtrl.delete(config)
85
86 @classmethod
87 def onos_load_config(cls, cordvtn_conf_file):
88 status, code = OnosCtrl.config(cordvtn_conf_file)
ChetanGaonker901727c2016-11-29 14:05:03 -080089 if status is False:
90 log.info('JSON request returned status %d' %code)
91 assert_equal(status, True)
92 time.sleep(3)
93
ChetanGaonkeraaea6b62016-12-16 17:06:39 -080094 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
ChetanGaonker71fe0302016-12-19 17:45:44 -0800102 def create_net(tenant_id, name, shared="", external=""):
103 cmd = "neutron net-create %s %s %s --tenant-id=%s"%(name, shared, external, tenant_id)
104 os.system(cmd)
105 time.sleep(1)
106
ChetanGaonker71fe0302016-12-19 17:45:44 -0800107 def create_subnet(tenant_id, name, subnet, dhcp=""):
108 cmd = "neutron subnet-create %s %s --name %s %s --tenant-id=%s"%(net, subnet, name, dhcp, tenant_id)
109 os.system(cmd)
110 time.sleep(1)
111
ChetanGaonker71fe0302016-12-19 17:45:44 -0800112 def del_net( tenant_id, name):
113 cmd = "neutron net-delete %s --tenant-id=%s"%(name, tenant_id)
114 os.system(cmd)
115 time.sleep(1)
116
ChetanGaonker71fe0302016-12-19 17:45:44 -0800117 def del_subnet( tenant_id, name):
118 cmd = "neutron subnet-create %s %s --name %s %s --tenant-id=%s"%(net,subnet,name, dhcp, tenant_id)
119 os.system(cmd)
120 time.sleep(1)
121
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800122 def create_network(i):
123 neutron_credentials = get_neutron_credentials()
124 neutron = neutron_client.Client(**neutron_credentials)
125 json = {'network': {'name': 'network-' + str(i),
126 'admin_state_up': True}}
127 while True:
128 try:
Chetan Gaonker3c8ae682017-02-18 00:50:45 +0000129 net = neutron.create_network(body=json)
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800130 print '\nnetwork-' + str(i) + ' created'
Chetan Gaonker3c8ae682017-02-18 00:50:45 +0000131 return net
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800132 except Exception as e:
133 print e
134 continue
135
ChetanGaonker901727c2016-11-29 14:05:03 -0800136 def create_tenant(tenant_name):
137 new_tenant = keystone.tenants.create(tenant_name=tenant_name,
138 description="CORD Tenant \
139 created",
140 enabled=True)
141 tenant_id = new_tenant.id
142 tenant_status = True
143 user_data = []
144 for j in range(2):
145 j += 1
146 user_name = tenant_name + '-user-' + str(j)
147 user_data.append(create_user(user_name, tenant_id))
148
149 print " Tenant and User Created"
150
151 tenant_data = {'tenant_name': tenant_name,
152 'tenant_id': tenant_id,
153 'status': tenant_status}
154 return tenant_data
155
156 def create_user(user_name, tenant_id):
157 new_user = keystone.users.create(name=user_name,
158 password="ubuntu",
159 tenant_id=tenant_id)
160 print(' - Created User %s' % user_name)
161 keystone.roles.add_user_role(new_user, member_role, tenant_id)
162 if assign_admin:
163 admin_user = keystone.users.find(name='admin')
164 admin_role = keystone.roles.find(name='admin')
165 keystone.roles.add_user_role(admin_user, admin_role, tenant_id)
166 user_data = {'name': new_user.name,
167 'id': new_user.id}
168 return user_data
169
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800170 def create_port( router_id, network_id):
171 credentials = get_credentials()
172 neutron = client.Client(**credentials)
173 router = neutron.show_router(router_id)
174
175 value = {'port':{
176 'admin_state_up':True,
177 'device_id': router_id,
178 'name': 'port1',
179 'network_id':network_id,
180 }}
181 response = neutron.create_port(body=value)
182
ChetanGaonker71fe0302016-12-19 17:45:44 -0800183 def router_create(self, name):
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800184 external_network = None
185 for network in self.neutron.list_networks()["networks"]:
186 if network.get("router:external"):
187 external_network = network
188 break
189
190 if not external_network:
191 raise Exception("Alarm! Can not to find external network")
192
193 gw_info = {
194 "network_id": external_network["id"],
195 "enable_snat": True
196 }
197 router_info = {
198 "router": {
199 "name": name,
200 "external_gateway_info": gw_info,
201 "tenant_id": self.tenant_id
202 }
203 }
ChetanGaonker71fe0302016-12-19 17:45:44 -0800204 router = self.neutron.router_create(router_info)['router']
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800205 return router
206
ChetanGaonker901727c2016-11-29 14:05:03 -0800207 def delete_tenant(tenant_name):
208 tenant = keystone.tenants.find(name=tenant_name)
209 for j in range(2):
210 j += 1
211 user_name = tenant_name + '-user-' + str(j)
212 delete_user(user_name, tenant.id)
213 tenant.delete()
214 print(' - Deleted Tenant %s ' % tenant_name)
215 return True
216
217 def delete_user(user_name, tenant_id):
218 user = keystone.users.find(name=user_name)
219 user.delete()
220
221 print(' - Deleted User %s' % user_name)
222 return True
223
ChetanGaonker71fe0302016-12-19 17:45:44 -0800224 def set_environment(tenants_num=0, networks_per_tenant=1, vms_per_network=2):
225 octet = 115
226 vm_inc = 11
227 image = nova_connection.images.get(IMAGE_ID)
228 flavor = nova_connection.flavors.get(FLAVOR_ID)
229
230 admin_user_id = keystone_connection.users.find(name=OS_USERNAME).id
231 member_role_id = keystone_connection.roles.find(name='Member').id
232 for num_tenant in range(1, tenants_num+1):
233 tenant = keystone_connection.tenants.create('%stenant%s' % (TENANT_PREFIX, num_tenant))
234 keystone_connection.roles.add_user_role(admin_user_id, member_role_id, tenant=tenant.id)
235 for num_network in range(networks_per_tenant):
236 network_json = {'name': '%snet%s' % (NETWORK_PREFIX, num_tenant*10+num_network),
237 'admin_state_up': True,
238 'tenant_id': tenant.id}
239 network = neutron_connection.create_network({'network': network_json})
240 subnet_json = {'name': '%ssubnet%s' % (NETWORK_PREFIX, num_tenant*10+num_network),
241 'network_id': network['network']['id'],
242 'tenant_id': tenant.id,
243 'enable_dhcp': True,
244 'cidr': '%s.%s.0/24' % (CIDR_PREFIX, octet), 'ip_version': 4}
245 octet += 1
246 subnet = neutron_connection.create_subnet({'subnet': subnet_json})
247 router_json = {'name': '%srouter%s' % (NETWORK_PREFIX, num_tenant*10+num_network),
248 'tenant_id': tenant.id}
249 router = neutron_connection.router_create({'router': router_json})
250 port = neutron_connection.add_interface_router(router['router']['id'], {'subnet_id': subnet['subnet']['id']})
251 for num_vm in range(vms_per_network):
252 tenant_nova_connection = novacli.Client(OS_USERNAME, OS_PASSWORD, tenant.name, OS_AUTH_URL)
253 m = tenant_nova_connection.servers.create('%svm%s' % (VM_PREFIX, vm_inc), image, flavor, nics=[{'net-id': network['network']['id']}, {'net-id': MGMT_NET}])
254 vm_inc += 1
255
ChetanGaonker71fe0302016-12-19 17:45:44 -0800256 def get_id(tenant_id, name):
257 cmd = "neutron %s-list --tenant-id=%s"%(objname,sdn_tenant_id)
258 output = os.system(cmd)
259 lis = output.split("\n")
260 for i in lis:
261 tokens = i.split()
Chetan Gaonker29e49842017-01-09 22:55:04 +0000262 if len(tokens)>3 and tokens[3] == name:
ChetanGaonker71fe0302016-12-19 17:45:44 -0800263 return tokens[1]
264 return none
265
ChetanGaonker71fe0302016-12-19 17:45:44 -0800266 def nova_boot(tenant_id, name, netid=None, portid=None):
267 if netid:
Chetan Gaonker29e49842017-01-09 22:55:04 +0000268 cmd = "nova --os-tenant-id %s boot --flavor 1 --image %s --nic net-id=%s %s"%(tenant_id, vm_image_id,netid,name)
ChetanGaonker71fe0302016-12-19 17:45:44 -0800269 if portid:
270 cmd = "nova --os-tenant-is %s boot --flavor 1 --image %s --nic port-id=%s %s"%(tenant_id,vm_image_id,portid,name)
271 os.system(cmd)
272
ChetanGaonker71fe0302016-12-19 17:45:44 -0800273 def port_create(sdn_tenant_id,name, net, fixedip, subnetid):
274 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)
275 os.system(cmd)
276 time.sleep(1)
277
ChetanGaonker71fe0302016-12-19 17:45:44 -0800278 def nova_wait_boot(sdn_tenant_id,name, state, retries=10):
279 global errno
280 cmd = "nova --os-tenant-id %s list" %(sdn_tenant_id)
281 for i in range(retries):
282 out = os.system(cmd)
283 lis = out.split("\n")
284 for line in lis:
285 toks = line.split()
286 if len(toks) >= 5 and toks[3] == name and toks[5] == state:
287 return
288 time.sleep(5)
Chetan Gaonker29e49842017-01-09 22:55:04 +0000289 errno=1
ChetanGaonker71fe0302016-12-19 17:45:44 -0800290
ChetanGaonker71fe0302016-12-19 17:45:44 -0800291 def port_delete(sdn_tenant_id,name):
292 cmd = "neutron port-delete %s" %(name)
293 os.system(cmd)
294 time.sleep(1)
295
ChetanGaonker71fe0302016-12-19 17:45:44 -0800296 def tenant_delete(name):
297 cmd = "keystone tenant-delete %s"%(name)
298 os.system(cmd)
299 time.sleep(1)
300
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800301 def verify_neutron_crud():
302 x = os.system("neutron_test.sh")
303 return x
ChetanGaonker901727c2016-11-29 14:05:03 -0800304
Author Name91eaeba2017-01-05 13:41:45 -0800305 def list_floatingips( **kwargs):
306 creds = get_neutron_credentials()
307 neutron = client.Client(**creds)
308 return neutron.list_floatingips(**kwargs)['floatingips']
309
310 def list_security_groups( **kwargs):
311 creds = get_neutron_credentials()
312 neutron = client.Client(**creds)
313 return neutron.list_security_groups(**kwargs)['security_groups']
314
315 def list_subnets( **kwargs):
316 creds = get_neutron_credentials()
317 neutron = client.Client(**creds)
318 return neutron.list_subnets(**kwargs)['subnets']
319
320 def list_networks( **kwargs):
321 creds = get_neutron_credentials()
322 neutron = client.Client(**creds)
323 return neutron.list_networks(**kwargs)['networks']
324
325 def list_ports( **kwargs):
326 creds = get_neutron_credentials()
327 neutron = client.Client(**creds)
328 return neutron.list_ports(**kwargs)['ports']
329
330 def list_routers( **kwargs):
331 creds = get_neutron_credentials()
332 neutron = client.Client(**creds)
333 return neutron.list_routers(**kwargs)['routers']
334
335 def update_floatingip( fip, port_id=None):
336 creds = get_neutron_credentials()
337 neutron = client.Client(**creds)
338 neutron.update_floatingip(fip, {"floatingip":
339 {"port_id": port_id}})
340
341 def update_subnet( subnet_id, **subnet_params):
342 creds = get_neutron_credentials()
343 neutron = client.Client(**creds)
344 neutron.update_subnet(subnet_id, {'subnet': subnet_params})
345
346 def update_router( router_id, **router_params):
347 creds = get_neutron_credentials()
348 neutron = client.Client(**creds)
349 neutron.update_router(router_id, {'router': router_params})
350
351 def router_gateway_set( router_id, external_gateway):
352 creds = get_neutron_credentials()
353 neutron = client.Client(**creds)
354 neutron.update_router(
355 router_id, {'router': {'external_gateway_info':
356 {'network_id': external_gateway}}})
357
358 def router_gateway_clear( router_id):
359 creds = get_neutron_credentials()
360 neutron = client.Client(**creds)
361 neutron.update_router(
362 router_id, {'router': {'external_gateway_info': None}})
363
364 def router_add_interface( router_id, subnet_id):
365 creds = get_neutron_credentials()
366 neutron = client.Client(**creds)
367 neutron.add_interface_router(router_id, {'subnet_id': subnet_id})
368
369 def router_rem_interface( router_id, subnet_id):
370 creds = get_neutron_credentials()
371 neutron = client.Client(**creds)
372 neutron.remove_interface_router(
373 router_id, {'subnet_id': subnet_id})
374
375 def create_floatingip( **floatingip_params):
376 creds = get_neutron_credentials()
377 neutron = client.Client(**creds)
378 response = neutron.create_floatingip(
379 {'floatingip': floatingip_params})
380 if 'floatingip' in response and 'id' in response['floatingip']:
381 return response['floatingip']['id']
382
Chetan Gaonker1f422af2017-01-13 21:59:16 +0000383 def make_iperf_pair(server, client, **kwargs):
384 ssh = SSHClient()
385 ssh.set_missing_host_key_policy(MissingHostKeyPolicy())
386
387 ssh.connect(server, username=VM_USERNAME, password=VM_PASSWORD)
388 ssh.exec_command('/usr/local/bin/iperf3 -s -D')
389
390 ssh.connect(client, username=VM_USERNAME, password=VM_PASSWORD)
391 stdin, stdout, stderr = ssh.exec_command('/usr/local/bin/iperf3 -c %s -J' % server)
392
393 rawdata = stdout.read()
394 data = json.loads(rawdata.translate(None,'\t').translate(None,'\n'))
395
396 return data
397
Chetan Gaonker0fb91c92017-02-07 01:52:18 +0000398 def connect_ssh(os_ip, private_key_file=None, user='ubuntu'):
399 key = ssh.RSAKey.from_private_key_file(private_key_file)
400 client = ssh.SSHClient()
401 client.set_missing_host_key_policy(ssh.WarningPolicy())
402 client.connect(ip, username=user, pkey=key, timeout=5)
403 return client
Chetan Gaonker1f422af2017-01-13 21:59:16 +0000404
Chetan Gaonker0fb91c92017-02-07 01:52:18 +0000405 def validate_vtn_flows(switch):
406 egress = 1
407 ingress = 2
408 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' }
409 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' }
410 device_id = 'of:{}'.format(get_mac(switch))
411 flow_id = flow.findFlow(device_id, IN_PORT = ('port', ingress),
412 ETH_TYPE = ('ethType','0x800'), IPV4_SRC = ('ip', ingress_map['ip']+'/32'),
413 IPV4_DST = ('ip', egress_map['ip']+'/32'))
414 if flow_id:
415 return True
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800416
Chetan Gaonker3c8ae682017-02-18 00:50:45 +0000417 def cordvtn_config_load(self, config = None):
418 if config:
419 for k in config.keys():
420 if cordvtn_config.has_key(k):
421 cordvtn_config[k] = config[k]
422 self.onos_load_config(self.cordvtn_dict)
423
424 def search_value(d, pat):
425 for k, v in d.items():
426 if isinstance(v, dict):
427 search_value(v, pat)
428 else:
429 if v == pat:
430 print "Network created successfully"
431 return True
432 else:
433 return False
434
435 def test_cordvtn_neutron_network_sync(self):
436 """
437 Algo:
438 0. Create Test-Net,
439 1. Load cordvtn config, vtn-cfg-1.json to cord-onos
440 2. Run sync command for cordvtn
441 3. Do GET Rest API and validate creation of network
442 4. Validate network synch with created network in cord-onos
443 """
444
445 vtnconfig = {
446 "apps" : {
447 "org.opencord.vtn" : {
448 "cordvtn" : {
449 "controllers" : [ "10.1.0.1:6654" ],
450 "localManagementIp" : "172.27.0.1/24",
451 "nodes" : [ {
452 "bridgeId" : "of:0000525400201852",
453 "dataPlaneIntf" : "fabric",
454 "dataPlaneIp" : "10.6.1.2/24",
455 "hostManagementIp" : "10.1.0.14/24",
456 "hostname" : "cold-flag"
457 } ],
458 "openstack" : {
459 "endpoint" : "https://keystone.cord.lab:5000/v2.0",
460 "password" : "VeryLongKeystoneAdminPassword",
461 "tenant" : "admin",
462 "user" : "admin"
463 },
464 "ovsdbPort" : "6641",
465 "privateGatewayMac" : "00:00:00:00:00:01",
466 "publicGateways" : [ {
467 "gatewayIp" : "10.6.1.193",
468 "gatewayMac" : "02:42:0a:06:01:01"
469 }, {
470 "gatewayIp" : "10.6.1.129",
471 "gatewayMac" : "02:42:0a:06:01:01"
472 } ],
473 "ssh" : {
474 "sshKeyFile" : "/root/node_key",
475 "sshPort" : "22",
476 "sshUser" : "root"
477 },
478 "xos" : {
479 "endpoint" : "http://xos:8888/",
480 "password" : "letmein",
481 "user" : "padmin@vicci.org"
482 }
483 }
484 }
485 }
486 }
487
488 self.onos_load_config(vtnconfig)
489 creds = get_neutron_credentials()
490 neutron = neutronclient.Client(**creds)
491 body_example = {"network":{"name": "Test-Net","admin_state_up":True}}
492 net = neutron.create_network(body=body_example)
493
494 url = "http://172.17.0.2/onos/cordvtn/serviceNetworks"
495 auth = ('karaf','karaf')
496
497 resp = requests.get(url=url, auth=auth)
498 data = json.loads(resp.text)
499
500 result = search_response(data, "Test-Net")
501 assert_equal(result, True)
502
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800503 def test_cordvtn_basic_tenant(self):
504 onos_load_config()
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800505
ChetanGaonker71fe0302016-12-19 17:45:44 -0800506 tenant_1= create_tenant("CORD_Subscriber_Test_Tenant_1")
Chetan Gaonker0fb91c92017-02-07 01:52:18 +0000507 if tenant1 != 0:
ChetanGaonker71fe0302016-12-19 17:45:44 -0800508 print "Creation of CORD Subscriber Test Tenant 1"
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800509
ChetanGaonker71fe0302016-12-19 17:45:44 -0800510 tenant_2 = create_tenant("CORD_Subscriber_Test_Tenant_2")
Chetan Gaonker0fb91c92017-02-07 01:52:18 +0000511 if tenant2 != 0:
ChetanGaonker71fe0302016-12-19 17:45:44 -0800512 print "Creation of CORD Subscriber Test Tenant 2"
513
514 create_net(tenant_1,"a1")
515 create_subnet(tenant_1,"a1","as1","10.0.1.0/24")
516
517 create_net(tenant_2,"a2")
518 create_subnet(tenant_2,"a2","as1","10.0.2.0/24")
519
520 netid_1 = get_id(tenant_1,"net","a1")
521 netid_2 = get_id(tenant_2,"net","a2")
522
523 nova_boot(tenant_1,"vm1",netid=netid)
524 nova_boot(tenant_2,"vm1",netid=netid)
525
526 nova_wait_boot(tenant_1,"vm1", "ACTIVE")
527 nova_wait_boot(tenant_2,"vm1", "ACTIVE")
528
529 router_create(tenant_1,"r1")
530 router_interface_add(tenant_1,"r1","as1")
531 router_create(tenant_2,"r1")
532 router_interface_add(tenant_2,"r1","as1")
533
534 create_net(tenant_1,"x1","","--router:external=True")
535 create_net(tenant_2,"x1","","--router:external=True")
536
537 router_gateway_set(tenant_1,"r1","x1")
538 router_gateway_set(tenant_2,"r1","x1")
539
540 subnetid_1 = get_id(tenant_1,"subnet","as1")
541 subnetid_2 = get_id(tenant_2,"subnet","as1")
542 port_create(tenant_1,"p1","a1","10.0.1.100",subnetid_1)
543 port_create(tenant_2,"p1","a1","10.0.1.100",subnetid_2)
544
545 port_id_1 = get_id(tenant_1,"port","p1")
546 port_id_2 = get_id(tenant_2,"port","p1")
Chetan Gaonker0fb91c92017-02-07 01:52:18 +0000547 status = validate_vtn_flows()
548 assert_equal(status, True)
ChetanGaonker71fe0302016-12-19 17:45:44 -0800549
Chetan Gaonker0fb91c92017-02-07 01:52:18 +0000550 def test_cordvtn_for_creation_of_network(self):
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800551 onos_load_config()
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800552
553 ret1 = create_tenant(netA)
554 if ret1 != 0:
555 print "Creation of Tenant netA Failed"
556
557 ret2 = create_tenant(netB)
558 if ret2 != 0:
559 print "Creation of Tenant netB Failed"
ChetanGaonkerd65b7612016-12-07 01:01:20 -0800560 network = {'name': self.network_name, 'admin_state_up': True}
561 self.neutron.create_network({'network':network})
562 log.info("Created network:{0}".format(self.network_name))
Chetan Gaonker0fb91c92017-02-07 01:52:18 +0000563 status = validate_vtn_flows()
564 assert_equal(status, True)
ChetanGaonkerd65b7612016-12-07 01:01:20 -0800565
566 def test_cordvtn_to_create_net_work_with_subnet(self):
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800567 onos_load_config()
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800568
569 ret1 = create_tenant(netA)
570 if ret1 != 0:
571 print "Creation of Tenant netA Failed"
572
573 ret2 = create_tenant(netB)
574 if ret2 != 0:
575 print "Creation of Tenant netB Failed"
ChetanGaonkerd65b7612016-12-07 01:01:20 -0800576 network_name = self.network_name
577 network = {'name': network_name, 'admin_state_up': True}
578 network_info = self.neutron.create_network({'network':network})
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800579 network_id = network_info['network']['id']
ChetanGaonkerd65b7612016-12-07 01:01:20 -0800580
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800581 log.info("Created network:{0}".format(network_id))
ChetanGaonkerd65b7612016-12-07 01:01:20 -0800582 self.network_ids.append(network_id)
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800583 subnet_count = 1
584 for cidr in self.subnet_cidrs:
ChetanGaonkerd65b7612016-12-07 01:01:20 -0800585 gateway_ip = str(list(cidr)[1])
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800586 subnet = {"network_id": network_id, "ip_version":4,
587 "cidr":str(cidr), "enable_dhcp":True,
588 "host_routes":[{"destination":"0.0.0.0/0", "nexthop":gateway_ip}]
589 }
ChetanGaonkerd65b7612016-12-07 01:01:20 -0800590 subnet = {"name":"subnet-"+str(subnet_count), "network_id": network_id, "ip_version":4, "cidr":str(cidr), "enable_dhcp":True}
591 print subnet
592 self.neutron.create_subnet({'subnet':subnet})
593 log.info("Created subnet:{0}".format(str(cidr)))
594 if not self.number_of_subnet - 1:
595 break
596 self.number_of_subnet -= 1
597 subnet_count += 1
Chetan Gaonker0fb91c92017-02-07 01:52:18 +0000598 status = validate_vtn_flows()
599 assert_equal(status, True)
ChetanGaonkerd65b7612016-12-07 01:01:20 -0800600
601 def test_cordvtn_subnet_limit(self):
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800602 onos_load_config()
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800603
604 ret1 = create_tenant(netA)
605 if ret1 != 0:
606 print "Creation of Tenant netA Failed"
607
608 ret2 = create_tenant(netB)
609 if ret2 != 0:
610 print "Creation of Tenant netB Failed"
ChetanGaonkerd65b7612016-12-07 01:01:20 -0800611 network_name = uuid.uuid4().get_hex()
612 network = {'name': network_name, 'admin_state_up': True}
613 network_info = self.neutron.create_network({'network':network})
614 log.info("Created network:{0}".format(network_name))
615 network_id = network_info['network']['id']
616 self.network_ids.append(network_id)
617 subnet_cidrs = ['11.2.2.0/29', '11.2.2.8/29']
618 for cidr in subnet_cidrs:
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800619 subnet = {"network_id": network_id, "ip_version":4, "cidr": cidr}
620 subnet_info = self.neutron.create_subnet({'subnet':subnet})
621 subnet_id = subnet_info['subnet']['id']
622 log.info("Created subnet:{0}".format(cidr))
ChetanGaonkerd65b7612016-12-07 01:01:20 -0800623 while True:
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800624 port = {"network_id": network_id, "admin_state_up": True}
625 port_info = self.neutron.create_port({'port':port})
626 port_id = port_info['port']['id']
627 self.port_ids.append(port_id)
628 log.info("Created Port:{0}".format(port_info['port']['id']))
629 if not self.quota_limit:
ChetanGaonkerd65b7612016-12-07 01:01:20 -0800630 break
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800631 self.quota_limit -= 1
Chetan Gaonker0fb91c92017-02-07 01:52:18 +0000632 status = validate_vtn_flows()
633 assert_equal(status, True)
ChetanGaonkerd65b7612016-12-07 01:01:20 -0800634
635 def test_cordvtn_floatingip_limit(self):
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800636 onos_load_config()
ChetanGaonkerd65b7612016-12-07 01:01:20 -0800637
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800638 ret1 = create_tenant(netA)
639 if ret1 != 0:
640 print "Creation of Tenant netA Failed"
641
642 ret2 = create_tenant(netB)
643 if ret2 != 0:
644 print "Creation of Tenant netB Failed"
645 while True:
646 floatingip = {"floating_network_id": self.floating_nw_id}
647 fip_info = self.neutron.create_floatingip({'floatingip':floatingip})
648 fip_id = fip_info['floatingip']['id']
649 log.info("Created Floating IP:{0}".format(fip_id))
650 self.fip_ids.append(fip_id)
651 if not self.quota_limit:
652 break
653 self.quota_limit -= 1
Chetan Gaonker0fb91c92017-02-07 01:52:18 +0000654 status = validate_vtn_flows()
655 assert_equal(status, True)
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800656
Chetan Gaonker0fb91c92017-02-07 01:52:18 +0000657 def test_cordvtn_for_10_neutron_networks(self):
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800658 onos_load_config()
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800659
660 ret1 = create_tenant(netA)
661 if ret1 != 0:
662 print "Creation of Tenant netA Failed"
663
664 ret2 = create_tenant(netB)
665 if ret2 != 0:
666 print "Creation of Tenant netB Failed"
667 pool = Pool(processes=10)
668 ret = os.system("neutron quote-update --network 15")
669 if ret1 != 0:
670 print "Neutron network install failed"
671 for i in range(1, 11):
672 pool.apply_asynch(create_network, (i, ))
673
674 pool.close()
675 pool.join()
Chetan Gaonker0fb91c92017-02-07 01:52:18 +0000676 status = validate_vtn_flows()
677 assert_equal(status, True)
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800678
Chetan Gaonker0fb91c92017-02-07 01:52:18 +0000679 def test_cordvtn_for_100_neutron_networks(self):
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800680 onos_load_config()
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800681
682 ret1 = create_tenant(netA)
683 if ret1 != 0:
684 print "Creation of Tenant netA Failed"
685
686 ret2 = create_tenant(netB)
687 if ret2 != 0:
688 print "Creation of Tenant netB Failed"
689 pool = Pool(processes=10)
690
691 ret = os.system("neutron quote-update --network 105")
692 if ret1 != 0:
693 print "Neutron network install failed"
694 for i in range(1, 101):
695 pool.apply_asynch(create_network, (i, ))
696
697 pool.close()
698 pool.join()
Chetan Gaonker0fb91c92017-02-07 01:52:18 +0000699 status = validate_vtn_flows()
700 assert_equal(status, True)
701
702 def test_cordvtn_nodes(self):
703 pass
704
705 def test_cordvtn_networks(self):
706 pass
707
708 def test_cordvtn_for_range_of_networks(self):
709 pass
710
711 def test_cordvtn_node_check(self):
712 pass
713
714 def test_cordvtn_init(self):
715 pass
716
717 def test_cordvtn_ports(self):
718 pass
719
720 def test_cordvtn_synching_neutron_states(self):
721 pass
722
723 def test_cordvtn_synching_xos_states(self):
724 pass
725
726 def test_cordvtn_config_on_restart(self):
727 pass
728
729 def test_cordvtn_arp_proxy(self):
730 pass
731
732 def test_cordvtn_gateway(self):
733 pass
734
735 def test_cordvtn_openstack_access(self):
736 pass
737
738 def test_cordvtn_xos_access(self):
739 pass
740
741 def test_cordvtn_ssh_access(self):
742 pass
743
744 def test_cordvtn_ovsdbport(self):
745 pass
746
747 def test_cordvtn_local_management_ip(self):
748 pass
749
750 def test_cordvtn_compute_nodes(self):
751 pass
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800752
753 def test_cordvtn_service_dependency_for_two_subnets(self):
754 pass
755
756 def test_cordvtn_service_dependency_for_three_subnets(self):
757 pass
758
759 def test_cordvtn_service_dependency_for_four_subnets(self):
760 pass
761
762 def test_cordvtn_service_dependency_for_five_subnets(self):
763 pass
764
765 def test_cordvtn_for_biderectional_connections(self):
766 pass
767
768 def test_cordvtn_authentication_from_openstack(self):
769 pass
770
771 def test_cordvtn_with_gateway(self):
772 pass
773
774 def test_cordvtn_without_gateway(self):
775 pass
776
777 def test_cordvtn_for_service_instance(self):
778 pass
779
780 def test_cordvtn_for_instance_to_network(self):
781 pass
782
783 def test_cordvtn_for_network_to_instance(self):
784 pass
785
786 def test_cordvtn_for_instance_to_instance(self):
787 pass
788
789 def test_cordvtn_for_network_to_network(self):
790 pass
791
792 def test_cordvtn_without_neutron_ml2_plugin(self):
793 pass
794
795 def test_cordvtn_with_neutron_ml2_plugin(self):
796 pass
797
798 def test_cordvtn_service_network_type_private(self):
799 pass
800
801 def test_cordvtn_service_network_type_management_local(self):
802 pass
803
804 def test_cordvtn_service_network_type_management_host(self):
805 pass
806
807 def test_cordvtn_service_network_type_vsg(self):
808 pass
809
810 def test_cordvtn_service_network_type_access_agent(self):
ChetanGaonker901727c2016-11-29 14:05:03 -0800811 pass
812
813 def test_cordvtn_mgmt_network(self):
814 pass
815
816 def test_cordvtn_data_network(self):
817 pass
818
819 def test_cordvtn_public_network(self):
820 pass
821
822 def test_cordvtn_in_same_network(self):
823 pass
824
825 def test_cordvtn_local_mgmt_network(self):
826 pass
827
828 def test_cordvtn_service_dependency(self):
829 pass
830
831 def test_cordvtn_service_dependency_with_xos(self):
832 pass
833
834 def test_cordvtn_vsg_xos_service_profile(self):
835 pass
836
837 def test_cordvtn_access_agent(self):
838 pass
839
840 def test_cordvtn_network_creation(self):
841 pass
842
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800843 def test_cordvtn_network_deletion(self):
844 pass
845
ChetanGaonker901727c2016-11-29 14:05:03 -0800846 def test_cordvtn_removing_service_network(self):
847 pass
848
849 def test_cordvtn_web_application(self):
850 pass
851
852 def test_cordvtn_service_port(self):
853 pass
ChetanGaonkeraaea6b62016-12-16 17:06:39 -0800854
855 def test_cordvtn_inetgration_bridge(self):
856 pass
857