Merge ~vultaire/charm-prometheus-blackbox-exporter:makefile-20.08 into charm-prometheus-blackbox-exporter:master

Proposed by Paul Goins
Status: Merged
Merged at revision: c541de54c0543f7614ff067ba0a39cfadf6fc729
Proposed branch: ~vultaire/charm-prometheus-blackbox-exporter:makefile-20.08
Merge into: charm-prometheus-blackbox-exporter:master
Diff against target: 388 lines (+153/-99)
5 files modified
.gitignore (+26/-9)
Makefile (+57/-25)
dev/null (+0/-65)
src/tests/unit/requirements.txt (+1/-0)
src/tox.ini (+69/-0)
Reviewer Review Type Date Requested Status
Xav Paice (community) Approve
Review via email: mp+388595@code.launchpad.net

Commit message

Updated Makefile/tox.ini/.gitignore and made related changes

Description of the change

Note: this charm lacked any unit tests, so while I fixed things so the unit tests would pass if there were any to test, the "make unittests" target _does_ fail since there are no tests (and thus no coverage data).

I could add a dummy test if strongly desired, but I feel like that could unintentionally "cover up" that this charm has no unit tests. At the very least I want to call this out so we can decide what to do here.

To post a comment you must log in.
Revision history for this message
Paul Goins (vultaire) wrote :

Also note that the 'Fixed "make lint"' commit is a combination of tox.ini tweaks and running black, and nothing more.

Revision history for this message
Paul Goins (vultaire) wrote :

