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
diff --git a/hooks/monitors_relation_changed.py b/hooks/monitors_relation_changed.py
index 4c86a63..b24ed5c 100755
--- a/hooks/monitors_relation_changed.py
+++ b/hooks/monitors_relation_changed.py
@@ -199,8 +199,9 @@ def main(argv, full_rewrite=False): # noqa: C901
199 else:199 else:
200 status_set("active", "ready")200 status_set("active", "ready")
201201
202 for relid, units in all_relations.items():202 new_file_set = set()
203 apply_relation_config(relid, units, all_hosts)203 for units in all_relations.itervalues():
204 apply_relation_config(units, all_hosts, new_file_set)
204205
205 cleanup_leftover_hosts(all_relations)206 cleanup_leftover_hosts(all_relations)
206 refresh_hostgroups()207 refresh_hostgroups()
@@ -261,13 +262,15 @@ def compute_host_prefixes(model_ids):
261 return result262 return result
262263
263264
264def apply_relation_config(relid, units, all_hosts): # noqa: C901265def apply_relation_config(units, all_hosts, new_file_set): # noqa: C901
265 for unit, relation_settings in units.iteritems():266 for relation_settings in units.itervalues():
266 target_id = relation_settings[TARGET_ID_KEY]267 target_id = relation_settings[TARGET_ID_KEY]
267 if os.path.exists(get_nagios_host_config_path(target_id)):268 host_config_path = get_nagios_host_config_path(target_id)
269 if os.path.exists(host_config_path) and host_config_path not in new_file_set:
268 # Skip updating files unrelated to the hook at hand unless they were270 # Skip updating files unrelated to the hook at hand unless they were
269 # deliberately removed with the intent of them being rewritten.271 # deliberately removed with the intent of them being rewritten.
270 continue272 continue
273 new_file_set.add(host_config_path)
271274
272 monitors = relation_settings["monitors"]275 monitors = relation_settings["monitors"]
273 machine_id = relation_settings.get(MACHINE_ID_KEY)276 machine_id = relation_settings.get(MACHINE_ID_KEY)

Subscribers

People subscribed via source and target branches

to all changes: