blob: e38a2067d4717c647a81533b14c7862f22231e5d [file] [log] [blame]
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -07001
2# Copyright 2017-present Open Networking Foundation
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
Chetan Gaonkercb122cc2016-05-10 10:58:34 -070017#!/usr/bin/env python
A.R Karthick95d044e2016-06-10 18:44:36 -070018#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070019# Copyright 2016-present Ciena Corporation
20#
21# Licensed under the Apache License, Version 2.0 (the "License");
22# you may not use this file except in compliance with the License.
23# You may obtain a copy of the License at
A.R Karthick95d044e2016-06-10 18:44:36 -070024#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070025# http://www.apache.org/licenses/LICENSE-2.0
A.R Karthick95d044e2016-06-10 18:44:36 -070026#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070027# Unless required by applicable law or agreed to in writing, software
28# distributed under the License is distributed on an "AS IS" BASIS,
29# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30# See the License for the specific language governing permissions and
31# limitations under the License.
32#
Chetan Gaonker93e302d2016-04-05 10:51:07 -070033from argparse import ArgumentParser
A R Karthick14118c62016-07-27 14:54:04 -070034import os,sys,time,socket,errno
ChetanGaonkereadad482016-08-26 01:21:47 -070035import shutil, platform, re
Chetan Gaonker4d842ad2016-04-26 10:04:24 -070036utils_dir = os.path.join( os.path.dirname(os.path.realpath(__file__)), '../utils')
A R Karthick03bd2812017-03-03 17:49:17 -080037cli_dir = os.path.join( os.path.dirname(os.path.realpath(__file__)), '../cli')
Chetan Gaonker7142a342016-04-07 14:53:12 -070038sys.path.append(utils_dir)
A R Karthick03bd2812017-03-03 17:49:17 -080039sys.path.append(cli_dir)
ChetanGaonker68a047f2016-10-12 10:31:48 -070040sys.path.insert(1, '/usr/local/lib/python2.7/dist-packages')
A.R Karthickbe7768c2017-03-17 11:39:41 -070041from CordTestUtils import get_mac
42from OnosCtrl import OnosCtrl
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -070043from OltConfig import OltConfig
A R Karthick946141b2017-01-24 16:37:47 -080044from OnosFlowCtrl import OnosFlowCtrl
A R Karthick1f03e912016-05-18 11:39:22 -070045from threadPool import ThreadPool
Chetan Gaonker3533faa2016-04-25 17:50:14 -070046from CordContainer import *
A R Karthicke99ab5c2016-09-30 13:59:57 -070047from CordTestServer import cord_test_server_start,cord_test_server_stop,cord_test_server_shutdown,CORD_TEST_HOST,CORD_TEST_PORT
A R Karthick07608ef2016-08-23 16:51:19 -070048from TestManifest import TestManifest
A.R Karthick57fa9372017-05-24 12:47:03 -070049from VolthaCtrl import VolthaService
A R Karthick6f2ac6f2017-07-26 12:55:24 -070050try:
51 from docker import APIClient as Client
52except:
53 from docker import Client
ChetanGaonkereadad482016-08-26 01:21:47 -070054from docker.utils import kwargs_from_env
A R Karthickea8bfce2016-10-13 16:32:07 -070055from Xos import XosServiceProfile
A R Karthick07608ef2016-08-23 16:51:19 -070056try:
57 from Fabric import FabricMAAS
58except:
59 FabricMAAS = None
Chetan Gaonker93e302d2016-04-05 10:51:07 -070060
Chetan Gaonker93e302d2016-04-05 10:51:07 -070061class CordTester(Container):
Chetan Gaonker93e302d2016-04-05 10:51:07 -070062 sandbox = '/root/test'
Chetan Gaonker7142a342016-04-07 14:53:12 -070063 sandbox_setup = '/root/test/src/test/setup'
Chetan Gaonker4d842ad2016-04-26 10:04:24 -070064 tester_base = os.path.dirname(os.path.realpath(__file__))
65 tester_paths = os.path.realpath(__file__).split(os.path.sep)
A R Karthickb7e80902016-05-17 09:38:31 -070066 tester_path_index = tester_paths.index('src') - 1
Chetan Gaonker7142a342016-04-07 14:53:12 -070067 sandbox_host = os.path.sep.join(tester_paths[:tester_path_index+1])
Chetan Gaonker93e302d2016-04-05 10:51:07 -070068
69 host_guest_map = ( (sandbox_host, sandbox),
Chetan Gaonker85b7bd52016-04-20 10:29:12 -070070 ('/lib/modules', '/lib/modules'),
71 ('/var/run/docker.sock', '/var/run/docker.sock')
Chetan Gaonker93e302d2016-04-05 10:51:07 -070072 )
73 basename = 'cord-tester'
A R Karthick36cfcef2016-08-18 15:20:07 -070074 switch_on_olt = False
A R Karthickf7a613b2017-02-24 09:36:44 -080075 IMAGE = 'cordtest/nose'
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -070076 ALL_TESTS = ('tls', 'dhcp', 'dhcprelay','igmp', 'subscriber',
77 'cordSubscriber', 'vrouter', 'flows', 'proxyarp', 'acl', 'xos', 'fabric',
Chetan Gaonkerefb55282017-01-27 23:07:41 +000078 'cbench', 'cluster', 'netCondition', 'cordvtn', 'iperf', 'mini', 'vsg')
Chetan Gaonker93e302d2016-04-05 10:51:07 -070079
A R Karthicka013a272016-08-16 16:40:19 -070080 def __init__(self, tests, instance = 0, num_instances = 1, ctlr_ip = None,
A R Karthick07608ef2016-08-23 16:51:19 -070081 name = '', image = IMAGE, prefix = '', tag = 'candidate',
A R Karthick85eb1862017-01-23 16:10:57 -080082 env = None, rm = False, update = False, network = None):
A R Karthick1f03e912016-05-18 11:39:22 -070083 self.tests = tests
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -070084 self.ctlr_ip = ctlr_ip
Chetan Gaonker93e302d2016-04-05 10:51:07 -070085 self.rm = rm
A R Karthicke4660f52017-02-23 12:08:41 -080086 self.name = name or self.get_name(num_instances)
A R Karthick07608ef2016-08-23 16:51:19 -070087 super(CordTester, self).__init__(self.name, image = image, prefix = prefix, tag = tag)
Chetan Gaonker93e302d2016-04-05 10:51:07 -070088 host_config = self.create_host_config(host_guest_map = self.host_guest_map, privileged = True)
89 volumes = []
Chetan Gaonkerb84835f2016-04-19 15:12:10 -070090 for _, g in self.host_guest_map:
Chetan Gaonker93e302d2016-04-05 10:51:07 -070091 volumes.append(g)
Chetan Gaonker85b7bd52016-04-20 10:29:12 -070092 if update is True or not self.img_exists():
A R Karthick07608ef2016-08-23 16:51:19 -070093 self.build_image(self.image_name)
A R Karthicka013a272016-08-16 16:40:19 -070094 self.create = True
95 #check if are trying to run tests on existing container
A R Karthicke4660f52017-02-23 12:08:41 -080096 if not self.exists():
A R Karthicka013a272016-08-16 16:40:19 -070097 ##Remove test container if any
98 self.remove_container(self.name, force=True)
99 else:
100 self.create = False
A R Karthicke4660f52017-02-23 12:08:41 -0800101 self.rm = False
A R Karthick078e63a2016-07-28 13:59:31 -0700102 self.olt = False
A R Karthicke8bd80e2017-08-01 12:36:24 -0700103 self.switch_started = False
A.R Karthick5968e0d2017-05-16 14:50:46 -0700104 olt_config_file = 'olt_config.json'
105 if env is not None:
106 if env.has_key('OLT_CONFIG'):
107 self.olt = True
108 if env.has_key('OLT_CONFIG_FILE'):
109 olt_config_file = os.path.basename(env['OLT_CONFIG_FILE'])
A.R Karthick5968e0d2017-05-16 14:50:46 -0700110 olt_conf_file = os.path.join(self.tester_base, olt_config_file)
A R Karthick078e63a2016-07-28 13:59:31 -0700111 olt_config = OltConfig(olt_conf_file)
112 self.port_map, _ = olt_config.olt_port_map()
A.R Karthick369f89e2017-03-02 15:22:45 -0800113 self.vcpes = olt_config.get_vcpes()
A R Karthick078e63a2016-07-28 13:59:31 -0700114 #Try using the host interface in olt conf to setup the switch
A.R Karthick88e80b92016-12-05 20:23:45 -0800115 self.switches = self.port_map['switches']
A R Karthick1f03e912016-05-18 11:39:22 -0700116 if env is not None:
A.R Karthick88e80b92016-12-05 20:23:45 -0800117 env['TEST_SWITCH'] = self.switches[0]
118 env['TEST_SWITCHES'] = ','.join(self.switches)
A R Karthick1f03e912016-05-18 11:39:22 -0700119 env['TEST_HOST'] = self.name
120 env['TEST_INSTANCE'] = instance
121 env['TEST_INSTANCES'] = num_instances
A R Karthicka013a272016-08-16 16:40:19 -0700122 if self.create:
123 print('Starting test container %s, image %s, tag %s' %(self.name, self.image, self.tag))
124 self.start(rm = False, volumes = volumes, environment = env,
125 host_config = host_config, tty = True)
A R Karthick85eb1862017-01-23 16:10:57 -0800126 if network is not None:
127 Container.connect_to_network(self.name, network)
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700128
A.R Karthicke4631062016-11-03 14:28:19 -0700129 def execute_switch(self, cmd, shell = False):
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700130 if self.olt:
131 return os.system(cmd)
132 return self.execute(cmd, shell = shell)
133
A R Karthick946141b2017-01-24 16:37:47 -0800134 def test_flow(self, switch):
135 if not self.olt:
136 return False
137 egress = 1
138 ingress = 2
139 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1' }
140 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1' }
141 device_id = 'of:{}'.format(get_mac(switch))
A R Karthick973010f2017-02-06 16:41:51 -0800142 ctlr = self.ctlr_ip.split(',')[0]
A R Karthick946141b2017-01-24 16:37:47 -0800143 flow = OnosFlowCtrl(deviceId = device_id,
144 egressPort = egress,
145 ingressPort = ingress,
146 ethType = '0x800',
147 ipSrc = ('IPV4_SRC', ingress_map['ip']+'/32'),
148 ipDst = ('IPV4_DST', egress_map['ip']+'/32'),
A R Karthick973010f2017-02-06 16:41:51 -0800149 controller = ctlr
A R Karthick946141b2017-01-24 16:37:47 -0800150 )
151 result = flow.addFlow()
152 if result != True:
153 return result
154 time.sleep(1)
155 #find and remove the flow
156 flow_id = flow.findFlow(device_id, IN_PORT = ('port', ingress),
157 ETH_TYPE = ('ethType','0x800'), IPV4_SRC = ('ip', ingress_map['ip']+'/32'),
158 IPV4_DST = ('ip', egress_map['ip']+'/32'))
159 result = False
160 if flow_id:
161 result = True
162 flow.removeFlow(device_id, flow_id)
163 return result
164
165 def ctlr_switch_availability(self, switch):
166 '''Test Add and verify flows with IPv4 selectors'''
167 if not self.olt:
168 return False
169 device_id = 'of:{}'.format(get_mac(switch))
A R Karthick973010f2017-02-06 16:41:51 -0800170 ctlr = self.ctlr_ip.split(',')[0]
171 devices = OnosCtrl.get_devices(controller = ctlr)
A R Karthick946141b2017-01-24 16:37:47 -0800172 if devices:
173 device = filter(lambda d: d['id'] == device_id, devices)
A R Karthicke8bd80e2017-08-01 12:36:24 -0700174 if device:
175 return True
A R Karthick946141b2017-01-24 16:37:47 -0800176 return False
177
A R Karthicke8bd80e2017-08-01 12:36:24 -0700178 def start_switch(self, manifest, boot_delay = 2):
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700179 """Start OVS"""
180 ##Determine if OVS has to be started locally or not
181 s_file,s_sandbox = ('of-bridge-local.sh',self.tester_base) if self.olt else ('of-bridge.sh',self.sandbox_setup)
A.R Karthick88e80b92016-12-05 20:23:45 -0800182 ovs_cmd = os.path.join(s_sandbox, s_file)
A R Karthicke8bd80e2017-08-01 12:36:24 -0700183 switches = filter(lambda sw: sw.startswith('br-int'), self.switches)
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700184 if self.olt:
A R Karthick36cfcef2016-08-18 15:20:07 -0700185 if CordTester.switch_on_olt is True:
186 return
187 CordTester.switch_on_olt = True
A R Karthicke8bd80e2017-08-01 12:36:24 -0700188 ovs_cmd += ' {} {}'.format(len(switches), self.ctlr_ip)
189 if manifest.voltha_enable and manifest.voltha_loc and Onos.ssl_key:
190 ovs_cmd += ' {}'.format(manifest.voltha_loc)
191 print('Starting OVS on the host with %d switches for controller: %s' %(len(switches), self.ctlr_ip))
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700192 else:
A.R Karthick88e80b92016-12-05 20:23:45 -0800193 ovs_cmd += ' {}'.format(self.switches[0])
194 print('Starting OVS on test container %s for controller: %s' %(self.name, self.ctlr_ip))
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700195 self.execute_switch(ovs_cmd)
A R Karthick946141b2017-01-24 16:37:47 -0800196 time.sleep(5)
197 ## Wait for the controller to see the switch
A R Karthicke8bd80e2017-08-01 12:36:24 -0700198 for switch in switches:
A.R Karthick88e80b92016-12-05 20:23:45 -0800199 status = 1
200 tries = 0
A R Karthick946141b2017-01-24 16:37:47 -0800201 result = self.ctlr_switch_availability(switch) and self.test_flow(switch)
202 if result == True:
203 status = 0
A.R Karthick88e80b92016-12-05 20:23:45 -0800204 while status != 0 and tries < 500:
205 cmd = 'sudo ovs-ofctl dump-flows {0} | grep \"type=0x8942\"'.format(switch)
206 status = self.execute_switch(cmd, shell = True)
207 tries += 1
A R Karthick946141b2017-01-24 16:37:47 -0800208 if status != 0 and tries > 100:
209 if self.ctlr_switch_availability(switch):
210 status = 0
A.R Karthick88e80b92016-12-05 20:23:45 -0800211 if tries % 10 == 0:
212 print('Waiting for test switch %s to be connected to ONOS controller ...' %switch)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700213
A.R Karthick88e80b92016-12-05 20:23:45 -0800214 if status != 0:
215 print('Test Switch %s not connected to ONOS container.'
216 'Please remove ONOS container and restart the test' %switch)
217 if self.rm:
218 self.kill()
219 sys.exit(1)
220 else:
221 print('Test Switch %s connected to ONOS container.' %switch)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700222
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700223 if boot_delay:
224 time.sleep(boot_delay)
225
A R Karthicke8bd80e2017-08-01 12:36:24 -0700226 self.switch_started = True
227
A.R Karthick369f89e2017-03-02 15:22:45 -0800228 def setup_vcpes(self, port_num = 0):
229 res = 0
230 for vcpe in self.vcpes:
231 port, s_tag, c_tag = vcpe['port'], vcpe['s_tag'], vcpe['c_tag']
232 if os.access('/sys/class/net/{}'.format(port), os.F_OK):
233 guest_port = 'vcpe{}'.format(port_num)
234 port_num += 1
A.R Karthick5968e0d2017-05-16 14:50:46 -0700235 print('Provisioning guest port %s for %s with host port: %s, s_tag: %d, c_tag: %d\n'
236 %(guest_port, self.name, port, s_tag, c_tag))
A.R Karthick369f89e2017-03-02 15:22:45 -0800237 cmd = 'pipework {} -i {} -l {} {} 0.0.0.0/24'.format(port, guest_port, guest_port, self.name)
238 res = os.system(cmd)
239 if res == 0:
240 vlan_outer_port = '{}.{}'.format(guest_port, s_tag)
241 vlan_inner_port = '{}.{}'.format(vlan_outer_port, c_tag)
242 #configure the s_tag/c_tag interfaces inside the guest container
243 cmds = ('ip link set {} up'.format(guest_port),
244 'ip link add link {} name {} type vlan id {}'.format(guest_port,
245 vlan_outer_port,
246 s_tag),
247 'ip link set {} up'.format(vlan_outer_port),
248 'ip link add link {} name {} type vlan id {}'.format(vlan_outer_port,
249 vlan_inner_port,
250 c_tag),
251 'ip link set {} up'.format(vlan_inner_port),
252 )
253 res += self.execute(cmds, shell = True)
254
255 @classmethod
256 def cleanup_vcpes(cls, vcpes):
257 port_num = 0
258 for vcpe in vcpes:
259 port = vcpe['port']
260 if os.access('/sys/class/net/{}'.format(port), os.F_OK):
261 local_port = 'vcpe{}'.format(port_num)
262 cmd = 'ip link del {}'.format(local_port)
263 os.system(cmd)
264 port_num += 1
265
A R Karthick1f03e912016-05-18 11:39:22 -0700266 def setup_intfs(self, port_num = 0):
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700267 tester_intf_subnet = '192.168.100'
268 res = 0
A.R Karthick88e80b92016-12-05 20:23:45 -0800269 switches = self.port_map['switches']
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700270 start_vlan = self.port_map['start_vlan']
A.R Karthick4f583842017-06-09 17:15:47 -0700271 ponsim = self.port_map['ponsim']
A R Karthick07769362016-07-28 17:36:15 -0700272 start_vlan += port_num
273 uplink = self.port_map['uplink']
274 wan = self.port_map['wan']
A.R Karthick4f583842017-06-09 17:15:47 -0700275 if ponsim is True:
276 if not wan:
277 wan = 'ponmgmt'
A.R Karthick369f89e2017-03-02 15:22:45 -0800278 vcpe_port_num = port_num
A.R Karthick88e80b92016-12-05 20:23:45 -0800279 port_list = self.port_map['switch_port_list'] + self.port_map['switch_relay_port_list']
A R Karthick52414732017-01-31 09:59:47 -0800280 print('Provisioning the ports for the test container\n')
A.R Karthick88e80b92016-12-05 20:23:45 -0800281 for host_intf, ports in port_list:
A R Karthicke8bd80e2017-08-01 12:36:24 -0700282 if self.switch_started is False and host_intf.startswith('br-int'):
283 continue
A.R Karthick4f583842017-06-09 17:15:47 -0700284 setup_ponsim = ponsim
285 host_index = 0
286 host_intf_base = 'pon1'
A R Karthickf97ee132017-03-23 09:48:37 -0700287 #if the host interface/switch does not exist, just create a dummy ovs switch
288 #needed if we are running with no-switch option
289 if not os.access('/sys/class/net/{}'.format(host_intf), os.F_OK):
290 os.system('ovs-vsctl add-br {}'.format(host_intf))
A.R Karthick88e80b92016-12-05 20:23:45 -0800291 uplink = self.port_map[host_intf]['uplink']
A.R Karthick4f583842017-06-09 17:15:47 -0700292 if setup_ponsim is True:
293 if host_intf.find('_') < 0:
294 print('Invalid host interface specified with ponsim. Disabling ponsim setup')
295 setup_ponsim = False
296 else:
297 try:
298 host_index = int(host_intf.split('_')[-1])
299 host_intf_base = host_intf.split('_')[0]
300 except:
301 print('Invalid host interface with ponsim. Disabling ponsim setup')
302 setup_ponsim = False
A.R Karthick88e80b92016-12-05 20:23:45 -0800303 for port in ports:
304 guest_if = port
A R Karthicke4660f52017-02-23 12:08:41 -0800305 local_if = 'l{}'.format(port_num+1) #port #'{0}_{1}'.format(guest_if, port_num+1)
A.R Karthick88e80b92016-12-05 20:23:45 -0800306 guest_ip = '{0}.{1}/24'.format(tester_intf_subnet, port_num+1)
A.R Karthick4f583842017-06-09 17:15:47 -0700307 if setup_ponsim is True:
308 if port != self.port_map[uplink]:
309 host_intf = '{}_{}'.format(host_intf_base, host_index)
310 host_index += 1
311
A.R Karthick88e80b92016-12-05 20:23:45 -0800312 ##Use pipeworks to configure container interfaces on host/bridge interfaces
313 pipework_cmd = 'pipework {0} -i {1} -l {2} {3} {4}'.format(host_intf, guest_if,
A R Karthick07769362016-07-28 17:36:15 -0700314 local_if, self.name, guest_ip)
A.R Karthick88e80b92016-12-05 20:23:45 -0800315 #if the wan interface is specified for uplink, then use it instead
316 if wan and port == self.port_map[uplink]:
317 pipework_cmd = 'pipework {0} -i {1} -l {2} {3} {4}'.format(wan, guest_if,
318 local_if, self.name, guest_ip)
319 else:
320 if start_vlan != 0:
321 pipework_cmd += ' @{}'.format(start_vlan)
322 start_vlan += 1
A.R Karthick4f583842017-06-09 17:15:47 -0700323 print('Running PIPEWORK cmd: %s' %pipework_cmd)
A.R Karthick88e80b92016-12-05 20:23:45 -0800324 res += os.system(pipework_cmd)
325 port_num += 1
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700326
A R Karthicke8bd80e2017-08-01 12:36:24 -0700327 if setup_ponsim is True:
328 ponsim = False
329 wan = None
330
A.R Karthick369f89e2017-03-02 15:22:45 -0800331 self.setup_vcpes(vcpe_port_num)
A R Karthick1f03e912016-05-18 11:39:22 -0700332 return res, port_num
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700333
334 @classmethod
A.R Karthick88e80b92016-12-05 20:23:45 -0800335 def get_intf_type(cls, intf):
336 intf_type = 0
337 if os.path.isdir('/sys/class/net/{}/bridge'.format(intf)):
338 intf_type = 1 ##linux bridge
339 else:
340 cmd = 'ovs-vsctl list-br | grep -q "^{0}$"'.format(intf)
341 res = os.system(cmd)
342 if res == 0: ##ovs bridge
343 intf_type = 2
344
345 return intf_type
346
347 @classmethod
A.R Karthick5968e0d2017-05-16 14:50:46 -0700348 def cleanup_intfs(cls, olt_conf_file):
349 if not os.access(olt_conf_file, os.F_OK):
350 olt_conf_file = os.path.join(cls.tester_base, os.path.basename(olt_conf_file))
A R Karthickb50f5592016-07-26 12:19:29 -0700351 olt_config = OltConfig(olt_conf_file)
A R Karthickb03cecd2016-07-27 10:27:55 -0700352 port_map, _ = olt_config.olt_port_map()
A.R Karthick369f89e2017-03-02 15:22:45 -0800353 vcpes = olt_config.get_vcpes()
A R Karthickb50f5592016-07-26 12:19:29 -0700354 port_num = 0
A R Karthickb50f5592016-07-26 12:19:29 -0700355 start_vlan = port_map['start_vlan']
A R Karthick07769362016-07-28 17:36:15 -0700356 wan = port_map['wan']
A R Karthickb50f5592016-07-26 12:19:29 -0700357 cmds = ()
358 res = 0
A.R Karthick88e80b92016-12-05 20:23:45 -0800359 port_list = port_map['switch_port_list'] + port_map['switch_relay_port_list']
360 for intf_host, ports in port_list:
361 intf_type = cls.get_intf_type(intf_host)
362 for port in ports:
A R Karthicke4660f52017-02-23 12:08:41 -0800363 local_if = 'l{}'.format(port_num+1) #port #'{0}_{1}'.format(port, port_num+1)
A.R Karthick88e80b92016-12-05 20:23:45 -0800364 if intf_type == 0:
365 if start_vlan != 0:
366 cmds = ('ip link del {}.{}'.format(intf_host, start_vlan),)
367 start_vlan += 1
A R Karthickb50f5592016-07-26 12:19:29 -0700368 else:
A.R Karthick88e80b92016-12-05 20:23:45 -0800369 if intf_type == 1:
370 cmds = ('brctl delif {} {}'.format(intf_host, local_if),
371 'ip link del {}'.format(local_if))
372 else:
373 cmds = ('ovs-vsctl del-port {} {}'.format(intf_host, local_if),
374 'ip link del {}'.format(local_if))
A R Karthickb50f5592016-07-26 12:19:29 -0700375
A.R Karthick88e80b92016-12-05 20:23:45 -0800376 for cmd in cmds:
377 res += os.system(cmd)
378 port_num += 1
A R Karthickb50f5592016-07-26 12:19:29 -0700379
A.R Karthick369f89e2017-03-02 15:22:45 -0800380 cls.cleanup_vcpes(vcpes)
381
A R Karthickb50f5592016-07-26 12:19:29 -0700382 @classmethod
A R Karthicke4660f52017-02-23 12:08:41 -0800383 def get_name(cls, num_instances):
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700384 cnt_name = '/{0}'.format(cls.basename)
385 cnt_name_len = len(cnt_name)
386 names = list(flatten(n['Names'] for n in cls.dckr.containers(all=True)))
387 test_names = filter(lambda n: n.startswith(cnt_name), names)
388 last_cnt_number = 0
389 if test_names:
390 last_cnt_name = reduce(lambda n1, n2: n1 if int(n1[cnt_name_len:]) > \
391 int(n2[cnt_name_len:]) else n2,
392 test_names)
393 last_cnt_number = int(last_cnt_name[cnt_name_len:])
A R Karthicke4660f52017-02-23 12:08:41 -0800394 if num_instances == 1:
395 last_cnt_number -= 1
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700396 test_cnt_name = cls.basename + str(last_cnt_number+1)
397 return test_cnt_name
398
399 @classmethod
400 def build_image(cls, image):
401 print('Building test container docker image %s' %image)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700402 ovs_version = '2.5.0'
403 image_format = (ovs_version,)*4
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700404 dockerfile = '''
405FROM ubuntu:14.04
406MAINTAINER chetan@ciena.com
A R Karthickc762df42016-05-25 10:09:21 -0700407RUN apt-get update && \
408 apt-get install -y git git-core autoconf automake autotools-dev pkg-config \
409 make gcc g++ libtool libc6-dev cmake libpcap-dev libxerces-c2-dev \
410 unzip libpcre3-dev flex bison libboost-dev \
411 python python-pip python-setuptools python-scapy tcpdump doxygen doxypy wget \
412 openvswitch-common openvswitch-switch \
A R Karthick07608ef2016-08-23 16:51:19 -0700413 python-twisted python-sqlite sqlite3 python-pexpect telnet arping isc-dhcp-server \
Chetan Gaonker53f16382017-02-20 20:31:22 +0000414 python-paramiko python-maas-client python-keystoneclient python-neutronclient \
A R Karthickc28f6a92017-04-18 16:05:18 -0700415 python-glanceclient python-novaclient python-dev libffi-dev libssl-dev
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700416RUN easy_install nose
A R Karthickc28f6a92017-04-18 16:05:18 -0700417RUN python -m pip install --upgrade pip
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700418RUN mkdir -p /root/ovs
419WORKDIR /root
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700420RUN wget http://openvswitch.org/releases/openvswitch-{}.tar.gz -O /root/ovs/openvswitch-{}.tar.gz && \
421(cd /root/ovs && tar zxpvf openvswitch-{}.tar.gz && \
422 cd openvswitch-{} && \
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700423 ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --disable-ssl && make && make install)
424RUN service openvswitch-switch restart || /bin/true
A.R Karthickec5b72a2016-11-03 09:53:07 -0700425RUN pip install scapy==2.3.2 scapy-ssl_tls==1.2.2 monotonic configObj docker-py pyyaml nsenter pyroute2 netaddr python-daemon
A R Karthickc28f6a92017-04-18 16:05:18 -0700426RUN pip install -U cryptography
427RUN pip install -U paramiko
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700428RUN mv /usr/sbin/tcpdump /sbin/
429RUN ln -sf /sbin/tcpdump /usr/sbin/tcpdump
A R Karthickf4999472016-07-01 16:42:13 -0700430RUN mv /usr/sbin/dhcpd /sbin/
431RUN ln -sf /sbin/dhcpd /usr/sbin/dhcpd
A.R Karthickcaf82ac2017-04-17 17:45:24 -0700432RUN mv /sbin/dhclient /usr/sbin/
433RUN ln -sf /usr/sbin/dhclient /sbin/dhclient
A R Karthickb7e80902016-05-17 09:38:31 -0700434WORKDIR /root
435RUN wget -nc http://de.archive.ubuntu.com/ubuntu/pool/main/b/bison/bison_2.5.dfsg-2.1_amd64.deb \
436 http://de.archive.ubuntu.com/ubuntu/pool/main/b/bison/libbison-dev_2.5.dfsg-2.1_amd64.deb
437RUN sudo dpkg -i bison_2.5.dfsg-2.1_amd64.deb libbison-dev_2.5.dfsg-2.1_amd64.deb
438RUN rm bison_2.5.dfsg-2.1_amd64.deb libbison-dev_2.5.dfsg-2.1_amd64.deb
439RUN wget -nc http://www.nbee.org/download/nbeesrc-jan-10-2013.zip && \
440 unzip nbeesrc-jan-10-2013.zip && \
441 cd nbeesrc-jan-10-2013/src && cmake . && make && \
442 cp ../bin/libn*.so /usr/local/lib && ldconfig && \
443 cp -R ../include/* /usr/include/
444WORKDIR /root
445RUN git clone https://github.com/CPqD/ofsoftswitch13.git && \
446 cd ofsoftswitch13 && \
A R Karthickb7e80902016-05-17 09:38:31 -0700447 ./boot.sh && \
448 ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --disable-ssl && \
449 make && make install
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700450CMD ["/bin/bash"]
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700451'''.format(*image_format)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700452 super(CordTester, cls).build_image(dockerfile, image)
453 print('Done building docker image %s' %image)
454
A R Karthick1f03e912016-05-18 11:39:22 -0700455 def run_tests(self):
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700456 '''Run the list of tests'''
A R Karthick9a5edc42016-08-24 19:10:22 -0700457 res = 0
Thangavelu K Sef6f0a52016-12-14 19:57:05 +0000458 print('Modifying scapy tool files before running a test: %s' %self.tests)
459 self.modify_scapy_files_for_specific_tests()
A R Karthick1f03e912016-05-18 11:39:22 -0700460 print('Running tests: %s' %self.tests)
461 for t in self.tests:
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700462 test = t.split(':')[0]
A R Karthick24f1de62016-05-12 15:16:38 -0700463 test_file = '{}Test.py'.format(test)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700464 if t.find(':') >= 0:
A R Karthick24f1de62016-05-12 15:16:38 -0700465 test_case = '{0}:{1}'.format(test_file, t.split(':')[1])
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700466 else:
467 test_case = test_file
Chetan Gaonker7142a342016-04-07 14:53:12 -0700468 cmd = 'nosetests -v {0}/src/test/{1}/{2}'.format(self.sandbox, test, test_case)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700469 status = self.execute(cmd, shell = True)
A R Karthick9a5edc42016-08-24 19:10:22 -0700470 if status > 255:
471 status = 1
472 res |= status
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700473 print('Test %s %s' %(test_case, 'Success' if status == 0 else 'Failure'))
474 print('Done running tests')
475 if self.rm:
476 print('Removing test container %s' %self.name)
477 self.kill(remove=True)
478
A R Karthick9a5edc42016-08-24 19:10:22 -0700479 return res
480
Thangavelu K Sef6f0a52016-12-14 19:57:05 +0000481 def modify_scapy_files_for_specific_tests(self):
482 name = self.name
A R Karthickf7a613b2017-02-24 09:36:44 -0800483 container_cmd_exec = Container(name = name, image = CordTester.IMAGE)
Thangavelu K Sef6f0a52016-12-14 19:57:05 +0000484 tty = False
485 dckr = Client()
486 cmd = 'cp test/src/test/scapy/fields.py /usr/local/lib/python2.7/dist-packages/scapy/fields.py '
487 i = container_cmd_exec.execute(cmd = cmd, tty= tty, stream = True)
488
Chetan Gaonkerfb3cb5e2016-05-06 11:55:44 -0700489 @classmethod
490 def list_tests(cls, tests):
491 print('Listing test cases')
492 for test in tests:
A R Karthick24f1de62016-05-12 15:16:38 -0700493 test_file = '{}Test.py'.format(test)
Chetan Gaonkerfb3cb5e2016-05-06 11:55:44 -0700494 cmd = 'nosetests -v --collect-only {0}/../{1}/{2}'.format(cls.tester_base, test, test_file)
495 os.system(cmd)
496
A R Karthicka013a272016-08-16 16:40:19 -0700497
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700498##default onos/radius/test container images and names
499onos_image_default='onosproject/onos:latest'
A R Karthick07608ef2016-08-23 16:51:19 -0700500nose_image_default= '{}:candidate'.format(CordTester.IMAGE)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700501test_type_default='dhcp'
A R Karthickb608d402017-06-02 11:48:41 -0700502onos_app_version = '3.0-SNAPSHOT'
Chetan Gaonker4d842ad2016-04-26 10:04:24 -0700503cord_tester_base = os.path.dirname(os.path.realpath(__file__))
A.R Karthick5968e0d2017-05-16 14:50:46 -0700504olt_config_default = os.path.join(cord_tester_base, 'olt_config.json')
A R Karthick38d5df42017-07-10 13:33:26 -0700505onos_app_file = os.path.abspath('{0}/../apps/ciena-cordigmp-multitable-'.format(cord_tester_base) + onos_app_version + '.oar')
A R Karthick81acbff2016-06-17 14:45:16 -0700506cord_test_server_address = '{}:{}'.format(CORD_TEST_HOST, CORD_TEST_PORT)
A R Karthick07608ef2016-08-23 16:51:19 -0700507identity_file_default = '/etc/maas/ansible/id_rsa'
A R Karthicke14fc022016-12-08 14:50:29 -0800508onos_log_level = 'INFO'
A R Karthick07608ef2016-08-23 16:51:19 -0700509
510##sets up the ssh key file for the test container
511def set_ssh_key_file(identity_file):
512 ssh_key_file = None
513 if os.access(identity_file, os.F_OK):
514 ##copy it to setup directory
515 identity_dest = os.path.join(CordTester.tester_base, 'id_rsa')
516 if os.path.abspath(identity_file) != identity_dest:
517 try:
518 shutil.copy(identity_file, identity_dest)
519 ssh_key_file = os.path.join(CordTester.sandbox_setup, 'id_rsa')
520 except: pass
521
522 return ssh_key_file
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700523
A R Karthickcaac5542017-03-06 16:20:57 -0800524def openstack_setup(test_cnt_env):
525 admin_rc = os.path.join(os.getenv('HOME'), 'admin-openrc.sh')
A R Karthick8983cb02017-06-09 11:32:53 -0700526 if not os.access(admin_rc, os.F_OK):
527 admin_rc = os.path.join('/opt/cord_profile', 'admin-openrc.sh')
A R Karthickcaac5542017-03-06 16:20:57 -0800528 if os.access(admin_rc, os.F_OK):
529 dest = os.path.join(CordTester.tester_base, 'admin-openrc.sh')
530 shutil.copy(admin_rc, dest)
531 with open(dest, 'r') as f:
532 cfg = {}
533 for data in f.read().splitlines():
534 try:
535 k, v = data.split('=')
536 except:
537 continue
538
539 k = k.split()[-1]
540 cfg[k] = v
541
542 if 'REQUESTS_CA_BUNDLE' in cfg:
543 #copy the certificate to setup directory
544 cert_src = cfg['REQUESTS_CA_BUNDLE']
545 shutil.copy(cert_src, CordTester.tester_base)
546 test_cert_loc = os.path.join(CordTester.sandbox_setup,
547 os.path.basename(cert_src))
548 cfg['REQUESTS_CA_BUNDLE'] = test_cert_loc
549
550 for key, value in cfg.iteritems():
551 test_cnt_env[key] = value
552
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700553def runTest(args):
Chetan Gaonker823cdc52016-05-09 15:51:23 -0700554 #Start the cord test tcp server
A.R Karthickb17e2022017-01-27 11:29:26 -0800555 test_manifest = TestManifest(args = args)
556 test_server_params = test_manifest.server.split(':')
A R Karthick81acbff2016-06-17 14:45:16 -0700557 test_host = test_server_params[0]
558 test_port = CORD_TEST_PORT
559 if len(test_server_params) > 1:
560 test_port = int(test_server_params[1])
A R Karthick81acbff2016-06-17 14:45:16 -0700561
A R Karthick1f03e912016-05-18 11:39:22 -0700562 test_containers = []
563 #These tests end up restarting ONOS/quagga/radius
A R Karthick4e0c0912016-08-17 16:57:42 -0700564 tests_exempt = ('vrouter', 'cordSubscriber', 'proxyarp', 'dhcprelay')
Chetan Gaonker503032a2016-05-12 12:06:29 -0700565 if args.test_type.lower() == 'all':
566 tests = CordTester.ALL_TESTS
Chetan Gaonker503032a2016-05-12 12:06:29 -0700567 args.quagga = True
568 else:
A R Karthickacae3b42016-05-12 15:27:24 -0700569 tests = args.test_type.split('-')
Chetan Gaonker503032a2016-05-12 12:06:29 -0700570
A R Karthick1f03e912016-05-18 11:39:22 -0700571 tests_parallel = [ t for t in tests if t.split(':')[0] not in tests_exempt ]
572 tests_not_parallel = [ t for t in tests if t.split(':')[0] in tests_exempt ]
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700573 onos_cnt = {'tag':'latest'}
A R Karthick07608ef2016-08-23 16:51:19 -0700574 nose_cnt = {'image': CordTester.IMAGE, 'tag': 'candidate'}
Chetan Gaonker503032a2016-05-12 12:06:29 -0700575 update_map = { 'quagga' : False, 'test' : False, 'radius' : False }
576 update_map[args.update.lower()] = True
A.R Karthick95d044e2016-06-10 18:44:36 -0700577
Chetan Gaonker503032a2016-05-12 12:06:29 -0700578 if args.update.lower() == 'all':
579 for c in update_map.keys():
580 update_map[c] = True
A.R Karthick95d044e2016-06-10 18:44:36 -0700581
A R Karthick07608ef2016-08-23 16:51:19 -0700582 use_manifest = False
583 if args.manifest:
584 if os.access(args.manifest, os.F_OK):
585 ##copy it to setup directory
A.R Karthick8b2f1e32017-02-09 15:10:07 -0800586 dest = os.path.join(CordTester.tester_base,
587 os.path.basename(args.manifest))
A R Karthick07608ef2016-08-23 16:51:19 -0700588 if os.path.abspath(args.manifest) != dest:
589 try:
590 shutil.copy(args.manifest, dest)
591 except: pass
A R Karthick65d950d2016-12-19 19:41:55 -0800592 test_manifest = TestManifest(manifest = dest)
A R Karthick07608ef2016-08-23 16:51:19 -0700593 use_manifest = True
594 else:
595 print('Unable to access test manifest: %s' %args.manifest)
Chetan Gaonkerfb3cb5e2016-05-06 11:55:44 -0700596
A R Karthick65d950d2016-12-19 19:41:55 -0800597 onos_ip = test_manifest.onos_ip
598 radius_ip = test_manifest.radius_ip
599 head_node = test_manifest.head_node
A R Karthick5af23712017-01-20 09:49:24 -0800600 iterations = test_manifest.iterations
A.R Karthick263d3fc2017-01-27 12:52:53 -0800601 onos_cord_loc = test_manifest.onos_cord
A.R Karthickf184b342017-01-27 19:30:50 -0800602 service_profile = test_manifest.service_profile
603 synchronizer = test_manifest.synchronizer
A.R Karthick5968e0d2017-05-16 14:50:46 -0700604 olt_config_file = test_manifest.olt_config
A.R Karthick57fa9372017-05-24 12:47:03 -0700605 voltha_loc = test_manifest.voltha_loc
606 voltha_intf = test_manifest.voltha_intf
A.R Karthick5968e0d2017-05-16 14:50:46 -0700607 if not os.access(olt_config_file, os.F_OK):
608 olt_config_file = os.path.join(CordTester.tester_base, 'olt_config.json')
609 else:
610 dest = os.path.join(CordTester.tester_base,
611 os.path.basename(olt_config_file))
612 if os.path.abspath(olt_config_file) != dest:
613 try:
614 shutil.copy(olt_config_file, dest)
615 except: pass
616
A.R Karthickf184b342017-01-27 19:30:50 -0800617 onos_cord = None
A R Karthick973010f2017-02-06 16:41:51 -0800618 Onos.update_data_dir(test_manifest.karaf_version)
A R Karthick184945a2017-07-25 17:23:57 -0700619 Onos.set_expose_port(test_manifest.expose_port)
A.R Karthick263d3fc2017-01-27 12:52:53 -0800620 if onos_cord_loc:
621 if onos_cord_loc.find(os.path.sep) < 0:
622 onos_cord_loc = os.path.join(os.getenv('HOME'), onos_cord_loc)
A.R Karthickf184b342017-01-27 19:30:50 -0800623 if not os.access(onos_cord_loc, os.F_OK):
624 print('ONOS cord config location %s is not accessible' %onos_cord_loc)
625 sys.exit(1)
A.R Karthick263d3fc2017-01-27 12:52:53 -0800626 if not onos_ip:
627 ##Unexpected case. Specify the external controller ip when running on cord node
628 print('Specify ONOS ip using \"-e\" option when running the cord-tester on cord node')
629 sys.exit(1)
A.R Karthickf184b342017-01-27 19:30:50 -0800630 if not service_profile:
A R Karthick03bd2812017-03-03 17:49:17 -0800631 print('Specify service profile for the ONOS cord instance. Eg: rcord')
A.R Karthickf184b342017-01-27 19:30:50 -0800632 sys.exit(1)
633 if not synchronizer:
634 print('Specify synchronizer to use for the ONOS cord instance. Eg: vtn, fabric, cord')
635 sys.exit(1)
A.R Karthickf184b342017-01-27 19:30:50 -0800636 onos_cord = OnosCord(onos_ip, onos_cord_loc, service_profile, synchronizer)
A.R Karthick263d3fc2017-01-27 12:52:53 -0800637
638 try:
639 test_server = cord_test_server_start(daemonize = False, cord_test_host = test_host, cord_test_port = test_port,
640 onos_cord = onos_cord)
641 except:
642 ##Most likely a server instance is already running (daemonized earlier)
643 test_server = None
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700644
A R Karthick65d950d2016-12-19 19:41:55 -0800645 Container.IMAGE_PREFIX = test_manifest.image_prefix
646 Onos.MAX_INSTANCES = test_manifest.onos_instances
A R Karthickc69d73e2017-01-20 11:44:34 -0800647 Onos.JVM_HEAP_SIZE = test_manifest.jvm_heap_size
A R Karthick65d950d2016-12-19 19:41:55 -0800648 cluster_mode = True if test_manifest.onos_instances > 1 else False
649 async_mode = cluster_mode and test_manifest.async_mode
650 existing_list = [ c['Names'][0][1:] for c in Container.dckr.containers() if c['Image'] == test_manifest.onos_image ]
651 setup_cluster = False if len(existing_list) == test_manifest.onos_instances else True
A.R Karthickc4e474d2016-12-12 15:24:57 -0800652 onos_ips = []
A R Karthick65d950d2016-12-19 19:41:55 -0800653 if cluster_mode is True and len(existing_list) > 1:
654 ##don't setup cluster config again
655 cluster_mode = False
A R Karthicka41c1c52017-08-02 15:30:48 -0700656 if voltha_loc:
657 voltha_key = os.path.join(voltha_loc, 'docker', 'onos_cfg', 'onos.jks')
658 Onos.update_ssl_key(voltha_key)
A R Karthick07608ef2016-08-23 16:51:19 -0700659 if onos_ip is None:
A R Karthick65d950d2016-12-19 19:41:55 -0800660 image_names = test_manifest.onos_image.rsplit(':', 1)
A R Karthick07608ef2016-08-23 16:51:19 -0700661 onos_cnt['image'] = image_names[0]
662 if len(image_names) > 1:
663 if image_names[1].find('/') < 0:
664 onos_cnt['tag'] = image_names[1]
665 else:
666 #tag cannot have slashes
A R Karthick65d950d2016-12-19 19:41:55 -0800667 onos_cnt['image'] = test_manifest.onos_image
A R Karthick07608ef2016-08-23 16:51:19 -0700668
669 Onos.IMAGE = onos_cnt['image']
A R Karthick65d950d2016-12-19 19:41:55 -0800670 Onos.PREFIX = test_manifest.image_prefix
A R Karthick07608ef2016-08-23 16:51:19 -0700671 Onos.TAG = onos_cnt['tag']
A R Karthick65d950d2016-12-19 19:41:55 -0800672 data_volume = '{}-data'.format(Onos.NAME) if test_manifest.shared_volume else None
A R Karthick07608ef2016-08-23 16:51:19 -0700673 onos = Onos(image = Onos.IMAGE,
A.R Karthickc4e474d2016-12-12 15:24:57 -0800674 tag = Onos.TAG, boot_delay = 60, cluster = cluster_mode,
A R Karthick85eb1862017-01-23 16:10:57 -0800675 data_volume = data_volume, async = async_mode, network = test_manifest.docker_network)
A.R Karthickc4e474d2016-12-12 15:24:57 -0800676 if onos.running:
A R Karthick65d950d2016-12-19 19:41:55 -0800677 onos_ips.append(onos.ipaddr)
A.R Karthickc4e474d2016-12-12 15:24:57 -0800678 else:
679 onos_ips.append(onos_ip)
680
A R Karthick65d950d2016-12-19 19:41:55 -0800681 num_onos_instances = test_manifest.onos_instances
ChetanGaonkerdbd4e4b2016-10-28 17:40:11 -0700682 if num_onos_instances > 1 and onos is not None:
683 onos_instances = []
684 onos_instances.append(onos)
685 for i in range(1, num_onos_instances):
686 name = '{}-{}'.format(Onos.NAME, i+1)
A R Karthick65d950d2016-12-19 19:41:55 -0800687 data_volume = '{}-data'.format(name) if test_manifest.shared_volume else None
A.R Karthickc4e474d2016-12-12 15:24:57 -0800688 quagga_config = Onos.get_quagga_config(i)
A R Karthickec2db322016-11-17 15:06:01 -0800689 onos = Onos(name = name, image = Onos.IMAGE, tag = Onos.TAG, boot_delay = 60, cluster = cluster_mode,
A R Karthick3b811152016-12-15 10:24:24 -0800690 data_volume = data_volume, async = async_mode,
A R Karthick184945a2017-07-25 17:23:57 -0700691 quagga_config = quagga_config, network = test_manifest.docker_network, instance = i)
ChetanGaonkerdbd4e4b2016-10-28 17:40:11 -0700692 onos_instances.append(onos)
A.R Karthickc4e474d2016-12-12 15:24:57 -0800693 if onos.running:
694 onos_ips.append(onos.ipaddr)
A R Karthick65d950d2016-12-19 19:41:55 -0800695 if async_mode is True and cluster_mode is True:
A.R Karthickc4e474d2016-12-12 15:24:57 -0800696 Onos.start_cluster_async(onos_instances)
697 if not onos_ips:
698 for onos in onos_instances:
699 onos_ips.append(onos.ipaddr)
A R Karthick65d950d2016-12-19 19:41:55 -0800700 if cluster_mode is True:
701 try:
702 for ip in onos_ips:
703 print('Installing cord tester ONOS app %s in ONOS instance %s' %(args.app,ip))
704 OnosCtrl.install_app(args.app, onos_ip = ip)
705 except: pass
A R Karthick1ef70552016-11-17 17:33:36 -0800706 if setup_cluster is True:
707 Onos.setup_cluster(onos_instances)
708 else:
709 print('ONOS instances already running. Skipping ONOS form cluster for %d instances' %num_onos_instances)
ChetanGaonkerdbd4e4b2016-10-28 17:40:11 -0700710 ctlr_addr = ','.join(onos_ips)
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700711
A R Karthick65d950d2016-12-19 19:41:55 -0800712 print('Controller IP %s, Test type %s' %(onos_ips, args.test_type))
713 if onos_ip is not None:
A R Karthickbd9b8a32016-07-21 09:56:45 -0700714 print('Installing ONOS cord apps')
A R Karthick07608ef2016-08-23 16:51:19 -0700715 try:
716 Onos.install_cord_apps(onos_ip = onos_ip)
717 except: pass
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700718
ChetanGaonkerdbd4e4b2016-10-28 17:40:11 -0700719 if not cluster_mode:
720 print('Installing cord tester ONOS app %s' %args.app)
721 try:
722 for ip in onos_ips:
A R Karthick65d950d2016-12-19 19:41:55 -0800723 OnosCtrl.install_app(args.app, onos_ip = ip)
ChetanGaonkerdbd4e4b2016-10-28 17:40:11 -0700724 except: pass
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700725
A.R Karthick57fa9372017-05-24 12:47:03 -0700726 if voltha_loc:
727 #start voltha
A.R Karthick4f583842017-06-09 17:15:47 -0700728 voltha = VolthaService(voltha_loc, onos_ips[0], interface = voltha_intf, olt_config = olt_config_file)
A.R Karthick57fa9372017-05-24 12:47:03 -0700729 voltha.start()
730
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700731 if radius_ip is None:
A R Karthicka661b552016-05-25 10:18:50 -0700732 ##Start Radius container
A R Karthick85eb1862017-01-23 16:10:57 -0800733 radius = Radius(prefix = Container.IMAGE_PREFIX, update = update_map['radius'],
734 network = test_manifest.docker_network)
A R Karthick75844572017-01-23 16:57:44 -0800735 radius_ip = radius.ip(network = test_manifest.docker_network)
A.R Karthick95d044e2016-06-10 18:44:36 -0700736
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700737 print('Radius server running with IP %s' %radius_ip)
A.R Karthick95d044e2016-06-10 18:44:36 -0700738
Chetan Gaonkerb84835f2016-04-19 15:12:10 -0700739 if args.quagga == True:
740 #Start quagga. Builds container if required
A R Karthick85eb1862017-01-23 16:10:57 -0800741 quagga = Quagga(prefix = Container.IMAGE_PREFIX, update = update_map['quagga'],
742 network = test_manifest.docker_network)
A R Karthick81acbff2016-06-17 14:45:16 -0700743
A R Karthick07608ef2016-08-23 16:51:19 -0700744 try:
745 maas_api_key = FabricMAAS.get_api_key()
746 except:
747 maas_api_key = 'UNKNOWN'
748
749 ssh_key_file = set_ssh_key_file(args.identity_file)
ChetanGaonkerdbd4e4b2016-10-28 17:40:11 -0700750 test_cnt_env = { 'ONOS_CONTROLLER_IP' : ctlr_addr,
Chetan Gaonkerc170f3f2016-04-19 17:24:45 -0700751 'ONOS_AAA_IP' : radius_ip if radius_ip is not None else '',
A R Karthick8d03cc52016-06-28 14:51:59 -0700752 'QUAGGA_IP': test_host,
A R Karthick81acbff2016-06-17 14:45:16 -0700753 'CORD_TEST_HOST' : test_host,
754 'CORD_TEST_PORT' : test_port,
A R Karthick65d950d2016-12-19 19:41:55 -0800755 'ONOS_RESTART' : 0 if test_manifest.olt and args.test_controller else 1,
756 'LOG_LEVEL': test_manifest.log_level,
A R Karthick07608ef2016-08-23 16:51:19 -0700757 'HEAD_NODE': head_node if head_node else CORD_TEST_HOST,
A R Karthick973010f2017-02-06 16:41:51 -0800758 'MAAS_API_KEY': maas_api_key,
A.R Karthick57fa9372017-05-24 12:47:03 -0700759 'KARAF_VERSION' : test_manifest.karaf_version,
A R Karthickfa2caab2017-07-24 18:04:46 -0700760 'VOLTHA_ENABLED' : int(test_manifest.voltha_enable)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700761 }
A R Karthick07608ef2016-08-23 16:51:19 -0700762
763 if ssh_key_file:
764 test_cnt_env['SSH_KEY_FILE'] = ssh_key_file
765
A.R Karthick5968e0d2017-05-16 14:50:46 -0700766 olt_conf_test_loc = os.path.join(CordTester.sandbox_setup, os.path.basename(olt_config_file))
767 test_cnt_env['OLT_CONFIG_FILE'] = olt_conf_test_loc
A R Karthick65d950d2016-12-19 19:41:55 -0800768 if test_manifest.olt:
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700769 test_cnt_env['OLT_CONFIG'] = olt_conf_test_loc
770
A.R Karthick8b2f1e32017-02-09 15:10:07 -0800771 if use_manifest:
772 test_cnt_env['MANIFEST'] = os.path.join(CordTester.sandbox_setup,
773 os.path.basename(args.manifest))
774
A.R Karthick5968e0d2017-05-16 14:50:46 -0700775
A R Karthick5af23712017-01-20 09:49:24 -0800776 if iterations is not None:
777 test_cnt_env['ITERATIONS'] = iterations
778
A R Karthickcaac5542017-03-06 16:20:57 -0800779 openstack_setup(test_cnt_env)
780
A R Karthicka013a272016-08-16 16:40:19 -0700781 if args.num_containers > 1 and args.container:
782 print('Cannot specify number of containers with container option')
783 sys.exit(1)
784 if args.container:
785 args.keep = True
A R Karthick1f03e912016-05-18 11:39:22 -0700786 port_num = 0
787 num_tests = len(tests_parallel)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700788 if num_tests > 0 and num_tests < args.num_containers:
789 tests_parallel *= args.num_containers/num_tests
790 num_tests = len(tests_parallel)
A R Karthick1f03e912016-05-18 11:39:22 -0700791 tests_per_container = max(1, num_tests/args.num_containers)
A R Karthicke4660f52017-02-23 12:08:41 -0800792 last_batch = num_tests % args.num_containers
A R Karthick1f03e912016-05-18 11:39:22 -0700793 test_slice_start = 0
794 test_slice_end = test_slice_start + tests_per_container
795 num_test_containers = min(num_tests, args.num_containers)
796 if tests_parallel:
797 print('Running %s tests across %d containers in parallel' %(tests_parallel, num_test_containers))
A R Karthicke4660f52017-02-23 12:08:41 -0800798 for container in xrange(num_test_containers):
799 if container + 1 == num_test_containers:
800 test_slice_end += last_batch
A R Karthick1f03e912016-05-18 11:39:22 -0700801 test_cnt = CordTester(tests_parallel[test_slice_start:test_slice_end],
802 instance = container, num_instances = num_test_containers,
ChetanGaonkerdbd4e4b2016-10-28 17:40:11 -0700803 ctlr_ip = ctlr_addr,
A R Karthick07608ef2016-08-23 16:51:19 -0700804 name = args.container,
805 image = nose_cnt['image'],
806 prefix = Container.IMAGE_PREFIX,
807 tag = nose_cnt['tag'],
A R Karthick1f03e912016-05-18 11:39:22 -0700808 env = test_cnt_env,
809 rm = False if args.keep else True,
A R Karthick85eb1862017-01-23 16:10:57 -0800810 update = update_map['test'],
811 network = test_manifest.docker_network)
A R Karthick1f03e912016-05-18 11:39:22 -0700812 test_slice_start = test_slice_end
813 test_slice_end = test_slice_start + tests_per_container
814 update_map['test'] = False
815 test_containers.append(test_cnt)
A R Karthicka013a272016-08-16 16:40:19 -0700816 if not test_cnt.create:
817 continue
A R Karthick65d950d2016-12-19 19:41:55 -0800818 if test_cnt.create and (test_manifest.start_switch or not test_manifest.olt):
A R Karthick07608ef2016-08-23 16:51:19 -0700819 if not args.no_switch:
A R Karthicke8bd80e2017-08-01 12:36:24 -0700820 test_cnt.start_switch(test_manifest)
A R Karthicka013a272016-08-16 16:40:19 -0700821 if test_cnt.create and test_cnt.olt:
A R Karthick1f03e912016-05-18 11:39:22 -0700822 _, port_num = test_cnt.setup_intfs(port_num = port_num)
823
A R Karthick9a5edc42016-08-24 19:10:22 -0700824 status = 0
825 if len(test_containers) > 1:
A R Karthicke4660f52017-02-23 12:08:41 -0800826 thread_pool = ThreadPool(len(test_containers), queue_size = 1, wait_timeout=1)
827 for test_cnt in test_containers:
828 thread_pool.addTask(test_cnt.run_tests)
829 thread_pool.cleanUpThreads()
A R Karthick9a5edc42016-08-24 19:10:22 -0700830 else:
A R Karthickcee37412016-08-29 10:10:56 -0700831 if test_containers:
832 status = test_containers[0].run_tests()
A R Karthick1f03e912016-05-18 11:39:22 -0700833
834 ##Run the linear tests
835 if tests_not_parallel:
836 test_cnt = CordTester(tests_not_parallel,
ChetanGaonkerdbd4e4b2016-10-28 17:40:11 -0700837 ctlr_ip = ctlr_addr,
A R Karthick07608ef2016-08-23 16:51:19 -0700838 name = args.container,
839 image = nose_cnt['image'],
840 prefix = Container.IMAGE_PREFIX,
841 tag = nose_cnt['tag'],
A R Karthick1f03e912016-05-18 11:39:22 -0700842 env = test_cnt_env,
843 rm = False if args.keep else True,
A R Karthick85eb1862017-01-23 16:10:57 -0800844 update = update_map['test'],
845 network = test_manifest.docker_network)
A R Karthick65d950d2016-12-19 19:41:55 -0800846 if test_cnt.create and (test_manifest.start_switch or not test_manifest.olt):
A R Karthick36cfcef2016-08-18 15:20:07 -0700847 #For non parallel tests, we just restart the switch also for OLT's
848 CordTester.switch_on_olt = False
A R Karthick07608ef2016-08-23 16:51:19 -0700849 if not args.no_switch:
A R Karthicke8bd80e2017-08-01 12:36:24 -0700850 test_cnt.start_switch(test_manifest)
A R Karthicka013a272016-08-16 16:40:19 -0700851 if test_cnt.create and test_cnt.olt:
A R Karthick1f03e912016-05-18 11:39:22 -0700852 test_cnt.setup_intfs(port_num = port_num)
ChetanGaonkerdbd4e4b2016-10-28 17:40:11 -0700853 test_cnt.run_tests()
A R Karthick1f03e912016-05-18 11:39:22 -0700854
A R Karthick81acbff2016-06-17 14:45:16 -0700855 if test_server:
A.R Karthickf184b342017-01-27 19:30:50 -0800856 if onos_cord:
857 onos_cord.restore()
A R Karthick81acbff2016-06-17 14:45:16 -0700858 cord_test_server_stop(test_server)
859
A R Karthick9a5edc42016-08-24 19:10:22 -0700860 return status
861
A R Karthick81acbff2016-06-17 14:45:16 -0700862##Starts onos/radius/quagga containers as appropriate
863def setupCordTester(args):
864 onos_cnt = {'tag':'latest'}
A R Karthick07608ef2016-08-23 16:51:19 -0700865 nose_cnt = {'image': CordTester.IMAGE, 'tag': 'candidate'}
A R Karthick92a0e5a2016-06-22 17:11:05 -0700866 update_map = { 'quagga' : False, 'radius' : False, 'test': False }
A R Karthick81acbff2016-06-17 14:45:16 -0700867 update_map[args.update.lower()] = True
A R Karthick65d950d2016-12-19 19:41:55 -0800868 test_manifest = TestManifest(args = args)
869
A R Karthick81acbff2016-06-17 14:45:16 -0700870 if args.update.lower() == 'all':
871 for c in update_map.keys():
872 update_map[c] = True
873
A R Karthick07608ef2016-08-23 16:51:19 -0700874 use_manifest = False
875 if args.manifest:
876 if os.access(args.manifest, os.F_OK):
877 ##copy it to setup directory
A.R Karthick8b2f1e32017-02-09 15:10:07 -0800878 dest = os.path.join(CordTester.tester_base,
879 os.path.basename(args.manifest))
A R Karthick07608ef2016-08-23 16:51:19 -0700880 if os.path.abspath(args.manifest) != dest:
881 try:
882 shutil.copy(args.manifest, dest)
883 except: pass
A R Karthick65d950d2016-12-19 19:41:55 -0800884 test_manifest = TestManifest(manifest = dest)
A R Karthick07608ef2016-08-23 16:51:19 -0700885 use_manifest = True
886
A.R Karthickf184b342017-01-27 19:30:50 -0800887 onos_ip = test_manifest.onos_ip
888 radius_ip = test_manifest.radius_ip
889 head_node = test_manifest.head_node
890 iterations = test_manifest.iterations
891 service_profile = test_manifest.service_profile
892 synchronizer = test_manifest.synchronizer
A.R Karthick57fa9372017-05-24 12:47:03 -0700893 voltha_loc = test_manifest.voltha_loc
894 voltha_intf = test_manifest.voltha_intf
A.R Karthickf184b342017-01-27 19:30:50 -0800895 onos_cord = None
A.R Karthick263d3fc2017-01-27 12:52:53 -0800896 onos_cord_loc = test_manifest.onos_cord
A R Karthick973010f2017-02-06 16:41:51 -0800897 Onos.update_data_dir(test_manifest.karaf_version)
A R Karthick184945a2017-07-25 17:23:57 -0700898 Onos.set_expose_port(test_manifest.expose_port)
A.R Karthick5968e0d2017-05-16 14:50:46 -0700899 olt_config_file = test_manifest.olt_config
900 if not os.access(olt_config_file, os.F_OK):
901 olt_config_file = os.path.join(CordTester.tester_base, 'olt_config.json')
902 else:
903 dest = os.path.join(CordTester.tester_base,
904 os.path.basename(olt_config_file))
905 if os.path.abspath(olt_config_file) != dest:
906 try:
907 shutil.copy(olt_config_file, dest)
908 except: pass
A R Karthick973010f2017-02-06 16:41:51 -0800909
A.R Karthick263d3fc2017-01-27 12:52:53 -0800910 if onos_cord_loc:
911 if onos_cord_loc.find(os.path.sep) < 0:
912 onos_cord_loc = os.path.join(os.getenv('HOME'), onos_cord_loc)
913 if not os.access(onos_cord_loc, os.F_OK):
914 print('ONOS cord config location %s is not accessible' %onos_cord_loc)
915 sys.exit(1)
A.R Karthick263d3fc2017-01-27 12:52:53 -0800916 if not onos_ip:
A R Karthickd44cea12016-07-20 12:16:41 -0700917 ##Unexpected case. Specify the external controller ip when running on cord node
918 print('Specify ONOS ip using \"-e\" option when running the cord-tester on cord node')
919 sys.exit(1)
A.R Karthickf184b342017-01-27 19:30:50 -0800920 if not service_profile:
A R Karthick03bd2812017-03-03 17:49:17 -0800921 print('Specify service profile for the ONOS cord instance. Eg: rcord')
A.R Karthickf184b342017-01-27 19:30:50 -0800922 sys.exit(1)
923 if not synchronizer:
924 print('Specify synchronizer to use for the ONOS cord instance. Eg: vtn, fabric, cord')
925 sys.exit(1)
A.R Karthickf184b342017-01-27 19:30:50 -0800926 onos_cord = OnosCord(onos_ip, onos_cord_loc, service_profile, synchronizer)
A R Karthickd44cea12016-07-20 12:16:41 -0700927
A R Karthick65d950d2016-12-19 19:41:55 -0800928 Container.IMAGE_PREFIX = test_manifest.image_prefix
A R Karthick81acbff2016-06-17 14:45:16 -0700929 #don't spawn onos if the user had started it externally
A R Karthick65d950d2016-12-19 19:41:55 -0800930 image_names = test_manifest.onos_image.rsplit(':', 1)
A R Karthick07608ef2016-08-23 16:51:19 -0700931 onos_cnt['image'] = image_names[0]
932 if len(image_names) > 1:
933 if image_names[1].find('/') < 0:
934 onos_cnt['tag'] = image_names[1]
935 else:
936 #tag cannot have slashes
A R Karthick65d950d2016-12-19 19:41:55 -0800937 onos_cnt['image'] = test_manifest.onos_image
A R Karthick81acbff2016-06-17 14:45:16 -0700938
A R Karthick07608ef2016-08-23 16:51:19 -0700939 Onos.IMAGE = onos_cnt['image']
A R Karthick65d950d2016-12-19 19:41:55 -0800940 Onos.PREFIX = test_manifest.image_prefix
A R Karthick07608ef2016-08-23 16:51:19 -0700941 Onos.TAG = onos_cnt['tag']
A R Karthick65d950d2016-12-19 19:41:55 -0800942 Onos.MAX_INSTANCES = test_manifest.onos_instances
A R Karthickc69d73e2017-01-20 11:44:34 -0800943 Onos.JVM_HEAP_SIZE = test_manifest.jvm_heap_size
A R Karthick65d950d2016-12-19 19:41:55 -0800944 cluster_mode = True if test_manifest.onos_instances > 1 else False
945 async_mode = cluster_mode and test_manifest.async_mode
946 existing_list = [ c['Names'][0][1:] for c in Container.dckr.containers() if c['Image'] == test_manifest.onos_image ]
947 setup_cluster = False if len(existing_list) == test_manifest.onos_instances else True
A R Karthickc41c2422016-12-09 10:59:19 -0800948 #cleanup existing volumes before forming a new cluster
949 if setup_cluster is True:
950 print('Cleaning up existing cluster volumes')
951 data_dir = os.path.join(Onos.setup_dir, 'cord-onos*-data')
952 try:
953 os.system('rm -rf {}'.format(data_dir))
954 except: pass
955
A R Karthick2b93d6a2016-09-06 15:19:09 -0700956 onos = None
A.R Karthickc4e474d2016-12-12 15:24:57 -0800957 onos_ips = []
A R Karthicka41c1c52017-08-02 15:30:48 -0700958 if voltha_loc:
959 voltha_key = os.path.join(voltha_loc, 'docker', 'onos_cfg', 'onos.jks')
960 Onos.update_ssl_key(voltha_key)
A R Karthick81acbff2016-06-17 14:45:16 -0700961 if onos_ip is None:
A R Karthick65d950d2016-12-19 19:41:55 -0800962 data_volume = '{}-data'.format(Onos.NAME) if test_manifest.shared_volume else None
A R Karthickec2db322016-11-17 15:06:01 -0800963 onos = Onos(image = Onos.IMAGE, tag = Onos.TAG, boot_delay = 60, cluster = cluster_mode,
A R Karthick85eb1862017-01-23 16:10:57 -0800964 data_volume = data_volume, async = async_mode, network = test_manifest.docker_network)
A.R Karthickc4e474d2016-12-12 15:24:57 -0800965 if onos.running:
A R Karthick65d950d2016-12-19 19:41:55 -0800966 onos_ips.append(onos.ipaddr)
A.R Karthickc4e474d2016-12-12 15:24:57 -0800967 else:
968 onos_ips.append(onos_ip)
A R Karthick81acbff2016-06-17 14:45:16 -0700969
A R Karthick65d950d2016-12-19 19:41:55 -0800970 num_onos_instances = test_manifest.onos_instances
A R Karthick2b93d6a2016-09-06 15:19:09 -0700971 if num_onos_instances > 1 and onos is not None:
972 onos_instances = []
973 onos_instances.append(onos)
974 for i in range(1, num_onos_instances):
975 name = '{}-{}'.format(Onos.NAME, i+1)
A R Karthick65d950d2016-12-19 19:41:55 -0800976 data_volume = '{}-data'.format(name) if test_manifest.shared_volume else None
A.R Karthickc4e474d2016-12-12 15:24:57 -0800977 quagga_config = Onos.get_quagga_config(i)
A R Karthickec2db322016-11-17 15:06:01 -0800978 onos = Onos(name = name, image = Onos.IMAGE, tag = Onos.TAG, boot_delay = 60, cluster = cluster_mode,
A R Karthick3b811152016-12-15 10:24:24 -0800979 data_volume = data_volume, async = async_mode,
A R Karthick184945a2017-07-25 17:23:57 -0700980 quagga_config = quagga_config, network = test_manifest.docker_network, instance = i)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700981 onos_instances.append(onos)
A.R Karthickc4e474d2016-12-12 15:24:57 -0800982 if onos.running:
983 onos_ips.append(onos.ipaddr)
984 if async_mode is True:
985 Onos.start_cluster_async(onos_instances)
986 if not onos_ips:
987 for onos in onos_instances:
988 onos_ips.append(onos.ipaddr)
A R Karthick51e6fd82016-11-22 14:39:19 -0800989 if setup_cluster is True:
990 Onos.setup_cluster(onos_instances)
A R Karthick2b93d6a2016-09-06 15:19:09 -0700991
992 ctlr_addr = ','.join(onos_ips)
993 print('Onos IP %s' %ctlr_addr)
A R Karthick65d950d2016-12-19 19:41:55 -0800994 if onos_ip is not None:
A R Karthickbd9b8a32016-07-21 09:56:45 -0700995 print('Installing ONOS cord apps')
A R Karthick07608ef2016-08-23 16:51:19 -0700996 try:
997 Onos.install_cord_apps(onos_ip = onos_ip)
998 except: pass
A R Karthickbd9b8a32016-07-21 09:56:45 -0700999
A R Karthickedab01c2016-09-08 14:05:44 -07001000 print('Installing cord tester ONOS app %s' %args.app)
A R Karthick07608ef2016-08-23 16:51:19 -07001001 try:
A R Karthick2b93d6a2016-09-06 15:19:09 -07001002 for ip in onos_ips:
1003 OnosCtrl.install_app(args.app, onos_ip = ip)
A R Karthick07608ef2016-08-23 16:51:19 -07001004 except: pass
A R Karthickeaf1c4e2016-07-19 12:22:35 -07001005
A.R Karthick57fa9372017-05-24 12:47:03 -07001006 if voltha_loc:
1007 #start voltha
A.R Karthick4f583842017-06-09 17:15:47 -07001008 voltha = VolthaService(voltha_loc, onos_ips[0], interface = voltha_intf, olt_config = olt_config_file)
A.R Karthick57fa9372017-05-24 12:47:03 -07001009 voltha.start()
1010
A R Karthick81acbff2016-06-17 14:45:16 -07001011 ##Start Radius container if not started
1012 if radius_ip is None:
A R Karthick85eb1862017-01-23 16:10:57 -08001013 radius = Radius(prefix = Container.IMAGE_PREFIX, update = update_map['radius'],
1014 network = test_manifest.docker_network)
A R Karthick75844572017-01-23 16:57:44 -08001015 radius_ip = radius.ip(network = test_manifest.docker_network)
A R Karthick81acbff2016-06-17 14:45:16 -07001016
1017 print('Radius server running with IP %s' %radius_ip)
A R Karthick81acbff2016-06-17 14:45:16 -07001018
1019 if args.quagga == True:
1020 #Start quagga. Builds container if required
A R Karthick85eb1862017-01-23 16:10:57 -08001021 quagga = Quagga(prefix = Container.IMAGE_PREFIX, update = update_map['quagga'],
1022 network = test_manifest.docker_network)
A R Karthick8d03cc52016-06-28 14:51:59 -07001023 print('Quagga started')
A R Karthick81acbff2016-06-17 14:45:16 -07001024
A.R Karthickb17e2022017-01-27 11:29:26 -08001025 params = test_manifest.server.split(':')
A R Karthick81acbff2016-06-17 14:45:16 -07001026 ip = params[0]
1027 port = CORD_TEST_PORT
1028 if len(params) > 1:
1029 port = int(params[1])
A R Karthick92a0e5a2016-06-22 17:11:05 -07001030
A R Karthick07608ef2016-08-23 16:51:19 -07001031 try:
1032 maas_api_key = FabricMAAS.get_api_key()
1033 except:
1034 maas_api_key = 'UNKNOWN'
1035
1036 ssh_key_file = set_ssh_key_file(args.identity_file)
1037
A R Karthick92a0e5a2016-06-22 17:11:05 -07001038 #provision the test container
1039 if not args.dont_provision:
A R Karthick2b93d6a2016-09-06 15:19:09 -07001040 test_cnt_env = { 'ONOS_CONTROLLER_IP' : ctlr_addr,
A R Karthick92a0e5a2016-06-22 17:11:05 -07001041 'ONOS_AAA_IP' : radius_ip,
A R Karthick8d03cc52016-06-28 14:51:59 -07001042 'QUAGGA_IP': ip,
A R Karthick92a0e5a2016-06-22 17:11:05 -07001043 'CORD_TEST_HOST' : ip,
1044 'CORD_TEST_PORT' : port,
A R Karthick65d950d2016-12-19 19:41:55 -08001045 'ONOS_RESTART' : 0 if test_manifest.olt and args.test_controller else 1,
1046 'LOG_LEVEL': test_manifest.log_level,
A R Karthick07608ef2016-08-23 16:51:19 -07001047 'HEAD_NODE': head_node if head_node else CORD_TEST_HOST,
A R Karthick973010f2017-02-06 16:41:51 -08001048 'MAAS_API_KEY': maas_api_key,
A.R Karthick57fa9372017-05-24 12:47:03 -07001049 'KARAF_VERSION' : test_manifest.karaf_version,
A R Karthickfa2caab2017-07-24 18:04:46 -07001050 'VOLTHA_ENABLED' : int(test_manifest.voltha_enable)
A R Karthick92a0e5a2016-06-22 17:11:05 -07001051 }
A R Karthick07608ef2016-08-23 16:51:19 -07001052
1053 if ssh_key_file:
1054 test_cnt_env['SSH_KEY_FILE'] = ssh_key_file
A.R Karthick5968e0d2017-05-16 14:50:46 -07001055 olt_conf_test_loc = os.path.join(CordTester.sandbox_setup, os.path.basename(olt_config_file))
1056 test_cnt_env['OLT_CONFIG_FILE'] = olt_conf_test_loc
A R Karthick65d950d2016-12-19 19:41:55 -08001057 if test_manifest.olt:
A R Karthick92a0e5a2016-06-22 17:11:05 -07001058 test_cnt_env['OLT_CONFIG'] = olt_conf_test_loc
A R Karthick5af23712017-01-20 09:49:24 -08001059 if test_manifest.iterations is not None:
1060 test_cnt_env['ITERATIONS'] = iterations
A.R Karthick8b2f1e32017-02-09 15:10:07 -08001061 if use_manifest:
1062 test_cnt_env['MANIFEST'] = os.path.join(CordTester.sandbox_setup,
1063 os.path.basename(args.manifest))
A R Karthickcaac5542017-03-06 16:20:57 -08001064
1065 openstack_setup(test_cnt_env)
1066
A R Karthick92a0e5a2016-06-22 17:11:05 -07001067 test_cnt = CordTester((),
A R Karthick2b93d6a2016-09-06 15:19:09 -07001068 ctlr_ip = ctlr_addr,
A R Karthick92a0e5a2016-06-22 17:11:05 -07001069 image = nose_cnt['image'],
A R Karthick07608ef2016-08-23 16:51:19 -07001070 prefix = Container.IMAGE_PREFIX,
A R Karthick92a0e5a2016-06-22 17:11:05 -07001071 tag = nose_cnt['tag'],
1072 env = test_cnt_env,
1073 rm = False,
A R Karthick85eb1862017-01-23 16:10:57 -08001074 update = update_map['test'],
1075 network = test_manifest.docker_network)
A R Karthick92a0e5a2016-06-22 17:11:05 -07001076
A R Karthick65d950d2016-12-19 19:41:55 -08001077 if test_manifest.start_switch or not test_manifest.olt:
A R Karthicke8bd80e2017-08-01 12:36:24 -07001078 test_cnt.start_switch(test_manifest)
A R Karthick92a0e5a2016-06-22 17:11:05 -07001079 if test_cnt.olt:
1080 test_cnt.setup_intfs(port_num = 0)
1081 print('Test container %s started and provisioned to run tests using nosetests' %(test_cnt.name))
1082
1083 #Finally start the test server and daemonize
A R Karthick14118c62016-07-27 14:54:04 -07001084 try:
A R Karthickbd82f362016-11-10 15:08:52 -08001085 cord_test_server_start(daemonize = not args.foreground, cord_test_host = ip, cord_test_port = port,
1086 onos_cord = onos_cord, foreground = args.foreground)
A R Karthick14118c62016-07-27 14:54:04 -07001087 except socket.error, e:
1088 #the test agent address could be remote or already running. Exit gracefully
1089 sys.exit(0)
Chetan Gaonker93e302d2016-04-05 10:51:07 -07001090
A R Karthick9a5edc42016-08-24 19:10:22 -07001091 return 0
1092
Chetan Gaonker503032a2016-05-12 12:06:29 -07001093def cleanupTests(args):
A R Karthick757eb4d2017-01-09 14:51:16 -08001094 if args.manifest and os.access(args.manifest, os.F_OK):
1095 manifest = TestManifest(manifest = args.manifest)
1096 args.prefix = manifest.image_prefix
1097 args.olt = manifest.olt
A.R Karthick5968e0d2017-05-16 14:50:46 -07001098 args.olt_config = manifest.olt_config
A R Karthick757eb4d2017-01-09 14:51:16 -08001099 args.onos = manifest.onos_image
1100 args.server = manifest.server
A.R Karthickb17e2022017-01-27 11:29:26 -08001101 args.onos_ip = manifest.onos_ip
1102 args.radius_ip = manifest.radius_ip
1103 args.onos_cord = manifest.onos_cord
A.R Karthickf184b342017-01-27 19:30:50 -08001104 args.service_profile = manifest.service_profile
1105 args.synchronizer = manifest.synchronizer
A.R Karthick57fa9372017-05-24 12:47:03 -07001106 args.voltha_loc = manifest.voltha_loc
A.R Karthickb17e2022017-01-27 11:29:26 -08001107 else:
1108 args.onos_ip = None
1109 args.radius_ip = None
1110 if args.test_controller:
1111 ips = args.test_controller.split('/')
1112 args.onos_ip = ips[0]
1113 if len(ips) > 1:
1114 args.radius_ip = ips[1]
A R Karthick757eb4d2017-01-09 14:51:16 -08001115
A R Karthick2b93d6a2016-09-06 15:19:09 -07001116 image_name = args.onos
A R Karthick07608ef2016-08-23 16:51:19 -07001117 prefix = args.prefix
1118 if prefix:
1119 prefix += '/'
1120 test_container = '{}{}:candidate'.format(prefix, CordTester.IMAGE)
Chetan Gaonker503032a2016-05-12 12:06:29 -07001121 print('Cleaning up Test containers ...')
1122 Container.cleanup(test_container)
A R Karthickb50f5592016-07-26 12:19:29 -07001123 if args.olt:
1124 print('Cleaning up test container OLT configuration')
A.R Karthick5968e0d2017-05-16 14:50:46 -07001125 CordTester.cleanup_intfs(args.olt_config)
A R Karthick2b93d6a2016-09-06 15:19:09 -07001126
1127 onos_list = [ c['Names'][0][1:] for c in Container.dckr.containers() if c['Image'] == image_name ]
1128 if len(onos_list) > 1:
1129 for onos in onos_list:
1130 Container.dckr.kill(onos)
1131 Container.dckr.remove_container(onos, force=True)
A R Karthickec2db322016-11-17 15:06:01 -08001132 for index in range(len(onos_list)):
1133 volume = '{}-data'.format(Onos.NAME) if index == 0 else '{}-{}-data'.format(Onos.NAME, index+1)
1134 Onos.remove_data_map(volume, Onos.guest_data_dir)
A R Karthick9d48c652016-09-15 09:16:36 -07001135 Onos.cleanup_runtime()
A R Karthickec2db322016-11-17 15:06:01 -08001136
A R Karthick394976f2017-01-31 14:25:16 -08001137 radius_container = '{}{}:candidate'.format(prefix, Radius.IMAGE)
1138 quagga_container = '{}{}:candidate'.format(prefix, Quagga.IMAGE)
1139 Container.cleanup(radius_container)
1140 Container.cleanup(quagga_container)
A.R Karthick57fa9372017-05-24 12:47:03 -07001141 if args.voltha_loc:
1142 voltha = VolthaService(args.voltha_loc, args.onos_ip)
1143 voltha.stop()
1144
A.R Karthickb17e2022017-01-27 11:29:26 -08001145 if args.onos_cord:
A.R Karthickf184b342017-01-27 19:30:50 -08001146 #try restoring the onos cord instance
1147 try:
1148 onos_cord = OnosCord(args.onos_ip, args.onos_cord, args.service_profile, args.synchronizer, start = False)
1149 onos_cord.restore(force = True)
1150 except Exception as e:
1151 print(e)
A.R Karthickb17e2022017-01-27 11:29:26 -08001152
A.R Karthick842f0122016-09-28 14:48:47 -07001153 if args.xos:
1154 ##cleanup XOS images
1155 xos_images = ( '{}:{}'.format(XosServer.IMAGE,XosServer.TAG),
1156 '{}:{}'.format(XosSynchronizerOpenstack.IMAGE,
1157 XosSynchronizerOpenstack.TAG),
1158 '{}:{}'.format(XosSynchronizerOnboarding.IMAGE,
1159 XosSynchronizerOnboarding.TAG),
1160 '{}:{}'.format(XosSynchronizerOpenvpn.IMAGE,
1161 XosSynchronizerOpenvpn.TAG),
1162 '{}:{}'.format(XosPostgresql.IMAGE,
1163 XosPostgresql.TAG),
1164 '{}:{}'.format(XosSyndicateMs.IMAGE,
1165 XosSyndicateMs.TAG),
1166 )
1167 for img in xos_images:
1168 print('Cleaning up XOS image: %s' %img)
1169 Container.cleanup(img)
1170
A R Karthicke99ab5c2016-09-30 13:59:57 -07001171 server_params = args.server.split(':')
1172 server_host = server_params[0]
1173 server_port = CORD_TEST_PORT
1174 if len(server_params) > 1:
1175 server_port = int(server_params[1])
1176 cord_test_server_shutdown(server_host, server_port)
A R Karthick9a5edc42016-08-24 19:10:22 -07001177 return 0
Chetan Gaonker503032a2016-05-12 12:06:29 -07001178
1179def listTests(args):
1180 if args.test == 'all':
1181 tests = CordTester.ALL_TESTS
1182 else:
A R Karthickacae3b42016-05-12 15:27:24 -07001183 tests = args.test.split('-')
Chetan Gaonker503032a2016-05-12 12:06:29 -07001184 CordTester.list_tests(tests)
A R Karthickcee37412016-08-29 10:10:56 -07001185 return 0
ChetanGaonkereadad482016-08-26 01:21:47 -07001186
1187def getMetrics(args):
A R Karthickcee37412016-08-29 10:10:56 -07001188 try:
1189 detail = c.inspect_container(args.container)
1190 except:
1191 print('Unknown container %s' %args.container)
1192 return 0
1193 user_hz = os.sysconf(os.sysconf_names['SC_CLK_TCK'])
ChetanGaonkereadad482016-08-26 01:21:47 -07001194 state = detail["State"]
1195 if bool(state["Paused"]):
1196 print("Container is in Paused State")
1197 elif bool(state["Running"]):
1198 print("Container is in Running State")
1199 elif int(state["ExitCode"]) == 0:
1200 print("Container is in Stopped State")
1201 else:
1202 print("Container is in Crashed State")
1203
A R Karthickcee37412016-08-29 10:10:56 -07001204 print("Ip Address of the container: " +detail['NetworkSettings']['IPAddress'])
ChetanGaonkereadad482016-08-26 01:21:47 -07001205
1206 if bool(detail["State"]["Running"]):
1207 container_id = detail['Id']
1208 cpu_usage = {}
A R Karthickcee37412016-08-29 10:10:56 -07001209 cur_usage = 0
1210 last_usage = 0
1211 for i in range(2):
1212 with open('/sys/fs/cgroup/cpuacct/docker/' + container_id + '/cpuacct.stat', 'r') as f:
1213 for line in f:
1214 m = re.search(r"(system|user)\s+(\d+)", line)
1215 if m:
1216 cpu_usage[m.group(1)] = int(m.group(2))
1217 cpu = cpu_usage["system"] + cpu_usage["user"]
1218 last_usage = cur_usage
1219 cur_usage = cpu
1220 time.sleep(1)
1221 cpu_percent = (cur_usage - last_usage)*100.0/user_hz
1222 print("CPU Usage: %.2f %%" %(cpu_percent))
ChetanGaonkereadad482016-08-26 01:21:47 -07001223 else:
1224 print(0)
1225
1226 if bool(detail["State"]["Running"]):
1227 container_id = detail['Id']
A R Karthickcee37412016-08-29 10:10:56 -07001228 print("Docker Port Info:")
ChetanGaonkereadad482016-08-26 01:21:47 -07001229 cmd = "sudo docker port {}".format(container_id)
1230 os.system(cmd)
1231
1232 if bool(detail["State"]["Running"]):
1233 container_id = detail['Id']
1234 with open('/sys/fs/cgroup/memory/docker/' + container_id + '/memory.stat', 'r') as f:
1235 for line in f:
1236 m = re.search(r"total_rss\s+(\d+)", line)
1237 if m:
A R Karthickcee37412016-08-29 10:10:56 -07001238 mem = int(m.group(1))
1239 print("Memory: %s KB "%(mem/1024.0))
ChetanGaonkereadad482016-08-26 01:21:47 -07001240 o = re.search(r"usage\s+(\d+)", line)
1241 if o:
A R Karthickcee37412016-08-29 10:10:56 -07001242 print("Usage: %s "%(o.group(1)))
ChetanGaonkereadad482016-08-26 01:21:47 -07001243 p = re.search(r"max_usage\s+(\d+)", line)
1244 if p:
A R Karthickcee37412016-08-29 10:10:56 -07001245 print("Max Usage: %s "%(p.group(1)))
ChetanGaonkereadad482016-08-26 01:21:47 -07001246
1247 if bool(detail["State"]["Running"]):
1248 container_id = detail['Id']
1249 with open('/sys/fs/cgroup/cpuacct/docker/' + container_id + '/cpuacct.stat', 'r') as f:
1250 for line in f:
1251 m = re.search(r"user\s+(\d+)", line)
1252 if m:
A R Karthickcee37412016-08-29 10:10:56 -07001253 user_ticks = int(m.group(1))
1254 print("Time spent by running processes: %.2f ms"%(user_ticks*1000.0/user_hz))
1255 print("List Networks:")
ChetanGaonkereadad482016-08-26 01:21:47 -07001256 cmd = "docker network ls"
1257 os.system(cmd)
A R Karthick9a5edc42016-08-24 19:10:22 -07001258 return 0
Chetan Gaonker503032a2016-05-12 12:06:29 -07001259
1260def buildImages(args):
A R Karthick07608ef2016-08-23 16:51:19 -07001261 tag = 'candidate'
1262 prefix = args.prefix
1263 if prefix:
1264 prefix += '/'
Chetan Gaonker503032a2016-05-12 12:06:29 -07001265 if args.image == 'all' or args.image == 'quagga':
A R Karthick07608ef2016-08-23 16:51:19 -07001266 image_name = '{}{}:{}'.format(prefix, Quagga.IMAGE, tag)
1267 Quagga.build_image(image_name)
A.R Karthick95d044e2016-06-10 18:44:36 -07001268
Chetan Gaonker503032a2016-05-12 12:06:29 -07001269 if args.image == 'all' or args.image == 'radius':
A R Karthick07608ef2016-08-23 16:51:19 -07001270 image_name = '{}{}:{}'.format(prefix, Radius.IMAGE, tag)
1271 Radius.build_image(image_name)
Chetan Gaonker503032a2016-05-12 12:06:29 -07001272
1273 if args.image == 'all' or args.image == 'test':
A R Karthick07608ef2016-08-23 16:51:19 -07001274 image_name = '{}{}:{}'.format(prefix, CordTester.IMAGE, tag)
1275 CordTester.build_image(image_name)
Chetan Gaonker503032a2016-05-12 12:06:29 -07001276
A R Karthick9a5edc42016-08-24 19:10:22 -07001277 return 0
1278
A R Karthickbec27762016-07-28 10:59:34 -07001279def startImages(args):
A R Karthickbec27762016-07-28 10:59:34 -07001280 ##starts the latest ONOS image
A R Karthick07608ef2016-08-23 16:51:19 -07001281 onos_cnt = {'tag': 'latest'}
1282 image_names = args.onos.rsplit(':', 1)
1283 onos_cnt['image'] = image_names[0]
1284 if len(image_names) > 1:
1285 if image_names[1].find('/') < 0:
1286 onos_cnt['tag'] = image_names[1]
1287 else:
1288 #tag cannot have slashes
1289 onos_cnt['image'] = args.onos
1290
A R Karthickbec27762016-07-28 10:59:34 -07001291 if args.image == 'all' or args.image == 'onos':
A R Karthick07608ef2016-08-23 16:51:19 -07001292 onos = Onos(image = onos_cnt['image'], tag = onos_cnt['tag'])
A R Karthickbec27762016-07-28 10:59:34 -07001293 print('ONOS started with ip %s' %(onos.ip()))
1294
1295 if args.image == 'all' or args.image == 'quagga':
A R Karthick07608ef2016-08-23 16:51:19 -07001296 quagga = Quagga(prefix = args.prefix)
A R Karthickbec27762016-07-28 10:59:34 -07001297 print('Quagga started with ip %s' %(quagga.ip()))
1298
1299 if args.image == 'all' or args.image == 'radius':
A R Karthick07608ef2016-08-23 16:51:19 -07001300 radius = Radius(prefix = args.prefix)
A R Karthickbec27762016-07-28 10:59:34 -07001301 print('Radius started with ip %s' %(radius.ip()))
1302
A R Karthick9a5edc42016-08-24 19:10:22 -07001303 return 0
1304
A R Karthickea8bfce2016-10-13 16:32:07 -07001305def xosCommand(args):
1306 update = False
1307 profile = args.profile
1308 if args.command == 'update':
1309 update = True
1310 xos = XosServiceProfile(profile = profile, update = update)
1311 if args.command == 'build':
1312 xos.build_images(force = True)
1313 if args.command == 'start':
1314 xos.start_services()
1315 if args.command == 'stop':
1316 xos.stop_services(rm = True)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001317 return 0
1318
Chetan Gaonker93e302d2016-04-05 10:51:07 -07001319if __name__ == '__main__':
Chetan Gaonker678743f2016-04-26 09:54:31 -07001320 parser = ArgumentParser(description='Cord Tester')
Chetan Gaonker503032a2016-05-12 12:06:29 -07001321 subparser = parser.add_subparsers()
1322 parser_run = subparser.add_parser('run', help='Run cord tester')
1323 parser_run.add_argument('-t', '--test-type', default=test_type_default, help='Specify test type or test case to run')
1324 parser_run.add_argument('-o', '--onos', default=onos_image_default, type=str, help='ONOS container image')
Chetan Gaonker503032a2016-05-12 12:06:29 -07001325 parser_run.add_argument('-q', '--quagga',action='store_true',help='Provision quagga container for vrouter')
1326 parser_run.add_argument('-a', '--app', default=onos_app_file, type=str, help='Cord ONOS app filename')
A R Karthick07608ef2016-08-23 16:51:19 -07001327 parser_run.add_argument('-l', '--olt', action='store_true', help='Use OLT config')
A.R Karthick5968e0d2017-05-16 14:50:46 -07001328 parser_run.add_argument('-olt-config', '--olt-config', default=olt_config_default, type=str, help='Provide OLT configuration')
Chetan Gaonker503032a2016-05-12 12:06:29 -07001329 parser_run.add_argument('-e', '--test-controller', default='', type=str, help='External test controller ip for Onos and/or radius server. '
Chetan Gaonker5209fe82016-04-19 10:09:53 -07001330 'Eg: 10.0.0.2/10.0.0.3 to specify ONOS and Radius ip to connect')
A R Karthick81acbff2016-06-17 14:45:16 -07001331 parser_run.add_argument('-r', '--server', default=cord_test_server_address, type=str,
1332 help='ip:port address to connect for cord test server for container requests')
Chetan Gaonker503032a2016-05-12 12:06:29 -07001333 parser_run.add_argument('-k', '--keep', action='store_true', help='Keep test container after tests')
1334 parser_run.add_argument('-s', '--start-switch', action='store_true', help='Start OVS when running under OLT config')
1335 parser_run.add_argument('-u', '--update', default='none', choices=['test','quagga','radius', 'all'], type=str, help='Update cord tester container images. '
1336 'Eg: --update=quagga to rebuild quagga image.'
1337 ' --update=radius to rebuild radius server image.'
1338 ' --update=test to rebuild cord test image.(Default)'
1339 ' --update=all to rebuild all cord tester images.')
A R Karthick1f03e912016-05-18 11:39:22 -07001340 parser_run.add_argument('-n', '--num-containers', default=1, type=int,
1341 help='Specify number of test containers to spawn for tests')
A R Karthicka013a272016-08-16 16:40:19 -07001342 parser_run.add_argument('-c', '--container', default='', type=str, help='Test container name for running tests')
A R Karthick07608ef2016-08-23 16:51:19 -07001343 parser_run.add_argument('-m', '--manifest', default='', type=str, help='Provide test configuration manifest')
1344 parser_run.add_argument('-p', '--prefix', default='', type=str, help='Provide container image prefix')
1345 parser_run.add_argument('-d', '--no-switch', action='store_true', help='Dont start test switch.')
1346 parser_run.add_argument('-i', '--identity-file', default=identity_file_default,
1347 type=str, help='ssh identity file to access compute nodes from test container')
ChetanGaonkerdbd4e4b2016-10-28 17:40:11 -07001348 parser_run.add_argument('-j', '--onos-instances', default=1, type=int,
1349 help='Specify number to test onos instances to form cluster')
A R Karthick09dbc6d2016-11-22 10:37:42 -08001350 parser_run.add_argument('-v', '--shared-volume', action='store_true', help='Start ONOS cluster instances with shared volume')
A.R Karthickc4e474d2016-12-12 15:24:57 -08001351 parser_run.add_argument('-async', '--async-mode', action='store_true',
1352 help='Start ONOS cluster instances in async mode')
A R Karthicke14fc022016-12-08 14:50:29 -08001353 parser_run.add_argument('-log', '--log-level', default=onos_log_level,
1354 choices=['DEBUG','TRACE','ERROR','WARN','INFO'],
1355 type=str,
1356 help='Specify the log level for the test cases')
A R Karthickc69d73e2017-01-20 11:44:34 -08001357 parser_run.add_argument('-jvm-heap-size', '--jvm-heap-size', default='', type=str, help='ONOS JVM heap size')
A R Karthick44a95602017-01-23 16:17:16 -08001358 parser_run.add_argument('-network', '--network', default='', type=str, help='Docker network to attach')
A.R Karthickb17e2022017-01-27 11:29:26 -08001359 parser_run.add_argument('-onos-cord', '--onos-cord', default='', type=str,
1360 help='Specify config location for ONOS cord when running on podd')
A.R Karthickf184b342017-01-27 19:30:50 -08001361 parser_run.add_argument('-service-profile', '--service-profile', default='', type=str,
1362 help='Specify config location for ONOS cord service profile when running on podd.'
1363 'Eg: $HOME/service-profile/cord-pod')
1364 parser_run.add_argument('-synchronizer', '--synchronizer', default='', type=str,
1365 help='Specify the synchronizer to use for ONOS cord instance when running on podd.'
1366 'Eg: vtn,fabric,cord')
A.R Karthickdda22062017-02-09 14:39:20 -08001367 parser_run.add_argument('-karaf', '--karaf', default='3.0.8', type=str, help='Karaf version for ONOS')
A.R Karthick57fa9372017-05-24 12:47:03 -07001368 parser_run.add_argument('-voltha-loc', '--voltha-loc', default='', type=str,
1369 help='Specify the voltha location in order to start voltha')
1370 parser_run.add_argument('-voltha-intf', '--voltha-intf', default='eth0', type=str,
1371 help='Specify the voltha interface for voltha to listen')
A R Karthickfa2caab2017-07-24 18:04:46 -07001372 parser_run.add_argument('-voltha-enable', '--voltha-enable', action='store_true',
1373 help='Run the tests with voltha environment enabled')
A R Karthick184945a2017-07-25 17:23:57 -07001374 parser_run.add_argument('-expose-port', '--expose-port', action='store_true',
1375 help='Start ONOS by exposing the controller ports to the host.'
1376 'Add +1 for every other onos/cluster instance when running more than 1 ONOS instances')
Chetan Gaonker503032a2016-05-12 12:06:29 -07001377 parser_run.set_defaults(func=runTest)
1378
A R Karthick81acbff2016-06-17 14:45:16 -07001379 parser_setup = subparser.add_parser('setup', help='Setup cord tester environment')
1380 parser_setup.add_argument('-o', '--onos', default=onos_image_default, type=str, help='ONOS container image')
1381 parser_setup.add_argument('-r', '--server', default=cord_test_server_address, type=str,
1382 help='ip:port address for cord test server to listen for container restart requests')
1383 parser_setup.add_argument('-q', '--quagga',action='store_true',help='Provision quagga container for vrouter')
1384 parser_setup.add_argument('-a', '--app', default=onos_app_file, type=str, help='Cord ONOS app filename')
1385 parser_setup.add_argument('-e', '--test-controller', default='', type=str, help='External test controller ip for Onos and/or radius server. '
1386 'Eg: 10.0.0.2/10.0.0.3 to specify ONOS and Radius ip to connect')
1387 parser_setup.add_argument('-u', '--update', default='none', choices=['quagga','radius', 'all'], type=str, help='Update cord tester container images. '
1388 'Eg: --update=quagga to rebuild quagga image.'
1389 ' --update=radius to rebuild radius server image.'
1390 ' --update=all to rebuild all cord tester images.')
A R Karthick92a0e5a2016-06-22 17:11:05 -07001391 parser_setup.add_argument('-d', '--dont-provision', action='store_true', help='Dont start test container.')
A R Karthick07608ef2016-08-23 16:51:19 -07001392 parser_setup.add_argument('-l', '--olt', action='store_true', help='Use OLT config')
A.R Karthick5968e0d2017-05-16 14:50:46 -07001393 parser_setup.add_argument('-olt-config', '--olt-config', default=olt_config_default, type=str, help='Provide OLT configuration')
A R Karthicke14fc022016-12-08 14:50:29 -08001394 parser_setup.add_argument('-log', '--log-level', default=onos_log_level, type=str,
1395 choices=['DEBUG','TRACE','ERROR','WARN','INFO'],
1396 help='Specify the log level for the test cases')
A R Karthick92a0e5a2016-06-22 17:11:05 -07001397 parser_setup.add_argument('-s', '--start-switch', action='store_true', help='Start OVS when running under OLT config')
A.R Karthickb17e2022017-01-27 11:29:26 -08001398 parser_setup.add_argument('-onos-cord', '--onos-cord', default='', type=str,
1399 help='Specify config location for ONOS cord when running on podd')
A.R Karthickf184b342017-01-27 19:30:50 -08001400 parser_setup.add_argument('-service-profile', '--service-profile', default='', type=str,
1401 help='Specify config location for ONOS cord service profile when running on podd.'
1402 'Eg: $HOME/service-profile/cord-pod')
1403 parser_setup.add_argument('-synchronizer', '--synchronizer', default='', type=str,
1404 help='Specify the synchronizer to use for ONOS cord instance when running on podd.'
1405 'Eg: vtn,fabric,cord')
A R Karthick07608ef2016-08-23 16:51:19 -07001406 parser_setup.add_argument('-m', '--manifest', default='', type=str, help='Provide test configuration manifest')
1407 parser_setup.add_argument('-p', '--prefix', default='', type=str, help='Provide container image prefix')
1408 parser_setup.add_argument('-i', '--identity-file', default=identity_file_default,
1409 type=str, help='ssh identity file to access compute nodes from test container')
A R Karthick2b93d6a2016-09-06 15:19:09 -07001410 parser_setup.add_argument('-n', '--onos-instances', default=1, type=int,
A R Karthickbd82f362016-11-10 15:08:52 -08001411 help='Specify number of test onos instances to spawn')
A R Karthick09dbc6d2016-11-22 10:37:42 -08001412 parser_setup.add_argument('-v', '--shared-volume', action='store_true',
1413 help='Start ONOS cluster instances with shared volume')
A.R Karthickc4e474d2016-12-12 15:24:57 -08001414 parser_setup.add_argument('-async', '--async-mode', action='store_true',
1415 help='Start ONOS cluster instances in async mode')
A R Karthickbd82f362016-11-10 15:08:52 -08001416 parser_setup.add_argument('-f', '--foreground', action='store_true', help='Run in foreground')
A R Karthickc69d73e2017-01-20 11:44:34 -08001417 parser_setup.add_argument('-jvm-heap-size', '--jvm-heap-size', default='', type=str, help='ONOS JVM heap size')
A R Karthick44a95602017-01-23 16:17:16 -08001418 parser_setup.add_argument('-network', '--network', default='', type=str, help='Docker network to attach')
A.R Karthickdda22062017-02-09 14:39:20 -08001419 parser_setup.add_argument('-karaf', '--karaf', default='3.0.8', type=str, help='Karaf version for ONOS')
A.R Karthick57fa9372017-05-24 12:47:03 -07001420 parser_setup.add_argument('-voltha-loc', '--voltha-loc', default='', type=str,
1421 help='Specify the voltha location in order to start voltha')
1422 parser_setup.add_argument('-voltha-intf', '--voltha-intf', default='eth0', type=str,
1423 help='Specify the voltha interface for voltha to listen')
A R Karthickfa2caab2017-07-24 18:04:46 -07001424 parser_setup.add_argument('-voltha-enable', '--voltha-enable', action='store_true',
1425 help='Run the tests with voltha environment enabled')
A R Karthick184945a2017-07-25 17:23:57 -07001426 parser_setup.add_argument('-expose-port', '--expose-port', action='store_true',
1427 help='Start ONOS by exposing the controller ports to the host.'
1428 'Add +1 for every other onos/cluster instance when running more than 1 ONOS instances')
A R Karthick81acbff2016-06-17 14:45:16 -07001429 parser_setup.set_defaults(func=setupCordTester)
1430
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001431 parser_xos = subparser.add_parser('xos', help='Building xos into cord tester environment')
A R Karthickea8bfce2016-10-13 16:32:07 -07001432 parser_xos.add_argument('command', choices=['build', 'update', 'start', 'stop'])
1433 parser_xos.add_argument('-p', '--profile', default='cord-pod', type=str, help='Provide service profile')
1434 parser_xos.set_defaults(func=xosCommand)
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001435
Chetan Gaonker503032a2016-05-12 12:06:29 -07001436 parser_list = subparser.add_parser('list', help='List test cases')
1437 parser_list.add_argument('-t', '--test', default='all', help='Specify test type to list test cases. '
1438 'Eg: -t tls to list tls test cases.'
1439 ' -t tls-dhcp-vrouter to list tls,dhcp and vrouter test cases.'
1440 ' -t all to list all test cases.')
1441 parser_list.set_defaults(func=listTests)
1442
1443 parser_build = subparser.add_parser('build', help='Build cord test container images')
ChetanGaonker2c0e9bb2016-09-21 13:38:37 -07001444 parser_build.add_argument('image', choices=['quagga', 'radius', 'test','all'])
A.R Karthick842f0122016-09-28 14:48:47 -07001445 parser_build.add_argument('-p', '--prefix', default='', type=str, help='Provide container image prefix')
Chetan Gaonker503032a2016-05-12 12:06:29 -07001446 parser_build.set_defaults(func=buildImages)
1447
ChetanGaonkereadad482016-08-26 01:21:47 -07001448 parser_metrics = subparser.add_parser('metrics', help='Info of container')
1449 parser_metrics.add_argument("container", help="Container name")
1450 parser_metrics.set_defaults(func=getMetrics)
1451
A R Karthickbec27762016-07-28 10:59:34 -07001452 parser_start = subparser.add_parser('start', help='Start cord tester containers')
A R Karthick07608ef2016-08-23 16:51:19 -07001453 parser_start.add_argument('-p', '--prefix', default='', type=str, help='Provide container image prefix')
1454 parser_start.add_argument('-o', '--onos', default=onos_image_default, type=str, help='ONOS container image')
A R Karthickbec27762016-07-28 10:59:34 -07001455 parser_start.add_argument('image', choices=['onos', 'quagga', 'radius', 'all'])
1456 parser_start.set_defaults(func=startImages)
1457
Chetan Gaonker503032a2016-05-12 12:06:29 -07001458 parser_cleanup = subparser.add_parser('cleanup', help='Cleanup test containers')
A R Karthick07608ef2016-08-23 16:51:19 -07001459 parser_cleanup.add_argument('-p', '--prefix', default='', type=str, help='Provide container image prefix')
1460 parser_cleanup.add_argument('-l', '--olt', action = 'store_true', help = 'Cleanup OLT config')
A.R Karthick5968e0d2017-05-16 14:50:46 -07001461 parser_cleanup.add_argument('-olt-config', '--olt-config', default=olt_config_default, type=str, help='Provide OLT configuration')
A R Karthick2b93d6a2016-09-06 15:19:09 -07001462 parser_cleanup.add_argument('-o', '--onos', default=onos_image_default, type=str,
1463 help='ONOS container image to cleanup')
A.R Karthick842f0122016-09-28 14:48:47 -07001464 parser_cleanup.add_argument('-x', '--xos', action='store_true',
1465 help='Cleanup XOS containers')
A R Karthicke99ab5c2016-09-30 13:59:57 -07001466 parser_cleanup.add_argument('-r', '--server', default=cord_test_server_address, type=str,
1467 help='ip:port address for cord test server to cleanup')
A.R Karthickb17e2022017-01-27 11:29:26 -08001468 parser_cleanup.add_argument('-e', '--test-controller', default='', type=str,
1469 help='External test controller ip for Onos and/or radius server. '
1470 'Eg: 10.0.0.2/10.0.0.3 to specify ONOS and Radius ip')
1471 parser_cleanup.add_argument('-onos-cord', '--onos-cord', default='', type=str,
1472 help='Specify config location for ONOS cord instance when running on podd to restore')
A.R Karthickf184b342017-01-27 19:30:50 -08001473 parser_cleanup.add_argument('-service-profile', '--service-profile', default='', type=str,
1474 help='Specify config location for ONOS cord service profile when running on podd.'
1475 'Eg: $HOME/service-profile/cord-pod')
1476 parser_cleanup.add_argument('-synchronizer', '--synchronizer', default='', type=str,
1477 help='Specify the synchronizer to use for ONOS cord instance when running on podd.'
1478 'Eg: vtn,fabric,cord')
A R Karthick757eb4d2017-01-09 14:51:16 -08001479 parser_cleanup.add_argument('-m', '--manifest', default='', type=str, help='Provide test manifest')
A.R Karthick57fa9372017-05-24 12:47:03 -07001480 parser_cleanup.add_argument('-voltha-loc', '--voltha-loc', default='', type=str,
1481 help='Specify the voltha location')
Chetan Gaonker503032a2016-05-12 12:06:29 -07001482 parser_cleanup.set_defaults(func=cleanupTests)
1483
ChetanGaonkereadad482016-08-26 01:21:47 -07001484 c = Client(**(kwargs_from_env()))
1485
Chetan Gaonker93e302d2016-04-05 10:51:07 -07001486 args = parser.parse_args()
A R Karthick9a5edc42016-08-24 19:10:22 -07001487 res = args.func(args)
1488 sys.exit(res)