forked from os-autoinst/openQA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
370 lines (318 loc) · 14 KB
/
Makefile
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
RETRY ?= 0
# STABILITY_TEST: Set to 1 to fail as soon as any of the RETRY fails rather
# than succeed if any of the RETRY succeed
STABILITY_TEST ?= 0
# KEEP_DB: Set to 1 to keep the test database process spawned for tests. This
# can help with faster re-runs of tests but might yield inconsistent results
KEEP_DB ?= 0
# CONTAINER_TEST: Set to 0 to exclude container tests needing a container
# runtime environment
CONTAINER_TEST ?= 1
# HELM_TEST: Set to 0 to exclude helm tests needing a kubernetes cluster
HELM_TEST ?= 1
# TESTS: Specify individual test files in a space separated lists. As the user
# most likely wants only the mentioned tests to be executed and no other
# checks this implicitly disables CHECKSTYLE
TESTS ?=
# EXTRA_PROVE_ARGS: Additional prove arguments to pass
EXTRA_PROVE_ARGS ?=
ifeq ($(TESTS),)
PROVE_ARGS ?= --trap -r ${EXTRA_PROVE_ARGS}
else
CHECKSTYLE ?= 0
PROVE_ARGS ?= --trap ${EXTRA_PROVE_ARGS} $(TESTS)
endif
PROVE_LIB_ARGS ?= -l
CONTAINER_IMG ?= openqa:latest
TEST_PG_PATH ?= /dev/shm/tpg
# TIMEOUT_M: Timeout for one retry of tests in minutes
TIMEOUT_M ?= 60
ifeq ($(CI),)
SCALE_FACTOR ?= 1
else
SCALE_FACTOR ?= 2
endif
TIMEOUT_RETRIES ?= $$((${TIMEOUT_M} * ${SCALE_FACTOR} * (${RETRY} + 1) ))m
CRE ?= podman
# avoid localized error messages (that are matched against in certain cases)
LC_ALL = C.utf8
LANGUAGE =
LANG = C.utf8
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
current_dir := $(patsubst %/,%,$(dir $(mkfile_path)))
container_env_file := "$(current_dir)/container.env"
unstables := $(shell cat tools/unstable_tests.txt | tr '\n' :)
shellfiles := $$(file --mime-type script/* t/* container/worker/*.sh tools/* | sed -n 's/^\(.*\):.*text\/x-shellscript.*$$/\1/p')
# tests need these environment variables to be unset
OPENQA_BASEDIR =
OPENQA_CONFIG =
OPENQA_SCHEDULER_HOST =
OPENQA_WEB_SOCKETS_HOST =
OPENQA_SCHEDULER_STARVATION_PROTECTION_PRIORITY_OFFSET =
.PHONY: help
help:
@echo Call one of the available targets:
@sed -n 's/\(^[^.#[:space:]A-Z]*\):.*$$/\1/p' Makefile | uniq
@echo See docs/Contributing.asciidoc for more details
.PHONY: install-generic
install-generic:
./tools/generate-packed-assets
for i in lib public script templates assets; do \
mkdir -p "$(DESTDIR)"/usr/share/openqa/$$i ;\
cp -a $$i/* "$(DESTDIR)"/usr/share/openqa/$$i ;\
done
for f in $(shell grep --perl-regexp '\.\.\/node_modules\/.*\.*+' assets/assetpack.def | sed -e 's|<* ../||') \
node_modules/fork-awesome/fonts/* node_modules/chosen-js/*.png; do \
install -m 644 -D --target-directory="$(DESTDIR)/usr/share/openqa/$${f%/*}" "$$f";\
done
for i in db images testresults pool ; do \
mkdir -p "$(DESTDIR)"/var/lib/openqa/$$i ;\
done
# shared dirs between openQA web and workers + compatibility links
for i in factory tests; do \
mkdir -p "$(DESTDIR)"/var/lib/openqa/share/$$i ;\
ln -sfn /var/lib/openqa/share/$$i "$(DESTDIR)"/var/lib/openqa/$$i ;\
done
for i in iso hdd repo other; do \
mkdir -p "$(DESTDIR)"/var/lib/openqa/share/factory/$$i ;\
done
for i in script; do \
ln -sfn /usr/share/openqa/$$i "$(DESTDIR)"/var/lib/openqa/$$i ;\
done
#
install -d -m 755 "$(DESTDIR)"/etc/apache2/vhosts.d
for i in openqa-common.inc openqa.conf.template openqa-ssl.conf.template; do \
install -m 644 etc/apache2/vhosts.d/$$i "$(DESTDIR)"/etc/apache2/vhosts.d ;\
done
install -d -m 755 "$(DESTDIR)"/etc/nginx/vhosts.d
for i in openqa-locations.inc openqa-upstreams.inc openqa.conf.template; do \
install -m 644 etc/nginx/vhosts.d/$$i "$(DESTDIR)"/etc/nginx/vhosts.d ;\
done
install -D -m 640 etc/openqa/client.conf "$(DESTDIR)"/etc/openqa/client.conf
install -D -m 644 etc/openqa/workers.ini "$(DESTDIR)"/etc/openqa/workers.ini
install -D -m 644 etc/openqa/openqa.ini "$(DESTDIR)"/etc/openqa/openqa.ini
install -D -m 640 etc/openqa/database.ini "$(DESTDIR)"/etc/openqa/database.ini
install -D -m 644 etc/logrotate.d/openqa "$(DESTDIR)"/etc/logrotate.d/openqa
#
install -d -m 755 "$(DESTDIR)"/usr/lib/systemd/system
install -d -m 755 "$(DESTDIR)"/usr/lib/systemd/system-generators
install -d -m 755 "$(DESTDIR)"/usr/lib/tmpfiles.d
for i in systemd/*.{service,slice,target,timer,path}; do \
install -m 644 $$i "$(DESTDIR)"/usr/lib/systemd/system ;\
done
ln -s [email protected] "$(DESTDIR)"/usr/lib/systemd/system/[email protected]
sed \
-e 's_^\(ExecStart=/usr/share/openqa/script/worker\) \(--instance %i\)$$_\1 --no-cleanup \2_' \
-e '/^$$/N;/\[Service\]/[email protected]' \
systemd/[email protected] > "$(DESTDIR)"/usr/lib/systemd/system/[email protected]
sed \
-e '/\[Service\]/aEnvironment=OPENQA_WORKER_TERMINATE_AFTER_JOBS_DONE=1' \
-e '/ExecStart=/aExecReload=\/bin\/kill -HUP $$MAINPID' \
-e 's/Restart=.*/Restart=always/' \
-e '/^$$/N;/\[Service\]/[email protected]' \
systemd/[email protected] > "$(DESTDIR)"/usr/lib/systemd/system/[email protected]
install -m 755 systemd/systemd-openqa-generator "$(DESTDIR)"/usr/lib/systemd/system-generators
install -m 644 systemd/tmpfiles-openqa.conf "$(DESTDIR)"/usr/lib/tmpfiles.d/openqa.conf
install -m 644 systemd/tmpfiles-openqa-webui.conf "$(DESTDIR)"/usr/lib/tmpfiles.d/openqa-webui.conf
install -d -m 755 "$(DESTDIR)"/usr/lib/systemd/system/openqa-gru.service.requires
ln -s ../postgresql.service "$(DESTDIR)"/usr/lib/systemd/system/openqa-gru.service.requires/postgresql.service
install -d -m 755 "$(DESTDIR)"/usr/lib/systemd/system/openqa-scheduler.service.requires
ln -s ../postgresql.service "$(DESTDIR)"/usr/lib/systemd/system/openqa-scheduler.service.requires/postgresql.service
install -d -m 755 "$(DESTDIR)"/usr/lib/systemd/system/openqa-websockets.service.requires
ln -s ../postgresql.service "$(DESTDIR)"/usr/lib/systemd/system/openqa-websockets.service.requires/postgresql.service
#
# install openQA apparmor profile
install -d -m 755 "$(DESTDIR)"/etc/apparmor.d
install -m 644 profiles/apparmor.d/usr.share.openqa.script.openqa "$(DESTDIR)"/etc/apparmor.d
install -m 644 profiles/apparmor.d/usr.share.openqa.script.worker "$(DESTDIR)"/etc/apparmor.d
install -d -m 755 "$(DESTDIR)"/etc/apparmor.d/local
install -m 644 profiles/apparmor.d/local/usr.share.openqa.script.openqa "$(DESTDIR)"/etc/apparmor.d/local
install -m 644 profiles/apparmor.d/local/usr.share.openqa.script.worker "$(DESTDIR)"/etc/apparmor.d/local
cp -Ra dbicdh "$(DESTDIR)"/usr/share/openqa/dbicdh
install -d -m 755 "$(DESTDIR)"/usr/lib/sysusers.d/
install -m 644 usr/lib/sysusers.d/openQA-worker.conf "$(DESTDIR)"/usr/lib/sysusers.d/
install -m 644 usr/lib/sysusers.d/geekotest.conf "$(DESTDIR)"/usr/lib/sysusers.d/
# Additional services which have a strong dependency on SUSE/openSUSE and do not
# make sense for other distributions
.PHONY: install-opensuse
install-opensuse: install-generic
for i in systemd/opensuse/*.{service,timer}; do \
install -m 644 $$i "$(DESTDIR)"/usr/lib/systemd/system ;\
done
# Match suse and opensuse
os := $(shell grep suse /etc/os-release)
.PHONY: install
ifeq ($(os),)
install: install-generic
else
install: install-opensuse
endif
.PHONY: test
ifeq ($(TRAVIS),true)
test: run-tests-within-container
else
ifeq ($(CHECKSTYLE),0)
checkstyle_tests =
else
checkstyle_tests = test-checkstyle-standalone
endif
test: $(checkstyle_tests) test-with-database
ifeq ($(CONTAINER_TEST),1)
ifeq ($(TESTS),)
test: test-containers-compose
endif
endif
ifeq ($(HELM_TEST),1)
ifeq ($(TESTS),)
test: test-helm-chart
endif
endif
endif
.PHONY: test-checkstyle
test-checkstyle: test-checkstyle-standalone test-tidy-compile
.PHONY: test-t
test-t:
$(MAKE) test-with-database TIMEOUT_M=25 PROVE_ARGS="$$HARNESS t/*.t" GLOBIGNORE="t/*tidy*:t/*compile*:$(unstables)"
.PHONY: test-heavy
test-heavy:
$(MAKE) test-with-database HEAVY=1 TIMEOUT_M=25 PROVE_ARGS="$$HARNESS $$(grep -l HEAVY=1 t/*.t | tr '\n' ' ')"
.PHONY: test-ui
test-ui:
$(MAKE) test-with-database TIMEOUT_M=25 PROVE_ARGS="$$HARNESS t/ui/*.t" GLOBIGNORE="t/*tidy*:t/*compile*:$(unstables)"
.PHONY: test-api
test-api:
$(MAKE) test-with-database TIMEOUT_M=20 PROVE_ARGS="$$HARNESS t/api/*.t" GLOBIGNORE="t/*tidy*:t/*compile*:$(unstables)"
# put unstable tests in tools/unstable_tests.txt and uncomment in circle CI config to handle unstables with retries
.PHONY: test-unstable
test-unstable:
for f in $$(cat tools/unstable_tests.txt); do $(MAKE) test-with-database COVERDB_SUFFIX=$$(echo $${COVERDB_SUFFIX}_$$f | tr '/' '_') TIMEOUT_M=10 PROVE_ARGS="$$HARNESS $$f" RETRY=5 || exit; done
.PHONY: test-fullstack
test-fullstack:
$(MAKE) test-with-database FULLSTACK=1 TIMEOUT_M=30 PROVE_ARGS="$$HARNESS t/full-stack.t t/33-developer_mode.t"
.PHONY: test-fullstack-unstable
test-fullstack-unstable:
$(MAKE) test-with-database FULLSTACK=1 TIMEOUT_M=15 PROVE_ARGS="$$HARNESS t/05-scheduler-full.t" RETRY=5
# we have apparently-redundant -I args in PERL5OPT here because Docker
# only works with one and Fedora's build system only works with the other
.PHONY: test-with-database
test-with-database:
test -d $(TEST_PG_PATH) && (pg_ctl -D $(TEST_PG_PATH) -s status >&/dev/null || pg_ctl -D $(TEST_PG_PATH) -s start) || ./t/test_postgresql $(TEST_PG_PATH)
$(MAKE) test-unit-and-integration TEST_PG="DBI:Pg:dbname=openqa_test;host=$(TEST_PG_PATH)"
-[ $(KEEP_DB) = 1 ] || pg_ctl -D $(TEST_PG_PATH) stop
.PHONY: test-unit-and-integration
test-unit-and-integration:
export GLOBIGNORE="$(GLOBIGNORE)";\
export DEVEL_COVER_DB_FORMAT=JSON;\
export PERL5OPT="$(COVEROPT)$(PERL5OPT) -It/lib -I$(PWD)/t/lib -I$(PWD)/external/os-autoinst-common/lib -MOpenQA::Test::PatchDeparse";\
RETRY=${RETRY} HOOK=./tools/delete-coverdb-folder timeout -s SIGINT -k 5 -v ${TIMEOUT_RETRIES} tools/retry prove ${PROVE_LIB_ARGS} ${PROVE_ARGS}
# prepares running the tests within a container (eg. pulls os-autoinst) and then runs the tests considering
# the test matrix environment variables
# note: This is supposed to run within the container unlike `launch-container-to-run-tests-within`
# which launches the container.
.PHONY: run-tests-within-container
run-tests-within-container:
tools/run-tests-within-container
ifeq ($(COVERAGE),1)
COVERDB_SUFFIX ?=
# We use JSON::PP because there is a bug producing a (harmless) 'redefined'
# warning when using Devel::Cover and Cpanel::JSON::XS
# https://progress.opensuse.org/issues/90371
COVEROPT ?= -mJSON::PP -MDevel::Cover=-select_re,'^/lib',+ignore_re,lib/perlcritic/Perl/Critic/Policy,-coverage,statement,-db,cover_db$(COVERDB_SUFFIX),
endif
.PHONY: coverage
coverage:
export DEVEL_COVER_DB_FORMAT=JSON;\
COVERAGE=1 cover ${COVER_OPTS} -test
COVER_REPORT_OPTS ?= -select_re '^(lib|script|t)/'
.PHONY: coverage-report-codecov
coverage-report-codecov:
export DEVEL_COVER_DB_FORMAT=JSON;\
cover $(COVER_REPORT_OPTS) -report codecovbash
.PHONY: coverage-codecov
coverage-codecov: coverage
$(MAKE) coverage-report-codecov
.PHONY: coverage-report-html
coverage-report-html:
cover $(COVER_REPORT_OPTS) -report html_minimal
.PHONY: coverage-html
coverage-html: coverage
$(MAKE) coverage-report-html
public/favicon.ico: assets/images/logo.svg
for w in 16 32 64 128; do \
(cd assets/images/ && for i in *.svg; do \
inkscape -e $${i%.svg}-$$w.png -w $$w $$i; \
done); \
done
convert assets/images/logo-16.png assets/images/logo-32.png assets/images/logo-64.png assets/images/logo-128.png -background white -alpha remove public/favicon.ico
rm assets/images/logo-128.png assets/images/logo-32.png assets/images/logo-64.png
.PHONY: container-test-build
container-test-build:
${CRE} build --no-cache $(current_dir)/container/openqa -t $(DOCKER_IMG)
.PHONY: $(container_env_file)
$(container_env_file):
env | grep -E 'CHECKSTYLE|FULLSTACK|UITEST|GH|TRAVIS|CPAN|DEBUG|ZYPPER' > $@
.PHONY: launch-container-to-run-tests-within
launch-container-to-run-tests-within: $(container_env_file)
${CRE} run --env-file $(container_env_file) -v $(current_dir):/opt/openqa \
$(CONTAINER_IMG) make coverage-codecov
rm $(container_env_file)
.PHONY: prepare-and-launch-container-to-run-tests-within
.NOTPARALLEL: prepare-and-launch-container-to-run-tests-within
prepare-and-launch-container-to-run-tests-within: container-test-build launch-container-to-run-tests-within
echo "Use '${CRE} rm' and '${CRE} rmi' to remove the container and image if necessary"
# all additional checks not called by prove
.PHONY: test-checkstyle-standalone
test-checkstyle-standalone: test-shellcheck test-yaml test-critic test-shfmt
ifeq ($(CONTAINER_TEST),1)
test-checkstyle-standalone: test-check-containers
endif
.PHONY: test-critic
test-critic:
PERL5LIB=lib/perlcritic:$$PERL5LIB perlcritic lib
.PHONY: test-tidy-compile
test-tidy-compile:
$(MAKE) test-unit-and-integration TIMEOUT_M=20 PROVE_ARGS="$$HARNESS t/*{tidy,compile}*.t" GLOBIGNORE="$(unstables)"
.PHONY: test-shellcheck
test-shellcheck:
@which shellcheck >/dev/null 2>&1 || (echo "Command 'shellcheck' not found, can not execute shell script checks" && false)
shellcheck -x $(shellfiles)
.PHONY: test-yaml
test-yaml:
@which yamllint >/dev/null 2>&1 || (echo "Command 'yamllint' not found, can not execute YAML syntax checks" && false)
@# Fall back to find if there is no git, e.g. in package builds
yamllint --strict $$((git ls-files "*.yml" "*.yaml" 2>/dev/null || find -name '*.y*ml') | grep -v ^dbicdh)
.PHONY: test-shfmt
test-shfmt:
@which shfmt >/dev/null 2>&1 || (echo "Command 'shfmt' not found, can not execute bash script syntax checks" && false)
shfmt -d -i 4 -bn -ci -sr $(shellfiles)
.PHONY: test-check-containers
test-check-containers:
tools/static_check_containers
.PHONY: tidy-js
tidy-js:
tools/js-tidy
.PHONY: tidy-perl
tidy-perl:
tools/tidy
.PHONY: tidy
tidy: tidy-js tidy-perl
.PHONY: test-containers-compose
test-containers-compose:
tools/test_containers_compose
.PHONY: test-helm-chart
test-helm-chart: test-helm-lint test-helm-install
.PHONY: test-helm-lint
test-helm-lint:
tools/test_helm_chart lint
.PHONY: test-helm-install
test-helm-install:
tools/test_helm_chart install
.PHONY: update-deps
update-deps:
tools/update-deps --cpanfile cpanfile --specfile dist/rpm/openQA.spec
.PHONY: generate-docs
generate-docs:
tools/generate-docs
.PHONY: serve-docs
serve-docs: generate-docs
(cd docs/build/; python3 -m http.server)