Re-pushed... Fixed "make lint" to _not_ run black (as that would kind of defeat the point of having a separate black commit)

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

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/.gitignore b/.gitignore
2index 2dc89c9..6f1f367 100644
3--- a/.gitignore
4+++ b/.gitignore
5@@ -1,24 +1,41 @@
6+# Juju files
7+.unit-state.db
8+.go-cookies
9+
10+layers/*
11+interfaces/*
12+
13 # Byte-compiled / optimized / DLL files
14 __pycache__/
15 *.py[cod]
16 *$py.class
17
18-# Log files
19-*.log
20-.tox/
21+# Tests files and dir
22+.pytest_cache/
23 .coverage
24+.tox
25+report/
26+htmlcov/
27
28-# vi
29-.*.swp
30+# Log files
31+*.log
32
33 # pycharm
34 .idea/
35
36+# vi
37+.*.swp
38+
39 # version data
40 repo-info
41+version
42+
43+# Python builds
44+deb_dist/
45+dist/
46
47-# reports
48-report/*
49+# Snaps
50+*.snap
51
52-# layers
53-layers/*
54\ No newline at end of file
55+# Builds
56+.build/
57\ No newline at end of file
58diff --git a/Makefile b/Makefile
59index 949713b..647cacd 100644
60--- a/Makefile
61+++ b/Makefile
62@@ -1,48 +1,80 @@
63+PYTHON := /usr/bin/python3
64+
65+PROJECTPATH=$(dir $(realpath $(MAKEFILE_LIST)))
66 ifndef CHARM_BUILD_DIR
67- CHARM_BUILD_DIR=/tmp/builds
68+ CHARM_BUILD_DIR=${PROJECTPATH}.build
69+endif
70+ifndef CHARM_LAYERS_DIR
71+ CHARM_LAYERS_DIR=${PROJECTPATH}/layers
72+endif
73+ifndef CHARM_INTERFACES_DIR
74+ CHARM_INTERFACES_DIR=${PROJECTPATH}/interfaces
75 endif
76+METADATA_FILE="src/metadata.yaml"
77+CHARM_NAME=$(shell cat ${PROJECTPATH}/${METADATA_FILE} | grep -E "^name:" | awk '{print $$2}')
78
79 help:
80 @echo "This project supports the following targets"
81 @echo ""
82 @echo " make help - show this text"
83+ @echo " make clean - remove unneeded files"
84 @echo " make submodules - make sure that the submodules are up-to-date"
85- @echo " make lint - run flake8"
86- @echo " make test - run the functional tests and lint"
87+ @echo " make submodules-update - update submodules to latest changes on remote branch"
88+ @echo " make build - build the charm"
89+ @echo " make release - run clean, submodules, and build targets"
90+ @echo " make lint - run flake8 and black --check"
91+ @echo " make black - run black and reformat files"
92+ @echo " make proof - run charm proof"
93+ @echo " make unittests - run the tests defined in the unittest subdirectory"
94 @echo " make functional - run the tests defined in the functional subdirectory"
95- @echo " make release - build the charm"
96- @echo " make clean - remove unneeded files"
97+ @echo " make test - run lint, proof, unittests and functional targets"
98 @echo ""
99
100+clean:
101+ @echo "Cleaning files"
102+ @git clean -ffXd -e '!.idea'
103+ @echo "Cleaning existing build"
104+ @rm -rf ${CHARM_BUILD_DIR}/${CHARM_NAME}
105+
106 submodules:
107 @echo "Cloning submodules"
108 @git submodule update --init --recursive
109
110+submodules-update:
111+ @echo "Pulling latest updates for submodules"
112+ @git submodule update --init --recursive --remote --merge
113+
114+build:
115+ @echo "Building charm to directory ${CHARM_BUILD_DIR}/${CHARM_NAME}"
116+ @-git rev-parse --abbrev-ref HEAD > ./src/repo-info
117+ @CHARM_LAYERS_DIR=${CHARM_LAYERS_DIR} CHARM_INTERFACES_DIR=${CHARM_INTERFACES_DIR} \
118+ TERM=linux CHARM_BUILD_DIR=${CHARM_BUILD_DIR} charm build src/
119+
120+release: clean build
121+ @echo "Charm is built at ${CHARM_BUILD_DIR}/${CHARM_NAME}"
122+
123 lint:
124- @mkdir -p report/lint/
125- @echo "Running flake8"
126- @tox -e lint
127+ @echo "Running lint checks"
128+ @cd src && tox -e lint
129
130-test: lint functional
131+black:
132+ @echo "Reformat files with black"
133+ @cd src && tox -e black
134
135-functional: build
136- @echo Executing with: CHARM_BUILD_DIR=$(CHARM_BUILD_DIR) tox -e func
137- @CHARM_BUILD_DIR=$(CHARM_BUILD_DIR) tox -e func
138+proof:
139+ @echo "Running charm proof"
140+ @charm proof src
141
142-build:
143- @echo "Building charm to base directory $(CHARM_BUILD_DIR)"
144- @-git describe --tags > ./repo-info
145- @CHARM_LAYERS_DIR=./layers CHARM_INTERFACES_DIR=./interfaces TERM=linux \
146- CHARM_BUILD_DIR=$(CHARM_BUILD_DIR) charm build . --force
147+unittests:
148+ @echo "Running unit tests"
149+ @cd src && tox -e unit
150
151-release: clean build
152- @echo "Charm is built at $(CHARM_BUILD_DIR)/prometheus-blackbox-exporter"
153+functional: build
154+ @echo "Executing functional tests in ${CHARM_BUILD_DIR}"
155+ @cd src && CHARM_BUILD_DIR=${CHARM_BUILD_DIR} tox -e func
156
157-clean:
158- @echo "Cleaning files"
159- @if [ -d .tox ] ; then rm -r .tox ; fi
160- @if [ -d .pytest_cache ] ; then rm -r .pytest_cache ; fi
161- @find . -iname __pycache__ -exec rm -r {} +
162+test: lint proof unittests functional
163+ @echo "Tests completed for charm ${CHARM_NAME}."
164
165 # The targets below don't depend on a file
166-.PHONY: lint test functional build release clean help submodules
167+.PHONY: help submodules submodules-update clean build release lint black proof unittests functional test
168diff --git a/README.md b/src/README.md
169similarity index 100%
170rename from README.md
171rename to src/README.md
172diff --git a/config.yaml b/src/config.yaml
173similarity index 100%
174rename from config.yaml
175rename to src/config.yaml
176diff --git a/copyright b/src/copyright
177similarity index 100%
178rename from copyright
179rename to src/copyright
180diff --git a/icon.svg b/src/icon.svg
181similarity index 100%
182rename from icon.svg
183rename to src/icon.svg
184diff --git a/layer.yaml b/src/layer.yaml
185similarity index 100%
186rename from layer.yaml
187rename to src/layer.yaml
188diff --git a/metadata.yaml b/src/metadata.yaml
189similarity index 100%
190rename from metadata.yaml
191rename to src/metadata.yaml
192diff --git a/reactive/prometheus_blackbox_exporter.py b/src/reactive/prometheus_blackbox_exporter.py
193similarity index 100%
194rename from reactive/prometheus_blackbox_exporter.py
195rename to src/reactive/prometheus_blackbox_exporter.py
196diff --git a/requirements.txt b/src/requirements.txt
197similarity index 100%
198rename from requirements.txt
199rename to src/requirements.txt
200diff --git a/templates/blackbox.yaml.j2 b/src/templates/blackbox.yaml.j2
201similarity index 100%
202rename from templates/blackbox.yaml.j2
203rename to src/templates/blackbox.yaml.j2
204diff --git a/tests/functional/requirements.txt b/src/tests/functional/requirements.txt
205similarity index 100%
206rename from tests/functional/requirements.txt
207rename to src/tests/functional/requirements.txt
208diff --git a/tests/functional/tests/__init__.py b/src/tests/functional/tests/__init__.py
209similarity index 100%
210rename from tests/functional/tests/__init__.py
211rename to src/tests/functional/tests/__init__.py
212diff --git a/tests/functional/tests/bundles/bionic.yaml b/src/tests/functional/tests/bundles/bionic.yaml
213similarity index 100%
214rename from tests/functional/tests/bundles/bionic.yaml
215rename to src/tests/functional/tests/bundles/bionic.yaml
216diff --git a/tests/functional/tests/bundles/focal.yaml b/src/tests/functional/tests/bundles/focal.yaml
217similarity index 100%
218rename from tests/functional/tests/bundles/focal.yaml
219rename to src/tests/functional/tests/bundles/focal.yaml
220diff --git a/tests/functional/tests/bundles/overlays/local-charm-overlay.yaml.j2 b/src/tests/functional/tests/bundles/overlays/local-charm-overlay.yaml.j2
221similarity index 100%
222rename from tests/functional/tests/bundles/overlays/local-charm-overlay.yaml.j2
223rename to src/tests/functional/tests/bundles/overlays/local-charm-overlay.yaml.j2
224diff --git a/tests/functional/tests/bundles/xenial.yaml b/src/tests/functional/tests/bundles/xenial.yaml
225similarity index 100%
226rename from tests/functional/tests/bundles/xenial.yaml
227rename to src/tests/functional/tests/bundles/xenial.yaml
228diff --git a/tests/functional/tests/test_prometheus_blackbox_exporter.py b/src/tests/functional/tests/test_prometheus_blackbox_exporter.py
229similarity index 100%
230rename from tests/functional/tests/test_prometheus_blackbox_exporter.py
231rename to src/tests/functional/tests/test_prometheus_blackbox_exporter.py
232diff --git a/tests/functional/tests/tests.yaml b/src/tests/functional/tests/tests.yaml
233similarity index 100%
234rename from tests/functional/tests/tests.yaml
235rename to src/tests/functional/tests/tests.yaml
236diff --git a/src/tests/unit/requirements.txt b/src/tests/unit/requirements.txt
237new file mode 100644
238index 0000000..4ebc8ae
239--- /dev/null
240+++ b/src/tests/unit/requirements.txt
241@@ -0,0 +1 @@
242+coverage
243diff --git a/src/tox.ini b/src/tox.ini
244new file mode 100644
245index 0000000..9cd7d44
246--- /dev/null
247+++ b/src/tox.ini
248@@ -0,0 +1,69 @@
249+[tox]
250+skipsdist=True
251+skip_missing_interpreters = True
252+envlist = lint, unit, func
253+
254+[testenv]
255+basepython = python3
256+setenv =
257+ PYTHONPATH = {toxinidir}:{toxinidir}/lib/:{toxinidir}/hooks/
258+passenv =
259+ HOME
260+ PATH
261+ CHARM_BUILD_DIR
262+ PYTEST_KEEP_MODEL
263+ PYTEST_CLOUD_NAME
264+ PYTEST_CLOUD_REGION
265+ PYTEST_MODEL
266+ MODEL_SETTINGS
267+ HTTP_PROXY
268+ HTTPS_PROXY
269+ NO_PROXY
270+ SNAP_HTTP_PROXY
271+ SNAP_HTTPS_PROXY
272+
273+[testenv:lint]
274+commands =
275+ flake8
276+#TODO black --check --exclude "/(\.eggs|\.git|\.tox|\.venv|\.build|dist|charmhelpers|mod)/" .
277+deps =
278+ black
279+ flake8
280+ flake8-docstrings
281+ flake8-import-order
282+ pep8-naming
283+ flake8-colors
284+
285+[flake8]
286+exclude =
287+ .git,
288+ __pycache__,
289+ .tox,
290+ charmhelpers,
291+ mod,
292+ .build
293+
294+#max-line-length = 88
295+max-complexity = 10
296+
297+# From previous tox.ini
298+max-line-length = 120
299+import-order-style = google
300+
301+[testenv:black]
302+commands =
303+ black --exclude "/(\.eggs|\.git|\.tox|\.venv|\.build|dist|charmhelpers|mod)/" .
304+deps =
305+ black
306+
307+[testenv:unit]
308+commands =
309+ coverage run -m unittest discover -s {toxinidir}/tests/unit -v
310+ coverage report --omit tests/*,mod/*,.tox/*
311+ coverage html --omit tests/*,mod/*,.tox/*
312+deps = -r{toxinidir}/tests/unit/requirements.txt
313+
314+[testenv:func]
315+changedir = {toxinidir}/tests/functional
316+commands = functest-run-suite {posargs}
317+deps = -r{toxinidir}/tests/functional/requirements.txt
318diff --git a/tox.ini b/tox.ini
319deleted file mode 100644
320index 1859695..0000000
321--- a/tox.ini
322+++ /dev/null
323@@ -1,65 +0,0 @@
324-[tox]
325-skipsdist=True
326-envlist = unit, functional
327-skip_missing_interpreters = True
328-
329-[testenv]
330-basepython = python3
331-setenv =
332- PYTHONPATH = .
333-passenv =
334- HOME
335- CHARM_BUILD_DIR
336- MODEL_SETTINGS
337-
338-[testenv:unit]
339-commands = pytest -v \
340- --ignore {toxinidir}/tests/ \
341- --ignore {toxinidir}/interfaces \
342- --ignore {toxinidir}/layers \
343- --cov=lib \
344- --cov=actions \
345- --cov-report=term \
346- --cov-report=annotate:report/unit/coverage-annotated \
347- --cov-report=html:report/unit/coverage-html \
348- --html=report/unit/tests/index.html \
349- --junitxml=report/unit/junit.xml
350-deps = -r{toxinidir}/tests/unit_tests/requirements.txt
351- -r{toxinidir}/tests/requirements.txt
352-setenv = PYTHONPATH={toxinidir}/lib
353-
354-[testenv:func]
355-changedir = {toxinidir}/tests/functional
356-commands = functest-run-suite --keep-model
357-deps = -r{toxinidir}/tests/functional/requirements.txt
358-
359-[testenv:lint]
360-commands = flake8 --tee
361-deps =
362- flake8
363- flake8-colors
364- flake8-docstrings
365- flake8-import-order
366- pep8-naming
367-
368-[flake8]
369-exclude =
370- .git,
371- __pycache__,
372- .tox,
373- layers,
374- interfaces,
375-max-line-length = 120
376-max-complexity = 10
377-import-order-style = google
378-
379-[isort]
380-order_by_type = true
381-from_first = true
382-line_length = 120
383-
384-[pytest]
385-markers =
386- deploy: mark deployment tests to allow running w/o redeploy
387-filterwarnings =
388- ignore::DeprecationWarning

Subscribers

People subscribed via source and target branches

to all changes: