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
|
#!/usr/bin/env python
from __future__ import print_function
import sys
import argparse
import pytest
from proboscis import TestProgram
from proboscis import register
from fuelweb_test.helpers.utils import pretty_log
from gates_tests.helpers.utils import map_test_review_in_fuel_library
from gates_tests.helpers.utils import \
map_test_review_in_openstack_puppet_projects
from system_test import register_system_test_cases
from system_test import get_groups
from system_test import define_custom_groups
from system_test import discover_import_tests
from system_test import tests_directory
from system_test import collect_yamls
from system_test import get_path_to_config
from system_test import get_list_confignames
from system_test import get_basepath
from system_test.core.repository import split_group_config
basedir = get_basepath()
def print_explain(names):
groups_nums = get_groups()
if not isinstance(names, list):
names = [names]
out = []
for name in [split_group_config(i)[0] if split_group_config(i) else i
for i in names]:
for i in groups_nums[name]:
if hasattr(i, 'home'):
out.append((i.home._proboscis_entry_.parent.home, i.home))
else:
out.append(i)
print(pretty_log(out))
def clean_argv_proboscis():
"""Removing argv params unused by Proboscis"""
argv = sys.argv
if '--with-config' in argv:
idx = argv.index('--with-config')
argv.pop(idx)
argv.pop(idx)
if '--explain' in argv:
idx = argv.index('--explain')
argv.pop(idx)
return argv
def cli():
cli = argparse.ArgumentParser(prog="System test runner",
description="Command line tool for run Fuel "
"System Test")
commands = cli.add_subparsers(title="Operation commands",
dest="command")
cli_run = commands.add_parser('run',
help="Run test",
description="Run some test group")
cli_run.add_argument("run_groups", nargs='*', default=None, )
cli_run.add_argument("--with-config", default=False, type=str,
action="store", dest="config_name",
help="Select name of yaml config.")
cli_run.add_argument("--explain", default=False, action="store_true",
help="Show explain for running groups. "
"Will not start Proboscis.")
cli_run.add_argument("--show-plan", default=False, action="store_true",
help="Show Proboscis test plan.")
cli_run.add_argument("--with-xunit", default=False, action="store_true",
help="Use xuint report.")
cli_run.add_argument("--nologcapture", default=False, action="store_true",
help="Disable log capture for Proboscis.")
cli_run.add_argument("-q", default=False, action="store_true",
dest="quite",
help="Run Proboscis in quite mode.")
cli_run.add_argument("-a", default=False, action="store_true",
dest="nose_attr",
help="Provide Nose attr to Proboscis.")
cli_run.add_argument("-A", default=False, action="store_true",
dest="eval_nose",
help="Eval Nose attr to Proboscis.")
cli_run.add_argument("--groups", default=None, action="append", type=str,
help="Test group for testing. "
"(backward compatibility)")
cli_explain_group = commands.add_parser("explain-group",
help="Explain selected group.")
cli_explain_group.add_argument("name",
help="Group name.")
commands.add_parser("show-all-groups",
help="Show all Proboscis groups")
commands.add_parser("show-fuelweb-groups",
help="Show Proboscis groups defined in fuelweb suite")
commands.add_parser("show-systest-groups",
help="Show Proboscis groups defined in Systest suite")
commands.add_parser("show-systest-configs",
help="Show configurations for Systest suite")
if len(sys.argv) == 1:
cli.print_help()
sys.exit(1)
return cli.parse_args()
def run(**kwargs):
config_name = kwargs.get('config_name', None)
groups = kwargs.get('run_groups', [])
old_groups = kwargs.get('groups', None)
explain = kwargs.get('explain', None)
groups_to_run = []
groups.extend(old_groups or [])
# Collect from pytest only once!
pytest.main(['--collect-only', 'fuel_tests', ])
from fuel_tests.tests.conftest import test_names
for g in set(groups):
if g in test_names:
sys.exit(pytest.main('-m {}'.format(g)))
if config_name:
register_system_test_cases(
groups=[g],
configs=[config_name])
groups_to_run.append("{0}({1})".format(g, config_name))
else:
register_system_test_cases(groups=[g])
groups_to_run.append(g)
if not set([split_group_config(i)[0] if split_group_config(i) else i
for i in groups_to_run]) < set(get_groups()):
sys.exit('There are no cases mapped to current group, '
'please be sure that you put right test group name.')
if explain:
print_explain(groups)
else:
register(groups=["run_system_test"], depends_on_groups=groups_to_run)
TestProgram(groups=['run_system_test'],
argv=clean_argv_proboscis()).run_and_exit()
def explain_group(**kwargs):
"""Explain selected group."""
name = kwargs.get('name', None)
print_explain(name)
def show_all_groups(**kwargs):
"""Show all Proboscis groups"""
groups_nums = get_groups()
out = {k: len(v) for k, v in groups_nums.items()}
print(pretty_log(out))
def show_fuelweb_groups(**kwargs):
"""Show Proboscis groups defined in fuelweb suite"""
groups_nums = get_groups()
out = {k: len(v) for k, v in groups_nums.items()
if not k.startswith('system_test')}
print(pretty_log(out))
def show_systest_groups(**kwargs):
"""Show Proboscis groups defined in Systest suite"""
groups_nums = get_groups()
out = {k: len(v) for k, v in groups_nums.items()
if k.startswith('system_test')}
print(pretty_log(out))
def show_systest_configs(**kwargs):
"""Show configurations for Systest suite"""
tests_configs = collect_yamls(get_path_to_config())
for c in get_list_confignames(tests_configs):
print(c)
COMMAND_MAP = {
"run": run,
"explain-group": explain_group,
"show-all-groups": show_all_groups,
"show-fuelweb-groups": show_fuelweb_groups,
"show-systest-groups": show_systest_groups,
"show-systest-configs": show_systest_configs
}
def shell():
args = cli()
discover_import_tests(basedir, tests_directory)
define_custom_groups()
map_test_review_in_fuel_library(**vars(args))
map_test_review_in_openstack_puppet_projects(**vars(args))
COMMAND_MAP[args.command](**vars(args))
if __name__ == '__main__':
shell()
|