blob: ccd6d92140853b1da7fa180e99399e6887082556 [file] [log] [blame]
Chetan Gaonkercb122cc2016-05-10 10:58:34 -07001#!/usr/bin/env python
A.R Karthick95d044e2016-06-10 18:44:36 -07002#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07003# Copyright 2016-present Ciena Corporation
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
A.R Karthick95d044e2016-06-10 18:44:36 -07008#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07009# http://www.apache.org/licenses/LICENSE-2.0
A.R Karthick95d044e2016-06-10 18:44:36 -070010#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070011# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
Chetan Gaonker93e302d2016-04-05 10:51:07 -070017from argparse import ArgumentParser
18import os,sys,time
Chetan Gaonker4d842ad2016-04-26 10:04:24 -070019utils_dir = os.path.join( os.path.dirname(os.path.realpath(__file__)), '../utils')
Chetan Gaonker7142a342016-04-07 14:53:12 -070020sys.path.append(utils_dir)
Chetan Gaonker93e302d2016-04-05 10:51:07 -070021from OnosCtrl import OnosCtrl
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -070022from OltConfig import OltConfig
A R Karthick1f03e912016-05-18 11:39:22 -070023from threadPool import ThreadPool
Chetan Gaonker3533faa2016-04-25 17:50:14 -070024from CordContainer import *
A R Karthick81acbff2016-06-17 14:45:16 -070025from CordTestServer import cord_test_server_start, cord_test_server_stop, CORD_TEST_HOST, CORD_TEST_PORT
Chetan Gaonker93e302d2016-04-05 10:51:07 -070026
Chetan Gaonker93e302d2016-04-05 10:51:07 -070027class CordTester(Container):
Chetan Gaonker93e302d2016-04-05 10:51:07 -070028 sandbox = '/root/test'
Chetan Gaonker7142a342016-04-07 14:53:12 -070029 sandbox_setup = '/root/test/src/test/setup'
Chetan Gaonker4d842ad2016-04-26 10:04:24 -070030 tester_base = os.path.dirname(os.path.realpath(__file__))
31 tester_paths = os.path.realpath(__file__).split(os.path.sep)
A R Karthickb7e80902016-05-17 09:38:31 -070032 tester_path_index = tester_paths.index('src') - 1
Chetan Gaonker7142a342016-04-07 14:53:12 -070033 sandbox_host = os.path.sep.join(tester_paths[:tester_path_index+1])
Chetan Gaonker93e302d2016-04-05 10:51:07 -070034
35 host_guest_map = ( (sandbox_host, sandbox),
Chetan Gaonker85b7bd52016-04-20 10:29:12 -070036 ('/lib/modules', '/lib/modules'),
37 ('/var/run/docker.sock', '/var/run/docker.sock')
Chetan Gaonker93e302d2016-04-05 10:51:07 -070038 )
39 basename = 'cord-tester'
Chetan Gaonker503032a2016-05-12 12:06:29 -070040 IMAGE = 'cord-test/nose'
ChetanGaonker42414a32016-07-05 16:43:28 -070041 ALL_TESTS = ('tls', 'dhcp', 'dhcprelay','igmp', 'subscriber', 'vrouter', 'flows')
Chetan Gaonker93e302d2016-04-05 10:51:07 -070042
A R Karthick1f03e912016-05-18 11:39:22 -070043 def __init__(self, tests, instance = 0, num_instances = 1, ctlr_ip = None, image = IMAGE, tag = 'latest',
Chetan Gaonker85b7bd52016-04-20 10:29:12 -070044 env = None, rm = False, update = False):
A R Karthick1f03e912016-05-18 11:39:22 -070045 self.tests = tests
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -070046 self.ctlr_ip = ctlr_ip
Chetan Gaonker93e302d2016-04-05 10:51:07 -070047 self.rm = rm
48 self.name = self.get_name()
49 super(CordTester, self).__init__(self.name, image = image, tag = tag)
50 host_config = self.create_host_config(host_guest_map = self.host_guest_map, privileged = True)
51 volumes = []
Chetan Gaonkerb84835f2016-04-19 15:12:10 -070052 for _, g in self.host_guest_map:
Chetan Gaonker93e302d2016-04-05 10:51:07 -070053 volumes.append(g)
Chetan Gaonker85b7bd52016-04-20 10:29:12 -070054 if update is True or not self.img_exists():
Chetan Gaonkerb84835f2016-04-19 15:12:10 -070055 self.build_image(image)
Chetan Gaonker7142a342016-04-07 14:53:12 -070056 ##Remove test container if any
57 self.remove_container(self.name, force=True)
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -070058 if env is not None and env.has_key('OLT_CONFIG'):
59 self.olt = True
Chetan Gaonker5209fe82016-04-19 10:09:53 -070060 olt_conf_file = os.path.join(self.tester_base, 'olt_config.json')
61 olt_config = OltConfig(olt_conf_file)
62 self.port_map = olt_config.olt_port_map()
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -070063 else:
64 self.olt = False
Chetan Gaonker5209fe82016-04-19 10:09:53 -070065 self.port_map = None
A R Karthick1f03e912016-05-18 11:39:22 -070066 if env is not None:
67 env['TEST_HOST'] = self.name
68 env['TEST_INSTANCE'] = instance
69 env['TEST_INSTANCES'] = num_instances
Chetan Gaonker93e302d2016-04-05 10:51:07 -070070 print('Starting test container %s, image %s, tag %s' %(self.name, self.image, self.tag))
A.R Karthick95d044e2016-06-10 18:44:36 -070071 self.start(rm = False, volumes = volumes, environment = env,
Chetan Gaonker93e302d2016-04-05 10:51:07 -070072 host_config = host_config, tty = True)
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -070073
74 def execute_switch(self, cmd, shell = False):
75 if self.olt:
76 return os.system(cmd)
77 return self.execute(cmd, shell = shell)
78
79 def start_switch(self, bridge = 'ovsbr0', boot_delay = 2):
80 """Start OVS"""
81 ##Determine if OVS has to be started locally or not
82 s_file,s_sandbox = ('of-bridge-local.sh',self.tester_base) if self.olt else ('of-bridge.sh',self.sandbox_setup)
83 ovs_cmd = os.path.join(s_sandbox, '{0}'.format(s_file)) + ' {0}'.format(bridge)
84 if self.olt:
85 ovs_cmd += ' {0}'.format(self.ctlr_ip)
86 print('Starting OVS on the host')
87 else:
88 print('Starting OVS on test container %s' %self.name)
89 self.execute_switch(ovs_cmd)
Chetan Gaonker93e302d2016-04-05 10:51:07 -070090 status = 1
91 ## Wait for the LLDP flows to be added to the switch
92 tries = 0
Chetan Gaonkera52016e2016-05-05 15:19:59 -070093 while status != 0 and tries < 200:
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -070094 cmd = 'sudo ovs-ofctl dump-flows {0} | grep \"type=0x8942\"'.format(bridge)
95 status = self.execute_switch(cmd, shell = True)
Chetan Gaonker93e302d2016-04-05 10:51:07 -070096 tries += 1
97 if tries % 10 == 0:
98 print('Waiting for test switch to be connected to ONOS controller ...')
99
100 if status != 0:
101 print('Test Switch not connected to ONOS container.'
102 'Please remove ONOS container and restart the test')
103 if self.rm:
104 self.kill()
105 sys.exit(1)
106
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700107 if boot_delay:
108 time.sleep(boot_delay)
109
A R Karthick1f03e912016-05-18 11:39:22 -0700110 def setup_intfs(self, port_num = 0):
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700111 tester_intf_subnet = '192.168.100'
112 res = 0
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700113 host_intf = self.port_map['host']
114 start_vlan = self.port_map['start_vlan']
115 for port in self.port_map['ports']:
116 guest_if = port
A R Karthick1f03e912016-05-18 11:39:22 -0700117 local_if = '{0}_{1}'.format(guest_if, port_num+1)
118 guest_ip = '{0}.{1}/24'.format(tester_intf_subnet, port_num+1)
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700119 ##Use pipeworks to configure container interfaces on host/bridge interfaces
120 pipework_cmd = 'pipework {0} -i {1} -l {2} {3} {4}'.format(host_intf, guest_if, local_if, self.name, guest_ip)
121 if start_vlan != 0:
A R Karthick1f03e912016-05-18 11:39:22 -0700122 pipework_cmd += ' @{}'.format(start_vlan + port_num)
A.R Karthick95d044e2016-06-10 18:44:36 -0700123
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700124 res += os.system(pipework_cmd)
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700125 port_num += 1
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700126
A R Karthick1f03e912016-05-18 11:39:22 -0700127 return res, port_num
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700128
129 @classmethod
130 def get_name(cls):
131 cnt_name = '/{0}'.format(cls.basename)
132 cnt_name_len = len(cnt_name)
133 names = list(flatten(n['Names'] for n in cls.dckr.containers(all=True)))
134 test_names = filter(lambda n: n.startswith(cnt_name), names)
135 last_cnt_number = 0
136 if test_names:
137 last_cnt_name = reduce(lambda n1, n2: n1 if int(n1[cnt_name_len:]) > \
138 int(n2[cnt_name_len:]) else n2,
139 test_names)
140 last_cnt_number = int(last_cnt_name[cnt_name_len:])
141 test_cnt_name = cls.basename + str(last_cnt_number+1)
142 return test_cnt_name
143
144 @classmethod
145 def build_image(cls, image):
146 print('Building test container docker image %s' %image)
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700147 ovs_version = '2.5.0'
148 image_format = (ovs_version,)*4
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700149 dockerfile = '''
150FROM ubuntu:14.04
151MAINTAINER chetan@ciena.com
A R Karthickc762df42016-05-25 10:09:21 -0700152RUN apt-get update && \
153 apt-get install -y git git-core autoconf automake autotools-dev pkg-config \
154 make gcc g++ libtool libc6-dev cmake libpcap-dev libxerces-c2-dev \
155 unzip libpcre3-dev flex bison libboost-dev \
156 python python-pip python-setuptools python-scapy tcpdump doxygen doxypy wget \
157 openvswitch-common openvswitch-switch \
A R Karthick8cf29ac2016-06-30 16:25:14 -0700158 python-twisted python-sqlite sqlite3 python-pexpect telnet arping isc-dhcp-server
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700159RUN easy_install nose
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700160RUN mkdir -p /root/ovs
161WORKDIR /root
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700162RUN wget http://openvswitch.org/releases/openvswitch-{}.tar.gz -O /root/ovs/openvswitch-{}.tar.gz && \
163(cd /root/ovs && tar zxpvf openvswitch-{}.tar.gz && \
164 cd openvswitch-{} && \
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700165 ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --disable-ssl && make && make install)
166RUN service openvswitch-switch restart || /bin/true
A R Karthick81acbff2016-06-17 14:45:16 -0700167RUN pip install -U scapy scapy-ssl_tls monotonic configObj docker-py pyyaml nsenter pyroute2 netaddr python-daemon
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700168RUN mv /usr/sbin/tcpdump /sbin/
169RUN ln -sf /sbin/tcpdump /usr/sbin/tcpdump
A R Karthickf4999472016-07-01 16:42:13 -0700170RUN mv /usr/sbin/dhcpd /sbin/
171RUN ln -sf /sbin/dhcpd /usr/sbin/dhcpd
A R Karthickb7e80902016-05-17 09:38:31 -0700172WORKDIR /root
173RUN wget -nc http://de.archive.ubuntu.com/ubuntu/pool/main/b/bison/bison_2.5.dfsg-2.1_amd64.deb \
174 http://de.archive.ubuntu.com/ubuntu/pool/main/b/bison/libbison-dev_2.5.dfsg-2.1_amd64.deb
175RUN sudo dpkg -i bison_2.5.dfsg-2.1_amd64.deb libbison-dev_2.5.dfsg-2.1_amd64.deb
176RUN rm bison_2.5.dfsg-2.1_amd64.deb libbison-dev_2.5.dfsg-2.1_amd64.deb
177RUN wget -nc http://www.nbee.org/download/nbeesrc-jan-10-2013.zip && \
178 unzip nbeesrc-jan-10-2013.zip && \
179 cd nbeesrc-jan-10-2013/src && cmake . && make && \
180 cp ../bin/libn*.so /usr/local/lib && ldconfig && \
181 cp -R ../include/* /usr/include/
182WORKDIR /root
183RUN git clone https://github.com/CPqD/ofsoftswitch13.git && \
184 cd ofsoftswitch13 && \
A R Karthickb7e80902016-05-17 09:38:31 -0700185 ./boot.sh && \
186 ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --disable-ssl && \
187 make && make install
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700188CMD ["/bin/bash"]
Chetan Gaonkerb6064fa2016-05-02 16:29:57 -0700189'''.format(*image_format)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700190 super(CordTester, cls).build_image(dockerfile, image)
191 print('Done building docker image %s' %image)
192
A R Karthick1f03e912016-05-18 11:39:22 -0700193 def run_tests(self):
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700194 '''Run the list of tests'''
A R Karthick1f03e912016-05-18 11:39:22 -0700195 print('Running tests: %s' %self.tests)
196 for t in self.tests:
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700197 test = t.split(':')[0]
A R Karthick24f1de62016-05-12 15:16:38 -0700198 test_file = '{}Test.py'.format(test)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700199 if t.find(':') >= 0:
A R Karthick24f1de62016-05-12 15:16:38 -0700200 test_case = '{0}:{1}'.format(test_file, t.split(':')[1])
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700201 else:
202 test_case = test_file
Chetan Gaonker7142a342016-04-07 14:53:12 -0700203 cmd = 'nosetests -v {0}/src/test/{1}/{2}'.format(self.sandbox, test, test_case)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700204 status = self.execute(cmd, shell = True)
205 print('Test %s %s' %(test_case, 'Success' if status == 0 else 'Failure'))
206 print('Done running tests')
207 if self.rm:
208 print('Removing test container %s' %self.name)
209 self.kill(remove=True)
210
Chetan Gaonkerfb3cb5e2016-05-06 11:55:44 -0700211 @classmethod
212 def list_tests(cls, tests):
213 print('Listing test cases')
214 for test in tests:
A R Karthick24f1de62016-05-12 15:16:38 -0700215 test_file = '{}Test.py'.format(test)
Chetan Gaonkerfb3cb5e2016-05-06 11:55:44 -0700216 cmd = 'nosetests -v --collect-only {0}/../{1}/{2}'.format(cls.tester_base, test, test_file)
217 os.system(cmd)
218
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700219##default onos/radius/test container images and names
220onos_image_default='onosproject/onos:latest'
Chetan Gaonker503032a2016-05-12 12:06:29 -0700221nose_image_default= '{}:latest'.format(CordTester.IMAGE)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700222test_type_default='dhcp'
A.R Karthick95d044e2016-06-10 18:44:36 -0700223onos_app_version = '2.0-SNAPSHOT'
Chetan Gaonker4d842ad2016-04-26 10:04:24 -0700224cord_tester_base = os.path.dirname(os.path.realpath(__file__))
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700225onos_app_file = os.path.abspath('{0}/../apps/ciena-cordigmp-'.format(cord_tester_base) + onos_app_version + '.oar')
A R Karthick81acbff2016-06-17 14:45:16 -0700226cord_test_server_address = '{}:{}'.format(CORD_TEST_HOST, CORD_TEST_PORT)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700227
228def runTest(args):
Chetan Gaonker823cdc52016-05-09 15:51:23 -0700229 #Start the cord test tcp server
A R Karthick81acbff2016-06-17 14:45:16 -0700230 test_server_params = args.server.split(':')
231 test_host = test_server_params[0]
232 test_port = CORD_TEST_PORT
233 if len(test_server_params) > 1:
234 test_port = int(test_server_params[1])
235 try:
236 test_server = cord_test_server_start(daemonize = False, cord_test_host = test_host, cord_test_port = test_port)
237 except:
238 ##Most likely a server instance is already running (daemonized earlier)
239 test_server = None
240
A R Karthick1f03e912016-05-18 11:39:22 -0700241 test_containers = []
242 #These tests end up restarting ONOS/quagga/radius
243 tests_exempt = ('vrouter',)
Chetan Gaonker503032a2016-05-12 12:06:29 -0700244 if args.test_type.lower() == 'all':
245 tests = CordTester.ALL_TESTS
Chetan Gaonker503032a2016-05-12 12:06:29 -0700246 args.quagga = True
247 else:
A R Karthickacae3b42016-05-12 15:27:24 -0700248 tests = args.test_type.split('-')
Chetan Gaonker503032a2016-05-12 12:06:29 -0700249
A R Karthick1f03e912016-05-18 11:39:22 -0700250 tests_parallel = [ t for t in tests if t.split(':')[0] not in tests_exempt ]
251 tests_not_parallel = [ t for t in tests if t.split(':')[0] in tests_exempt ]
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700252 onos_cnt = {'tag':'latest'}
Chetan Gaonker503032a2016-05-12 12:06:29 -0700253 nose_cnt = {'image': CordTester.IMAGE, 'tag': 'latest'}
254 update_map = { 'quagga' : False, 'test' : False, 'radius' : False }
255 update_map[args.update.lower()] = True
A.R Karthick95d044e2016-06-10 18:44:36 -0700256
Chetan Gaonker503032a2016-05-12 12:06:29 -0700257 if args.update.lower() == 'all':
258 for c in update_map.keys():
259 update_map[c] = True
A.R Karthick95d044e2016-06-10 18:44:36 -0700260
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700261 radius_ip = None
Chetan Gaonkerfb3cb5e2016-05-06 11:55:44 -0700262
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700263 #don't spawn onos if the user has specified external test controller with test interface config
264 if args.test_controller:
265 ips = args.test_controller.split('/')
266 onos_ip = ips[0]
267 if len(ips) > 1:
268 radius_ip = ips[1]
269 else:
270 radius_ip = None
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700271 else:
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700272 onos_cnt['image'] = args.onos.split(':')[0]
273 if args.onos.find(':') >= 0:
274 onos_cnt['tag'] = args.onos.split(':')[1]
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700275
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700276 onos = Onos(image = onos_cnt['image'], tag = onos_cnt['tag'], boot_delay = 60)
277 onos_ip = onos.ip()
278
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700279 print('Onos IP %s, Test type %s' %(onos_ip, args.test_type))
A R Karthickbd9b8a32016-07-21 09:56:45 -0700280 if args.test_controller:
281 print('Installing ONOS cord apps')
282 Onos.install_cord_apps(onos_ip = onos_ip)
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700283
284 print('Installing cord tester ONOS app %s' %onos_app_file)
285 OnosCtrl.install_app(args.app, onos_ip = onos_ip)
286
287 if radius_ip is None:
A R Karthicka661b552016-05-25 10:18:50 -0700288 ##Start Radius container
289 radius = Radius( update = update_map['radius'])
290 radius_ip = radius.ip()
A.R Karthick95d044e2016-06-10 18:44:36 -0700291
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700292 print('Radius server running with IP %s' %radius_ip)
A.R Karthick95d044e2016-06-10 18:44:36 -0700293
Chetan Gaonkerb84835f2016-04-19 15:12:10 -0700294 if args.quagga == True:
295 #Start quagga. Builds container if required
Chetan Gaonker503032a2016-05-12 12:06:29 -0700296 quagga = Quagga(update = update_map['quagga'])
A R Karthick81acbff2016-06-17 14:45:16 -0700297
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700298 test_cnt_env = { 'ONOS_CONTROLLER_IP' : onos_ip,
Chetan Gaonkerc170f3f2016-04-19 17:24:45 -0700299 'ONOS_AAA_IP' : radius_ip if radius_ip is not None else '',
A R Karthick8d03cc52016-06-28 14:51:59 -0700300 'QUAGGA_IP': test_host,
A R Karthick81acbff2016-06-17 14:45:16 -0700301 'CORD_TEST_HOST' : test_host,
302 'CORD_TEST_PORT' : test_port,
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700303 'ONOS_RESTART_DISABLED' : 1 if args.olt and args.test_controller else 0,
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700304 }
305 if args.olt:
Chetan Gaonker7142a342016-04-07 14:53:12 -0700306 olt_conf_test_loc = os.path.join(CordTester.sandbox_setup, 'olt_config.json')
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700307 test_cnt_env['OLT_CONFIG'] = olt_conf_test_loc
308
A R Karthick1f03e912016-05-18 11:39:22 -0700309 port_num = 0
310 num_tests = len(tests_parallel)
311 tests_per_container = max(1, num_tests/args.num_containers)
312 test_slice_start = 0
313 test_slice_end = test_slice_start + tests_per_container
314 num_test_containers = min(num_tests, args.num_containers)
315 if tests_parallel:
316 print('Running %s tests across %d containers in parallel' %(tests_parallel, num_test_containers))
317 for container in range(num_test_containers):
318 test_cnt = CordTester(tests_parallel[test_slice_start:test_slice_end],
319 instance = container, num_instances = num_test_containers,
320 ctlr_ip = onos_ip, image = nose_cnt['image'], tag = nose_cnt['tag'],
321 env = test_cnt_env,
322 rm = False if args.keep else True,
323 update = update_map['test'])
324 test_slice_start = test_slice_end
325 test_slice_end = test_slice_start + tests_per_container
326 update_map['test'] = False
327 test_containers.append(test_cnt)
328 if args.start_switch or not args.olt:
329 test_cnt.start_switch()
330 if test_cnt.olt:
331 _, port_num = test_cnt.setup_intfs(port_num = port_num)
332
333 thread_pool = ThreadPool(len(test_containers), queue_size = 1, wait_timeout=1)
334 for test_cnt in test_containers:
335 thread_pool.addTask(test_cnt.run_tests)
336 thread_pool.cleanUpThreads()
337
338 ##Run the linear tests
339 if tests_not_parallel:
340 test_cnt = CordTester(tests_not_parallel,
341 ctlr_ip = onos_ip, image = nose_cnt['image'], tag = nose_cnt['tag'],
342 env = test_cnt_env,
343 rm = False if args.keep else True,
344 update = update_map['test'])
345 if args.start_switch or not args.olt:
346 test_cnt.start_switch()
347 if test_cnt.olt:
348 test_cnt.setup_intfs(port_num = port_num)
349 test_cnt.run_tests()
350
A R Karthick81acbff2016-06-17 14:45:16 -0700351 if test_server:
352 cord_test_server_stop(test_server)
353
354##Starts onos/radius/quagga containers as appropriate
355def setupCordTester(args):
356 onos_cnt = {'tag':'latest'}
A R Karthick92a0e5a2016-06-22 17:11:05 -0700357 nose_cnt = {'image': CordTester.IMAGE, 'tag': 'latest'}
358 update_map = { 'quagga' : False, 'radius' : False, 'test': False }
A R Karthick81acbff2016-06-17 14:45:16 -0700359 update_map[args.update.lower()] = True
360
361 if args.update.lower() == 'all':
362 for c in update_map.keys():
363 update_map[c] = True
364
365 onos_ip = None
366 radius_ip = None
A R Karthickd44cea12016-07-20 12:16:41 -0700367 onos_cord_loc = args.onos_cord
368 if onos_cord_loc:
369 if onos_cord_loc.find(os.path.sep) < 0:
370 onos_cord_loc = os.path.join(os.getenv('HOME'), onos_cord_loc)
371 if not os.access(onos_cord_loc, os.F_OK):
372 print('ONOS cord config location %s is not accessible' %onos_cord_loc)
373 sys.exit(1)
374 #Disable test container provisioning on the ONOS compute node
375 args.dont_provision = True
A R Karthick81acbff2016-06-17 14:45:16 -0700376
377 ##If onos/radius was already started
378 if args.test_controller:
379 ips = args.test_controller.split('/')
380 onos_ip = ips[0]
381 if len(ips) > 1:
382 radius_ip = ips[1]
383 else:
384 radius_ip = None
385
A R Karthickd44cea12016-07-20 12:16:41 -0700386 onos_cord = None
387 if onos_cord_loc:
388 if not args.test_controller:
389 ##Unexpected case. Specify the external controller ip when running on cord node
390 print('Specify ONOS ip using \"-e\" option when running the cord-tester on cord node')
391 sys.exit(1)
A R Karthickbd9b8a32016-07-21 09:56:45 -0700392 onos_cord = OnosCord(onos_ip, onos_cord_loc)
A R Karthickd44cea12016-07-20 12:16:41 -0700393
A R Karthick81acbff2016-06-17 14:45:16 -0700394 #don't spawn onos if the user had started it externally
395 onos_cnt['image'] = args.onos.split(':')[0]
396 if args.onos.find(':') >= 0:
397 onos_cnt['tag'] = args.onos.split(':')[1]
398
399 if onos_ip is None:
400 onos = Onos(image = onos_cnt['image'], tag = onos_cnt['tag'], boot_delay = 60)
401 onos_ip = onos.ip()
402
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700403 print('Onos IP %s' %onos_ip)
A R Karthickbd9b8a32016-07-21 09:56:45 -0700404 if args.test_controller:
405 print('Installing ONOS cord apps')
406 Onos.install_cord_apps(onos_ip = onos_ip)
407
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700408 print('Installing cord tester ONOS app %s' %onos_app_file)
409 OnosCtrl.install_app(args.app, onos_ip = onos_ip)
410
A R Karthick81acbff2016-06-17 14:45:16 -0700411 ##Start Radius container if not started
412 if radius_ip is None:
413 radius = Radius( update = update_map['radius'])
414 radius_ip = radius.ip()
415
416 print('Radius server running with IP %s' %radius_ip)
A R Karthick81acbff2016-06-17 14:45:16 -0700417
418 if args.quagga == True:
419 #Start quagga. Builds container if required
420 quagga = Quagga(update = update_map['quagga'])
A R Karthick8d03cc52016-06-28 14:51:59 -0700421 print('Quagga started')
A R Karthick81acbff2016-06-17 14:45:16 -0700422
A R Karthick81acbff2016-06-17 14:45:16 -0700423 params = args.server.split(':')
424 ip = params[0]
425 port = CORD_TEST_PORT
426 if len(params) > 1:
427 port = int(params[1])
A R Karthick92a0e5a2016-06-22 17:11:05 -0700428
429 #provision the test container
430 if not args.dont_provision:
431 test_cnt_env = { 'ONOS_CONTROLLER_IP' : onos_ip,
432 'ONOS_AAA_IP' : radius_ip,
A R Karthick8d03cc52016-06-28 14:51:59 -0700433 'QUAGGA_IP': ip,
A R Karthick92a0e5a2016-06-22 17:11:05 -0700434 'CORD_TEST_HOST' : ip,
435 'CORD_TEST_PORT' : port,
A R Karthickeaf1c4e2016-07-19 12:22:35 -0700436 'ONOS_RESTART_DISABLED' : 1 if args.olt and args.test_controller else 0,
A R Karthick92a0e5a2016-06-22 17:11:05 -0700437 }
438 if args.olt:
439 olt_conf_test_loc = os.path.join(CordTester.sandbox_setup, 'olt_config.json')
440 test_cnt_env['OLT_CONFIG'] = olt_conf_test_loc
441
442 test_cnt = CordTester((),
443 ctlr_ip = onos_ip,
444 image = nose_cnt['image'],
445 tag = nose_cnt['tag'],
446 env = test_cnt_env,
447 rm = False,
448 update = update_map['test'])
449
450 if args.start_switch or not args.olt:
451 test_cnt.start_switch()
452 if test_cnt.olt:
453 test_cnt.setup_intfs(port_num = 0)
454 print('Test container %s started and provisioned to run tests using nosetests' %(test_cnt.name))
455
456 #Finally start the test server and daemonize
A R Karthickd44cea12016-07-20 12:16:41 -0700457 cord_test_server_start(daemonize = True, cord_test_host = ip, cord_test_port = port,
458 onos_cord = onos_cord)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700459
Chetan Gaonker503032a2016-05-12 12:06:29 -0700460def cleanupTests(args):
461 test_container = '{}:latest'.format(CordTester.IMAGE)
462 print('Cleaning up Test containers ...')
463 Container.cleanup(test_container)
464
465def listTests(args):
466 if args.test == 'all':
467 tests = CordTester.ALL_TESTS
468 else:
A R Karthickacae3b42016-05-12 15:27:24 -0700469 tests = args.test.split('-')
Chetan Gaonker503032a2016-05-12 12:06:29 -0700470 CordTester.list_tests(tests)
471
472def buildImages(args):
473 if args.image == 'all' or args.image == 'quagga':
474 Quagga.build_image(Quagga.IMAGE)
A.R Karthick95d044e2016-06-10 18:44:36 -0700475
Chetan Gaonker503032a2016-05-12 12:06:29 -0700476 if args.image == 'all' or args.image == 'radius':
477 Radius.build_image(Radius.IMAGE)
478
479 if args.image == 'all' or args.image == 'test':
480 CordTester.build_image(CordTester.IMAGE)
481
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700482if __name__ == '__main__':
Chetan Gaonker678743f2016-04-26 09:54:31 -0700483 parser = ArgumentParser(description='Cord Tester')
Chetan Gaonker503032a2016-05-12 12:06:29 -0700484 subparser = parser.add_subparsers()
485 parser_run = subparser.add_parser('run', help='Run cord tester')
486 parser_run.add_argument('-t', '--test-type', default=test_type_default, help='Specify test type or test case to run')
487 parser_run.add_argument('-o', '--onos', default=onos_image_default, type=str, help='ONOS container image')
Chetan Gaonker503032a2016-05-12 12:06:29 -0700488 parser_run.add_argument('-q', '--quagga',action='store_true',help='Provision quagga container for vrouter')
489 parser_run.add_argument('-a', '--app', default=onos_app_file, type=str, help='Cord ONOS app filename')
490 parser_run.add_argument('-p', '--olt', action='store_true', help='Use OLT config')
491 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 -0700492 '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 -0700493 parser_run.add_argument('-r', '--server', default=cord_test_server_address, type=str,
494 help='ip:port address to connect for cord test server for container requests')
Chetan Gaonker503032a2016-05-12 12:06:29 -0700495 parser_run.add_argument('-k', '--keep', action='store_true', help='Keep test container after tests')
496 parser_run.add_argument('-s', '--start-switch', action='store_true', help='Start OVS when running under OLT config')
497 parser_run.add_argument('-u', '--update', default='none', choices=['test','quagga','radius', 'all'], type=str, help='Update cord tester container images. '
498 'Eg: --update=quagga to rebuild quagga image.'
499 ' --update=radius to rebuild radius server image.'
500 ' --update=test to rebuild cord test image.(Default)'
501 ' --update=all to rebuild all cord tester images.')
A R Karthick1f03e912016-05-18 11:39:22 -0700502 parser_run.add_argument('-n', '--num-containers', default=1, type=int,
503 help='Specify number of test containers to spawn for tests')
Chetan Gaonker503032a2016-05-12 12:06:29 -0700504 parser_run.set_defaults(func=runTest)
505
A R Karthick81acbff2016-06-17 14:45:16 -0700506
507 parser_setup = subparser.add_parser('setup', help='Setup cord tester environment')
508 parser_setup.add_argument('-o', '--onos', default=onos_image_default, type=str, help='ONOS container image')
509 parser_setup.add_argument('-r', '--server', default=cord_test_server_address, type=str,
510 help='ip:port address for cord test server to listen for container restart requests')
511 parser_setup.add_argument('-q', '--quagga',action='store_true',help='Provision quagga container for vrouter')
512 parser_setup.add_argument('-a', '--app', default=onos_app_file, type=str, help='Cord ONOS app filename')
513 parser_setup.add_argument('-e', '--test-controller', default='', type=str, help='External test controller ip for Onos and/or radius server. '
514 'Eg: 10.0.0.2/10.0.0.3 to specify ONOS and Radius ip to connect')
515 parser_setup.add_argument('-u', '--update', default='none', choices=['quagga','radius', 'all'], type=str, help='Update cord tester container images. '
516 'Eg: --update=quagga to rebuild quagga image.'
517 ' --update=radius to rebuild radius server image.'
518 ' --update=all to rebuild all cord tester images.')
A R Karthick92a0e5a2016-06-22 17:11:05 -0700519 parser_setup.add_argument('-d', '--dont-provision', action='store_true', help='Dont start test container.')
520 parser_setup.add_argument('-p', '--olt', action='store_true', help='Use OLT config')
521 parser_setup.add_argument('-s', '--start-switch', action='store_true', help='Start OVS when running under OLT config')
A R Karthickd44cea12016-07-20 12:16:41 -0700522 parser_setup.add_argument('-c', '--onos-cord', default='', type=str,
523 help='Specify cord location for ONOS cord when running on podd')
A R Karthick81acbff2016-06-17 14:45:16 -0700524 parser_setup.set_defaults(func=setupCordTester)
525
Chetan Gaonker503032a2016-05-12 12:06:29 -0700526 parser_list = subparser.add_parser('list', help='List test cases')
527 parser_list.add_argument('-t', '--test', default='all', help='Specify test type to list test cases. '
528 'Eg: -t tls to list tls test cases.'
529 ' -t tls-dhcp-vrouter to list tls,dhcp and vrouter test cases.'
530 ' -t all to list all test cases.')
531 parser_list.set_defaults(func=listTests)
532
533 parser_build = subparser.add_parser('build', help='Build cord test container images')
534 parser_build.add_argument('image', choices=['quagga', 'radius', 'test', 'all'])
535 parser_build.set_defaults(func=buildImages)
536
537 parser_cleanup = subparser.add_parser('cleanup', help='Cleanup test containers')
538 parser_cleanup.set_defaults(func=cleanupTests)
539
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700540 args = parser.parse_args()
541 args.func(args)