Merge ~vultaire/charm-nagios:allow-multiple-relation-data-sets-per-host into charm-nagios:master

Proposed by Paul Goins
Status: Merged
Approved by: James Troup
Approved revision: 525739b24923babdde61f66b5caf292340c1181b
Merged at revision: 054394442a902a178477b9855a4e06d1aa974bea
Proposed branch: ~vultaire/charm-nagios:allow-multiple-relation-data-sets-per-host
Merge into: charm-nagios:master
Prerequisite: ~vultaire/charm-nagios:skip-dedupe-prefix-for-same-model
Diff against target: 35 lines (+8/-5)
1 file modified
hooks/monitors_relation_changed.py (+8/-5)
Reviewer Review Type Date Requested Status
Garrett Neugent (community) Approve
Xav Paice (community) Approve
🤖 prod-jenkaas-bootstack continuous-integration Approve
BootStack Reviewers Pending
Review via email: mp+407788@code.launchpad.net

Commit message

Keep writing config for newly-created config files

With the new logic, we try to write only the files we need to.
However, there may legitimately be cases where there's multiple sets
of data associated with the same host name (e.g. multiple nrpe units),
and at present, only the first set of such data will actually be
written.

This change tracks files which are being newly created, and will allow
multiple sets of relation data to be written to the same file, if
necessary.

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
🤖 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
Paul Goins (vultaire) wrote :

Note: I did replace some items/iteritems calls with itervalues as a cleanup to remove unused vars.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)
Revision history for this message
Xav Paice (xavpaice) wrote :

LGTM

review: Approve
Revision history for this message
Garrett Neugent (thogarre) wrote :

LGTM

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

Change successfully merged at revision 054394442a902a178477b9855a4e06d1aa974bea

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/hooks/monitors_relation_changed.py b/hooks/monitors_relation_changed.py
2index 4c86a63..b24ed5c 100755
3--- a/hooks/monitors_relation_changed.py
4+++ b/hooks/monitors_relation_changed.py
5@@ -199,8 +199,9 @@ def main(argv, full_rewrite=False): # noqa: C901
6 else:
7 status_set("active", "ready")
8
9- for relid, units in all_relations.items():
10- apply_relation_config(relid, units, all_hosts)
11+ new_file_set = set()
12+ for units in all_relations.itervalues():
13+ apply_relation_config(units, all_hosts, new_file_set)
14
15 cleanup_leftover_hosts(all_relations)
16 refresh_hostgroups()
17@@ -261,13 +262,15 @@ def compute_host_prefixes(model_ids):
18 return result
19
20
21-def apply_relation_config(relid, units, all_hosts): # noqa: C901
22- for unit, relation_settings in units.iteritems():
23+def apply_relation_config(units, all_hosts, new_file_set): # noqa: C901
24+ for relation_settings in units.itervalues():
25 target_id = relation_settings[TARGET_ID_KEY]
26- if os.path.exists(get_nagios_host_config_path(target_id)):
27+ host_config_path = get_nagios_host_config_path(target_id)
28+ if os.path.exists(host_config_path) and host_config_path not in new_file_set:
29 # Skip updating files unrelated to the hook at hand unless they were
30 # deliberately removed with the intent of them being rewritten.
31 continue
32+ new_file_set.add(host_config_path)
33
34 monitors = relation_settings["monitors"]
35 machine_id = relation_settings.get(MACHINE_ID_KEY)

Subscribers

People subscribed via source and target branches

to all changes: