Merge ~vultaire/charm-elasticsearch:makefile-20.08 into charm-elasticsearch:master

Proposed by Paul Goins
Status: Merged
Approved by: Xav Paice
Approved revision: dbf735aa8e70235ce5c1a1fe4c49066775806249
Merged at revision: f40a19ab29181f778500d52eabaed251110c0f31
Proposed branch: ~vultaire/charm-elasticsearch:makefile-20.08
Merge into: charm-elasticsearch:master
Diff against target: 293 lines (+170/-52)
6 files modified
.gitignore (+39/-11)
Makefile (+64/-31)
bin/wait_for_peer.py (+2/-2)
tests/functional/requirements.txt (+2/-0)
tests/unit/requirements.txt (+3/-0)
tox.ini (+60/-8)
Reviewer Review Type Date Requested Status
Xav Paice (community) Approve
Review via email: mp+388617@code.launchpad.net

Commit message

Makefile reworks

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Xav Paice (xavpaice) wrote :

LGTM

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision f40a19ab29181f778500d52eabaed251110c0f31

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/.gitignore b/.gitignore
2index a9bc955..6f1f367 100644
3--- a/.gitignore
4+++ b/.gitignore
5@@ -1,13 +1,41 @@
6-bin/*
7-.tox/
8-__pycache/
9-*.pyc
10-files/*
11-revision
12-exec.d
13-local.yaml
14+# Juju files
15+.unit-state.db
16+.go-cookies
17
18-repo-info
19+layers/*
20+interfaces/*
21+
22+# Byte-compiled / optimized / DLL files
23+__pycache__/
24+*.py[cod]
25+*$py.class
26+
27+# Tests files and dir
28+.pytest_cache/
29+.coverage
30+.tox
31+report/
32+htmlcov/
33+
34+# Log files
35+*.log
36+
37+# pycharm
38 .idea/
39-*.pyc
40-__pycache__
41+
42+# vi
43+.*.swp
44+
45+# version data
46+repo-info
47+version
48+
49+# Python builds
50+deb_dist/
51+dist/
52+
53+# Snaps
54+*.snap
55+
56+# Builds
57+.build/
58\ No newline at end of file
59diff --git a/Makefile b/Makefile
60index 8a16beb..7e1e684 100644
61--- a/Makefile
62+++ b/Makefile
63@@ -1,42 +1,75 @@
64-#!/usr/bin/make
65-PYTHON := /usr/bin/env python3
66-CHARM_HELPERS = charm-helpers/.gitignore
67 PYTHON := /usr/bin/python3
68-export PYTHONPATH := hooks
69-PROJECTPATH = $(dir $(realpath $(MAKEFILE_LIST)))
70-METADATA_FILE = "metadata.yaml"
71-CHARM_NAME = $(shell cat ${PROJECTPATH}/${METADATA_FILE} | grep -E '^name:' | awk '{print $$2}')
72+
73+PROJECTPATH=$(dir $(realpath $(MAKEFILE_LIST)))
74 ifndef CHARM_BUILD_DIR
75- CHARM_BUILD_DIR := /tmp/charm-builds
76- $(warning Warning CHARM_BUILD_DIR was not set, defaulting to $(CHARM_BUILD_DIR))
77+ CHARM_BUILD_DIR=${PROJECTPATH}.build
78 endif
79+METADATA_FILE="metadata.yaml"
80+CHARM_NAME=$(shell cat ${PROJECTPATH}/${METADATA_FILE} | grep -E '^name:' | awk '{print $$2}')
81+
82+help:
83+ @echo "This project supports the following targets"
84+ @echo ""
85+ @echo " make help - show this text"
86+ @echo " make clean - remove unneeded files"
87+ @echo " make submodules - make sure that the submodules are up-to-date"
88+ @echo " make submodules-update - update submodules to latest changes on remote branch"
89+ @echo " make build - build the charm"
90+ @echo " make release - run clean and build targets"
91+ @echo " make lint - run flake8 and black --check"
92+ @echo " make black - run black and reformat files"
93+ @echo " make proof - run charm proof"
94+ @echo " make unittests - run the tests defined in the unittest subdirectory"
95+ @echo " make functional - run the tests defined in the functional subdirectory"
96+ @echo " make test - run lint, proof, unittests and functional targets"
97+ @echo ""
98+
99+clean:
100+ @echo "Cleaning files"
101+ @git clean -ffXd -e '!.idea'
102+ @echo "Cleaning existing build"
103+ @rm -rf ${CHARM_BUILD_DIR}/${CHARM_NAME}
104+
105+submodules:
106+ @echo "Cloning submodules"
107+ @git submodule update --init --recursive
108+
109+submodules-update:
110+ @echo "Pulling latest updates for submodules"
111+ @git submodule update --init --recursive --remote --merge
112+
113+build:
114+ @echo "Building charm to base directory ${CHARM_BUILD_DIR}/${CHARM_NAME}"
115+ @-git rev-parse --abbrev-ref HEAD > ./repo-info
116+ @-git describe --always > ./version
117+ @mkdir -p ${CHARM_BUILD_DIR}/${CHARM_NAME}
118+ @cp -a ./* ${CHARM_BUILD_DIR}/${CHARM_NAME}
119
120-build: test
121- @echo "Building charm to base directory $(CHARM_BUILD_DIR)/$(CHARM_NAME)"
122- @-git describe --tags > ./repo-info
123- @mkdir -p $(CHARM_BUILD_DIR)/$(CHARM_NAME)
124- @cp -r * $(CHARM_BUILD_DIR)/$(CHARM_NAME)
125+release: clean build
126+ @echo "Charm is built at ${CHARM_BUILD_DIR}/${CHARM_NAME}"
127
128-lint: $(CHARM_HELPERS)
129- @tox -e pep8
130- @charm proof
131+lint:
132+ @echo "Running lint checks"
133+ @tox -e lint
134
135-test: $(CHARM_HELPERS)
136- @echo Starting unit tests...
137- @tox -e py3
138+black:
139+ @echo "Reformat files with black"
140+ @tox -e black
141
142-deploy:
143- @echo Deploying local elasticsearch charm
144- @juju deploy --num-units=2 --repository=../.. local:trusty/elasticsearch
145+proof:
146+ @echo "Running charm proof"
147+ @-charm proof
148
149-health:
150- juju ssh elasticsearch/0 "curl http://localhost:9200/_cluster/health?pretty=true"
151+unittests:
152+ @echo "Running unit tests"
153+ @tox -e unit
154
155-.PHONY: sync-charm-helpers-stable
156-sync-charm-helpers-stable: $(CHARM_HELPERS)
157+functional: build
158+ @echo "Executing functional tests in ${CHARM_BUILD_DIR}"
159+ @CHARM_BUILD_DIR=${CHARM_BUILD_DIR} tox -e func
160
161-$(CHARM_HELPERS): .gitmodules
162- @git submodule update --init
163+test: lint proof unittests functional
164+ @echo "Charm ${CHARM_NAME} has been tested"
165
166-sync-charm-helpers-master:
167- @git submodule foreach git pull origin master
168+# The targets below don't depend on a file
169+.PHONY: help submodules submodules-update clean build release lint black proof unittests functional test
170diff --git a/bin/wait_for_peer.py b/bin/wait_for_peer.py
171index bffd549..fbefcbc 100755
172--- a/bin/wait_for_peer.py
173+++ b/bin/wait_for_peer.py
174@@ -13,10 +13,10 @@ logging.basicConfig(
175 format="%(asctime)s [%(levelname)s] %(message)s",
176 )
177
178-import requests
179+import requests # noqa: E402
180
181 sys.path.append(os.path.abspath("charm-helpers"))
182-from charmhelpers.core.host import service_restart
183+from charmhelpers.core.host import service_restart # noqa: E402
184
185
186 CONNECTION_TIMEOUT = 5
187diff --git a/tests/functional/requirements.txt b/tests/functional/requirements.txt
188new file mode 100644
189index 0000000..16c7715
190--- /dev/null
191+++ b/tests/functional/requirements.txt
192@@ -0,0 +1,2 @@
193+git+https://github.com/openstack-charmers/zaza.git#egg=zaza
194+
195diff --git a/unit_tests/__init__.py b/tests/unit/__init__.py
196similarity index 100%
197rename from unit_tests/__init__.py
198rename to tests/unit/__init__.py
199diff --git a/tests/unit/requirements.txt b/tests/unit/requirements.txt
200new file mode 100644
201index 0000000..e4de175
202--- /dev/null
203+++ b/tests/unit/requirements.txt
204@@ -0,0 +1,3 @@
205+PyYAML
206+mock
207+coverage
208diff --git a/unit_tests/test_hooks.py b/tests/unit/test_hooks.py
209similarity index 100%
210rename from unit_tests/test_hooks.py
211rename to tests/unit/test_hooks.py
212diff --git a/tox.ini b/tox.ini
213index 254230c..68de47d 100644
214--- a/tox.ini
215+++ b/tox.ini
216@@ -1,17 +1,69 @@
217 [tox]
218-envlist = py3,pep8
219-skipsdist = True
220+skipsdist=True
221+skip_missing_interpreters = True
222+envlist = lint, unit, func
223
224 [testenv]
225 basepython = python3
226+setenv =
227+ PYTHONPATH = {toxinidir}:{toxinidir}/lib/:{toxinidir}/hooks/
228+passenv =
229+ HOME
230+ PATH
231+ CHARM_BUILD_DIR
232+ PYTEST_KEEP_MODEL
233+ PYTEST_CLOUD_NAME
234+ PYTEST_CLOUD_REGION
235+ PYTEST_MODEL
236+ MODEL_SETTINGS
237+ HTTP_PROXY
238+ HTTPS_PROXY
239+ NO_PROXY
240+ SNAP_HTTP_PROXY
241+ SNAP_HTTPS_PROXY
242+
243+[testenv:lint]
244+commands =
245+ flake8
246+#TODO black --check --exclude "/(\.eggs|\.git|\.tox|\.venv|\.build|dist|charmhelpers|mod)/" .
247 deps =
248- -rrequirements.txt
249- -rtest-requirements.txt
250+ black
251+ flake8
252+# flake8-docstrings
253+# flake8-import-order
254+# pep8-naming
255+ flake8-colors
256+
257+[flake8]
258+exclude =
259+ .git,
260+ __pycache__,
261+ .tox,
262+ charm-helpers, # not part of template but needed for now
263+ charmhelpers,
264+ mod,
265+ .build
266+
267+#max-line-length = 88
268+max-complexity = 10
269
270-[testenv:py3]
271+# From old tox.ini
272+max-line-length = 120
273+
274+[testenv:black]
275 commands =
276- python -m unit_tests.test_hooks
277+ black --exclude "/(\.eggs|\.git|\.tox|\.venv|\.build|dist|charmhelpers|mod)/" .
278+deps =
279+ black
280
281-[testenv:pep8]
282+[testenv:unit]
283 commands =
284- python -m pycodestyle --verbose --max-line-length=120 --exclude hooks/charmhelpers hooks unit_tests
285+ coverage run -m unittest discover -s {toxinidir}/tests/unit -v
286+ coverage report --omit tests/*,mod/*,.tox/*
287+ coverage html --omit tests/*,mod/*,.tox/*
288+deps = -r{toxinidir}/tests/unit/requirements.txt
289+
290+[testenv:func]
291+changedir = {toxinidir}/tests/functional
292+commands = functest-run-suite {posargs}
293+deps = -r{toxinidir}/tests/functional/requirements.txt

Subscribers

People subscribed via source and target branches

to all changes: