forked from os-autoinst/openQA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
316 lines (271 loc) · 11.8 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
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
# 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
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' :)
# 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 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 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,target,timer,path}; do \
install -m 644 $$i "$(DESTDIR)"/usr/lib/systemd/system ;\
done
sed \
-e 's_^\(ExecStart=/usr/share/openqa/script/worker\) \(--instance %i\)$$_\1 --no-cleanup \2_' \
-e '/Wants/[email protected]' \
systemd/[email protected] > "$(DESTDIR)"/usr/lib/systemd/system/[email protected]
sed \
-e '/Type/aEnvironment=OPENQA_WORKER_TERMINATE_AFTER_JOBS_DONE=1' \
-e '/ExecStart=/aExecReload=\/bin\/kill -HUP $$MAINPID' \
-e 's/Restart=on-failure/Restart=always/' \
-e '/Wants/[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 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)
test: test-with-database
else
test: test-checkstyle-standalone test-with-database
endif
ifeq ($(CONTAINER_TEST),1)
ifeq ($(TESTS),)
test: test-containers-compose
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 RETRY=15 PROVE_ARGS="$$HARNESS t/full-stack.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 t/33-developer_mode.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 -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:
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
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 $$(file --mime-type script/* t/* container/worker/*.sh tools/* | sed -n 's/^\(.*\):.*text\/x-shellscript.*$$/\1/p')
.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-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: update-deps
update-deps:
tools/update-deps --specfile dist/rpm/openQA.spec