Merge ~peter-sabaini/charm-grafana:test-fixes-race-cleanup into charm-grafana:master

Proposed by Peter Sabaini
Status: Rejected
Rejected by: Haw Loeung
Proposed branch: ~peter-sabaini/charm-grafana:test-fixes-race-cleanup
Merge into: charm-grafana:master
Diff against target: 94 lines (+39/-8)
1 file modified
src/tests/functional/tests/test_grafana.py (+39/-8)
Reviewer Review Type Date Requested Status
Alvaro Uria (community) Needs Fixing
🤖 prod-jenkaas-bootstack continuous-integration Needs Fixing
Drew Freiberger (community) Needs Fixing
BootStack Reviewers mr tracking; do not claim Pending
BootStack Reviewers Pending
BootStack Reviewers Pending
Review via email: mp+397160@code.launchpad.net

Commit message

Functional test fixes

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.

dd9e6e4... by Peter Sabaini

Don't hardcode default port

When resetting datasource config

c651bd8... by Peter Sabaini

Fix port param

Revision history for this message
Drew Freiberger (afreiberger) wrote :

The focal-snap bundle failed on the upgrade tests oddly:

https://pastebin.canonical.com/p/zQmBpDFyW2/

bionic-snap had no such trouble, and the rest of tests run.

2021-01-29 21:12:10 [INFO] ======================================================================
2021-01-29 21:12:10 [INFO] FAIL: test_50_snap_upgrade (tests.test_grafana.SnappedGrafanaTest)
2021-01-29 21:12:10 [INFO] Test a snap upgrade from 6 to 7.
2021-01-29 21:12:10 [INFO] ----------------------------------------------------------------------
2021-01-29 21:12:10 [INFO] Traceback (most recent call last):
2021-01-29 21:12:10 [INFO] File "./tests/test_grafana.py", line 310, in test_50_snap_upgrade
2021-01-29 21:12:10 [INFO] "PACKAGE UPGRADE REQUIRES MANUAL INTERVENTION" in status_message
2021-01-29 21:12:10 [INFO] AssertionError: False is not true
2021-01-29 21:12:10 [INFO] ======================================================================
2021-01-29 21:12:10 [INFO] FAIL: test_51_snap_downgrade_block (tests.test_grafana.SnappedGrafanaTest)
2021-01-29 21:12:10 [INFO] Test that after the previous upgrade, downgrades are blocked.
2021-01-29 21:12:10 [INFO] ----------------------------------------------------------------------
2021-01-29 21:12:10 [INFO] Traceback (most recent call last):
2021-01-29 21:12:10 [INFO] File "./tests/test_grafana.py", line 324, in test_51_snap_downgrade_block
2021-01-29 21:12:10 [INFO] self.assertTrue("PACKAGE DOWNGRADES ARE NOT SUPPORTED" in status_message)
2021-01-29 21:12:10 [INFO] AssertionError: False is not true
2021-01-29 21:12:10 [INFO] ----------------------------------------------------------------------

review: Needs Fixing
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 :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alvaro Uria (aluria) wrote :

this is not actually the fault of this MP, but a URL has a wrong format [1], which makes unit tests fail.

The other error is this one (test_get_installed_package_version):
"""
subprocess.CalledProcessError: Command 'apt list --installed | grep python3-pip' returned non-zero exit status 1.
"""

1. https://git.launchpad.net/~peter-sabaini/charm-grafana/tree/src/tests/unit/test_grafana.py?h=test-fixes-race-cleanup#n46

review: Needs Fixing
Revision history for this message
Drew Freiberger (afreiberger) wrote :

Regarding the python3-pip apt list command:

https://git.launchpad.net/~peter-sabaini/charm-grafana/tree/src/lib/charms/layer/grafana.py?h=test-fixes-race-cleanup#n181

Update this to subprocess.getoutput() instead of check_output to toss out the exception handling if it's uninstalled. Or add a try: except: return False kind of thing to handle these package install exceptions.

Unmerged commits

c651bd8... by Peter Sabaini

Fix port param

dd9e6e4... by Peter Sabaini

Don't hardcode default port

When resetting datasource config

bb58345... by Peter Sabaini

Functional test fixes

