This repository has been archived by the owner on Apr 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
317 lines (282 loc) · 11.9 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
DEFAULT_REGISTRY = salttoaster
DEFAULT_DISTRO = opensuse151
DEFAULT_FLAVOR = devel
SUSE_DEFAULT_REGISTRY = registry.mgr.suse.de
SUSE_DEFAULT_VERSION = sles12sp3
SUSE_DEFAULT_FLAVOR = products
TOASTER_MOUNTPOINT = /salt-toaster
ROOT_MOUNTPOINT = /salt/src
SALT_REPO_MOUNTPOINT = $(ROOT_MOUNTPOINT)/salt-devel
SALT_OLDTESTS = tests
NO_NOX_SALT_TESTS = $(ROOT_MOUNTPOINT)/salt-*/tests
SALT_PYTESTS = tests/pytests
DOCKER_VOLUMES = -v "$(CURDIR)/:$(TOASTER_MOUNTPOINT)"
DESTRUCTIVE_TESTS = False
EXPENSIVE_TESTS = False
NOX = True
ifndef ST_JOB_ID
export ST_JOB_ID = local-test-run
endif
ifndef DISTRO
DISTRO = $(DEFAULT_DISTRO)
endif
ifneq (,$(findstring sles,$(FLAVOR)))
FLAVOR = $(SUSE_DEFAULT_FLAVOR)
else ifneq (,$(findstring rhel,$(FLAVOR)))
FLAVOR = $(SUSE_DEFAULT_FLAVOR)
else ifneq (,$(findstring ubuntu,$(FLAVOR)))
FLAVOR = $(SUSE_DEFAULT_FLAVOR)
else ifndef FLAVOR
FLAVOR = $(DEFAULT_FLAVOR)
endif
ifneq (,$(findstring sles,$(DISTRO)))
DOCKER_REGISTRY = $(SUSE_DEFAULT_REGISTRY)
else ifneq (,$(findstring rhel,$(DISTRO)))
DOCKER_REGISTRY = $(SUSE_DEFAULT_REGISTRY)
else ifneq (,$(findstring ubuntu,$(DISTRO)))
DOCKER_REGISTRY = $(SUSE_DEFAULT_REGISTRY)
else ifndef DOCKER_REGISTRY
DOCKER_REGISTRY = $(DEFAULT_REGISTRY)
endif
# Ubuntu devel images are stored on DockerHub
ifneq (,$(findstring ubuntu,$(DISTRO)))
ifneq (,$(findstring devel,$(FLAVOR)))
DOCKER_REGISTRY = $(DEFAULT_REGISTRY)
endif
endif
ifeq ("$(FLAVOR)", "devel")
ifdef SALT_REPO
$(eval DOCKER_VOLUMES:=$(DOCKER_VOLUMES) -v $(SALT_REPO):$(SALT_REPO_MOUNTPOINT))
endif
endif
ifndef DOCKER_IMAGE
DOCKER_IMAGE = $(DOCKER_REGISTRY)/toaster-$(DISTRO)-$(FLAVOR)
endif
ifdef DOCKER_MEM
DOCKER_RES_LIMITS = --memory="$(DOCKER_MEM)"
endif
ifdef DOCKER_CPUS
DOCKER_RES_LIMITS := $(DOCKER_RES_LIMITS) --cpus="$(DOCKER_CPUS)"
endif
ifeq ("$(FLAVOR)", "products-old")
NOX = False
else ifeq ("$(FLAVOR)", "products-old-testing")
NOX = False
else ifeq ("$(FLAVOR)", "products-3000")
NOX = False
else ifeq ("$(FLAVOR)", "products-3000-testing")
NOX = False
endif
ifndef DOCKER_FILE
DOCKER_FILE = $(DISTRO).$(FLAVOR).dockerfile
endif
EXPORTS += \
-e "SALT_OLDTESTS=$(SALT_OLDTESTS)" \
-e "NO_NOX_SALT_TESTS=$(NO_NOX_SALT_TESTS)" \
-e "SALT_PYTESTS=$(SALT_PYTESTS)" \
-e "NOX=$(NOX)" \
-e "DISTRO=$(DISTRO)" \
-e "FLAVOR=$(FLAVOR)" \
-e "DOCKER_IMAGE=$(DOCKER_IMAGE)" \
-e "MINION_VERSION=$(MINION_VERSION)" \
-e "MINION_FLAVOR=$(MINION_FLAVOR)" \
-e "ROOT_MOUNTPOINT=$(ROOT_MOUNTPOINT)" \
-e "SALT_REPO_MOUNTPOINT=$(SALT_REPO_MOUNTPOINT)" \
-e "TOASTER_MOUNTPOINT=$(TOASTER_MOUNTPOINT)" \
-e "DESTRUCTIVE_TESTS=$(DESTRUCTIVE_TESTS)" \
-e "EXPENSIVE_TESTS=$(EXPENSIVE_TESTS)"
# Setting the defaults for a job execution in Jenkins
ifdef BUILD_ID
ifndef DOCKER_RES_LIMITS
DOCKER_RES_LIMITS := --memory="3G" --cpus="1.5"
endif
endif
title:
@echo
@echo "███████╗ █████╗ ██╗ ████████╗ ████████╗ ██████╗ █████╗ ███████╗████████╗███████╗██████╗"
@echo "██╔════╝██╔══██╗██║ ╚══██╔══╝ ╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝╚══██╔══╝██╔════╝██╔══██╗"
@echo "███████╗███████║██║ ██║ ██║ ██║ ██║███████║███████╗ ██║ █████╗ ██████╔╝"
@echo "╚════██║██╔══██║██║ ██║ ██║ ██║ ██║██╔══██║╚════██║ ██║ ██╔══╝ ██╔══██╗"
@echo "███████║██║ ██║███████╗██║ ██║ ╚██████╔╝██║ ██║███████║ ██║ ███████╗██║ ██║"
@echo "╚══════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝"
@echo
@echo "///////////////////////////////////////////////////"
@echo "// Salt Toaster: An ultimate test suite for Salt //"
@echo "// https://github.com/openSUSE/salt-toaster/ //"
@echo "///////////////////////////////////////////////////"
@echo
help: title
@echo "Commands:"
@echo " set_env Create environment"
@echo " list_targets List available versions and flavors targets"
@echo " docker_shell Start Docker shell"
@echo " saltstack.integration Run Salt integration tests"
@echo " saltstack.unit Run Salt unit tests"
@echo " suse.tests Run SUSE custom integration tests"
@echo " build Build the docker images and set the entrypoint to one of the predefined ones."
@echo " build_image Build the docker images and set the entrypoint to BASH."
@echo " archive-salt Pack salt into a tarball and archive it"
@echo ""
default: help
set_env:
bin/prepare_environment.sh --create sandbox
list_targets: title
@echo "Available public targets:"
@echo " openSUSE Leap 15.1 DISTRO: leap15.1 - FLAVOR: devel"
@echo " openSUSE Leap 15.2 DISTRO: leap15.2 - FLAVOR: devel"
@echo " openSUSE Leap 15.3 DISTRO: leap15.3 - FLAVOR: devel"
@echo " openSUSE Leap 15.4 DISTRO: leap15.4 - FLAVOR: products, products-testing, devel"
@echo " openSUSE Tumbleweed DISTRO: tumbleweed - FLAVOR: devel"
@echo " CentOS 7 DISTRO: centos7 - FLAVOR: devel"
@echo " Ubuntu 16.04 DISTRO: ubuntu16.04 - FLAVOR: devel"
@echo " Ubuntu 18.04 DISTRO: ubuntu18.04 - FLAVOR: devel"
@echo
@echo "SUSE internal use only:"
@echo " SUSE SLE11SP4 DISTRO: sles11sp4 - FLAVOR: products-old, products-old-testing, devel"
@echo " SUSE SLE12SP3 DISTRO: sles12sp3 - FLAVOR: products, products-testing, products-next, devel"
@echo " SUSE SLE12SP4 DISTRO: sles12sp4 - FLAVOR: products, products-testing, products-next, devel"
@echo " SUSE SLE15 DISTRO: sles15 - FLAVOR: products, products-testing, products-next, devel"
@echo " SUSE SLE15SP1 DISTRO: sles15sp1 - FLAVOR: products, products-testing, products-next, devel"
@echo " SUSE SLE15SP2 DISTRO: sles15sp2 - FLAVOR: products-next, devel"
@echo " RedHat RHEL6 DISTRO: rhel6 - FLAVOR: products-old, products-old-testing, devel"
@echo " RedHat RHEL7 DISTRO: rhel7 - FLAVOR: products, products-testing, products-next, devel"
@echo " RedHat RHEL8 DISTRO: rhel8 - FLAVOR: products, products-testing, products-next, devel"
@echo " Ubuntu 16.04 DISTRO: ubuntu16.04 - FLAVOR: products, products-testing, products-next, devel"
@echo " Ubuntu 18.04 DISTRO: ubuntu18.04 - FLAVOR: products, products-testing, products-next, devel"
@echo
pull_image:
ifndef NOPULL
docker pull $(DOCKER_IMAGE)
endif
LEGACY_PYTEST_ARGS=-c $(PYTEST_CFG) $(NO_NOX_SALT_TESTS) $(PYTEST_FLAGS)
LEGACY_PYTEST_CMD=pytest $(LEGACY_PYTEST_ARGS) --junitxml results.xml
# New Toaster with pytest in nox
NOX_PYTEST_ARGS=-c $(PYTEST_CFG) $(SALT_OLDTESTS) $(SALT_PYTESTS) $(PYTEST_FLAGS)
ifneq (,$(findstring 3000,$(FLAVOR)))
REQUIREMENTS_FILE=requirements/static/py3.6/linux.txt
else
REQUIREMENTS_FILE=requirements/static/ci/py3.6/linux.txt
endif
GOTO_SALT_ROOT=cd $(ROOT_MOUNTPOINT)/salt-*
PATCH_REQUIREMENTS=sed -i 's/attrs==19.1.0/attrs==19.2.0/' $(REQUIREMENTS_FILE)
NOX_CMD=$(GOTO_SALT_ROOT) && mv ../conftest.py . && $(PATCH_REQUIREMENTS) && nox --session 'pytest-3(coverage=False)' -- $(NOX_PYTEST_ARGS) --junitxml results.xml
ifeq ("$(NOX)", "True")
CMD=$(NOX_CMD)
else
ifeq ("$(FLAVOR)", "devel")
CMD=PYTHONPATH=/salt/src/salt-devel/ $(LEGACY_PYTEST_CMD)
else
CMD=$(LEGACY_PYTEST_CMD)
endif
endif
EXEC=docker run $(EXPORTS) -t -e "CMD=$(CMD)" --label=$(ST_JOB_ID) --rm $(DOCKER_VOLUMES) $(DOCKER_RES_LIMITS) $(DOCKER_IMAGE) tests
ifndef RPDB_PORT
docker_shell : EXEC=docker run -it $(EXPORTS) -e "CMD=$(CMD)" --rm $(DOCKER_VOLUMES) $(DOCKER_RES_LIMITS) $(DOCKER_IMAGE)
else
docker_shell : EXEC=docker run -p $(RPDB_PORT):4444 -it $(EXPORTS) -e "CMD=$(CMD)" --rm $(DOCKER_VOLUMES) $(DOCKER_RES_LIMITS) $(DOCKER_IMAGE)
endif
docker_shell : CMD=/bin/bash
docker_shell :: title pull_image
ifeq ("$(FLAVOR)", "devel")
ifndef SALT_REPO
@echo "ERROR: Using 'devel' FLAVOR requires SALT_REPO";
exit 1
endif
endif
$(EXEC)
ifeq ("$(DISTRO)", "sles11sp4")
saltstack.unit : PYTEST_CFG=$(TOASTER_MOUNTPOINT)/configs/saltstack.unit/sles11sp4.cfg
else ifeq ("$(DISTRO)", "rhel6")
saltstack.unit : PYTEST_CFG=$(TOASTER_MOUNTPOINT)/configs/saltstack.unit/rhel6.cfg
else
ifeq ("$(NOX)", "True")
saltstack.unit : PYTEST_CFG=$(TOASTER_MOUNTPOINT)/configs/saltstack.unit/common.cfg
else
saltstack.unit : PYTEST_CFG=$(TOASTER_MOUNTPOINT)/configs/saltstack.unit/common_legacy.cfg
endif
endif
saltstack.unit : SALT_OLDTESTS:=$(SALT_OLDTESTS)/unit
saltstack.unit : SALT_PYTESTS:=$(SALT_PYTESTS)/unit
saltstack.unit : NO_NOX_SALT_TESTS:=$(NO_NOX_SALT_TESTS)/unit
ifneq ("$(FLAVOR)", "devel")
ifdef JENKINS_HOME
saltstack.unit : PYTEST_ARGS:=$(PYTEST_ARGS) --timeout=500
saltstack.unit : CMD:=timeout 180m sh -c \"$(CMD)\"
endif
endif
saltstack.unit :: title pull_image
ifeq ("$(FLAVOR)", "devel")
ifndef SALT_REPO
@echo "ERROR: Using 'devel' FLAVOR requires SALT_REPO"
exit 1
endif
endif
$(EXEC)
ifeq ("$(DISTRO)", "sles11sp4")
saltstack.integration : PYTEST_CFG=$(TOASTER_MOUNTPOINT)/configs/saltstack.integration/sles11sp4.cfg
else ifeq ("$(DISTRO)", "rhel6")
saltstack.integration : PYTEST_CFG=$(TOASTER_MOUNTPOINT)/configs/saltstack.integration/rhel6.cfg
else
ifeq ("$(NOX)", "True")
saltstack.integration : PYTEST_CFG=$(TOASTER_MOUNTPOINT)/configs/saltstack.integration/common.cfg
else
saltstack.integration : PYTEST_CFG=$(TOASTER_MOUNTPOINT)/configs/saltstack.integration/common_legacy.cfg
endif
endif
saltstack.integration : SALT_OLDTESTS:=$(SALT_OLDTESTS)/integration
saltstack.integration : SALT_PYTESTS:=$(SALT_PYTESTS)/integration
saltstack.integration : NO_NOX_SALT_TESTS:=$(NO_NOX_SALT_TESTS)/integration
ifneq ("$(FLAVOR)", "devel")
ifdef JENKINS_HOME
saltstack.integration : PYTEST_ARGS:=$(PYTEST_ARGS) --timeout=500
saltstack.integration : CMD:=timeout 180m sh -c \"$(CMD)\"
endif
endif
saltstack.integration :: title pull_image
ifeq ("$(FLAVOR)", "devel")
ifndef SALT_REPO
@echo "ERROR: Using 'devel' FLAVOR requires SALT_REPO"
exit 1
endif
endif
$(EXEC)
suse.tests : PYTEST_CFG=./configs/suse.tests/$(DISTRO)/$(FLAVOR).cfg
suse.tests : SALT_TESTS=./tests
suse.tests : PYTEST_ARGS=-c $(PYTEST_CFG) $(SALT_TESTS) $(PYTEST_FLAGS)
suse.tests : CMD=pytest $(PYTEST_ARGS) --junitxml results.xml
suse.tests : EXEC=sandbox/bin/$(CMD)
ifneq ("$(FLAVOR)", "devel")
ifdef JENKINS_HOME
suse.tests : PYTEST_ARGS:=$(PYTEST_ARGS) --timeout=500
suse.tests : EXEC:=timeout 180m $(EXEC)
endif
endif
suse.tests : EXEC:=DISTRO=$(DISTRO) FLAVOR=$(FLAVOR) $(EXEC)
suse.tests : title pull_image
ifeq ("$(FLAVOR)", "devel")
ifndef SALT_REPO
@echo "ERROR: Using 'devel' FLAVOR requires SALT_REPO"
exit 1
endif
endif
$(EXEC)
archive-salt:
ifeq ("$(FLAVOR)", "devel")
ifdef SALT_REPO
tar -X .tarexclude -czf images/docker/salt.archive -C $(SALT_REPO) .
endif
endif
build::
@echo "Building images"
ifeq ("$(NOPULL)", "true")
$(eval BUILD_OPTS:=--nopull)
endif
ifndef VENV
DOCKER_IMAGE=$(DOCKER_IMAGE) DOCKER_FILE=$(DOCKER_FILE) python3 images/build.py $(BUILD_OPTS)
else
DOCKER_IMAGE=$(DOCKER_IMAGE) DOCKER_FILE=$(DOCKER_FILE) $(VENV)/bin/python images/build.py $(BUILD_OPTS)
endif
rm -f images/docker/salt.archive
build_image : CMD=""
build_image :: archive-salt build
$(EXEC)