-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
198 lines (172 loc) · 5.83 KB
/
main.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
import os
import sys
import argparse
import asyncio
from core.config import BATCH_SIZE, DC_IN_MAINTENANCE
from scripts.cicd import run_cicd_tests
from scripts.data_quality import run_rrc_check
from scripts.compare_dc_versions import run_version_comparison
if os.path.abspath(".") not in sys.path:
sys.path.append(os.path.abspath('.'))
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--host",
type=str,
choices=["localhost", "stat.ripe.net", "beta001.stat.ripe.net"] +
[f"dev00{n}.stat.ripe.net" for n in range(1, 10)],
help="Host to connect"
)
parser.add_argument(
"--batch_size",
type=int,
default=BATCH_SIZE,
help="Batch size. 20 by default."
)
parser.add_argument(
"--path",
type=str,
default="",
help="File path to process"
)
parser.add_argument(
"--limit",
type=str,
default="",
help="Max number of lines or range to read. Example syntax: --limit 10 or --limit 10-20"
)
parser.add_argument(
"--random",
nargs='*',
default=False,
help="Sample a specific number of test cases per data call"
)
parser.add_argument(
"--dc",
dest="preferred_data_calls",
type=str,
nargs='*',
default=[""],
help=(
"Preferred data call(s) and versions to run the tests for."
"Example syntax: --dc bgplay abuse-contact-finder_2.0_2.1"
)
)
parser.add_argument(
"--maintenance",
dest="excluded_data_calls",
type=str,
nargs='*',
default=DC_IN_MAINTENANCE,
help=(
"Excluded data call(s) that are in maintenance"
"Example syntax: --dc blocklist mlab-clients"
)
)
parser.add_argument(
"--compare_versions",
type=bool,
default=False,
help="If True, TESTstat compares versions of DC passed by --dc"
)
parser.add_argument(
"--comparison_fields",
type=str,
nargs='*',
default=[""],
help="Data fields to compare"
)
parser.add_argument(
"--slack_hooks",
action="store_true",
help="If set, TESTstat will post messages to the configured Slack channel."
)
parser.add_argument(
"--okr",
type=bool,
default=False,
help="If True, TESTstat runs for OKRs"
)
parser.add_argument(
"--dq",
type=str,
choices=["rrc"],
help="Data quality test selection"
)
args = parser.parse_args()
# Argument validation
if int(args.batch_size) < 0 or int(args.batch_size) > 200:
parser.error("Batch size should be in the range [0, 200]!")
if args.random:
try:
args.random = int(args.random.pop())
except ValueError:
parser.error("random should be an integer!")
if args.compare_versions:
# Argument validation
if not args.preferred_data_calls:
parser.error("No data call found! Example syntax: --dc abuse-contact-finder_2.0_2.1")
if len(args.preferred_data_calls) > 1:
parser.error("Only one data call is allowed for comparison!")
if args.preferred_data_calls[0].count('_') < 2:
parser.error(
"No enough versions to compare! Example syntax: --dc abuse-contact-finder_2.0_2.1"
)
if not args.path:
parser.error("File Error: No data given!")
if not args.path.endswith(".txt"):
parser.error("File Error: Data source must be a text file!")
loop = asyncio.get_event_loop()
loop.run_until_complete(
run_version_comparison(
args.host,
args.batch_size,
args.path,
args.limit,
args.preferred_data_calls.pop(),
args.comparison_fields
)
)
elif args.host:
if not args.path:
args.path = "data/service_reliability_tests/test_cases_200.csv"
# If there is a preferred data call, ignore the randomness in any case
if args.preferred_data_calls and args.preferred_data_calls[0]:
args.random = False
# If 'excluded_data_calls' is a type of list, this means arg '--maintenance' has been used in local run instead of Jenkins.
# In such case, pass that list directly to test run and override DC_IN_MAINTENANCE in config.
if not isinstance(args.excluded_data_calls, list) and args.excluded_data_calls:
args.excluded_data_calls = args.excluded_data_calls.split(' ')
loop = asyncio.get_event_loop()
# The asyncio.run() function was added in Python 3.7
# The solution below is for compatibility concerns for the systems with Python < 3.7
if args.okr:
# Import here to avoid matplotlib dependency on Jenkins
from scripts.okr import run_okr_tests
loop.run_until_complete(
run_okr_tests(args.host, args.batch_size)
)
elif args.dq == "rrc":
run_rrc_check(args.host, args.slack_hooks)
else:
loop.run_until_complete(
run_cicd_tests(
args.host,
args.batch_size,
args.path,
args.random,
args.preferred_data_calls,
args.excluded_data_calls,
args.slack_hooks
)
)
# GUI usage
else:
from PyQt5.QtWidgets import QApplication
from gui.main_window import MainWindow
app = QApplication(sys.argv)
app.setStyle("fusion")
ui = MainWindow()
ui.setup_ui()
ui.show()
sys.exit(app.exec_())