Fix races on file contents checking. Add cleanup to restore SUT after
config changes

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/tests/functional/tests/test_grafana.py b/src/tests/functional/tests/test_grafana.py
2index d0e54d4..5709ca5 100644
3--- a/src/tests/functional/tests/test_grafana.py
4+++ b/src/tests/functional/tests/test_grafana.py
5@@ -1,4 +1,5 @@
6 """Encapsulate prometheus-openstack-exporter testing."""
7+import asyncio
8 import json
9 import logging
10 import time
11@@ -103,6 +104,21 @@ class BaseGrafanaTest(unittest.TestCase):
12 number_of_backups_end = backups_end["Stdout"].count(".json")
13 self.assertTrue(number_of_backups_end > number_of_backups_start)
14
15+ def file_pattern_test(self, app, pattern, file, message):
16+ """Test if remote file matches a pattern.
17+
18+ Retry pattern matching for 30s before giving up and failing test with message
19+ """
20+ try:
21+ model.block_until_file_matches_re(
22+ app,
23+ file,
24+ pattern,
25+ timeout=30,
26+ )
27+ except asyncio.exceptions.TimeoutError:
28+ self.fail(message)
29+
30
31 class CharmOperationTest(BaseGrafanaTest):
32 """Verify operations."""
33@@ -228,12 +244,15 @@ class CharmOperationTest(BaseGrafanaTest):
34 {"dashboards_backup_schedule": "* * * * *"},
35 )
36 model.block_until_all_units_idle()
37- crontab = model.run_on_unit(
38- self.lead_unit_name,
39- "cat /etc/cron.d/juju-dashboards-backup",
40+ expect_pat = "dashboards_backup -d {} -p {}".format(
41+ DEFAULT_BACKUP_DIRECTORY, DEFAULT_API_PORT
42+ )
43+ self.file_pattern_test(
44+ self.application_name,
45+ expect_pat,
46+ "/etc/cron.d/juju-dashboards-backup",
47+ "Cronjob doesn't match pattern {}".format(expect_pat),
48 )
49- self.assertTrue(DEFAULT_BACKUP_DIRECTORY in crontab["Stdout"])
50- self.assertTrue(DEFAULT_API_PORT in crontab["Stdout"])
51 self.verify_iterative_backups()
52
53 def test_14_grafana_dashboard_backup_port_change(self):
54@@ -245,11 +264,19 @@ class CharmOperationTest(BaseGrafanaTest):
55 model.block_until_all_units_idle()
56 model.set_application_config(self.application_name, {"port": port})
57 model.block_until_all_units_idle()
58- crontab = model.run_on_unit(
59- self.lead_unit_name, "cat /etc/cron.d/juju-dashboards-backup"
60+ expect_pat = "dashboards_backup -d {} -p {}".format(
61+ DEFAULT_BACKUP_DIRECTORY, port
62+ )
63+ self.file_pattern_test(
64+ self.application_name,
65+ expect_pat,
66+ "/etc/cron.d/juju-dashboards-backup",
67+ "Cronjob doesn't match pattern {}".format(expect_pat),
68 )
69- self.assertTrue(port in crontab["Stdout"])
70 self.verify_iterative_backups()
71+ # Cleanup: restore orig. port to make test re-runnable
72+ model.set_application_config(self.application_name, {"port": DEFAULT_API_PORT})
73+ model.block_until_all_units_idle()
74
75 def test_15_grafana_datasource_updates(self):
76 """Change the port on the associated datasource.
77@@ -263,6 +290,9 @@ class CharmOperationTest(BaseGrafanaTest):
78 port_config = {"web-listen-port": "1234"}
79 model.set_application_config(datasource_application, port_config)
80 model.block_until_all_units_idle()
81+ # Cleanup: reset to default port
82+ model.reset_application_config(datasource_application, ["web-listen-port"])
83+ model.block_until_all_units_idle()
84
85
86 class SnappedGrafanaTest(BaseGrafanaTest):
87@@ -301,6 +331,7 @@ class SnappedGrafanaTest(BaseGrafanaTest):
88 model.set_application_config( # set it back to 6
89 self.application_name, {"snap_channel": "6/stable"}
90 )
91+ model.block_until_unit_wl_status(self.lead_unit_name, "active")
92 model.block_until_all_units_idle()
93
94 def test_52_latest(self):

Subscribers

People subscribed via source and target branches

to all changes: