Merge ~verterok/charm-telegraf:fix-1939583 into charm-telegraf:master

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: Drew Freiberger
Approved revision: 6a86df99324924f4f1464fb75e57bc18267c6a0c
Merged at revision: 5a41b9fb39887d000a5a6eaf528aba3eaeb5f2bc
Proposed branch: ~verterok/charm-telegraf:fix-1939583
Merge into: charm-telegraf:master
Diff against target: 61 lines (+30/-2)
2 files modified
src/reactive/ (+1/-0)
src/tests/unit/ (+29/-2)
Reviewer Review Type Date Requested Status
prod-jenkaas-bootstack (community) continuous-integration Needs Fixing
Drew Freiberger (community) Approve
Tom Haddon Pending
BootStack Reviewers Pending
Review via email:

Commit message

Fix lp:1939583. clear prometheus-client.relation.configured flag on upgrade-charm

Description of the change

Find details in the bug description.
This is basically to keep things in a consistent state and clear the prometheus-client.relation.configured state/flag when doing charm upgrade as plugins.prometheus-client.configured is already cleared.

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
Guillermo Gonzalez (verterok) wrote :

comments for reviewers

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

LGTM +1. Thanks for the submission!

review: Approve
Revision history for this message
prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Tom Haddon (mthaddon) wrote :

Also LGTM, claiming review to remove from ~canonical-is-reviewers dashboard.

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

CI job misconfig/failure, but testing worked fine on my laptop. merging.

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

Change successfully merged at revision 5a41b9fb39887d000a5a6eaf528aba3eaeb5f2bc

Revision history for this message
prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/reactive/ b/src/reactive/
2index 7a19d16..ecbbf57 100644
3--- a/src/reactive/
4+++ b/src/reactive/
5@@ -961,6 +961,7 @@ def configure_telegraf_snap():
6 def upgrade_charm():
7 for plugin in list_supported_plugins():
8 clear_flag("plugins.{}.configured".format(plugin))
9+ clear_flag("prometheus-client.relation.configured")
10 clear_flag("extra_plugins.configured")
11 clear_flag("telegraf.configured")
12 clear_flag("telegraf.apt.configured")
13diff --git a/src/tests/unit/ b/src/tests/unit/
14index 251a9b9..55eae97 100644
15--- a/src/tests/unit/
16+++ b/src/tests/unit/
17@@ -70,7 +70,7 @@ def setup(monkeypatch, tmpdir):
18 # mock this to avoid permission errors
19 monkeypatch.setattr(telegraf, "update_sysstat_config_with_sdac_xall", lambda: True)
20 monkeypatch.setattr(telegraf.hookenv, "status_set", lambda status, msg: None)
21- monkeypatch.setattr(telegraf.hookenv, "log", lambda msg, **kw: None)
22+ monkeypatch.setattr(telegraf.hookenv, "log", lambda msg, *a, **kw: None)
23 monkeypatch.setattr(, "service_resume", lambda svc: None)
24 monkeypatch.setattr(, "service_reload", lambda svc: None)
25 monkeypatch.setattr(, "service_pause", lambda svc: None)
26@@ -1370,7 +1370,34 @@ def test_upgrade_charm(mocker):
27 clear_flag.assert_any_call("")
28 clear_flag.assert_any_call("extra_plugins.configured")
29 clear_flag.assert_any_call("grafana.configured")
30- assert clear_flag.call_count == 7
31+ clear_flag.assert_any_call("prometheus-client.relation.configured")
32+ assert clear_flag.call_count == 8
35+def test_upgrade_charm_prometheus_client(mocker, monkeypatch, config):
36+ service_restart = mocker.patch("")
37+ monkeypatch.setattr(, "service_running", lambda n: True)
38+ mocker.patch("reactive.telegraf.check_prometheus_port")
39+ mocker.patch("charms.reactive.relations.relation_factory")
41+ def relation_ids(reltype):
42+ if reltype == "prometheus-client":
43+ return ["prometheprometheus-client:0"]
44+ else:
45+ return []
47+ monkeypatch.setattr(telegraf.hookenv, "relation_ids", relation_ids)
48+ mocker.patch.object(
49+ telegraf.hookenv, "network_get", return_value={"ingress_addresses": [""]}
50+ )
51+ set_flag("apt.installed.telegraf")
52+ set_flag("prometheus-client.relation.configured")
53+ set_flag("prometheus-client.available")
54+ set_flag("plugins.prometheus-client.configured")
55+ assert not base_dir().join("telegraf.conf").exists()
56+ bus.dispatch()
57+ assert "telegraf.configured" in bus.get_states().keys()
58+ service_restart.assert_called_with(telegraf.DEB_SERVICE)
61 def test_get_socket_listener_port(monkeypatch, config):


People subscribed via source and target branches

to all changes: