forked from StackStorm/st2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
405 lines (344 loc) · 15.4 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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
SHELL := /bin/bash
TOX_DIR := .tox
VIRTUALENV_DIR ?= virtualenv
BINARIES := bin
# All components are prefixed by st2
COMPONENTS := $(wildcard st2*)
COMPONENTS += $(wildcard contrib/runners/*)
# Components that implement a component-controlled test-runner. These components provide an
# in-component Makefile. (Temporary fix until I can generalize the pecan unittest setup. -mar)
# Note: We also want to ignore egg-info dir created during build
COMPONENT_SPECIFIC_TESTS := st2tests st2client.egg-info
# nasty hack to get a space into a variable
space_char :=
space_char +=
comma := ,
COMPONENT_PYTHONPATH = $(subst $(space_char),:,$(realpath $(COMPONENTS)))
COMPONENTS_TEST := $(foreach component,$(filter-out $(COMPONENT_SPECIFIC_TESTS),$(COMPONENTS)),$(component))
COMPONENTS_TEST_COMMA := $(subst $(space_char),$(comma),$(COMPONENTS_TEST))
PYTHON_TARGET := 2.7
REQUIREMENTS := test-requirements.txt requirements.txt
PIP_OPTIONS := $(ST2_PIP_OPTIONS)
NOSE_OPTS := --rednose --immediate
NOSE_TIME := $(NOSE_TIME)
ifdef NOSE_TIME
NOSE_OPTS := --rednose --immediate --with-timer
endif
ifndef PIP_OPTIONS
PIP_OPTIONS := -U -q
endif
.PHONY: all
all: requirements configgen check tests
# Target for debugging Makefile variable assembly
.PHONY: play
play:
@echo COMPONENTS=$(COMPONENTS)
@echo COMPONENTS_TEST=$(COMPONENTS_TEST)
@echo COMPONENTS_TEST_COMMA=$(COMPONENTS_TEST_COMMA)
@echo COMPONENT_PYTHONPATH=$(COMPONENT_PYTHONPATH)
.PHONY: check
check: requirements flake8 checklogs
.PHONY: checklogs
checklogs:
@echo
@echo "================== LOG WATCHER ===================="
@echo
. $(VIRTUALENV_DIR)/bin/activate; ./tools/log_watcher.py 10
.PHONY: pylint
pylint: requirements .pylint
.PHONY: configgen
configgen:
@echo
@echo "================== config gen ===================="
@echo
# Lint st2 components
echo "# Sample config which contains all the available options which the corresponding descriptions" > conf/st2.conf.sample;
echo "# Note: This file is automatically generated using tools/config_gen.py - DO NOT UPDATE MANUALLY" >> conf/st2.conf.sample
echo "" >> conf/st2.conf.sample
. $(VIRTUALENV_DIR)/bin/activate; python ./tools/config_gen.py >> conf/st2.conf.sample;
.PHONY: .pylint
.pylint:
@echo
@echo "================== pylint ===================="
@echo
# Lint st2 components
@for component in $(COMPONENTS); do\
echo "==========================================================="; \
echo "Running pylint on" $$component; \
echo "==========================================================="; \
. $(VIRTUALENV_DIR)/bin/activate; pylint -E --rcfile=./lint-configs/python/.pylintrc --load-plugins=pylint_plugins.api_models --load-plugins=pylint_plugins.db_models $$component/$$component || exit 1; \
done
# Lint Python pack management actions
. $(VIRTUALENV_DIR)/bin/activate; pylint -E --rcfile=./lint-configs/python/.pylintrc --load-plugins=pylint_plugins.api_models contrib/packs/actions/ || exit 1;
# Lint other packs
. $(VIRTUALENV_DIR)/bin/activate; pylint -E --rcfile=./lint-configs/python/.pylintrc --load-plugins=pylint_plugins.api_models contrib/linux || exit 1;
. $(VIRTUALENV_DIR)/bin/activate; pylint -E --rcfile=./lint-configs/python/.pylintrc --load-plugins=pylint_plugins.api_models contrib/chatops || exit 1;
# Lint Python scripts
. $(VIRTUALENV_DIR)/bin/activate; pylint -E --rcfile=./lint-configs/python/.pylintrc --load-plugins=pylint_plugins.api_models scripts/*.py || exit 1;
. $(VIRTUALENV_DIR)/bin/activate; pylint -E --rcfile=./lint-configs/python/.pylintrc --load-plugins=pylint_plugins.api_models tools/*.py || exit 1;
. $(VIRTUALENV_DIR)/bin/activate; pylint -E --rcfile=./lint-configs/python/.pylintrc pylint_plugins/*.py || exit 1;
.PHONY: flake8
flake8: requirements .flake8
.PHONY: .flake8
.flake8:
@echo
@echo "==================== flake ===================="
@echo
. $(VIRTUALENV_DIR)/bin/activate; flake8 --config ./lint-configs/python/.flake8 $(COMPONENTS)
. $(VIRTUALENV_DIR)/bin/activate; flake8 --config ./lint-configs/python/.flake8 contrib/packs/actions/
. $(VIRTUALENV_DIR)/bin/activate; flake8 --config ./lint-configs/python/.flake8 contrib/linux
. $(VIRTUALENV_DIR)/bin/activate; flake8 --config ./lint-configs/python/.flake8 contrib/chatops/
. $(VIRTUALENV_DIR)/bin/activate; flake8 --config ./lint-configs/python/.flake8 scripts/
. $(VIRTUALENV_DIR)/bin/activate; flake8 --config ./lint-configs/python/.flake8 tools/
. $(VIRTUALENV_DIR)/bin/activate; flake8 --config ./lint-configs/python/.flake8 pylint_plugins/
.PHONY: bandit
bandit: requirements .bandit
.PHONY: .bandit
.bandit:
@echo
@echo "==================== bandit ===================="
@echo
. $(VIRTUALENV_DIR)/bin/activate; bandit -r $(COMPONENTS) -lll
.PHONY: lint
lint: requirements .lint
.PHONY: .lint
.lint: .flake8 .pylint .bandit .st2client-dependencies-check .st2common-circular-dependencies-check
.PHONY: clean
clean: .cleanpycs
.PHONY: compile
compile:
@echo "======================= compile ========================"
@echo "------- Compile all .py files (syntax check test) ------"
@if python -c 'import compileall,re; compileall.compile_dir(".", rx=re.compile(r"/virtualenv"), quiet=True)' | grep .; then exit 1; else exit 0; fi
.PHONY: .cleanpycs
.cleanpycs:
@echo "Removing all .pyc files"
find $(COMPONENTS) -name \*.pyc -type f -print0 | xargs -0 -I {} rm {}
.PHONY: .st2client-dependencies-check
.st2client-dependencies-check:
@echo "Checking for st2common imports inside st2client"
find ${ROOT_DIR}/st2client/st2client/ -name \*.py -type f -print0 | xargs -0 cat | grep st2common ; test $$? -eq 1
.PHONY: .st2common-circular-dependencies-check
.st2common-circular-dependencies-check:
@echo "Checking st2common for circular dependencies"
find ${ROOT_DIR}/st2common/st2common/ -name \*.py -type f -print0 | xargs -0 cat | grep st2reactor ; test $$? -eq 1
find ${ROOT_DIR}/st2common/st2common/ \( -name \*.py ! -name runnersregistrar\.py ! -wholename "*runners/__init__.py" ! -name python_action_wrapper.py ! -wholename "*/query/base.py" \) -type f -print0 | xargs -0 cat | grep st2actions ; test $$? -eq 1
find ${ROOT_DIR}/st2common/st2common/ -name \*.py -type f -print0 | xargs -0 cat | grep st2api ; test $$? -eq 1
find ${ROOT_DIR}/st2common/st2common/ -name \*.py -type f -print0 | xargs -0 cat | grep st2auth ; test $$? -eq 1
find ${ROOT_DIR}/st2common/st2common/ -name \*.py -type f -print0 | xargs -0 cat | grep st2debug; test $$? -eq 1
find ${ROOT_DIR}/st2common/st2common/ -name \*.py -type f -print0 | xargs -0 cat | grep st2stream; test $$? -eq 1
find ${ROOT_DIR}/st2common/st2common/ -name \*.py -type f -print0 | xargs -0 cat | grep st2exporter; test $$? -eq 1
.PHONY: .cleanmongodb
.cleanmongodb:
@echo "==================== cleanmongodb ===================="
@echo "----- Dropping all MongoDB databases -----"
@sudo pkill -9 mongod
@sudo rm -rf /var/lib/mongodb/*
@sudo chown -R mongodb:mongodb /var/lib/mongodb/
@sudo service mongodb start
@sleep 15
@mongo --eval "rs.initiate()"
@sleep 15
.PHONY: .cleanmysql
.cleanmysql:
@echo "==================== cleanmysql ===================="
@echo "----- Dropping all Mistral MYSQL databases -----"
@mysql -uroot -pStackStorm -e "DROP DATABASE IF EXISTS mistral"
@mysql -uroot -pStackStorm -e "CREATE DATABASE mistral"
@mysql -uroot -pStackStorm -e "GRANT ALL PRIVILEGES ON mistral.* TO 'mistral'@'127.0.0.1' IDENTIFIED BY 'StackStorm'"
@mysql -uroot -pStackStorm -e "FLUSH PRIVILEGES"
@/opt/openstack/mistral/.venv/bin/python /opt/openstack/mistral/tools/sync_db.py --config-file /etc/mistral/mistral.conf
.PHONY: .cleanrabbitmq
.cleanrabbitmq:
@echo "==================== cleanrabbitmq ===================="
@echo "Deleting all RabbitMQ queue and exchanges"
@sudo rabbitmqctl stop_app
@sudo rabbitmqctl reset
@sudo rabbitmqctl start_app
.PHONY: distclean
distclean: clean
@echo
@echo "==================== distclean ===================="
@echo
rm -rf $(VIRTUALENV_DIR)
.PHONY: requirements
requirements: virtualenv .sdist-requirements
@echo
@echo "==================== requirements ===================="
@echo
# Make sure we use latest version of pip
$(VIRTUALENV_DIR)/bin/pip install --upgrade "pip>=8.1.2,<8.2"
$(VIRTUALENV_DIR)/bin/pip install virtualenv # Required for packs.install in dev envs.
# Generate all requirements to support current CI pipeline.
$(VIRTUALENV_DIR)/bin/python scripts/fixate-requirements.py --skip=virtualenv -s st2*/in-requirements.txt -f fixed-requirements.txt -o requirements.txt
# Install requirements
#
for req in $(REQUIREMENTS); do \
echo "Installing $$req..." ; \
$(VIRTUALENV_DIR)/bin/pip install $(PIP_OPTIONS) -r $$req ; \
done
# Workaround for Travis caching issues (corrupted cache)
$(VIRTUALENV_DIR)/bin/pip install --no-cache-dir --no-binary :all: --upgrade --force-reinstall "greenlet>=0.4.10,<0.5"
.PHONY: virtualenv
virtualenv: $(VIRTUALENV_DIR)/bin/activate
$(VIRTUALENV_DIR)/bin/activate:
@echo
@echo "==================== virtualenv ===================="
@echo
test -d $(VIRTUALENV_DIR) || virtualenv --no-site-packages $(VIRTUALENV_DIR)
# Setup PYTHONPATH in bash activate script...
echo '' >> $(VIRTUALENV_DIR)/bin/activate
echo '_OLD_PYTHONPATH=$$PYTHONPATH' >> $(VIRTUALENV_DIR)/bin/activate
echo 'PYTHONPATH=$$_OLD_PYTHONPATH:$(COMPONENT_PYTHONPATH)' >> $(VIRTUALENV_DIR)/bin/activate
echo 'export PYTHONPATH' >> $(VIRTUALENV_DIR)/bin/activate
touch $(VIRTUALENV_DIR)/bin/activate
# Setup PYTHONPATH in fish activate script...
echo '' >> $(VIRTUALENV_DIR)/bin/activate.fish
echo 'set -gx _OLD_PYTHONPATH $$PYTHONPATH' >> $(VIRTUALENV_DIR)/bin/activate.fish
echo 'set -gx PYTHONPATH $$_OLD_PYTHONPATH $(COMPONENT_PYTHONPATH)' >> $(VIRTUALENV_DIR)/bin/activate.fish
echo 'functions -c deactivate old_deactivate' >> $(VIRTUALENV_DIR)/bin/activate.fish
echo 'function deactivate' >> $(VIRTUALENV_DIR)/bin/activate.fish
echo ' if test -n $$_OLD_PYTHONPATH' >> $(VIRTUALENV_DIR)/bin/activate.fish
echo ' set -gx PYTHONPATH $$_OLD_PYTHONPATH' >> $(VIRTUALENV_DIR)/bin/activate.fish
echo ' set -e _OLD_PYTHONPATH' >> $(VIRTUALENV_DIR)/bin/activate.fish
echo ' end' >> $(VIRTUALENV_DIR)/bin/activate.fish
echo ' old_deactivate' >> $(VIRTUALENV_DIR)/bin/activate.fish
echo ' functions -e old_deactivate' >> $(VIRTUALENV_DIR)/bin/activate.fish
echo 'end' >> $(VIRTUALENV_DIR)/bin/activate.fish
touch $(VIRTUALENV_DIR)/bin/activate.fish
.PHONY: tests
tests: pytests
.PHONY: pytests
pytests: compile requirements .flake8 .pylint .pytests-coverage
.PHONY: .pytests
.pytests: compile .unit-tests .itests clean
.PHONY: .pytests-coverage
.pytests-coverage: .unit-tests-coverage-html .itests-coverage-html clean
.PHONY: unit-tests
unit-tests: requirements .unit-tests
.PHONY: .unit-tests
.unit-tests:
@echo
@echo "==================== tests ===================="
@echo
@echo "----- Dropping st2-test db -----"
@mongo st2-test --eval "db.dropDatabase();"
@for component in $(COMPONENTS_TEST); do\
echo "==========================================================="; \
echo "Running tests in" $$component; \
echo "==========================================================="; \
. $(VIRTUALENV_DIR)/bin/activate; nosetests $(NOSE_OPTS) -s -v $$component/tests/unit || exit 1; \
done
.PHONY: .unit-tests-coverage-html
.unit-tests-coverage-html:
@echo
@echo "==================== unit tests with coverage (HTML reports) ===================="
@echo
@echo "----- Dropping st2-test db -----"
@mongo st2-test --eval "db.dropDatabase();"
@for component in $(COMPONENTS_TEST); do\
echo "==========================================================="; \
echo "Running tests in" $$component; \
echo "==========================================================="; \
. $(VIRTUALENV_DIR)/bin/activate; nosetests -sv --with-coverage \
--cover-inclusive --cover-html \
--cover-package=$(COMPONENTS_TEST_COMMA) $$component/tests/unit || exit 1; \
done
.PHONY: itests
itests: requirements .itests
.PHONY: .itests
.itests:
@echo
@echo "==================== integration tests ===================="
@echo
@echo "----- Dropping st2-test db -----"
@mongo st2-test --eval "db.dropDatabase();"
@for component in $(COMPONENTS_TEST); do\
echo "==========================================================="; \
echo "Running tests in" $$component; \
echo "==========================================================="; \
. $(VIRTUALENV_DIR)/bin/activate; nosetests $(NOSE_OPTS) -sv $$component/tests/integration || exit 1; \
done
.PHONY: .itests-coverage-html
.itests-coverage-html:
@echo
@echo "================ integration tests with coverage (HTML reports) ================"
@echo
@echo "----- Dropping st2-test db -----"
@mongo st2-test --eval "db.dropDatabase();"
@for component in $(COMPONENTS_TEST); do\
echo "==========================================================="; \
echo "Running tests in" $$component; \
echo "==========================================================="; \
. $(VIRTUALENV_DIR)/bin/activate; nosetests -sv --with-coverage \
--cover-inclusive --cover-html \
--cover-package=$(COMPONENTS_TEST_COMMA) $$component/tests/integration || exit 1; \
done
.PHONY: mistral-itests
mistral-itests: requirements .mistral-itests
.PHONY: .mistral-itests
.mistral-itests:
@echo
@echo "==================== MISTRAL integration tests ===================="
@echo "The tests assume both st2 and mistral are running on 127.0.0.1."
@echo
. $(VIRTUALENV_DIR)/bin/activate; nosetests -s -v st2tests/integration/mistral || exit 1;
.PHONY: .mistral-itests-coverage-html
.mistral-itests-coverage-html:
@echo
@echo "==================== MISTRAL integration tests with coverage (HTML reports) ===================="
@echo "The tests assume both st2 and mistral are running on 127.0.0.1."
@echo
. $(VIRTUALENV_DIR)/bin/activate; nosetests -s -v --with-coverage \
--cover-inclusive --cover-html st2tests/integration/mistral || exit 1;
.PHONY: packs-tests
packs-tests: requirements .packs-tests
.PHONY: .packs-tests
.packs-tests:
@echo
@echo "==================== packs-tests ===================="
@echo
. $(VIRTUALENV_DIR)/bin/activate; find ${ROOT_DIR}/contrib/* -maxdepth 0 -type d -print0 | xargs -0 -I FILENAME ./st2common/bin/st2-run-pack-tests -x -p FILENAME
.PHONY: cli
cli:
@echo
@echo "=================== Building st2 client ==================="
@echo
pushd $(CURDIR) && cd st2client && ((python setup.py develop || printf "\n\n!!! ERROR: BUILD FAILED !!!\n") || popd)
.PHONY: rpms
rpms:
@echo
@echo "==================== rpm ===================="
@echo
rm -Rf ~/rpmbuild
$(foreach COM,$(COMPONENTS), pushd $(COM); make rpm; popd;)
pushd st2client && make rpm && popd
rhel-rpms:
@echo
@echo "==================== rpm ===================="
@echo
rm -Rf ~/rpmbuild
$(foreach COM,$(COMPONENTS), pushd $(COM); make rhel-rpm; popd;)
pushd st2client && make rhel-rpm && popd
.PHONY: debs
debs:
@echo
@echo "==================== deb ===================="
@echo
rm -Rf ~/debbuild
$(foreach COM,$(COMPONENTS), pushd $(COM); make deb; popd;)
pushd st2client && make deb && popd
# >>>>
.PHONY: .sdist-requirements
.sdist-requirements:
# Copy over shared dist utils module which is needed by setup.py
@for component in $(COMPONENTS_TEST); do\
cp -f ./scripts/dist_utils.py $$component/dist_utils.py;\
done
# Copy over CHANGELOG.RST, CONTRIBUTING.RST and LICENSE file to each component directory
#@for component in $(COMPONENTS_TEST); do\
# test -s $$component/README.rst || cp -f README.rst $$component/; \
# cp -f CONTRIBUTING.rst $$component/; \
# cp -f LICENSE $$component/; \
#done