blob: 09c04db89109b4151bba2e9a33a409cf39605d9f [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),
Chetan Gaonker85b7bd52016-04-20 10:29:12 -0700228 ('/lib/modules', '/lib/modules'),
229 ('/var/run/docker.sock', '/var/run/docker.sock')
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700230 )
231 basename = 'cord-tester'
232
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700233 def __init__(self, ctlr_ip = None, image = 'cord-test/nose', tag = 'latest',
Chetan Gaonker85b7bd52016-04-20 10:29:12 -0700234 env = None, rm = False, update = False):
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700235 self.ctlr_ip = ctlr_ip
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700236 self.rm = rm
237 self.name = self.get_name()
238 super(CordTester, self).__init__(self.name, image = image, tag = tag)
239 host_config = self.create_host_config(host_guest_map = self.host_guest_map, privileged = True)
240 volumes = []
Chetan Gaonkerb84835f2016-04-19 15:12:10 -0700241 for _, g in self.host_guest_map:
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700242 volumes.append(g)
Chetan Gaonker85b7bd52016-04-20 10:29:12 -0700243 if update is True or not self.img_exists():
Chetan Gaonkerb84835f2016-04-19 15:12:10 -0700244 self.build_image(image)
Chetan Gaonker7142a342016-04-07 14:53:12 -0700245 ##Remove test container if any
246 self.remove_container(self.name, force=True)
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700247 if env is not None and env.has_key('OLT_CONFIG'):
248 self.olt = True
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700249 olt_conf_file = os.path.join(self.tester_base, 'olt_config.json')
250 olt_config = OltConfig(olt_conf_file)
251 self.port_map = olt_config.olt_port_map()
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700252 else:
253 self.olt = False
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700254 self.port_map = None
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700255 print('Starting test container %s, image %s, tag %s' %(self.name, self.image, self.tag))
256 self.start(rm = False, volumes = volumes, environment = env,
257 host_config = host_config, tty = True)
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700258
259 def execute_switch(self, cmd, shell = False):
260 if self.olt:
261 return os.system(cmd)
262 return self.execute(cmd, shell = shell)
263
264 def start_switch(self, bridge = 'ovsbr0', boot_delay = 2):
265 """Start OVS"""
266 ##Determine if OVS has to be started locally or not
267 s_file,s_sandbox = ('of-bridge-local.sh',self.tester_base) if self.olt else ('of-bridge.sh',self.sandbox_setup)
268 ovs_cmd = os.path.join(s_sandbox, '{0}'.format(s_file)) + ' {0}'.format(bridge)
269 if self.olt:
270 ovs_cmd += ' {0}'.format(self.ctlr_ip)
271 print('Starting OVS on the host')
272 else:
273 print('Starting OVS on test container %s' %self.name)
274 self.execute_switch(ovs_cmd)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700275 status = 1
276 ## Wait for the LLDP flows to be added to the switch
277 tries = 0
278 while status != 0 and tries < 100:
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700279 cmd = 'sudo ovs-ofctl dump-flows {0} | grep \"type=0x8942\"'.format(bridge)
280 status = self.execute_switch(cmd, shell = True)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700281 tries += 1
282 if tries % 10 == 0:
283 print('Waiting for test switch to be connected to ONOS controller ...')
284
285 if status != 0:
286 print('Test Switch not connected to ONOS container.'
287 'Please remove ONOS container and restart the test')
288 if self.rm:
289 self.kill()
290 sys.exit(1)
291
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700292 if boot_delay:
293 time.sleep(boot_delay)
294
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700295 def setup_intfs(self):
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700296 if not self.olt:
297 return 0
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700298 tester_intf_subnet = '192.168.100'
299 res = 0
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700300 port_num = 0
301 host_intf = self.port_map['host']
302 start_vlan = self.port_map['start_vlan']
303 for port in self.port_map['ports']:
304 guest_if = port
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700305 local_if = guest_if
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700306 guest_ip = '{0}.{1}/24'.format(tester_intf_subnet, str(port_num+1))
307 ##Use pipeworks to configure container interfaces on host/bridge interfaces
308 pipework_cmd = 'pipework {0} -i {1} -l {2} {3} {4}'.format(host_intf, guest_if, local_if, self.name, guest_ip)
309 if start_vlan != 0:
310 pipework_cmd += ' @{}'.format(str(start_vlan + port_num))
311
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700312 res += os.system(pipework_cmd)
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700313 port_num += 1
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700314
315 return res
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700316
317 @classmethod
318 def get_name(cls):
319 cnt_name = '/{0}'.format(cls.basename)
320 cnt_name_len = len(cnt_name)
321 names = list(flatten(n['Names'] for n in cls.dckr.containers(all=True)))
322 test_names = filter(lambda n: n.startswith(cnt_name), names)
323 last_cnt_number = 0
324 if test_names:
325 last_cnt_name = reduce(lambda n1, n2: n1 if int(n1[cnt_name_len:]) > \
326 int(n2[cnt_name_len:]) else n2,
327 test_names)
328 last_cnt_number = int(last_cnt_name[cnt_name_len:])
329 test_cnt_name = cls.basename + str(last_cnt_number+1)
330 return test_cnt_name
331
332 @classmethod
333 def build_image(cls, image):
334 print('Building test container docker image %s' %image)
335 dockerfile = '''
336FROM ubuntu:14.04
337MAINTAINER chetan@ciena.com
338RUN apt-get update
339RUN apt-get -y install git python python-pip python-setuptools python-scapy tcpdump doxygen doxypy wget
340RUN easy_install nose
341RUN apt-get -y install openvswitch-common openvswitch-switch
342RUN mkdir -p /root/ovs
343WORKDIR /root
344RUN wget http://openvswitch.org/releases/openvswitch-2.4.0.tar.gz -O /root/ovs/openvswitch-2.4.0.tar.gz && \
345(cd /root/ovs && tar zxpvf openvswitch-2.4.0.tar.gz && \
346 cd openvswitch-2.4.0 && \
347 ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --disable-ssl && make && make install)
348RUN service openvswitch-switch restart || /bin/true
Chetan Gaonkerc170f3f2016-04-19 17:24:45 -0700349RUN apt-get -y install python-twisted python-sqlite sqlite3 python-pexpect telnet
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700350RUN pip install scapy-ssl_tls
351RUN pip install -U scapy
352RUN pip install monotonic
Chetan Gaonker3ff8eae2016-04-12 14:50:26 -0700353RUN pip install configObj
Chetan Gaonkerc170f3f2016-04-19 17:24:45 -0700354RUN pip install -U docker-py
355RUN pip install -U pyyaml
356RUN pip install -U nsenter
357RUN pip install -U pyroute2
358RUN pip install -U netaddr
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700359RUN mv /usr/sbin/tcpdump /sbin/
360RUN ln -sf /sbin/tcpdump /usr/sbin/tcpdump
361CMD ["/bin/bash"]
362'''
363 super(CordTester, cls).build_image(dockerfile, image)
364 print('Done building docker image %s' %image)
365
366 def run_tests(self, tests):
367 '''Run the list of tests'''
368 for t in tests:
369 test = t.split(':')[0]
370 if test == 'tls':
371 test_file = test + 'AuthTest.py'
372 else:
373 test_file = test + 'Test.py'
374
375 if t.find(':') >= 0:
376 test_case = test_file + ':' + t.split(':')[1]
377 else:
378 test_case = test_file
Chetan Gaonker7142a342016-04-07 14:53:12 -0700379 cmd = 'nosetests -v {0}/src/test/{1}/{2}'.format(self.sandbox, test, test_case)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700380 status = self.execute(cmd, shell = True)
381 print('Test %s %s' %(test_case, 'Success' if status == 0 else 'Failure'))
382 print('Done running tests')
383 if self.rm:
384 print('Removing test container %s' %self.name)
385 self.kill(remove=True)
386
Chetan Gaonkerb84835f2016-04-19 15:12:10 -0700387class Quagga(Container):
388
389 quagga_config = { 'bridge' : 'quagga-br', 'ip': '10.10.0.3', 'mask' : 16 }
390 ports = [ 179, 2601, 2602, 2603, 2604, 2605, 2606 ]
391 host_quagga_config = os.path.join(CordTester.tester_base, 'quagga-config')
392 guest_quagga_config = '/root/config'
393 host_guest_map = ( (host_quagga_config, guest_quagga_config), )
394
395 def __init__(self, name = 'cord-quagga', image = 'cord-test/quagga', tag = 'latest', boot_delay = 60):
396 super(Quagga, self).__init__(name, image, tag = tag, quagga_config = self.quagga_config)
397 if not self.img_exists():
398 self.build_image(image)
399 if not self.exists():
400 self.remove_container(name, force=True)
401 host_config = self.create_host_config(port_list = self.ports,
402 host_guest_map = self.host_guest_map,
403 privileged = True)
404 volumes = []
405 for _,g in self.host_guest_map:
406 volumes.append(g)
407 self.start(ports = self.ports,
408 host_config = host_config,
409 volumes = volumes, tty = True)
410 print('Starting Quagga on container %s' %self.name)
411 self.execute('{}/start.sh'.format(self.guest_quagga_config))
412
413 @classmethod
414 def build_image(cls, image):
415 onos_quagga_ip = Onos.quagga_config['ip']
416 print('Building Quagga image %s' %image)
417 dockerfile = '''
418FROM ubuntu:latest
419WORKDIR /root
420RUN useradd -M quagga
421RUN mkdir /var/log/quagga && chown quagga:quagga /var/log/quagga
422RUN mkdir /var/run/quagga && chown quagga:quagga /var/run/quagga
423RUN apt-get update && apt-get install -qy git autoconf libtool gawk make telnet libreadline6-dev
424RUN git clone git://git.sv.gnu.org/quagga.git quagga && \
425(cd quagga && git checkout HEAD && ./bootstrap.sh && \
426sed -i -r 's,htonl.*?\(INADDR_LOOPBACK\),inet_addr\("{0}"\),g' zebra/zebra_fpm.c && \
427./configure --enable-fpm --disable-doc --localstatedir=/var/run/quagga && make && make install)
428RUN ldconfig
429'''.format(onos_quagga_ip)
430 super(Quagga, cls).build_image(dockerfile, image)
431 print('Done building image %s' %image)
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700432
433##default onos/radius/test container images and names
434onos_image_default='onosproject/onos:latest'
435nose_image_default='cord-test/nose:latest'
436test_type_default='dhcp'
437onos_app_version = '1.0-SNAPSHOT'
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700438cord_tester_base = os.path.dirname(os.path.realpath(sys.argv[0]))
439onos_app_file = os.path.abspath('{0}/../apps/ciena-cordigmp-'.format(cord_tester_base) + onos_app_version + '.oar')
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700440
441def runTest(args):
442 onos_cnt = {'tag':'latest'}
443 radius_cnt = {'tag':'latest'}
444 nose_cnt = {'image': 'cord-test/nose','tag': 'latest'}
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700445 radius_ip = None
Chetan Gaonkerc170f3f2016-04-19 17:24:45 -0700446 quagga_ip = None
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700447 #print('Test type %s, onos %s, radius %s, app %s, olt %s, cleanup %s, kill flag %s, build image %s'
448 # %(args.test_type, args.onos, args.radius, args.app, args.olt, args.cleanup, args.kill, args.build))
449 if args.cleanup:
450 cleanup_container = args.cleanup
451 if cleanup_container.find(':') < 0:
452 cleanup_container += ':latest'
453 print('Cleaning up containers %s' %cleanup_container)
454 Container.cleanup(cleanup_container)
455 sys.exit(0)
456
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700457 #don't spawn onos if the user has specified external test controller with test interface config
458 if args.test_controller:
459 ips = args.test_controller.split('/')
460 onos_ip = ips[0]
461 if len(ips) > 1:
462 radius_ip = ips[1]
463 else:
464 radius_ip = None
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700465 else:
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700466 onos_cnt['image'] = args.onos.split(':')[0]
467 if args.onos.find(':') >= 0:
468 onos_cnt['tag'] = args.onos.split(':')[1]
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700469
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700470 onos = Onos(image = onos_cnt['image'], tag = onos_cnt['tag'], boot_delay = 60)
471 onos_ip = onos.ip()
472
473 ##Start Radius container if specified
474 if args.radius:
475 radius_cnt['image'] = args.radius.split(':')[0]
476 if args.radius.find(':') >= 0:
477 radius_cnt['tag'] = args.radius.split(':')[1]
478 radius = Radius(image = radius_cnt['image'], tag = radius_cnt['tag'])
479 radius_ip = radius.ip()
480 print('Started Radius server with IP %s' %radius_ip)
481 else:
482 radius_ip = None
483
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700484 print('Onos IP %s, Test type %s' %(onos_ip, args.test_type))
485 print('Installing ONOS app %s' %onos_app_file)
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700486 OnosCtrl.install_app(args.app, onos_ip = onos_ip)
Chetan Gaonkerb84835f2016-04-19 15:12:10 -0700487
488 if args.quagga == True:
489 #Start quagga. Builds container if required
490 quagga = Quagga()
Chetan Gaonkerc170f3f2016-04-19 17:24:45 -0700491 quagga_ip = quagga.ip()
Chetan Gaonkerb84835f2016-04-19 15:12:10 -0700492
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700493 test_cnt_env = { 'ONOS_CONTROLLER_IP' : onos_ip,
Chetan Gaonkerc170f3f2016-04-19 17:24:45 -0700494 'ONOS_AAA_IP' : radius_ip if radius_ip is not None else '',
495 'QUAGGA_IP': quagga_ip if quagga_ip is not None else '',
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700496 }
497 if args.olt:
Chetan Gaonker7142a342016-04-07 14:53:12 -0700498 olt_conf_test_loc = os.path.join(CordTester.sandbox_setup, 'olt_config.json')
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700499 test_cnt_env['OLT_CONFIG'] = olt_conf_test_loc
500
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700501 test_cnt = CordTester(ctlr_ip = onos_ip, image = nose_cnt['image'], tag = nose_cnt['tag'],
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700502 env = test_cnt_env,
Chetan Gaonker85b7bd52016-04-20 10:29:12 -0700503 rm = args.kill,
504 update = args.update)
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700505 if args.start_switch or not args.olt:
506 test_cnt.start_switch()
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700507 test_cnt.setup_intfs()
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700508 tests = args.test_type.split('-')
509 test_cnt.run_tests(tests)
510
511if __name__ == '__main__':
512 parser = ArgumentParser(description='Cord Tester for ONOS')
513 parser.add_argument('-t', '--test-type', default=test_type_default, type=str)
514 parser.add_argument('-o', '--onos', default=onos_image_default, type=str, help='ONOS container image')
515 parser.add_argument('-r', '--radius',default='',type=str, help='Radius container image')
Chetan Gaonkerb84835f2016-04-19 15:12:10 -0700516 parser.add_argument('-q', '--quagga',action='store_true',help='Provision quagga container for vrouter')
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700517 parser.add_argument('-a', '--app', default=onos_app_file, type=str, help='Cord ONOS app filename')
518 parser.add_argument('-l', '--olt', action='store_true', help='Use OLT config')
Chetan Gaonker5209fe82016-04-19 10:09:53 -0700519 parser.add_argument('-e', '--test-controller', default='', type=str, help='External test controller ip for Onos and/or radius server.'
520 'Eg: 10.0.0.2/10.0.0.3 to specify ONOS and Radius ip to connect')
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700521 parser.add_argument('-c', '--cleanup', default='', type=str, help='Cleanup test containers')
522 parser.add_argument('-k', '--kill', action='store_true', help='Remove test container after tests')
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -0700523 parser.add_argument('-s', '--start-switch', action='store_true', help='Start OVS')
Chetan Gaonker85b7bd52016-04-20 10:29:12 -0700524 parser.add_argument('-u', '--update', action='store_true', help='Update test container image')
Chetan Gaonker93e302d2016-04-05 10:51:07 -0700525 parser.set_defaults(func=runTest)
526 args = parser.parse_args()
527 args.func(args)