-
Notifications
You must be signed in to change notification settings - Fork 3
/
tsm-run.py
executable file
·286 lines (259 loc) · 10.4 KB
/
tsm-run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/usr/bin/env python
# Copyright 2015 Midokura SARL
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import datetime
import getopt
import logging
import os
import sys
import traceback
from zephyr.common.exceptions import ArgMismatchException
from zephyr.common.exceptions import ExitCleanException
from zephyr.common.exceptions import ObjectNotFoundException
from zephyr.common.exceptions import SubprocessFailedException
from zephyr.common.exceptions import TestException
from zephyr.common.log_manager import LogManager
from zephyr.common import zephyr_constants as z_con
from zephyr.tsm.test_case import TestCase
from zephyr.tsm.test_system_manager import TestSystemManager
from zephyr.vtm.neutron_api import create_neutron_client
from zephyr.vtm.virtual_topology_manager import VirtualTopologyManager
def usage(except_obj):
print('Usage: tsm-run.py -t <tests> ')
print(' [-u <underlay_config>] [-n <name>] [-d]')
print(' [extra_options]')
print('')
print(' Test Execution Options:')
print(' -t, --tests <tests>')
print(' List of fully-qualified names of tests to run,')
print(' separated by commas with no spaces.')
print(' -n, --name <name>')
print(' Name this test run (timestamp by default).')
print(' Underlay Options:')
print(' -u, --underlay_config <config>')
print(' Load the underlay from the given config file. ')
print(' ("' + z_con.DEFAULT_UNDERLAY_CONFIG + '" by default)')
print(' Client API Options:')
print(' -c, --client <client>')
print(' OpenStack Network client to use. Currently can be')
print(' either "neutron" (default) or "midonet".')
print(' -a, --client-auth <auth>')
print(' Authentication scheme to use for Openstack ')
print(' authentication. Can be"noauth" or "keystone" ("noauth"')
print(' is default).')
print(' --client-args <args>')
print(' List of arguments to give the selected client. These')
print(' should be key=value pairs, separated by commas, with no')
print(' spaces.')
print(' Debug Options:')
print(' -d, --debug')
print(' Turn on DEBUG logging (and split log output to stdout).')
print(' Output File Options:')
print(' -l, --log-dir <dir>')
print(' Log file directory (default: /tmp/zephyr/results)')
print(' -r, --results-dir <dir>')
print(' Results file directory (default: /tmp/zephyr/logs).')
print(' Timestamp will be appended to prevent overwriting')
print(' results.')
if except_obj is not None:
raise except_obj
try:
arg_map, extra_args = getopt.getopt(
sys.argv[1:],
(
'h'
'v'
'd'
't:'
'n:'
'u:'
'c:'
'l:'
'r:'
'a:'
),
[
'help',
'tests=',
'name=',
'underlay_config=',
'client=',
'client-auth=',
'client-args=',
'log-dir=',
'debug',
'results-dir=',
'debug-test'
])
# Defaults
client_impl_type = 'neutron'
client_auth_type = 'noauth'
client_args = {}
tests = ''
underlay_config = z_con.DEFAULT_UNDERLAY_CONFIG
debug = False
test_debug = False
log_dir = '/tmp/zephyr/logs'
results_dir = '/tmp/zephyr/results'
topology = '2z-3c-2edge.json'
name = datetime.datetime.utcnow().strftime('%Y_%m_%d_%H-%M-%S')
for arg, value in arg_map:
if arg in ('-h', '--help'):
usage(None)
sys.exit(0)
elif arg in ('-t', '--tests'):
if value == '':
usage(ArgMismatchException(
'Tests should be given as a comma-delimited list '
'with no spaces'))
tests = value.split(',')
elif arg in ('-n', '--name'):
name = value
elif arg in ('-u', '--underlay-config'):
underlay_config = value
elif arg in ('-c', '--client'):
client_impl_type = value
elif arg in ('-a', '--client-auth'):
client_auth_type = value
elif arg in ('-l', '--log-dir'):
log_dir = value
elif arg in ('-d', '--debug'):
debug = True
elif arg in '--debug-test':
test_debug = True
elif arg in ('-r', '--results-dir'):
results_dir = value
elif arg == '--client-args':
for kv in value.split(','):
if kv == '':
usage(ArgMismatchException(
'Client args should be key=value pairs, '
'with one "=", separated by "," and no spaces.'))
p = kv.split('=')
if len(p) != 2:
usage(ArgMismatchException(
'Client args should be key=value pairs, with '
'one "=", separated by "," and no spaces.'))
client_args[p[0]] = p[1]
else:
raise ArgMismatchException('Invalid argument' + arg)
if len(tests) == 0:
usage(ArgMismatchException(
'Must specify at least one test with the -t or --tests option'))
tsm_run_dir = os.path.dirname(os.path.abspath(__file__))
z_con.ZephyrInit.init(tsm_run_dir + "/zephyr.conf")
root_dir = z_con.ZephyrInit.BIN_ROOT_DIR
print('Setting root dir to: ' + root_dir)
client_impl = None
base_client_args = dict()
if client_impl_type == 'neutron':
if client_auth_type == 'keystone':
base_client_args = {
'auth_strategy': 'keystone',
'auth_url':
os.environ.get('OS_ATUH_URL',
'http://localhost:5000/v2.0'),
'username': os.environ.get('OS_USERNAME', 'admin'),
'password': os.environ.get('OS_PASSWORD', 'cat'),
'tenant_name': os.environ.get('OS_TENANT_NAME', 'admin')}
base_client_args.update(client_args)
client_impl = create_neutron_client(**base_client_args)
else:
raise ArgMismatchException(
'Invalid client API implementation:' + client_impl_type)
print('Setting up log manager with debug=' + str(debug))
log_manager = LogManager(root_dir=log_dir)
console_log = log_manager.add_stdout_logger(
name='tsm-run-console',
log_level=logging.DEBUG if debug is True else logging.INFO)
log_manager.rollover_logs_fresh(file_filter='*.log')
# TODO(micucci): This will take a map specifying how to create VMs
# instead of a PTM
console_log.debug('Setting up vtm')
vtm = VirtualTopologyManager(
client_api_impl=client_impl,
log_manager=log_manager)
vtm.configure_logging(debug=debug)
vtm.read_underlay_config(underlay_config)
console_log.debug('Setting up tsm')
tsm = TestSystemManager(vtm, log_manager=log_manager)
tsm.configure_logging(debug=debug)
if test_debug:
tsm.set_test_debug()
console_log.debug('Test Case Classes = ' + str(tests))
# Run test cases, possibly filtered on scenarios
tsm.load_tests(tests)
console_log.debug('Running all tests with topology: ' + str(topology))
try:
results = tsm.run_all_tests(name, topology)
for suite, result in tsm.result_map.iteritems():
print('========================================')
print('Suite [' + suite + ']')
print('Passed [{0}/{1}]'.format(
len(result.successes), result.testsRun))
print('Expected Failures [{0}/{1}]'.format(
len(result.expectedFailures), result.testsRun))
print('Failed [{0}/{1}]'.format(
len(result.failures), result.testsRun))
print('Error [{0}/{1}]'.format(
len(result.errors), result.testsRun))
print('')
for tc, err in result.failures:
print('------------------------------')
print('Test Case FAILED: [' + tc.get_name() + ']')
print('Failure Message:')
print(err)
for tc, err in result.expectedFailures:
print('------------------------------')
print('Test Case passed with EXPECTED FAILURE: [' +
tc.get_name() +
'], see issue(s) [' +
','.join(tc.expected_failure_issue_ids) + ']')
print('Failure Message:')
print(err)
for tc, err in result.errors:
if isinstance(tc, TestCase):
print('------------------------------')
print('Test Case ERROR: [' + tc.get_name() + ']')
print('Error Message:')
print(err)
else:
print('------------------------------')
print('Test Framework ERROR')
print('Error Message:')
print(err)
for tc, err in result.skipped:
print('------------------------------')
print('Test Case SKIPPED: [' + tc.get_name() + ']')
print('Reason:')
print(err)
finally:
rdir = results_dir + '/' + name
tsm.create_results(results_dir=rdir)
except ExitCleanException:
exit(1)
except ArgMismatchException as a:
print('Argument mismatch: ' + str(a))
exit(2)
except ObjectNotFoundException as e:
print('Object not found: ' + str(e))
exit(2)
except SubprocessFailedException as e:
print('Subprocess failed to execute: ' + str(e))
traceback.print_tb(sys.exc_traceback)
exit(2)
except TestException as e:
print('Unknown exception: ' + str(e))
traceback.print_tb(sys.exc_traceback)
exit(2)