blob: 3c4e8c14188f4d0c4424007a876169776d588cd2 [file] [log] [blame]
Chetan Gaonker93e302d2016-04-05 10:51:07 -07001#!/usr/bin/env python
2from argparse import ArgumentParser
3import os,sys,time
4import io
5import yaml
6from pyroute2 import IPRoute
7from itertools import chain
8from nsenter import Namespace
9from docker import Client
10from shutil import copy
Chetan Gaonker7142a342016-04-07 14:53:12 -070011utils_dir = os.path.join( os.path.dirname(os.path.realpath(sys.argv[0])), '../utils')
12sys.path.append(utils_dir)
Chetan Gaonker93e302d2016-04-05 10:51:07 -070013from OnosCtrl import OnosCtrl
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -070014from OltConfig import OltConfig
Chetan Gaonker93e302d2016-04-05 10:51:07 -070015
16class docker_netns(object):
17
18 dckr = Client()
19 def __init__(self, name):
20 pid = int(self.dckr.inspect_container(name)['State']['Pid'])
21 if pid == 0:
22 raise Exception('no container named {0}'.format(name))
23 self.pid = pid
24
25 def __enter__(self):
26 pid = self.pid
27 if not os.path.exists('/var/run/netns'):
28 os.mkdir('/var/run/netns')
29 os.symlink('/proc/{0}/ns/net'.format(pid), '/var/run/netns/{0}'.format(pid))
30 return str(pid)
31
32 def __exit__(self, type, value, traceback):
33 pid = self.pid
34 os.unlink('/var/run/netns/{0}'.format(pid))
35
36flatten = lambda l: chain.from_iterable(l)
37
38class Container(object):
39 dckr = Client()
40 def __init__(self, name, image, tag = 'latest', command = 'bash', quagga_config = None):
41 self.name = name
42 self.image = image
43 self.tag = tag
44 self.image_name = image + ':' + tag
45 self.id = None
46 self.command = command
47 if quagga_config is not None:
48 self.bridge = quagga_config['bridge']
49 self.ipaddress = quagga_config['ip']
50 self.mask = quagga_config['mask']
51 else:
52 self.bridge = None
53 self.ipaddress = None
54 self.mask = None
55
56 @classmethod
57 def build_image(cls, dockerfile, tag, force=True, nocache=False):
58 f = io.BytesIO(dockerfile.encode('utf-8'))
59 if force or not cls.image_exists(tag):
60 print('Build {0}...'.format(tag))
61 for line in cls.dckr.build(fileobj=f, rm=True, tag=tag, decode=True, nocache=nocache):
62 if 'stream' in line:
63 print(line['stream'].strip())
64
65 @classmethod
66 def image_exists(cls, name):
67 return name in [ctn['RepoTags'][0] for ctn in cls.dckr.images()]
68
69 @classmethod
70 def create_host_config(cls, port_list = None, host_guest_map = None, privileged = False):
71 port_bindings = None
72 binds = None
73 if port_list:
74 port_bindings = {}
75 for p in port_list:
76 port_bindings[str(p)] = str(p)
77
78 if host_guest_map:
79 binds = []
80 for h, g in host_guest_map:
81 binds.append('{0}:{1}'.format(h, g))
82
83 return cls.dckr.create_host_config(binds = binds, port_bindings = port_bindings, privileged = privileged)
84
85 @classmethod
86 def cleanup(cls, image):
87 cnt_list = filter(lambda c: c['Image'] == image, cls.dckr.containers())
88 for cnt in cnt_list:
89 print('Cleaning container %s' %cnt['Id'])
90 cls.dckr.kill(cnt['Id'])
91 cls.dckr.remove_container(cnt['Id'], force=True)
92
Chetan Gaonker7142a342016-04-07 14:53:12 -070093 @classmethod
94 def remove_container(cls, name, force=True):
95 try:
96 cls.dckr.remove_container(name, force = force)
97 except: pass
98
Chetan Gaonker93e302d2016-04-05 10:51:07 -070099 def exists(self):
100 return '/{0}'.format(self.name) in list(flatten(n['Names'] for n in self.dckr.containers()))
101
102 def img_exists(self):
103 return self.image_name in [ctn['RepoTags'][0] for ctn in self.dckr.images()]
104
105 def ip(self):
106 cnt_list = filter(lambda c: c['Image'] == self.image_name, self.dckr.containers())
107 cnt_settings = cnt_list.pop()
108 return cnt_settings['NetworkSettings']['Networks']['bridge']['IPAddress']
109
110 def kill(self, remove = True):
111 self.dckr.kill(self.name)
112 self.dckr.remove_container(self.name, force=True)
113
114 def start(self, rm = True, ports = None, volumes = None, host_config = None,
115 environment = None, tty = False, stdin_open = True):
116
117 if rm and self.exists():
118 print('Removing container:', self.name)
119 self.dckr.remove_container(self.name, force=True)
120
121 ctn = self.dckr.create_container(image=self.image_name, ports = ports, command=self.command,
122 detach=True, name=self.name,
123 environment = environment,
124 volumes = volumes,
125 host_config = host_config, stdin_open=stdin_open, tty = tty)
126 self.dckr.start(container=self.name)
127 if self.bridge:
128 self.connect_to_br()
129 self.id = ctn['Id']
130 return ctn
131
132 def connect_to_br(self):
133 with docker_netns(self.name) as pid:
134 ip = IPRoute()
135 br = ip.link_lookup(ifname=self.bridge)
136 if len(br) == 0:
137 ip.link_create(ifname=self.bridge, kind='bridge')
138 br = ip.link_lookup(ifname=self.bridge)
139 br = br[0]
140 ip.link('set', index=br, state='up')
141
142 ifs = ip.link_lookup(ifname=self.name)
143 if len(ifs) > 0:
144 ip.link_remove(ifs[0])
145
146 ip.link_create(ifname=self.name, kind='veth', peer=pid)
147 host = ip.link_lookup(ifname=self.name)[0]
148 ip.link('set', index=host, master=br)
149 ip.link('set', index=host, state='up')
150 guest = ip.link_lookup(ifname=pid)[0]
151 ip.link('set', index=guest, net_ns_fd=pid)
152 with Namespace(pid, 'net'):
153 ip = IPRoute()
154 ip.link('set', index=guest, ifname='eth1')
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700155 ip.addr('add', index=guest, address=self.ipaddress, mask=self.mask)
Chetan Gaonkerb84835f2016-04-19 15:12:10 -0700156 ip.link('set', index=guest, state='up')
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700157
158 def execute(self, cmd, tty = True, stream = False, shell = False):
159 res = 0
160 if type(cmd) == str:
161 cmds = (cmd,)
162 else:
163 cmds = cmd
164 if shell:
165 for c in cmds:
166 res += os.system('docker exec {0} {1}'.format(self.name, c))
167 return res
168 for c in cmds:
169 i = self.dckr.exec_create(container=self.name, cmd=c, tty = tty, privileged = True)
Chetan Gaonkerb84835f2016-04-19 15:12:10 -0700170 self.dckr.exec_start(i['Id'], stream = stream, detach=True)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700171 result = self.dckr.exec_inspect(i['Id'])
172 res += 0 if result['ExitCode'] == None else result['ExitCode']
173 return res
174
175class Onos(Container):
176
177 quagga_config = { 'bridge' : 'quagga-br', 'ip': '10.10.0.4', 'mask' : 16 }
178 env = { 'ONOS_APPS' : 'drivers,openflow,proxyarp,aaa,igmp,vrouter' }
179 ports = [ 8181, 8101, 9876, 6653, 6633, 2000, 2620 ]
180
181 def __init__(self, name = 'cord-onos', image = 'onosproject/onos', tag = 'latest', boot_delay = 60):
182 super(Onos, self).__init__(name, image, tag = tag, quagga_config = self.quagga_config)
183 if not self.exists():
Chetan Gaonker7142a342016-04-07 14:53:12 -0700184 self.remove_container(name, force=True)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700185 host_config = self.create_host_config(port_list = self.ports)
186 print('Starting ONOS container %s' %self.name)
187 self.start(ports = self.ports, environment = self.env,
188 host_config = host_config, tty = True)
189 print('Waiting %d seconds for ONOS to boot' %(boot_delay))
190 time.sleep(boot_delay)
191
192class Radius(Container):
193 ports = [ 1812, 1813 ]
194 env = {'TIMEZONE':'America/Los_Angeles',
195 'DEBUG': 'true', 'cert_password':'whatever', 'primary_shared_secret':'radius_password'
196 }
197 host_db_dir = os.path.join(os.getenv('HOME'), 'services', 'radius', 'data', 'db')
198 guest_db_dir = os.path.join(os.path.sep, 'opt', 'db')
199 host_config_dir = os.path.join(os.getenv('HOME'), 'services', 'radius', 'freeradius')
200 guest_config_dir = os.path.join(os.path.sep, 'etc', 'freeradius')
201 start_command = '/root/start-radius.py'
202 host_guest_map = ( (host_db_dir, guest_db_dir),
203 (host_config_dir, guest_config_dir)
204 )
205 def __init__(self, name = 'cord-radius', image = 'freeradius', tag = 'podd'):
206 super(Radius, self).__init__(name, image, tag = tag, command = self.start_command)
207 if not self.exists():
Chetan Gaonker7142a342016-04-07 14:53:12 -0700208 self.remove_container(name, force=True)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700209 host_config = self.create_host_config(port_list = self.ports,
210 host_guest_map = self.host_guest_map)
211 volumes = []
Chetan Gaonkerb84835f2016-04-19 15:12:10 -0700212 for _,g in self.host_guest_map:
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700213 volumes.append(g)
214 self.start(ports = self.ports, environment = self.env,
215 volumes = volumes,
216 host_config = host_config, tty = True)
217
218class CordTester(Container):
219
220 sandbox = '/root/test'
Chetan Gaonker7142a342016-04-07 14:53:12 -0700221 sandbox_setup = '/root/test/src/test/setup'
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700222 tester_base = os.path.dirname(os.path.realpath(sys.argv[0]))
Chetan Gaonker7142a342016-04-07 14:53:12 -0700223 tester_paths = os.path.realpath(sys.argv[0]).split(os.path.sep)
224 tester_path_index = tester_paths.index('cord-tester')
225 sandbox_host = os.path.sep.join(tester_paths[:tester_path_index+1])
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700226
227 host_guest_map = ( (sandbox_host, sandbox),
228 ('/lib/modules', '/lib/modules')
229 )
230 basename = 'cord-tester'
231
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700232 def __init__(self, ctlr_ip = None, image = 'cord-test/nose', tag = 'latest',
233 env = None, rm = False):
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700234 self.ctlr_ip = ctlr_ip
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700235 self.rm = rm
236 self.name = self.get_name()
237 super(CordTester, self).__init__(self.name, image = image, tag = tag)
238 host_config = self.create_host_config(host_guest_map = self.host_guest_map, privileged = True)
239 volumes = []
Chetan Gaonkerb84835f2016-04-19 15:12:10 -0700240 for _, g in self.host_guest_map:
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700241 volumes.append(g)
Chetan Gaonkerb84835f2016-04-19 15:12:10 -0700242 if not self.img_exists():
243 self.build_image(image)
Chetan Gaonker7142a342016-04-07 14:53:12 -0700244 ##Remove test container if any
245 self.remove_container(self.name, force=True)
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700246 if env is not None and env.has_key('OLT_CONFIG'):
247 self.olt = True
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700248 olt_conf_file = os.path.join(self.tester_base, 'olt_config.json')
249 olt_config = OltConfig(olt_conf_file)
250 self.port_map = olt_config.olt_port_map()
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700251 else:
252 self.olt = False
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700253 self.port_map = None
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700254 print('Starting test container %s, image %s, tag %s' %(self.name, self.image, self.tag))
255 self.start(rm = False, volumes = volumes, environment = env,
256 host_config = host_config, tty = True)
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700257
258 def execute_switch(self, cmd, shell = False):
259 if self.olt:
260 return os.system(cmd)
261 return self.execute(cmd, shell = shell)
262
263 def start_switch(self, bridge = 'ovsbr0', boot_delay = 2):
264 """Start OVS"""
265 ##Determine if OVS has to be started locally or not
266 s_file,s_sandbox = ('of-bridge-local.sh',self.tester_base) if self.olt else ('of-bridge.sh',self.sandbox_setup)
267 ovs_cmd = os.path.join(s_sandbox, '{0}'.format(s_file)) + ' {0}'.format(bridge)
268 if self.olt:
269 ovs_cmd += ' {0}'.format(self.ctlr_ip)
270 print('Starting OVS on the host')
271 else:
272 print('Starting OVS on test container %s' %self.name)
273 self.execute_switch(ovs_cmd)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700274 status = 1
275 ## Wait for the LLDP flows to be added to the switch
276 tries = 0
277 while status != 0 and tries < 100:
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700278 cmd = 'sudo ovs-ofctl dump-flows {0} | grep \"type=0x8942\"'.format(bridge)
279 status = self.execute_switch(cmd, shell = True)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700280 tries += 1
281 if tries % 10 == 0:
282 print('Waiting for test switch to be connected to ONOS controller ...')
283
284 if status != 0:
285 print('Test Switch not connected to ONOS container.'
286 'Please remove ONOS container and restart the test')
287 if self.rm:
288 self.kill()
289 sys.exit(1)
290
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700291 if boot_delay:
292 time.sleep(boot_delay)
293
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700294 def setup_intfs(self):
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700295 if not self.olt:
296 return 0
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700297 tester_intf_subnet = '192.168.100'
298 res = 0
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700299 port_num = 0
300 host_intf = self.port_map['host']
301 start_vlan = self.port_map['start_vlan']
302 for port in self.port_map['ports']:
303 guest_if = port
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700304 local_if = guest_if
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700305 guest_ip = '{0}.{1}/24'.format(tester_intf_subnet, str(port_num+1))
306 ##Use pipeworks to configure container interfaces on host/bridge interfaces
307 pipework_cmd = 'pipework {0} -i {1} -l {2} {3} {4}'.format(host_intf, guest_if, local_if, self.name, guest_ip)
308 if start_vlan != 0:
309 pipework_cmd += ' @{}'.format(str(start_vlan + port_num))
310
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700311 res += os.system(pipework_cmd)
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700312 port_num += 1
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700313
314 return res
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700315
316 @classmethod
317 def get_name(cls):
318 cnt_name = '/{0}'.format(cls.basename)
319 cnt_name_len = len(cnt_name)
320 names = list(flatten(n['Names'] for n in cls.dckr.containers(all=True)))
321 test_names = filter(lambda n: n.startswith(cnt_name), names)
322 last_cnt_number = 0
323 if test_names:
324 last_cnt_name = reduce(lambda n1, n2: n1 if int(n1[cnt_name_len:]) > \
325 int(n2[cnt_name_len:]) else n2,
326 test_names)
327 last_cnt_number = int(last_cnt_name[cnt_name_len:])
328 test_cnt_name = cls.basename + str(last_cnt_number+1)
329 return test_cnt_name
330
331 @classmethod
332 def build_image(cls, image):
333 print('Building test container docker image %s' %image)
334 dockerfile = '''
335FROM ubuntu:14.04
336MAINTAINER chetan@ciena.com
337RUN apt-get update
338RUN apt-get -y install git python python-pip python-setuptools python-scapy tcpdump doxygen doxypy wget
339RUN easy_install nose
340RUN apt-get -y install openvswitch-common openvswitch-switch
341RUN mkdir -p /root/ovs
342WORKDIR /root
343RUN wget http://openvswitch.org/releases/openvswitch-2.4.0.tar.gz -O /root/ovs/openvswitch-2.4.0.tar.gz && \
344(cd /root/ovs && tar zxpvf openvswitch-2.4.0.tar.gz && \
345 cd openvswitch-2.4.0 && \
346 ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --disable-ssl && make && make install)
347RUN service openvswitch-switch restart || /bin/true
Chetan Gaonker3ff8eae2016-04-12 14:50:26 -0700348RUN apt-get -y install python-twisted python-sqlite sqlite3 python-pexpect
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700349RUN pip install scapy-ssl_tls
350RUN pip install -U scapy
351RUN pip install monotonic
Chetan Gaonker3ff8eae2016-04-12 14:50:26 -0700352RUN pip install configObj
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700353RUN mv /usr/sbin/tcpdump /sbin/
354RUN ln -sf /sbin/tcpdump /usr/sbin/tcpdump
355CMD ["/bin/bash"]
356'''
357 super(CordTester, cls).build_image(dockerfile, image)
358 print('Done building docker image %s' %image)
359
360 def run_tests(self, tests):
361 '''Run the list of tests'''
362 for t in tests:
363 test = t.split(':')[0]
364 if test == 'tls':
365 test_file = test + 'AuthTest.py'
366 else:
367 test_file = test + 'Test.py'
368
369 if t.find(':') >= 0:
370 test_case = test_file + ':' + t.split(':')[1]
371 else:
372 test_case = test_file
Chetan Gaonker7142a342016-04-07 14:53:12 -0700373 cmd = 'nosetests -v {0}/src/test/{1}/{2}'.format(self.sandbox, test, test_case)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700374 status = self.execute(cmd, shell = True)
375 print('Test %s %s' %(test_case, 'Success' if status == 0 else 'Failure'))
376 print('Done running tests')
377 if self.rm:
378 print('Removing test container %s' %self.name)
379 self.kill(remove=True)
380
Chetan Gaonkerb84835f2016-04-19 15:12:10 -0700381class Quagga(Container):
382
383 quagga_config = { 'bridge' : 'quagga-br', 'ip': '10.10.0.3', 'mask' : 16 }
384 ports = [ 179, 2601, 2602, 2603, 2604, 2605, 2606 ]
385 host_quagga_config = os.path.join(CordTester.tester_base, 'quagga-config')
386 guest_quagga_config = '/root/config'
387 host_guest_map = ( (host_quagga_config, guest_quagga_config), )
388
389 def __init__(self, name = 'cord-quagga', image = 'cord-test/quagga', tag = 'latest', boot_delay = 60):
390 super(Quagga, self).__init__(name, image, tag = tag, quagga_config = self.quagga_config)
391 if not self.img_exists():
392 self.build_image(image)
393 if not self.exists():
394 self.remove_container(name, force=True)
395 host_config = self.create_host_config(port_list = self.ports,
396 host_guest_map = self.host_guest_map,
397 privileged = True)
398 volumes = []
399 for _,g in self.host_guest_map:
400 volumes.append(g)
401 self.start(ports = self.ports,
402 host_config = host_config,
403 volumes = volumes, tty = True)
404 print('Starting Quagga on container %s' %self.name)
405 self.execute('{}/start.sh'.format(self.guest_quagga_config))
406
407 @classmethod
408 def build_image(cls, image):
409 onos_quagga_ip = Onos.quagga_config['ip']
410 print('Building Quagga image %s' %image)
411 dockerfile = '''
412FROM ubuntu:latest
413WORKDIR /root
414RUN useradd -M quagga
415RUN mkdir /var/log/quagga && chown quagga:quagga /var/log/quagga
416RUN mkdir /var/run/quagga && chown quagga:quagga /var/run/quagga
417RUN apt-get update && apt-get install -qy git autoconf libtool gawk make telnet libreadline6-dev
418RUN git clone git://git.sv.gnu.org/quagga.git quagga && \
419(cd quagga && git checkout HEAD && ./bootstrap.sh && \
420sed -i -r 's,htonl.*?\(INADDR_LOOPBACK\),inet_addr\("{0}"\),g' zebra/zebra_fpm.c && \
421./configure --enable-fpm --disable-doc --localstatedir=/var/run/quagga && make && make install)
422RUN ldconfig
423'''.format(onos_quagga_ip)
424 super(Quagga, cls).build_image(dockerfile, image)
425 print('Done building image %s' %image)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700426
427##default onos/radius/test container images and names
428onos_image_default='onosproject/onos:latest'
429nose_image_default='cord-test/nose:latest'
430test_type_default='dhcp'
431onos_app_version = '1.0-SNAPSHOT'
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700432cord_tester_base = os.path.dirname(os.path.realpath(sys.argv[0]))
433onos_app_file = os.path.abspath('{0}/../apps/ciena-cordigmp-'.format(cord_tester_base) + onos_app_version + '.oar')
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700434
435def runTest(args):
436 onos_cnt = {'tag':'latest'}
437 radius_cnt = {'tag':'latest'}
438 nose_cnt = {'image': 'cord-test/nose','tag': 'latest'}
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700439 radius_ip = None
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700440 #print('Test type %s, onos %s, radius %s, app %s, olt %s, cleanup %s, kill flag %s, build image %s'
441 # %(args.test_type, args.onos, args.radius, args.app, args.olt, args.cleanup, args.kill, args.build))
442 if args.cleanup:
443 cleanup_container = args.cleanup
444 if cleanup_container.find(':') < 0:
445 cleanup_container += ':latest'
446 print('Cleaning up containers %s' %cleanup_container)
447 Container.cleanup(cleanup_container)
448 sys.exit(0)
449
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700450 #don't spawn onos if the user has specified external test controller with test interface config
451 if args.test_controller:
452 ips = args.test_controller.split('/')
453 onos_ip = ips[0]
454 if len(ips) > 1:
455 radius_ip = ips[1]
456 else:
457 radius_ip = None
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700458 else:
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700459 onos_cnt['image'] = args.onos.split(':')[0]
460 if args.onos.find(':') >= 0:
461 onos_cnt['tag'] = args.onos.split(':')[1]
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700462
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700463 onos = Onos(image = onos_cnt['image'], tag = onos_cnt['tag'], boot_delay = 60)
464 onos_ip = onos.ip()
465
466 ##Start Radius container if specified
467 if args.radius:
468 radius_cnt['image'] = args.radius.split(':')[0]
469 if args.radius.find(':') >= 0:
470 radius_cnt['tag'] = args.radius.split(':')[1]
471 radius = Radius(image = radius_cnt['image'], tag = radius_cnt['tag'])
472 radius_ip = radius.ip()
473 print('Started Radius server with IP %s' %radius_ip)
474 else:
475 radius_ip = None
476
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700477 print('Onos IP %s, Test type %s' %(onos_ip, args.test_type))
478 print('Installing ONOS app %s' %onos_app_file)
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700479 OnosCtrl.install_app(args.app, onos_ip = onos_ip)
Chetan Gaonkerb84835f2016-04-19 15:12:10 -0700480
481 if args.quagga == True:
482 #Start quagga. Builds container if required
483 quagga = Quagga()
484
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700485 test_cnt_env = { 'ONOS_CONTROLLER_IP' : onos_ip,
486 'ONOS_AAA_IP' : radius_ip,
487 }
488 if args.olt:
Chetan Gaonker7142a342016-04-07 14:53:12 -0700489 olt_conf_test_loc = os.path.join(CordTester.sandbox_setup, 'olt_config.json')
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700490 test_cnt_env['OLT_CONFIG'] = olt_conf_test_loc
491
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700492 test_cnt = CordTester(ctlr_ip = onos_ip, image = nose_cnt['image'], tag = nose_cnt['tag'],
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700493 env = test_cnt_env,
494 rm = args.kill)
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700495 if args.start_switch or not args.olt:
496 test_cnt.start_switch()
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700497 test_cnt.setup_intfs()
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700498 tests = args.test_type.split('-')
499 test_cnt.run_tests(tests)
500
501if __name__ == '__main__':
502 parser = ArgumentParser(description='Cord Tester for ONOS')
503 parser.add_argument('-t', '--test-type', default=test_type_default, type=str)
504 parser.add_argument('-o', '--onos', default=onos_image_default, type=str, help='ONOS container image')
505 parser.add_argument('-r', '--radius',default='',type=str, help='Radius container image')
Chetan Gaonkerb84835f2016-04-19 15:12:10 -0700506 parser.add_argument('-q', '--quagga',action='store_true',help='Provision quagga container for vrouter')
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700507 parser.add_argument('-a', '--app', default=onos_app_file, type=str, help='Cord ONOS app filename')
508 parser.add_argument('-l', '--olt', action='store_true', help='Use OLT config')
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700509 parser.add_argument('-e', '--test-controller', default='', type=str, help='External test controller ip for Onos and/or radius server.'
510 'Eg: 10.0.0.2/10.0.0.3 to specify ONOS and Radius ip to connect')
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700511 parser.add_argument('-c', '--cleanup', default='', type=str, help='Cleanup test containers')
512 parser.add_argument('-k', '--kill', action='store_true', help='Remove test container after tests')
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700513 parser.add_argument('-s', '--start-switch', action='store_true', help='Start OVS')
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700514 parser.set_defaults(func=runTest)
515 args = parser.parse_args()
516 args.func(args)