This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathconftest.py
283 lines (233 loc) · 6.85 KB
/
conftest.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
import logging
import os
import pytest
import sys
log_level = os.getenv("TEST_LOG_LEVEL", "INFO").upper()
log_levels = ("DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL", "EXCEPTION")
assert log_level in log_levels, "{} is not a valid log level. Use one of: {}".format(
log_level, ", ".join(log_levels)
)
# write everything to stdout due to the following circumstances:
# - shakedown uses print() aka stdout
# - teamcity splits out stdout vs stderr into separate outputs, we'd want them combined
logging.basicConfig(
format="[%(asctime)s|%(name)s|%(levelname)s]: %(message)s",
level=log_level,
stream=sys.stdout,
)
def pytest_addoption(parser):
parser.addoption(
"--masters",
action="store",
default=1,
type=int,
help="Number of Jenkins masters to launch.",
)
parser.addoption(
"--jobs",
action="store",
default=1,
type=int,
help="Number of test jobs to launch.",
)
parser.addoption(
"--single-use",
action="store",
default="False",
type=str,
help="Use Mesos Single-Use agents",
)
parser.addoption(
"--run-delay",
action="store",
default=10,
type=int,
help="Run job every X minutes.",
)
parser.addoption(
"--cpu-quota",
action="store",
default=0.0,
type=float,
help="CPU quota to set. 0.0 to set no" " quota.",
)
parser.addoption(
"--memory-quota",
action="store",
default=0.0,
type=float,
help="Memory quota to set. 0.0 to set no" " quota.",
)
parser.addoption(
"--work-duration",
action="store",
default=600,
type=int,
help="Duration, in seconds, for the " "workload to last (sleep).",
)
parser.addoption(
"--mom", action="store", default="", help="Marathon on Marathon instance name."
)
parser.addoption(
"--external-volume", action="store_true", help="Use rexray external volumes."
)
parser.addoption(
"--scenario",
action="store",
default="sleep",
help="Test scenario to run (sleep, buildmarathon) " "(default: sleep).",
)
parser.addoption(
"--min",
action="store",
default=-1,
help="min jenkins index to start from" "(default: -1).",
)
parser.addoption(
"--max",
action="store",
default=-1,
help="max jenkins index to end at" "(default: -1).",
)
parser.addoption(
"--batch-size",
action="store",
default=1,
help="batch size to deploy jenkins masters in" "(default: 1).",
)
parser.addoption(
"--service-ids",
action="store",
default="",
help="list of jenkins masters to delete",
)
parser.addoption(
"--enforce-quota-guarantee",
action="store",
default="True",
type=str,
help="Set quota values as guarantee.",
)
parser.addoption(
"--enforce-quota-limit",
action="store",
default="True",
type=str,
help="Set quota values as limit.",
)
parser.addoption(
"--create-framework",
action="store",
default="True",
type=str,
help="Only create service-accounts and Jenkins frameworks.",
)
parser.addoption(
"--create-jobs",
action="store",
default="True",
type=str,
help="Only create jobs on deployed Jenkins frameworks.",
)
parser.addoption(
"--containerizer",
action="store",
choices=['MESOS', 'DOCKER'],
default='MESOS',
type=str,
help="Select the containerizer used to launch the Jenkins master.",
)
parser.addoption(
"--mesos-agent-label",
action="store",
default="linux",
type=str,
help="Set default jenkins-agent mesos label.",
)
parser.addoption(
"--service-user",
action="store",
default="nobody",
type=str,
help="Set user for the jenkins scheduler and service.",
)
parser.addoption(
"--agent-user",
action="store",
default="nobody",
type=str,
help="Set user for the jenkins agents.",
)
@pytest.fixture
def master_count(request) -> int:
return int(request.config.getoption("--masters"))
@pytest.fixture
def job_count(request) -> int:
return int(request.config.getoption("--jobs"))
@pytest.fixture
def single_use(request) -> bool:
return _str2bool(request.config.getoption("--single-use"))
@pytest.fixture
def run_delay(request) -> int:
return int(request.config.getoption("--run-delay"))
@pytest.fixture
def cpu_quota(request) -> float:
return float(request.config.getoption("--cpu-quota"))
@pytest.fixture
def memory_quota(request) -> float:
return float(request.config.getoption("--memory-quota"))
@pytest.fixture
def work_duration(request) -> int:
return int(request.config.getoption("--work-duration"))
@pytest.fixture
def mom(request) -> str:
return request.config.getoption("--mom")
@pytest.fixture
def scenario(request) -> str:
return request.config.getoption("--scenario")
@pytest.fixture
def external_volume(request) -> bool:
return bool(request.config.getoption("--external-volume"))
@pytest.fixture
def min_index(request) -> int:
return int(request.config.getoption("--min"))
@pytest.fixture
def max_index(request) -> int:
return int(request.config.getoption("--max"))
@pytest.fixture
def batch_size(request) -> int:
return int(request.config.getoption("--batch-size"))
@pytest.fixture
def service_id_list(request) -> str:
return request.config.getoption("--service-ids")
@pytest.fixture
def enforce_quota_guarantee(request) -> bool:
return _str2bool(request.config.getoption("--enforce-quota-guarantee"))
@pytest.fixture
def enforce_quota_limit(request) -> bool:
return _str2bool(request.config.getoption("--enforce-quota-limit"))
@pytest.fixture
def create_framework(request) -> bool:
return _str2bool(request.config.getoption("--create-framework"))
@pytest.fixture
def create_jobs(request) -> bool:
return _str2bool(request.config.getoption("--create-jobs"))
@pytest.fixture
def containerizer(request) -> str:
return request.config.getoption("--containerizer")
@pytest.fixture
def mesos_agent_label(request) -> str:
return request.config.getoption("--mesos-agent-label")
@pytest.fixture
def service_user(request) -> str:
return request.config.getoption("--service-user")
@pytest.fixture
def agent_user(request) -> str:
return request.config.getoption("--agent-user")
def _str2bool(v) -> bool:
if isinstance(v, bool):
return v
if v.lower() in ("yes", "true", "t", "y", "1"):
return True
elif v.lower() in ("no", "false", "f", "n", "0"):
return False