Chetan Gaonker | cb122cc | 2016-05-10 10:58:34 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 2 | # |
Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 3 | # 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 Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 8 | # |
Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 10 | # |
Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 11 | # 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 Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 17 | from argparse import ArgumentParser |
A R Karthick | 14118c6 | 2016-07-27 14:54:04 -0700 | [diff] [blame] | 18 | import os,sys,time,socket,errno |
Chetan Gaonker | 4d842ad | 2016-04-26 10:04:24 -0700 | [diff] [blame] | 19 | utils_dir = os.path.join( os.path.dirname(os.path.realpath(__file__)), '../utils') |
Chetan Gaonker | 7142a34 | 2016-04-07 14:53:12 -0700 | [diff] [blame] | 20 | sys.path.append(utils_dir) |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 21 | from OnosCtrl import OnosCtrl |
Chetan Gaonker | 4ca5cca | 2016-04-11 13:59:35 -0700 | [diff] [blame] | 22 | from OltConfig import OltConfig |
A R Karthick | 1f03e91 | 2016-05-18 11:39:22 -0700 | [diff] [blame] | 23 | from threadPool import ThreadPool |
Chetan Gaonker | 3533faa | 2016-04-25 17:50:14 -0700 | [diff] [blame] | 24 | from CordContainer import * |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 25 | from CordTestServer import cord_test_server_start, cord_test_server_stop, CORD_TEST_HOST, CORD_TEST_PORT |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 26 | |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 27 | class CordTester(Container): |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 28 | sandbox = '/root/test' |
Chetan Gaonker | 7142a34 | 2016-04-07 14:53:12 -0700 | [diff] [blame] | 29 | sandbox_setup = '/root/test/src/test/setup' |
Chetan Gaonker | 4d842ad | 2016-04-26 10:04:24 -0700 | [diff] [blame] | 30 | tester_base = os.path.dirname(os.path.realpath(__file__)) |
| 31 | tester_paths = os.path.realpath(__file__).split(os.path.sep) |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 32 | tester_path_index = tester_paths.index('src') - 1 |
Chetan Gaonker | 7142a34 | 2016-04-07 14:53:12 -0700 | [diff] [blame] | 33 | sandbox_host = os.path.sep.join(tester_paths[:tester_path_index+1]) |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 34 | |
| 35 | host_guest_map = ( (sandbox_host, sandbox), |
Chetan Gaonker | 85b7bd5 | 2016-04-20 10:29:12 -0700 | [diff] [blame] | 36 | ('/lib/modules', '/lib/modules'), |
| 37 | ('/var/run/docker.sock', '/var/run/docker.sock') |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 38 | ) |
| 39 | basename = 'cord-tester' |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 40 | IMAGE = 'cord-test/nose' |
ChetanGaonker | 006429b | 2016-07-22 10:24:34 -0700 | [diff] [blame] | 41 | ALL_TESTS = ('tls', 'dhcp', 'dhcprelay','igmp', 'subscriber', 'vrouter', 'flows', 'proxyarp') |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 42 | |
A R Karthick | 1f03e91 | 2016-05-18 11:39:22 -0700 | [diff] [blame] | 43 | def __init__(self, tests, instance = 0, num_instances = 1, ctlr_ip = None, image = IMAGE, tag = 'latest', |
Chetan Gaonker | 85b7bd5 | 2016-04-20 10:29:12 -0700 | [diff] [blame] | 44 | env = None, rm = False, update = False): |
A R Karthick | 1f03e91 | 2016-05-18 11:39:22 -0700 | [diff] [blame] | 45 | self.tests = tests |
Chetan Gaonker | 4ca5cca | 2016-04-11 13:59:35 -0700 | [diff] [blame] | 46 | self.ctlr_ip = ctlr_ip |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 47 | 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 Gaonker | b84835f | 2016-04-19 15:12:10 -0700 | [diff] [blame] | 52 | for _, g in self.host_guest_map: |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 53 | volumes.append(g) |
Chetan Gaonker | 85b7bd5 | 2016-04-20 10:29:12 -0700 | [diff] [blame] | 54 | if update is True or not self.img_exists(): |
Chetan Gaonker | b84835f | 2016-04-19 15:12:10 -0700 | [diff] [blame] | 55 | self.build_image(image) |
Chetan Gaonker | 7142a34 | 2016-04-07 14:53:12 -0700 | [diff] [blame] | 56 | ##Remove test container if any |
| 57 | self.remove_container(self.name, force=True) |
Chetan Gaonker | 4ca5cca | 2016-04-11 13:59:35 -0700 | [diff] [blame] | 58 | if env is not None and env.has_key('OLT_CONFIG'): |
| 59 | self.olt = True |
Chetan Gaonker | 5209fe8 | 2016-04-19 10:09:53 -0700 | [diff] [blame] | 60 | olt_conf_file = os.path.join(self.tester_base, 'olt_config.json') |
| 61 | olt_config = OltConfig(olt_conf_file) |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 62 | self.port_map, _ = olt_config.olt_port_map() |
Chetan Gaonker | 4ca5cca | 2016-04-11 13:59:35 -0700 | [diff] [blame] | 63 | else: |
| 64 | self.olt = False |
Chetan Gaonker | 5209fe8 | 2016-04-19 10:09:53 -0700 | [diff] [blame] | 65 | self.port_map = None |
A R Karthick | 1f03e91 | 2016-05-18 11:39:22 -0700 | [diff] [blame] | 66 | if env is not None: |
| 67 | env['TEST_HOST'] = self.name |
| 68 | env['TEST_INSTANCE'] = instance |
| 69 | env['TEST_INSTANCES'] = num_instances |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 70 | print('Starting test container %s, image %s, tag %s' %(self.name, self.image, self.tag)) |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 71 | self.start(rm = False, volumes = volumes, environment = env, |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 72 | host_config = host_config, tty = True) |
Chetan Gaonker | 4ca5cca | 2016-04-11 13:59:35 -0700 | [diff] [blame] | 73 | |
| 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 Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 90 | status = 1 |
| 91 | ## Wait for the LLDP flows to be added to the switch |
| 92 | tries = 0 |
Chetan Gaonker | a52016e | 2016-05-05 15:19:59 -0700 | [diff] [blame] | 93 | while status != 0 and tries < 200: |
Chetan Gaonker | 4ca5cca | 2016-04-11 13:59:35 -0700 | [diff] [blame] | 94 | cmd = 'sudo ovs-ofctl dump-flows {0} | grep \"type=0x8942\"'.format(bridge) |
| 95 | status = self.execute_switch(cmd, shell = True) |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 96 | 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 Gaonker | 4ca5cca | 2016-04-11 13:59:35 -0700 | [diff] [blame] | 107 | if boot_delay: |
| 108 | time.sleep(boot_delay) |
| 109 | |
A R Karthick | 1f03e91 | 2016-05-18 11:39:22 -0700 | [diff] [blame] | 110 | def setup_intfs(self, port_num = 0): |
Chetan Gaonker | 4ca5cca | 2016-04-11 13:59:35 -0700 | [diff] [blame] | 111 | tester_intf_subnet = '192.168.100' |
| 112 | res = 0 |
Chetan Gaonker | 5209fe8 | 2016-04-19 10:09:53 -0700 | [diff] [blame] | 113 | 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 Karthick | 1f03e91 | 2016-05-18 11:39:22 -0700 | [diff] [blame] | 117 | local_if = '{0}_{1}'.format(guest_if, port_num+1) |
| 118 | guest_ip = '{0}.{1}/24'.format(tester_intf_subnet, port_num+1) |
Chetan Gaonker | 5209fe8 | 2016-04-19 10:09:53 -0700 | [diff] [blame] | 119 | ##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 Karthick | 1f03e91 | 2016-05-18 11:39:22 -0700 | [diff] [blame] | 122 | pipework_cmd += ' @{}'.format(start_vlan + port_num) |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 123 | |
Chetan Gaonker | 4ca5cca | 2016-04-11 13:59:35 -0700 | [diff] [blame] | 124 | res += os.system(pipework_cmd) |
Chetan Gaonker | 5209fe8 | 2016-04-19 10:09:53 -0700 | [diff] [blame] | 125 | port_num += 1 |
Chetan Gaonker | 4ca5cca | 2016-04-11 13:59:35 -0700 | [diff] [blame] | 126 | |
A R Karthick | 1f03e91 | 2016-05-18 11:39:22 -0700 | [diff] [blame] | 127 | return res, port_num |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 128 | |
| 129 | @classmethod |
A R Karthick | b50f559 | 2016-07-26 12:19:29 -0700 | [diff] [blame] | 130 | def cleanup_intfs(cls): |
| 131 | olt_conf_file = os.path.join(cls.tester_base, 'olt_config.json') |
| 132 | olt_config = OltConfig(olt_conf_file) |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 133 | port_map, _ = olt_config.olt_port_map() |
A R Karthick | b50f559 | 2016-07-26 12:19:29 -0700 | [diff] [blame] | 134 | port_num = 0 |
| 135 | intf_host = port_map['host'] |
| 136 | start_vlan = port_map['start_vlan'] |
| 137 | intf_type = 0 |
| 138 | if os.path.isdir('/sys/class/net/{}/bridge'.format(intf_host)): |
| 139 | intf_type = 1 ##linux bridge |
| 140 | else: |
| 141 | cmd = 'ovs-vsctl list-br | grep -q "^{0}$"'.format(intf_host) |
| 142 | res = os.system(cmd) |
| 143 | if res == 0: ##ovs bridge |
| 144 | intf_type = 2 |
| 145 | cmds = () |
| 146 | res = 0 |
| 147 | for port in port_map['ports']: |
| 148 | local_if = '{0}_{1}'.format(port, port_num+1) |
| 149 | if intf_type == 0: |
| 150 | if start_vlan != 0: |
| 151 | cmds = ('ip link del {}.{}'.format(intf_host, start_vlan + port_num),) |
| 152 | else: |
| 153 | if intf_type == 1: |
| 154 | cmds = ('brctl delif {} {}'.format(intf_host, local_if), |
| 155 | 'ip link del {}'.format(local_if)) |
| 156 | else: |
| 157 | cmds = ('ovs-vsctl del-port {} {}'.format(intf_host, local_if),) |
| 158 | |
| 159 | for cmd in cmds: |
| 160 | res += os.system(cmd) |
| 161 | |
| 162 | port_num += 1 |
| 163 | |
| 164 | @classmethod |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 165 | def get_name(cls): |
| 166 | cnt_name = '/{0}'.format(cls.basename) |
| 167 | cnt_name_len = len(cnt_name) |
| 168 | names = list(flatten(n['Names'] for n in cls.dckr.containers(all=True))) |
| 169 | test_names = filter(lambda n: n.startswith(cnt_name), names) |
| 170 | last_cnt_number = 0 |
| 171 | if test_names: |
| 172 | last_cnt_name = reduce(lambda n1, n2: n1 if int(n1[cnt_name_len:]) > \ |
| 173 | int(n2[cnt_name_len:]) else n2, |
| 174 | test_names) |
| 175 | last_cnt_number = int(last_cnt_name[cnt_name_len:]) |
| 176 | test_cnt_name = cls.basename + str(last_cnt_number+1) |
| 177 | return test_cnt_name |
| 178 | |
| 179 | @classmethod |
| 180 | def build_image(cls, image): |
| 181 | print('Building test container docker image %s' %image) |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 182 | ovs_version = '2.5.0' |
| 183 | image_format = (ovs_version,)*4 |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 184 | dockerfile = ''' |
| 185 | FROM ubuntu:14.04 |
| 186 | MAINTAINER chetan@ciena.com |
A R Karthick | c762df4 | 2016-05-25 10:09:21 -0700 | [diff] [blame] | 187 | RUN apt-get update && \ |
| 188 | apt-get install -y git git-core autoconf automake autotools-dev pkg-config \ |
| 189 | make gcc g++ libtool libc6-dev cmake libpcap-dev libxerces-c2-dev \ |
| 190 | unzip libpcre3-dev flex bison libboost-dev \ |
| 191 | python python-pip python-setuptools python-scapy tcpdump doxygen doxypy wget \ |
| 192 | openvswitch-common openvswitch-switch \ |
A R Karthick | 8cf29ac | 2016-06-30 16:25:14 -0700 | [diff] [blame] | 193 | python-twisted python-sqlite sqlite3 python-pexpect telnet arping isc-dhcp-server |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 194 | RUN easy_install nose |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 195 | RUN mkdir -p /root/ovs |
| 196 | WORKDIR /root |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 197 | RUN wget http://openvswitch.org/releases/openvswitch-{}.tar.gz -O /root/ovs/openvswitch-{}.tar.gz && \ |
| 198 | (cd /root/ovs && tar zxpvf openvswitch-{}.tar.gz && \ |
| 199 | cd openvswitch-{} && \ |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 200 | ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --disable-ssl && make && make install) |
| 201 | RUN service openvswitch-switch restart || /bin/true |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 202 | RUN pip install -U scapy scapy-ssl_tls monotonic configObj docker-py pyyaml nsenter pyroute2 netaddr python-daemon |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 203 | RUN mv /usr/sbin/tcpdump /sbin/ |
| 204 | RUN ln -sf /sbin/tcpdump /usr/sbin/tcpdump |
A R Karthick | f499947 | 2016-07-01 16:42:13 -0700 | [diff] [blame] | 205 | RUN mv /usr/sbin/dhcpd /sbin/ |
| 206 | RUN ln -sf /sbin/dhcpd /usr/sbin/dhcpd |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 207 | WORKDIR /root |
| 208 | RUN wget -nc http://de.archive.ubuntu.com/ubuntu/pool/main/b/bison/bison_2.5.dfsg-2.1_amd64.deb \ |
| 209 | http://de.archive.ubuntu.com/ubuntu/pool/main/b/bison/libbison-dev_2.5.dfsg-2.1_amd64.deb |
| 210 | RUN sudo dpkg -i bison_2.5.dfsg-2.1_amd64.deb libbison-dev_2.5.dfsg-2.1_amd64.deb |
| 211 | RUN rm bison_2.5.dfsg-2.1_amd64.deb libbison-dev_2.5.dfsg-2.1_amd64.deb |
| 212 | RUN wget -nc http://www.nbee.org/download/nbeesrc-jan-10-2013.zip && \ |
| 213 | unzip nbeesrc-jan-10-2013.zip && \ |
| 214 | cd nbeesrc-jan-10-2013/src && cmake . && make && \ |
| 215 | cp ../bin/libn*.so /usr/local/lib && ldconfig && \ |
| 216 | cp -R ../include/* /usr/include/ |
| 217 | WORKDIR /root |
| 218 | RUN git clone https://github.com/CPqD/ofsoftswitch13.git && \ |
| 219 | cd ofsoftswitch13 && \ |
A R Karthick | b7e8090 | 2016-05-17 09:38:31 -0700 | [diff] [blame] | 220 | ./boot.sh && \ |
| 221 | ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --disable-ssl && \ |
| 222 | make && make install |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 223 | CMD ["/bin/bash"] |
Chetan Gaonker | b6064fa | 2016-05-02 16:29:57 -0700 | [diff] [blame] | 224 | '''.format(*image_format) |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 225 | super(CordTester, cls).build_image(dockerfile, image) |
| 226 | print('Done building docker image %s' %image) |
| 227 | |
A R Karthick | 1f03e91 | 2016-05-18 11:39:22 -0700 | [diff] [blame] | 228 | def run_tests(self): |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 229 | '''Run the list of tests''' |
A R Karthick | 1f03e91 | 2016-05-18 11:39:22 -0700 | [diff] [blame] | 230 | print('Running tests: %s' %self.tests) |
| 231 | for t in self.tests: |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 232 | test = t.split(':')[0] |
A R Karthick | 24f1de6 | 2016-05-12 15:16:38 -0700 | [diff] [blame] | 233 | test_file = '{}Test.py'.format(test) |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 234 | if t.find(':') >= 0: |
A R Karthick | 24f1de6 | 2016-05-12 15:16:38 -0700 | [diff] [blame] | 235 | test_case = '{0}:{1}'.format(test_file, t.split(':')[1]) |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 236 | else: |
| 237 | test_case = test_file |
Chetan Gaonker | 7142a34 | 2016-04-07 14:53:12 -0700 | [diff] [blame] | 238 | cmd = 'nosetests -v {0}/src/test/{1}/{2}'.format(self.sandbox, test, test_case) |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 239 | status = self.execute(cmd, shell = True) |
| 240 | print('Test %s %s' %(test_case, 'Success' if status == 0 else 'Failure')) |
| 241 | print('Done running tests') |
| 242 | if self.rm: |
| 243 | print('Removing test container %s' %self.name) |
| 244 | self.kill(remove=True) |
| 245 | |
Chetan Gaonker | fb3cb5e | 2016-05-06 11:55:44 -0700 | [diff] [blame] | 246 | @classmethod |
| 247 | def list_tests(cls, tests): |
| 248 | print('Listing test cases') |
| 249 | for test in tests: |
A R Karthick | 24f1de6 | 2016-05-12 15:16:38 -0700 | [diff] [blame] | 250 | test_file = '{}Test.py'.format(test) |
Chetan Gaonker | fb3cb5e | 2016-05-06 11:55:44 -0700 | [diff] [blame] | 251 | cmd = 'nosetests -v --collect-only {0}/../{1}/{2}'.format(cls.tester_base, test, test_file) |
| 252 | os.system(cmd) |
| 253 | |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 254 | ##default onos/radius/test container images and names |
| 255 | onos_image_default='onosproject/onos:latest' |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 256 | nose_image_default= '{}:latest'.format(CordTester.IMAGE) |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 257 | test_type_default='dhcp' |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 258 | onos_app_version = '2.0-SNAPSHOT' |
Chetan Gaonker | 4d842ad | 2016-04-26 10:04:24 -0700 | [diff] [blame] | 259 | cord_tester_base = os.path.dirname(os.path.realpath(__file__)) |
Chetan Gaonker | 4ca5cca | 2016-04-11 13:59:35 -0700 | [diff] [blame] | 260 | onos_app_file = os.path.abspath('{0}/../apps/ciena-cordigmp-'.format(cord_tester_base) + onos_app_version + '.oar') |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 261 | cord_test_server_address = '{}:{}'.format(CORD_TEST_HOST, CORD_TEST_PORT) |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 262 | |
| 263 | def runTest(args): |
Chetan Gaonker | 823cdc5 | 2016-05-09 15:51:23 -0700 | [diff] [blame] | 264 | #Start the cord test tcp server |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 265 | test_server_params = args.server.split(':') |
| 266 | test_host = test_server_params[0] |
| 267 | test_port = CORD_TEST_PORT |
| 268 | if len(test_server_params) > 1: |
| 269 | test_port = int(test_server_params[1]) |
| 270 | try: |
| 271 | test_server = cord_test_server_start(daemonize = False, cord_test_host = test_host, cord_test_port = test_port) |
| 272 | except: |
| 273 | ##Most likely a server instance is already running (daemonized earlier) |
| 274 | test_server = None |
| 275 | |
A R Karthick | 1f03e91 | 2016-05-18 11:39:22 -0700 | [diff] [blame] | 276 | test_containers = [] |
| 277 | #These tests end up restarting ONOS/quagga/radius |
A R Karthick | b03cecd | 2016-07-27 10:27:55 -0700 | [diff] [blame] | 278 | tests_exempt = ('vrouter', 'cordSubscriber', 'proxyarp') |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 279 | if args.test_type.lower() == 'all': |
| 280 | tests = CordTester.ALL_TESTS |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 281 | args.quagga = True |
| 282 | else: |
A R Karthick | acae3b4 | 2016-05-12 15:27:24 -0700 | [diff] [blame] | 283 | tests = args.test_type.split('-') |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 284 | |
A R Karthick | 1f03e91 | 2016-05-18 11:39:22 -0700 | [diff] [blame] | 285 | tests_parallel = [ t for t in tests if t.split(':')[0] not in tests_exempt ] |
| 286 | tests_not_parallel = [ t for t in tests if t.split(':')[0] in tests_exempt ] |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 287 | onos_cnt = {'tag':'latest'} |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 288 | nose_cnt = {'image': CordTester.IMAGE, 'tag': 'latest'} |
| 289 | update_map = { 'quagga' : False, 'test' : False, 'radius' : False } |
| 290 | update_map[args.update.lower()] = True |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 291 | |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 292 | if args.update.lower() == 'all': |
| 293 | for c in update_map.keys(): |
| 294 | update_map[c] = True |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 295 | |
Chetan Gaonker | 5209fe8 | 2016-04-19 10:09:53 -0700 | [diff] [blame] | 296 | radius_ip = None |
Chetan Gaonker | fb3cb5e | 2016-05-06 11:55:44 -0700 | [diff] [blame] | 297 | |
Chetan Gaonker | 5209fe8 | 2016-04-19 10:09:53 -0700 | [diff] [blame] | 298 | #don't spawn onos if the user has specified external test controller with test interface config |
| 299 | if args.test_controller: |
| 300 | ips = args.test_controller.split('/') |
| 301 | onos_ip = ips[0] |
| 302 | if len(ips) > 1: |
| 303 | radius_ip = ips[1] |
| 304 | else: |
| 305 | radius_ip = None |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 306 | else: |
Chetan Gaonker | 5209fe8 | 2016-04-19 10:09:53 -0700 | [diff] [blame] | 307 | onos_cnt['image'] = args.onos.split(':')[0] |
| 308 | if args.onos.find(':') >= 0: |
| 309 | onos_cnt['tag'] = args.onos.split(':')[1] |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 310 | |
Chetan Gaonker | 5209fe8 | 2016-04-19 10:09:53 -0700 | [diff] [blame] | 311 | onos = Onos(image = onos_cnt['image'], tag = onos_cnt['tag'], boot_delay = 60) |
| 312 | onos_ip = onos.ip() |
| 313 | |
A R Karthick | eaf1c4e | 2016-07-19 12:22:35 -0700 | [diff] [blame] | 314 | print('Onos IP %s, Test type %s' %(onos_ip, args.test_type)) |
A R Karthick | bd9b8a3 | 2016-07-21 09:56:45 -0700 | [diff] [blame] | 315 | if args.test_controller: |
| 316 | print('Installing ONOS cord apps') |
| 317 | Onos.install_cord_apps(onos_ip = onos_ip) |
A R Karthick | eaf1c4e | 2016-07-19 12:22:35 -0700 | [diff] [blame] | 318 | |
| 319 | print('Installing cord tester ONOS app %s' %onos_app_file) |
| 320 | OnosCtrl.install_app(args.app, onos_ip = onos_ip) |
| 321 | |
| 322 | if radius_ip is None: |
A R Karthick | a661b55 | 2016-05-25 10:18:50 -0700 | [diff] [blame] | 323 | ##Start Radius container |
| 324 | radius = Radius( update = update_map['radius']) |
| 325 | radius_ip = radius.ip() |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 326 | |
A R Karthick | eaf1c4e | 2016-07-19 12:22:35 -0700 | [diff] [blame] | 327 | print('Radius server running with IP %s' %radius_ip) |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 328 | |
Chetan Gaonker | b84835f | 2016-04-19 15:12:10 -0700 | [diff] [blame] | 329 | if args.quagga == True: |
| 330 | #Start quagga. Builds container if required |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 331 | quagga = Quagga(update = update_map['quagga']) |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 332 | |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 333 | test_cnt_env = { 'ONOS_CONTROLLER_IP' : onos_ip, |
Chetan Gaonker | c170f3f | 2016-04-19 17:24:45 -0700 | [diff] [blame] | 334 | 'ONOS_AAA_IP' : radius_ip if radius_ip is not None else '', |
A R Karthick | 8d03cc5 | 2016-06-28 14:51:59 -0700 | [diff] [blame] | 335 | 'QUAGGA_IP': test_host, |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 336 | 'CORD_TEST_HOST' : test_host, |
| 337 | 'CORD_TEST_PORT' : test_port, |
A R Karthick | eaf1c4e | 2016-07-19 12:22:35 -0700 | [diff] [blame] | 338 | 'ONOS_RESTART_DISABLED' : 1 if args.olt and args.test_controller else 0, |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 339 | } |
| 340 | if args.olt: |
Chetan Gaonker | 7142a34 | 2016-04-07 14:53:12 -0700 | [diff] [blame] | 341 | olt_conf_test_loc = os.path.join(CordTester.sandbox_setup, 'olt_config.json') |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 342 | test_cnt_env['OLT_CONFIG'] = olt_conf_test_loc |
| 343 | |
A R Karthick | 1f03e91 | 2016-05-18 11:39:22 -0700 | [diff] [blame] | 344 | port_num = 0 |
| 345 | num_tests = len(tests_parallel) |
| 346 | tests_per_container = max(1, num_tests/args.num_containers) |
| 347 | test_slice_start = 0 |
| 348 | test_slice_end = test_slice_start + tests_per_container |
| 349 | num_test_containers = min(num_tests, args.num_containers) |
| 350 | if tests_parallel: |
| 351 | print('Running %s tests across %d containers in parallel' %(tests_parallel, num_test_containers)) |
| 352 | for container in range(num_test_containers): |
| 353 | test_cnt = CordTester(tests_parallel[test_slice_start:test_slice_end], |
| 354 | instance = container, num_instances = num_test_containers, |
| 355 | ctlr_ip = onos_ip, image = nose_cnt['image'], tag = nose_cnt['tag'], |
| 356 | env = test_cnt_env, |
| 357 | rm = False if args.keep else True, |
| 358 | update = update_map['test']) |
| 359 | test_slice_start = test_slice_end |
| 360 | test_slice_end = test_slice_start + tests_per_container |
| 361 | update_map['test'] = False |
| 362 | test_containers.append(test_cnt) |
| 363 | if args.start_switch or not args.olt: |
| 364 | test_cnt.start_switch() |
| 365 | if test_cnt.olt: |
| 366 | _, port_num = test_cnt.setup_intfs(port_num = port_num) |
| 367 | |
| 368 | thread_pool = ThreadPool(len(test_containers), queue_size = 1, wait_timeout=1) |
| 369 | for test_cnt in test_containers: |
| 370 | thread_pool.addTask(test_cnt.run_tests) |
| 371 | thread_pool.cleanUpThreads() |
| 372 | |
| 373 | ##Run the linear tests |
| 374 | if tests_not_parallel: |
| 375 | test_cnt = CordTester(tests_not_parallel, |
| 376 | ctlr_ip = onos_ip, image = nose_cnt['image'], tag = nose_cnt['tag'], |
| 377 | env = test_cnt_env, |
| 378 | rm = False if args.keep else True, |
| 379 | update = update_map['test']) |
| 380 | if args.start_switch or not args.olt: |
| 381 | test_cnt.start_switch() |
| 382 | if test_cnt.olt: |
| 383 | test_cnt.setup_intfs(port_num = port_num) |
| 384 | test_cnt.run_tests() |
| 385 | |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 386 | if test_server: |
| 387 | cord_test_server_stop(test_server) |
| 388 | |
| 389 | ##Starts onos/radius/quagga containers as appropriate |
| 390 | def setupCordTester(args): |
| 391 | onos_cnt = {'tag':'latest'} |
A R Karthick | 92a0e5a | 2016-06-22 17:11:05 -0700 | [diff] [blame] | 392 | nose_cnt = {'image': CordTester.IMAGE, 'tag': 'latest'} |
| 393 | update_map = { 'quagga' : False, 'radius' : False, 'test': False } |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 394 | update_map[args.update.lower()] = True |
| 395 | |
| 396 | if args.update.lower() == 'all': |
| 397 | for c in update_map.keys(): |
| 398 | update_map[c] = True |
| 399 | |
| 400 | onos_ip = None |
| 401 | radius_ip = None |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 402 | onos_cord_loc = args.onos_cord |
| 403 | if onos_cord_loc: |
| 404 | if onos_cord_loc.find(os.path.sep) < 0: |
| 405 | onos_cord_loc = os.path.join(os.getenv('HOME'), onos_cord_loc) |
| 406 | if not os.access(onos_cord_loc, os.F_OK): |
| 407 | print('ONOS cord config location %s is not accessible' %onos_cord_loc) |
| 408 | sys.exit(1) |
| 409 | #Disable test container provisioning on the ONOS compute node |
| 410 | args.dont_provision = True |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 411 | |
| 412 | ##If onos/radius was already started |
| 413 | if args.test_controller: |
| 414 | ips = args.test_controller.split('/') |
| 415 | onos_ip = ips[0] |
| 416 | if len(ips) > 1: |
| 417 | radius_ip = ips[1] |
| 418 | else: |
| 419 | radius_ip = None |
| 420 | |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 421 | onos_cord = None |
| 422 | if onos_cord_loc: |
| 423 | if not args.test_controller: |
| 424 | ##Unexpected case. Specify the external controller ip when running on cord node |
| 425 | print('Specify ONOS ip using \"-e\" option when running the cord-tester on cord node') |
| 426 | sys.exit(1) |
A R Karthick | bd9b8a3 | 2016-07-21 09:56:45 -0700 | [diff] [blame] | 427 | onos_cord = OnosCord(onos_ip, onos_cord_loc) |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 428 | |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 429 | #don't spawn onos if the user had started it externally |
| 430 | onos_cnt['image'] = args.onos.split(':')[0] |
| 431 | if args.onos.find(':') >= 0: |
| 432 | onos_cnt['tag'] = args.onos.split(':')[1] |
| 433 | |
| 434 | if onos_ip is None: |
| 435 | onos = Onos(image = onos_cnt['image'], tag = onos_cnt['tag'], boot_delay = 60) |
| 436 | onos_ip = onos.ip() |
| 437 | |
A R Karthick | eaf1c4e | 2016-07-19 12:22:35 -0700 | [diff] [blame] | 438 | print('Onos IP %s' %onos_ip) |
A R Karthick | bd9b8a3 | 2016-07-21 09:56:45 -0700 | [diff] [blame] | 439 | if args.test_controller: |
| 440 | print('Installing ONOS cord apps') |
| 441 | Onos.install_cord_apps(onos_ip = onos_ip) |
| 442 | |
A R Karthick | eaf1c4e | 2016-07-19 12:22:35 -0700 | [diff] [blame] | 443 | print('Installing cord tester ONOS app %s' %onos_app_file) |
| 444 | OnosCtrl.install_app(args.app, onos_ip = onos_ip) |
| 445 | |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 446 | ##Start Radius container if not started |
| 447 | if radius_ip is None: |
| 448 | radius = Radius( update = update_map['radius']) |
| 449 | radius_ip = radius.ip() |
| 450 | |
| 451 | print('Radius server running with IP %s' %radius_ip) |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 452 | |
| 453 | if args.quagga == True: |
| 454 | #Start quagga. Builds container if required |
| 455 | quagga = Quagga(update = update_map['quagga']) |
A R Karthick | 8d03cc5 | 2016-06-28 14:51:59 -0700 | [diff] [blame] | 456 | print('Quagga started') |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 457 | |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 458 | params = args.server.split(':') |
| 459 | ip = params[0] |
| 460 | port = CORD_TEST_PORT |
| 461 | if len(params) > 1: |
| 462 | port = int(params[1]) |
A R Karthick | 92a0e5a | 2016-06-22 17:11:05 -0700 | [diff] [blame] | 463 | |
| 464 | #provision the test container |
| 465 | if not args.dont_provision: |
| 466 | test_cnt_env = { 'ONOS_CONTROLLER_IP' : onos_ip, |
| 467 | 'ONOS_AAA_IP' : radius_ip, |
A R Karthick | 8d03cc5 | 2016-06-28 14:51:59 -0700 | [diff] [blame] | 468 | 'QUAGGA_IP': ip, |
A R Karthick | 92a0e5a | 2016-06-22 17:11:05 -0700 | [diff] [blame] | 469 | 'CORD_TEST_HOST' : ip, |
| 470 | 'CORD_TEST_PORT' : port, |
A R Karthick | eaf1c4e | 2016-07-19 12:22:35 -0700 | [diff] [blame] | 471 | 'ONOS_RESTART_DISABLED' : 1 if args.olt and args.test_controller else 0, |
A R Karthick | 92a0e5a | 2016-06-22 17:11:05 -0700 | [diff] [blame] | 472 | } |
| 473 | if args.olt: |
| 474 | olt_conf_test_loc = os.path.join(CordTester.sandbox_setup, 'olt_config.json') |
| 475 | test_cnt_env['OLT_CONFIG'] = olt_conf_test_loc |
| 476 | |
| 477 | test_cnt = CordTester((), |
| 478 | ctlr_ip = onos_ip, |
| 479 | image = nose_cnt['image'], |
| 480 | tag = nose_cnt['tag'], |
| 481 | env = test_cnt_env, |
| 482 | rm = False, |
| 483 | update = update_map['test']) |
| 484 | |
| 485 | if args.start_switch or not args.olt: |
| 486 | test_cnt.start_switch() |
| 487 | if test_cnt.olt: |
| 488 | test_cnt.setup_intfs(port_num = 0) |
| 489 | print('Test container %s started and provisioned to run tests using nosetests' %(test_cnt.name)) |
| 490 | |
| 491 | #Finally start the test server and daemonize |
A R Karthick | 14118c6 | 2016-07-27 14:54:04 -0700 | [diff] [blame] | 492 | try: |
| 493 | cord_test_server_start(daemonize = True, cord_test_host = ip, cord_test_port = port, |
| 494 | onos_cord = onos_cord) |
| 495 | except socket.error, e: |
| 496 | #the test agent address could be remote or already running. Exit gracefully |
| 497 | sys.exit(0) |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 498 | |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 499 | def cleanupTests(args): |
| 500 | test_container = '{}:latest'.format(CordTester.IMAGE) |
| 501 | print('Cleaning up Test containers ...') |
| 502 | Container.cleanup(test_container) |
A R Karthick | b50f559 | 2016-07-26 12:19:29 -0700 | [diff] [blame] | 503 | if args.olt: |
| 504 | print('Cleaning up test container OLT configuration') |
| 505 | CordTester.cleanup_intfs() |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 506 | |
| 507 | def listTests(args): |
| 508 | if args.test == 'all': |
| 509 | tests = CordTester.ALL_TESTS |
| 510 | else: |
A R Karthick | acae3b4 | 2016-05-12 15:27:24 -0700 | [diff] [blame] | 511 | tests = args.test.split('-') |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 512 | CordTester.list_tests(tests) |
| 513 | |
| 514 | def buildImages(args): |
| 515 | if args.image == 'all' or args.image == 'quagga': |
| 516 | Quagga.build_image(Quagga.IMAGE) |
A.R Karthick | 95d044e | 2016-06-10 18:44:36 -0700 | [diff] [blame] | 517 | |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 518 | if args.image == 'all' or args.image == 'radius': |
| 519 | Radius.build_image(Radius.IMAGE) |
| 520 | |
| 521 | if args.image == 'all' or args.image == 'test': |
| 522 | CordTester.build_image(CordTester.IMAGE) |
| 523 | |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 524 | if __name__ == '__main__': |
Chetan Gaonker | 678743f | 2016-04-26 09:54:31 -0700 | [diff] [blame] | 525 | parser = ArgumentParser(description='Cord Tester') |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 526 | subparser = parser.add_subparsers() |
| 527 | parser_run = subparser.add_parser('run', help='Run cord tester') |
| 528 | parser_run.add_argument('-t', '--test-type', default=test_type_default, help='Specify test type or test case to run') |
| 529 | parser_run.add_argument('-o', '--onos', default=onos_image_default, type=str, help='ONOS container image') |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 530 | parser_run.add_argument('-q', '--quagga',action='store_true',help='Provision quagga container for vrouter') |
| 531 | parser_run.add_argument('-a', '--app', default=onos_app_file, type=str, help='Cord ONOS app filename') |
| 532 | parser_run.add_argument('-p', '--olt', action='store_true', help='Use OLT config') |
| 533 | parser_run.add_argument('-e', '--test-controller', default='', type=str, help='External test controller ip for Onos and/or radius server. ' |
Chetan Gaonker | 5209fe8 | 2016-04-19 10:09:53 -0700 | [diff] [blame] | 534 | 'Eg: 10.0.0.2/10.0.0.3 to specify ONOS and Radius ip to connect') |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 535 | parser_run.add_argument('-r', '--server', default=cord_test_server_address, type=str, |
| 536 | help='ip:port address to connect for cord test server for container requests') |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 537 | parser_run.add_argument('-k', '--keep', action='store_true', help='Keep test container after tests') |
| 538 | parser_run.add_argument('-s', '--start-switch', action='store_true', help='Start OVS when running under OLT config') |
| 539 | parser_run.add_argument('-u', '--update', default='none', choices=['test','quagga','radius', 'all'], type=str, help='Update cord tester container images. ' |
| 540 | 'Eg: --update=quagga to rebuild quagga image.' |
| 541 | ' --update=radius to rebuild radius server image.' |
| 542 | ' --update=test to rebuild cord test image.(Default)' |
| 543 | ' --update=all to rebuild all cord tester images.') |
A R Karthick | 1f03e91 | 2016-05-18 11:39:22 -0700 | [diff] [blame] | 544 | parser_run.add_argument('-n', '--num-containers', default=1, type=int, |
| 545 | help='Specify number of test containers to spawn for tests') |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 546 | parser_run.set_defaults(func=runTest) |
| 547 | |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 548 | |
| 549 | parser_setup = subparser.add_parser('setup', help='Setup cord tester environment') |
| 550 | parser_setup.add_argument('-o', '--onos', default=onos_image_default, type=str, help='ONOS container image') |
| 551 | parser_setup.add_argument('-r', '--server', default=cord_test_server_address, type=str, |
| 552 | help='ip:port address for cord test server to listen for container restart requests') |
| 553 | parser_setup.add_argument('-q', '--quagga',action='store_true',help='Provision quagga container for vrouter') |
| 554 | parser_setup.add_argument('-a', '--app', default=onos_app_file, type=str, help='Cord ONOS app filename') |
| 555 | parser_setup.add_argument('-e', '--test-controller', default='', type=str, help='External test controller ip for Onos and/or radius server. ' |
| 556 | 'Eg: 10.0.0.2/10.0.0.3 to specify ONOS and Radius ip to connect') |
| 557 | parser_setup.add_argument('-u', '--update', default='none', choices=['quagga','radius', 'all'], type=str, help='Update cord tester container images. ' |
| 558 | 'Eg: --update=quagga to rebuild quagga image.' |
| 559 | ' --update=radius to rebuild radius server image.' |
| 560 | ' --update=all to rebuild all cord tester images.') |
A R Karthick | 92a0e5a | 2016-06-22 17:11:05 -0700 | [diff] [blame] | 561 | parser_setup.add_argument('-d', '--dont-provision', action='store_true', help='Dont start test container.') |
| 562 | parser_setup.add_argument('-p', '--olt', action='store_true', help='Use OLT config') |
| 563 | parser_setup.add_argument('-s', '--start-switch', action='store_true', help='Start OVS when running under OLT config') |
A R Karthick | d44cea1 | 2016-07-20 12:16:41 -0700 | [diff] [blame] | 564 | parser_setup.add_argument('-c', '--onos-cord', default='', type=str, |
| 565 | help='Specify cord location for ONOS cord when running on podd') |
A R Karthick | 81acbff | 2016-06-17 14:45:16 -0700 | [diff] [blame] | 566 | parser_setup.set_defaults(func=setupCordTester) |
| 567 | |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 568 | parser_list = subparser.add_parser('list', help='List test cases') |
| 569 | parser_list.add_argument('-t', '--test', default='all', help='Specify test type to list test cases. ' |
| 570 | 'Eg: -t tls to list tls test cases.' |
| 571 | ' -t tls-dhcp-vrouter to list tls,dhcp and vrouter test cases.' |
| 572 | ' -t all to list all test cases.') |
| 573 | parser_list.set_defaults(func=listTests) |
| 574 | |
| 575 | parser_build = subparser.add_parser('build', help='Build cord test container images') |
| 576 | parser_build.add_argument('image', choices=['quagga', 'radius', 'test', 'all']) |
| 577 | parser_build.set_defaults(func=buildImages) |
| 578 | |
| 579 | parser_cleanup = subparser.add_parser('cleanup', help='Cleanup test containers') |
A R Karthick | b50f559 | 2016-07-26 12:19:29 -0700 | [diff] [blame] | 580 | parser_cleanup.add_argument('-p', '--olt', action = 'store_true', help = 'Cleanup OLT config') |
Chetan Gaonker | 503032a | 2016-05-12 12:06:29 -0700 | [diff] [blame] | 581 | parser_cleanup.set_defaults(func=cleanupTests) |
| 582 | |
Chetan Gaonker | 93e302d | 2016-04-05 10:51:07 -0700 | [diff] [blame] | 583 | args = parser.parse_args() |
| 584 | args.func(args) |