Merge charm-hw-health:improve-dev-workflow into charm-hw-health:master

Proposed by Facundo Ciccioli
Status: Rejected
Rejected by: Haw Loeung
Proposed branch: charm-hw-health:improve-dev-workflow
Merge into: charm-hw-health:master
Diff against target: 113 lines (+57/-5)
4 files modified
src/README.md (+41/-0)
src/tests/functional/conftest.py (+7/-3)
src/tests/functional/test_hwhealth.py (+5/-1)
src/tox.ini (+4/-1)
Reviewer Review Type Date Requested Status
Tom Haddon Abstain
Paul Goins Needs Fixing
🤖 prod-jenkaas-bootstack (community) continuous-integration Needs Fixing
BootStack Reviewers mr tracking; do not claim Pending
BootStack Reviewers Pending
Review via email: mp+399589@code.launchpad.net
To post a comment you must log in.
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :

A CI job is currently in progress. A follow up comment will be added when it completes.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :

FAILED: Continuous integration, rev:6e476272c328c0f0739f4103299546aa54a42cae

No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want jenkins to rebuild you need to trigger it yourself):
https://code.launchpad.net/~llama-charmers/charm-hw-health/+git/charm-hw-health/+merge/399589/+edit-commit-message

https://jenkins.canonical.com/bootstack/job/lp-charm-hw-health-ci/2/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/bootstack/job/lp-charm-test-unit/53/
    None: https://jenkins.canonical.com/bootstack/job/lp-update-mp/140/

Click here to trigger a rebuild:
https://jenkins.canonical.com/bootstack/job/lp-charm-hw-health-ci/2//rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Paul Goins (vultaire) wrote :

This is an interesting patch. I have some small concerns; please take a look.

review: Needs Fixing
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
Tom Haddon (mthaddon) wrote :

Abstaining, just claimed the review to take it off the canonical-is-reviewers dashboard, mergebot has been switched to add bootstack-reviewers for future MPs.

review: Abstain

Unmerged commits

6e47627... by Facundo Ciccioli

Some docs and funcionality that came in handy while working on this charm

It's the second time I have to learn these stuff, maybe it's useful for
others here.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/README.md b/src/README.md
2index e367400..8b9d4b2 100644
3--- a/src/README.md
4+++ b/src/README.md
5@@ -117,6 +117,47 @@ file a bug (see link below) and it will be added.
6
7 Manufacturer option needs to be left in auto mode.
8
9+# Functional tests' tricks
10+
11+The functional tests obey a couple of environment variables meant to facilitate
12+a quicker write-execute-modify cycle.
13+
14+* `TESTS_PRESERVE_MODEL`: Setting this to whatever non-empty string will
15+ prevent the tests' code from destroying the test model after the tests have
16+ ran (note that not setting this will cause the model to be destroyed in any
17+ case, not just on a successful run).
18+* `TESTS_USE_MODEL`: Set it to a pre-existent model so that the tests are run
19+ in it, instead of creating a new one.
20+* `TESTS_JUJU_SETTLE_TIMEOUT_sec`: Set this to the desired timeout when waiting
21+ for the model to settle after having performed some action on it (like adding
22+ a relation or deploying a unit). Defaults to 600 (10 minutes).
23+
24+Tox is configured to let those variables through (anything starting with
25+`TESTS_`) to the commands it executes. Hence if you're using the `Makefile` for
26+instance, you can do this:
27+
28+```
29+$ make TESTS_JUJU_SETTLE_TIMEOUT_sec=1200 functional
30+```
31+
32+Also, for the functional tests only, any positional arguments passed in to tox
33+after a double dash (`--`) will be inserted at the end of the `pytest` command.
34+This can be very handy to filter out everything except the tests you're working
35+on:
36+
37+```
38+$ make TESTS_PRESERVE_MODEL=1 functional # This will take a long time
39+$ . $(find -path '/func/' -name activate)
40+(func)$ cd src
41+(func)$ TEST_USE_MODEL=$(juju models | awk '/functest-/ {print $1;}' | tr -d \*) \
42+ tox -e func -- -k 'test_my_wip_test and bionic'
43+
44+```
45+
46+If you're changing you charm's code and not only your test's, you'll have to
47+remember to `make build` and `juju upgrade-charm ...` before re-running your
48+test.
49+
50 # Contact Information
51
52 Please contact the Nagios charmers via the "Submit a bug" link.
53diff --git a/src/tests/functional/conftest.py b/src/tests/functional/conftest.py
54index c7c856c..f898e30 100644
55--- a/src/tests/functional/conftest.py
56+++ b/src/tests/functional/conftest.py
57@@ -60,11 +60,15 @@ async def controller():
58 @pytest.fixture(scope="module")
59 async def model(controller): # pylint: disable=redefined-outer-name
60 """Create model which lives only for the duration of the test."""
61- model_name = "functest-{}".format(uuid.uuid4())
62- _model = await controller.add_model(model_name)
63+ model_name = os.getenv("TESTS_USE_MODEL", "functest-{}".format(uuid.uuid4()))
64+ if os.getenv("TESTS_USE_MODEL"):
65+ model_f = controller.get_model
66+ else:
67+ model_f = controller.add_model
68+ _model = await model_f(model_name)
69 yield _model
70 await _model.disconnect()
71- if not os.getenv("test_preserve_model"):
72+ if not os.getenv("TESTS_PRESERVE_MODEL"):
73 await controller.destroy_model(model_name)
74 while model_name in await controller.list_models():
75 await asyncio.sleep(1)
76diff --git a/src/tests/functional/test_hwhealth.py b/src/tests/functional/test_hwhealth.py
77index 634c545..5b84b36 100644
78--- a/src/tests/functional/test_hwhealth.py
79+++ b/src/tests/functional/test_hwhealth.py
80@@ -22,7 +22,7 @@ SERIES = [
81 CHARM_DIR = dirname(dirname(dirname(abspath(__file__))))
82 CHARM_BUILD_DIR = dirname(CHARM_DIR)
83 NRPECFG_DIR = "/etc/nagios/nrpe.d"
84-DEF_TIMEOUT = 600
85+DEF_TIMEOUT = int(os.getenv('TESTS_JUJU_SETTLE_TIMEOUT_sec', '600'))
86 # These go along with the hpe repos for the hp* tools
87
88 ################
89@@ -75,6 +75,10 @@ async def deploy_app(request, model):
90 release = request.param
91 channel = "stable"
92 hw_health_app_name = "hw-health-{}".format(release)
93+ if os.getenv("TESTS_USE_MODEL"):
94+ yield model.applications[hw_health_app_name]
95+ return
96+
97 hw_health_checksum_app_name = "hw-health-checksum-{}".format(release)
98
99 for principal_app in ["ubuntu", "nagios"]:
100diff --git a/src/tox.ini b/src/tox.ini
101index 7da331e..1acdf41 100644
102--- a/src/tox.ini
103+++ b/src/tox.ini
104@@ -76,5 +76,8 @@ commands =
105 deps = -r{toxinidir}/tests/unit/requirements.txt
106
107 [testenv:func]
108-commands = pytest -v --ignore {toxinidir}/tests/unit
109+passenv =
110+ {[testenv]passenv}
111+ TESTS_*
112+commands = pytest -v --ignore {toxinidir}/tests/unit {posargs}
113 deps = -r{toxinidir}/tests/functional/requirements.txt

Subscribers

No one subscribed via source and target branches