Merge ~afreiberger/charm-hw-health:makefile-20.08 into charm-hw-health:master
- Git
- lp:~afreiberger/charm-hw-health
- makefile-20.08
- Merge into master
Proposed by
Drew Freiberger
Status: | Merged |
---|---|
Merged at revision: | 94d40ef4bbf468bad9c95255d54d95e048167cef |
Proposed branch: | ~afreiberger/charm-hw-health:makefile-20.08 |
Merge into: | charm-hw-health:master |
Diff against target: |
402 lines (+170/-87) 7 files modified
.gitignore (+28/-9) Makefile (+69/-44) dev/null (+0/-5) src/files/mdadm/cron_mdadm.py (+1/-1) src/files/megacli/check_megacli.py (+1/-1) src/tests/functional/test_hwhealth.py (+7/-5) src/tox.ini (+64/-22) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Xav Paice (community) | Approve | ||
Review via email: mp+388946@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/.gitignore b/.gitignore |
2 | index 06bf3e8..aa54058 100644 |
3 | --- a/.gitignore |
4 | +++ b/.gitignore |
5 | @@ -1,25 +1,44 @@ |
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 | +# Tests files and dir |
19 | +.pytest_cache/ |
20 | +.coverage |
21 | +.tox |
22 | +report/ |
23 | +htmlcov/ |
24 | + |
25 | # Log files |
26 | *.log |
27 | |
28 | -.tox/ |
29 | -.coverage |
30 | +# pycharm |
31 | +.idea/ |
32 | |
33 | # vi |
34 | .*.swp |
35 | |
36 | -# pycharm |
37 | -.idea/ |
38 | - |
39 | # version data |
40 | -src/repo-info |
41 | +repo-info |
42 | +version |
43 | + |
44 | +# Python builds |
45 | +deb_dist/ |
46 | +dist/ |
47 | + |
48 | +# Snaps |
49 | +*.snap |
50 | |
51 | -# build artifacts |
52 | -builds |
53 | +# Builds |
54 | +.build/ |
55 | |
56 | -# tools bundle (needed for functional testing) |
57 | +# Functest artifacts |
58 | tools.zip |
59 | diff --git a/Makefile b/Makefile |
60 | index d314eb8..279ba3d 100644 |
61 | --- a/Makefile |
62 | +++ b/Makefile |
63 | @@ -1,78 +1,103 @@ |
64 | -ifndef JUJU_REPOSITORY |
65 | -JUJU_REPOSITORY := $(CURDIR) |
66 | -export JUJU_REPOSITORY |
67 | -$(warning Warning JUJU_REPOSITORY was not set, defaulting to $(JUJU_REPOSITORY)) |
68 | +PYTHON := /usr/bin/python3 |
69 | + |
70 | +PROJECTPATH=$(dir $(realpath $(MAKEFILE_LIST))) |
71 | +ifndef CHARM_BUILD_DIR |
72 | + CHARM_BUILD_DIR=${PROJECTPATH}.build |
73 | +endif |
74 | +ifndef CHARM_LAYERS_DIR |
75 | + CHARM_LAYERS_DIR=${PROJECTPATH}/layers |
76 | endif |
77 | +ifndef CHARM_INTERFACES_DIR |
78 | + CHARM_INTERFACES_DIR=${PROJECTPATH}/interfaces |
79 | +endif |
80 | +METADATA_FILE="src/metadata.yaml" |
81 | +CHARM_NAME=$(shell cat ${PROJECTPATH}/${METADATA_FILE} | grep -E "^name:" | awk '{print $$2}') |
82 | |
83 | help: |
84 | @echo "This project supports the following targets" |
85 | @echo "" |
86 | @echo " make help - show this text" |
87 | + @echo " make clean - remove unneeded files" |
88 | @echo " make submodules - make sure that the submodules are up-to-date" |
89 | - @echo " make lint - use pre-commit to ensure consistent layout" |
90 | - @echo " make test - run the functional test, unittests and lint" |
91 | - @echo " make unittest - run the tests defined in the unittest subdirectory" |
92 | + @echo " make submodules-update - update submodules to latest changes on remote branch" |
93 | + @echo " make build - build the charm" |
94 | + @echo " make release - run clean, submodules, and build targets" |
95 | + @echo " make lint - run flake8 and black --check" |
96 | + @echo " make black - run black and reformat files" |
97 | + @echo " make proof - run charm proof" |
98 | + @echo " make unittests - run the tests defined in the unittest subdirectory" |
99 | @echo " make functional - run the tests defined in the functional subdirectory" |
100 | - @echo " make release - build the charm" |
101 | - @echo " make clean - remove unneeded files" |
102 | + @echo " make test - run lint, proof, unittests and functional targets" |
103 | @echo "" |
104 | |
105 | +clean: |
106 | + @echo "Cleaning files" |
107 | + @git clean -ffXd -e '!.idea' -e '!tools.zip' |
108 | + @echo "Cleaning existing build" |
109 | + @rm -rf ${CHARM_BUILD_DIR}/${CHARM_NAME} |
110 | + |
111 | submodules: |
112 | @echo "Cloning submodules" |
113 | @git submodule update --init --recursive |
114 | |
115 | +submodules-update: |
116 | + @echo "Pulling latest updates for submodules" |
117 | + @git submodule update --init --recursive --remote --merge |
118 | + |
119 | +build: clean |
120 | + @echo "Building charm to directory ${CHARM_BUILD_DIR}/${CHARM_NAME}" |
121 | + @-git rev-parse --abbrev-ref HEAD > ./src/repo-info |
122 | + @CHARM_LAYERS_DIR=${CHARM_LAYERS_DIR} CHARM_INTERFACES_DIR=${CHARM_INTERFACES_DIR} \ |
123 | + TERM=linux CHARM_BUILD_DIR=${CHARM_BUILD_DIR} charm build src/ |
124 | + |
125 | +release: clean build |
126 | + @echo "Charm is built at ${CHARM_BUILD_DIR}/${CHARM_NAME}" |
127 | + |
128 | lint: |
129 | - @echo "Running flake8" |
130 | - cd src && tox -e pep8 |
131 | + @echo "Running lint checks" |
132 | + @cd src && tox -e lint |
133 | + |
134 | +black: |
135 | + @echo "Reformat files with black" |
136 | + @cd src && tox -e black |
137 | |
138 | -test: lint unittest functional |
139 | +proof: build |
140 | + @echo "Running charm proof" |
141 | + @charm proof ${CHARM_BUILD_DIR}/${CHARM_NAME} |
142 | |
143 | -unittest: build |
144 | - @cd $(JUJU_REPOSITORY)/builds/hw-health && tox -e unit |
145 | +unittests: build |
146 | + @echo "Running unit tests" |
147 | + @cd ${CHARM_BUILD_DIR}/${CHARM_NAME} && tox -e unit |
148 | |
149 | functional: resource_check build buildresources |
150 | - @cd $(JUJU_REPOSITORY)/builds/hw-health && tox -e functional |
151 | + @echo "Executing functional tests in ${CHARM_BUILD_DIR}" |
152 | + @cd ${CHARM_BUILD_DIR}/${CHARM_NAME} && tox -e func |
153 | + |
154 | +test: lint proof unittests functional |
155 | + @echo "Tests completed for charm ${CHARM_NAME}." |
156 | |
157 | resource_check: |
158 | -ifeq ("$(wildcard $(JUJU_REPOSITORY)/tools.zip)","") |
159 | - $(error ERROR: You must save the tools resource in $(JUJU_REPOSITORY)/tools.zip \ |
160 | +ifeq (${PROJECTPATH}tools.zip,) |
161 | + $(error ERROR: You must save the tools resource in ${PROJECTPATH}tools.zip \ |
162 | before running functional tests. \ |
163 | Check the README for instructions on how to do so.) |
164 | endif |
165 | |
166 | buildresources: |
167 | @echo "Copying tools.zip to the builds directory" |
168 | - @cp $(JUJU_REPOSITORY)/tools.zip $(JUJU_REPOSITORY)/builds/tools.zip |
169 | + @cp ${PROJECTPATH}/tools.zip ${CHARM_BUILD_DIR}/tools.zip |
170 | @echo "Building tools-missing.zip" |
171 | - @zip $(JUJU_REPOSITORY)/tools.zip --copy \ |
172 | - --out $(JUJU_REPOSITORY)/builds/tools-missing.zip \ |
173 | + @zip ${PROJECTPATH}/tools.zip --copy \ |
174 | + --out ${CHARM_BUILD_DIR}/tools-missing.zip \ |
175 | --exclude megacli |
176 | @echo "Building tools-checksum.zip" |
177 | - @zip $(JUJU_REPOSITORY)/tools.zip --copy \ |
178 | - --out $(JUJU_REPOSITORY)/builds/tools-checksum.zip \ |
179 | + @zip ${PROJECTPATH}/tools.zip --copy \ |
180 | + --out ${CHARM_BUILD_DIR}/tools-checksum.zip \ |
181 | --exclude megacli |
182 | - @touch $(JUJU_REPOSITORY)/builds/megacli |
183 | - @zip --move --junk-path $(JUJU_REPOSITORY)/builds/tools-checksum.zip \ |
184 | - $(JUJU_REPOSITORY)/builds/megacli |
185 | - |
186 | -build: |
187 | - @echo "Building charm to base directory $(JUJU_REPOSITORY)" |
188 | - @git show -s --format="commit-sha-1: %H%ncommit-short: %h" > ./src/repo-info |
189 | - @echo -n "info-generated: " >> ./src/repo-info |
190 | - @date --utc >> ./src/repo-info |
191 | - @echo "note: This file should exist only in a built or released charm artifact (not in the charm source code tree)." >> ./src/repo-info |
192 | - @CHARM_LAYERS_DIR=./layers CHARM_INTERFACES_DIR=./interfaces\ |
193 | - JUJU_REPOSITORY=$(JUJU_REPOSITORY) charm build ./src --force |
194 | - |
195 | -release: lint clean build |
196 | - # Maybe add the command to push the build bundle to the store? |
197 | - # |
198 | - charm push ./builds/hw-health cs:~nagios-charmers/hw-health |
199 | + @touch ${CHARM_BUILD_DIR}/megacli |
200 | + @zip --move --junk-path ${CHARM_BUILD_DIR}/tools-checksum.zip \ |
201 | + ${CHARM_BUILD_DIR}/megacli |
202 | |
203 | -clean: |
204 | - @echo "Cleaning files" |
205 | - @for dir in src/.tox src/.pytest_cache builds deps; do \ |
206 | - rm -rf $$dir ; done |
207 | |
208 | # The targets below don't depend on a file |
209 | -.PHONY: lint test unittest build release clean help submodules |
210 | +.PHONY: help submodules submodules-update clean build release lint black proof unittests functional test buildresources resource_check |
211 | diff --git a/requirements.txt b/requirements.txt |
212 | deleted file mode 100644 |
213 | index 4235f99..0000000 |
214 | --- a/requirements.txt |
215 | +++ /dev/null |
216 | @@ -1,5 +0,0 @@ |
217 | -charm-tools |
218 | -charmhelpers |
219 | -charms.reactive |
220 | -pre-commit |
221 | -tox |
222 | diff --git a/src/files/mdadm/cron_mdadm.py b/src/files/mdadm/cron_mdadm.py |
223 | index ddf5d5e..3e7e8e9 100755 |
224 | --- a/src/files/mdadm/cron_mdadm.py |
225 | +++ b/src/files/mdadm/cron_mdadm.py |
226 | @@ -133,7 +133,7 @@ def get_devices_stats(devices): |
227 | return devices_stats |
228 | |
229 | |
230 | -def parse_output(): |
231 | +def parse_output(): # noqa:C901 |
232 | devices = get_devices() |
233 | if len(devices) == 0: |
234 | return generate_output('WARNING: unexpectedly checked no devices') |
235 | diff --git a/src/files/megacli/check_megacli.py b/src/files/megacli/check_megacli.py |
236 | index ed1e8d3..b587d10 100755 |
237 | --- a/src/files/megacli/check_megacli.py |
238 | +++ b/src/files/megacli/check_megacli.py |
239 | @@ -55,7 +55,7 @@ def handle_results( |
240 | print(msg) |
241 | |
242 | |
243 | -def parse_output(policy=False): |
244 | +def parse_output(policy=False): # noqa:C901 |
245 | noadapter_re = r'^Adapter \d+: No Virtual Drive Configured' |
246 | adapter_re = r'^Adapter (\d+) -- Virtual Drive Information:' |
247 | ldrive_re = r'^Virtual Drive\s*:\s+(\d+)' |
248 | diff --git a/src/tests/functional/test_hwhealth.py b/src/tests/functional/test_hwhealth.py |
249 | index 6a7966e..cae8fd4 100644 |
250 | --- a/src/tests/functional/test_hwhealth.py |
251 | +++ b/src/tests/functional/test_hwhealth.py |
252 | @@ -3,6 +3,7 @@ import pytest |
253 | import sys |
254 | import subprocess |
255 | import asyncio |
256 | +from os.path import abspath, dirname |
257 | |
258 | sys.path.append('lib') |
259 | |
260 | @@ -17,7 +18,8 @@ SERIES = [ |
261 | 'bionic', |
262 | 'xenial', |
263 | ] |
264 | -JUJU_REPOSITORY = os.getenv('JUJU_REPOSITORY', '.') |
265 | +CHARM_DIR = dirname(dirname(dirname(abspath(__file__)))) |
266 | +CHARM_BUILD_DIR = dirname(CHARM_DIR) |
267 | NRPECFG_DIR = '/etc/nagios/nrpe.d' |
268 | DEF_TIMEOUT = 600 |
269 | # These go along with the hpe repos for the hp* tools |
270 | @@ -30,13 +32,13 @@ DEF_TIMEOUT = 600 |
271 | async def deploy_hwhealth_res(model, app_name, res_filename): |
272 | # Attaching resources is not implemented yet in libjuju |
273 | # see https://github.com/juju/python-libjuju/issues/294 |
274 | - tools_res_path = os.path.join(JUJU_REPOSITORY, 'builds', res_filename) |
275 | + tools_res_path = os.path.join(CHARM_BUILD_DIR, res_filename) |
276 | subprocess.check_call([ |
277 | 'juju', |
278 | 'deploy', |
279 | '-m', |
280 | model.info.name, |
281 | - os.path.join(JUJU_REPOSITORY, 'builds', 'hw-health'), |
282 | + os.path.join(CHARM_BUILD_DIR, 'hw-health'), |
283 | app_name, |
284 | '--resource', |
285 | 'tools={}'.format(tools_res_path), |
286 | @@ -44,7 +46,7 @@ async def deploy_hwhealth_res(model, app_name, res_filename): |
287 | |
288 | |
289 | async def update_hwhealth_res(model, app_name, res_filename): |
290 | - tools_res_path = os.path.join(JUJU_REPOSITORY, 'builds', res_filename) |
291 | + tools_res_path = os.path.join(CHARM_BUILD_DIR, res_filename) |
292 | subprocess.check_call([ |
293 | 'juju', |
294 | 'attach-resource', |
295 | @@ -165,7 +167,7 @@ async def toolset(monkeypatch): |
296 | # deployed charm |
297 | with monkeypatch.context() as m: |
298 | m.setattr('charmhelpers.core.hookenv.charm_dir', |
299 | - lambda: JUJU_REPOSITORY) |
300 | + lambda: CHARM_BUILD_DIR) |
301 | m.setattr('charmhelpers.core.hookenv.config', |
302 | lambda x=None: dict()) |
303 | m.setattr('charmhelpers.contrib.charmsupport.nrpe.get_nagios_hostname', |
304 | diff --git a/src/tox.ini b/src/tox.ini |
305 | index 803d942..db563e9 100644 |
306 | --- a/src/tox.ini |
307 | +++ b/src/tox.ini |
308 | @@ -1,30 +1,72 @@ |
309 | [tox] |
310 | -envlist = unit, functional, pep8 |
311 | -skipsdist = true |
312 | +skipsdist=True |
313 | +skip_missing_interpreters = True |
314 | +envlist = lint, unit, func |
315 | |
316 | -[testenv:unit] |
317 | -basepython=python3 |
318 | -setenv = PYTHONPATH={toxinidir}/lib:{envdir}/lib/python3.8 |
319 | +[testenv] |
320 | +basepython = python3 |
321 | +setenv = |
322 | + PYTHONPATH = {toxinidir}:{toxinidir}/lib/:{toxinidir}/hooks/ |
323 | +passenv = |
324 | + HOME |
325 | + PATH |
326 | + CHARM_BUILD_DIR |
327 | + PYTEST_KEEP_MODEL |
328 | + PYTEST_CLOUD_NAME |
329 | + PYTEST_CLOUD_REGION |
330 | + PYTEST_MODEL |
331 | + MODEL_SETTINGS |
332 | + HTTP_PROXY |
333 | + HTTPS_PROXY |
334 | + NO_PROXY |
335 | + SNAP_HTTP_PROXY |
336 | + SNAP_HTTPS_PROXY |
337 | + |
338 | +[testenv:lint] |
339 | commands = |
340 | - {toxworkdir}/../tests/download_nagios_plugin3.py |
341 | - pytest -v --ignore {toxinidir}/tests/functional --cov=lib/hwhealth --cov=reactive/hw_health.py --cov=actions --cov=files --cov-report=term |
342 | + flake8 |
343 | +#TODO black --check --exclude "/(\.eggs|\.git|\.tox|\.venv|\.build|dist|charmhelpers|mod)/" . |
344 | deps = |
345 | - -r{toxinidir}/tests/unit/requirements.txt |
346 | - -r{toxinidir}/requirements.txt |
347 | + black |
348 | + flake8 |
349 | +#TODO flake8-docstrings |
350 | +#TODO flake8-import-order |
351 | +#TODO pep8-naming |
352 | + flake8-colors |
353 | |
354 | +[flake8] |
355 | +exclude = |
356 | + .git, |
357 | + __pycache__, |
358 | + .tox, |
359 | + charmhelpers, |
360 | + mod, |
361 | + .build |
362 | |
363 | -[testenv:functional] |
364 | -passenv = |
365 | - HOME |
366 | - JUJU_REPOSITORY |
367 | - PATH |
368 | - test_preserve_model |
369 | -commands = pytest -v --ignore {toxinidir}/tests/unit |
370 | -deps = -r{toxinidir}/tests/functional/requirements.txt |
371 | - -r{toxinidir}/requirements.txt |
372 | +#TODO max-line-length = 88 |
373 | +max-line-length = 120 |
374 | +max-complexity = 10 |
375 | |
376 | -[testenv:pep8] |
377 | -basepython = python3 |
378 | +[testenv:black] |
379 | +commands = |
380 | + black --exclude "/(\.eggs|\.git|\.tox|\.venv|\.build|dist|charmhelpers|mod)/" . |
381 | deps = |
382 | - flake8 |
383 | -commands = flake8 {posargs} --max-complexity=12 --max-line-length=120 . |
384 | + black |
385 | + |
386 | +[testenv:unit] |
387 | +commands = |
388 | + {toxworkdir}/../tests/download_nagios_plugin3.py |
389 | + pytest -v --ignore {toxinidir}/tests/functional \ |
390 | + --cov=lib \ |
391 | + --cov=reactive \ |
392 | + --cov=actions \ |
393 | + --cov=hooks \ |
394 | + --cov=src \ |
395 | + --cov-report=term \ |
396 | + --cov-report=annotate:report/annotated \ |
397 | + --cov-report=html:report/html |
398 | +deps = -r{toxinidir}/tests/unit/requirements.txt |
399 | + |
400 | +[testenv:func] |
401 | +commands = pytest -v --ignore {toxinidir}/tests/unit |
402 | +deps = -r{toxinidir}/tests/functional/requirements.txt |
LGTM, intermittent xenial functest fail but I think that's unrelated to this change.