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/telegraf.py (+1/-0)
src/tests/unit/test_telegraf.py (+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: mp+406953@code.launchpad.net

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/telegraf.py b/src/reactive/telegraf.py
2index 7a19d16..ecbbf57 100644
3--- a/src/reactive/telegraf.py
4+++ b/src/reactive/telegraf.py
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/test_telegraf.py b/src/tests/unit/test_telegraf.py
14index 251a9b9..55eae97 100644
15--- a/src/tests/unit/test_telegraf.py
16+++ b/src/tests/unit/test_telegraf.py
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(telegraf.host, "service_resume", lambda svc: None)
24 monkeypatch.setattr(telegraf.host, "service_reload", lambda svc: None)
25 monkeypatch.setattr(telegraf.host, "service_pause", lambda svc: None)
26@@ -1370,7 +1370,34 @@ def test_upgrade_charm(mocker):
27 clear_flag.assert_any_call("plugins.bar.configured")
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
33+
34+
35+def test_upgrade_charm_prometheus_client(mocker, monkeypatch, config):
36+ service_restart = mocker.patch("reactive.telegraf.host.service_restart")
37+ monkeypatch.setattr(telegraf.host, "service_running", lambda n: True)
38+ mocker.patch("reactive.telegraf.check_prometheus_port")
39+ mocker.patch("charms.reactive.relations.relation_factory")
40+
41+ def relation_ids(reltype):
42+ if reltype == "prometheus-client":
43+ return ["prometheprometheus-client:0"]
44+ else:
45+ return []
46+
47+ monkeypatch.setattr(telegraf.hookenv, "relation_ids", relation_ids)
48+ mocker.patch.object(
49+ telegraf.hookenv, "network_get", return_value={"ingress_addresses": ["1.2.3.4"]}
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)
59
60
61 def test_get_socket_listener_port(monkeypatch, config):

Subscribers

People subscribed via source and target branches

to all changes: