Merge ~arif-ali/charm-nagios:nrpe_v2_fix_config_changed into charm-nagios:master

Proposed by Arif Ali
Status: Merged
Approved by: Andrea Ieri
Approved revision: b33f0e12cee1fc5f258bfb10edb7160fa9c23847
Merged at revision: a2aa5e8935b885fd5d415bf5b791744ad0d0c3bd
Proposed branch: ~arif-ali/charm-nagios:nrpe_v2_fix_config_changed
Merge into: charm-nagios:master
Diff against target: 157 lines (+39/-10)
4 files modified
hooks/common.py (+14/-3)
hooks/monitors_relation_changed.py (+6/-6)
hooks/upgrade_charm.py (+10/-0)
tests/functional/conftest.py (+9/-1)
Reviewer Review Type Date Requested Status
Andrea Ieri Approve
Ashley James Approve
BootStack Reviewers Pending
Review via email: mp+459713@code.launchpad.net

Commit message

Fix config-changed hook for nrpe_packet_version change

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
Arif Ali (arif-ali) wrote :

Below are the results from the lint and unit tests. The functional tests don't work, and hang after active/idle state of the model. Tried to fix that put the same issue with xenial. The xenial functional tests wouldn't work as the ch default channels didn't have xenial.

More work is required to get the functional tests to work. I may have a further dig, but if this can be reviewed without that, then that would help me

❱❱❱ tox -e lint | pastebinit
All done! ✨ 🍰 ✨
15 files would be left unchanged.
https://paste.ubuntu.com/p/JbhT49hKFz/

❱❱❱ tox -e unit | pastebinit
/home/arif/gitRepos/openstack/charm-nagios/.tox/unit/lib/python3.11/site-packages/coverage/inorout.py:503: CoverageWarning: Module lib was never imported. (module-not-imported)
  self.warn(f"Module {pkg} was never imported.", slug="module-not-imported")
/home/arif/gitRepos/openstack/charm-nagios/.tox/unit/lib/python3.11/site-packages/coverage/inorout.py:503: CoverageWarning: Module reactive was never imported. (module-not-imported)
  self.warn(f"Module {pkg} was never imported.", slug="module-not-imported")
/home/arif/gitRepos/openstack/charm-nagios/.tox/unit/lib/python3.11/site-packages/coverage/inorout.py:503: CoverageWarning: Module src was never imported. (module-not-imported)
  self.warn(f"Module {pkg} was never imported.", slug="module-not-imported")
https://paste.ubuntu.com/p/jDxK2GCDVn/

Revision history for this message
Ashley James (dashmage) wrote :

Changes LGTM! Thanks for sharing the test results as well. If the func tests aren't failing due to your changes then it's alright.

review: Approve
Revision history for this message
Andrea Ieri (aieri) wrote :

a couple of comments in-line

review: Needs Fixing
Revision history for this message
Arif Ali (arif-ali) wrote :

Can I get another review please, thanks

Revision history for this message
Andrea Ieri (aieri) :
review: Approve
Revision history for this message
Andrea Ieri (aieri) wrote :

The fact that functional tests don't work is mildly terrifying, but it's on us to get them sorted out before we can promote to stable. We can push to edge for now.
I have rerun lint and unit tests and they pass.

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

Change successfully merged at revision a2aa5e8935b885fd5d415bf5b791744ad0d0c3bd

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/hooks/common.py b/hooks/common.py
2index ee65735..9d23d68 100644
3--- a/hooks/common.py
4+++ b/hooks/common.py
5@@ -6,6 +6,7 @@ import re
6 import shutil
7 import socket
8 import subprocess
9+import sys
10 import tempfile
11 import time
12
13@@ -149,7 +150,7 @@ def refresh_hostgroups(): # noqa:C901
14 except (ValueError, KeyError):
15 pass
16
17- for hgroup_name, members in hgroups.iteritems():
18+ for hgroup_name, members in hgroups.items():
19 if os.path.exists(get_nagios_hostgroup_config_path(hgroup_name)):
20 # Skip updating files unrelated to the hook at hand unless they were
21 # deliberately removed with the intent of them being rewritten.
22@@ -472,8 +473,13 @@ def apply_host_policy(target_id, owner_unit, owner_relation):
23 def _replace_in_config(find_me, replacement):
24 with open(INPROGRESS_CFG) as cf:
25 with tempfile.NamedTemporaryFile(dir=INPROGRESS_DIR, delete=False) as new_cf:
26+ py_version = sys.version_info[0]
27 for line in cf:
28- new_cf.write(line.replace(find_me, replacement))
29+ line_to_write = line.replace(find_me, replacement)
30+ if py_version == 2:
31+ new_cf.write(line_to_write)
32+ else:
33+ new_cf.write(line_to_write.encode("UTF-8"))
34 new_cf.flush()
35 os.chmod(new_cf.name, 0o644)
36 os.unlink(INPROGRESS_CFG)
37@@ -483,8 +489,13 @@ def _replace_in_config(find_me, replacement):
38 def _commit_in_config(find_me, replacement):
39 with open(MAIN_NAGIOS_CFG) as cf:
40 with tempfile.NamedTemporaryFile(dir=MAIN_NAGIOS_DIR, delete=False) as new_cf:
41+ py_version = sys.version_info[0]
42 for line in cf:
43- new_cf.write(line.replace(find_me, replacement))
44+ line_to_write = line.replace(find_me, replacement)
45+ if py_version == 2:
46+ new_cf.write(line_to_write)
47+ else:
48+ new_cf.write(line_to_write.encode("UTF-8"))
49 new_cf.flush()
50 os.chmod(new_cf.name, 0o644)
51 os.unlink(MAIN_NAGIOS_CFG)
52diff --git a/hooks/monitors_relation_changed.py b/hooks/monitors_relation_changed.py
53index 0bdb0cc..48b4e99 100755
54--- a/hooks/monitors_relation_changed.py
55+++ b/hooks/monitors_relation_changed.py
56@@ -124,13 +124,13 @@ def main(argv, full_rewrite=False): # noqa: C901
57 # Hack to work around http://pad.lv/1025478
58 targets_with_addresses = set()
59
60- for relid, units in all_relations.iteritems():
61+ for relid, units in all_relations.items():
62 for unit, relation_settings in units.items():
63 if TARGET_ID_KEY in relation_settings:
64 targets_with_addresses.add(relation_settings.get(TARGET_ID_KEY))
65 new_all_relations = {}
66
67- for relid, units in all_relations.iteritems():
68+ for relid, units in all_relations.items():
69 for unit, relation_settings in units.items():
70 if relation_settings.get(TARGET_ID_KEY) in targets_with_addresses:
71 if relid not in new_all_relations:
72@@ -196,7 +196,7 @@ def main(argv, full_rewrite=False): # noqa: C901
73 status_set("active", "ready")
74
75 new_file_set = set()
76- for units in all_relations.itervalues():
77+ for units in all_relations.values():
78 apply_relation_config(units, all_hosts, new_file_set)
79
80 cleanup_leftover_hosts(all_relations)
81@@ -253,7 +253,7 @@ def compute_host_prefixes(model_ids):
82
83
84 def apply_relation_config(units, all_hosts, new_file_set): # noqa: C901
85- for relation_settings in units.itervalues():
86+ for relation_settings in units.values():
87 target_id = relation_settings[TARGET_ID_KEY]
88 host_config_path = get_nagios_host_config_path(target_id)
89 if os.path.exists(host_config_path) and host_config_path not in new_file_set:
90@@ -305,8 +305,8 @@ def apply_relation_config(units, all_hosts, new_file_set): # noqa: C901
91 host.set_attribute("parents", parent_host)
92 host.save()
93
94- for mon_family, mons in monitors["monitors"]["remote"].iteritems():
95- for mon_name, mon in mons.iteritems():
96+ for mon_family, mons in monitors["monitors"]["remote"].items():
97+ for mon_name, mon in mons.items():
98 service_name = "%s-%s" % (target_id, mon_name)
99 service = get_pynag_service(target_id, service_name)
100 try:
101diff --git a/hooks/upgrade_charm.py b/hooks/upgrade_charm.py
102index 3ea6453..f837d2e 100755
103--- a/hooks/upgrade_charm.py
104+++ b/hooks/upgrade_charm.py
105@@ -37,6 +37,8 @@ from common import (
106 update_notification_options,
107 )
108
109+config = hookenv.config()
110+
111 # Gather facts
112 legacy_relations = hookenv.config("legacy")
113 extra_config = hookenv.config("extraconfig")
114@@ -698,6 +700,12 @@ def configure_livestatus_xinetd():
115 hookenv.log("Livestatus xinetd configured.", "INFO")
116
117
118+def update_nrpe():
119+ from monitors_relation_changed import main # noqa: E402
120+
121+ main([__file__], full_rewrite=True)
122+
123+
124 warn_legacy_relations()
125 write_extra_config()
126 # enable_traps_config and enable_pagerduty_config modify forced_contactgroup_members
127@@ -719,6 +727,8 @@ update_contacts()
128 update_password("nagiosro", ro_password)
129 configure_livestatus_xinetd()
130 application_dashboard_relation_changed()
131+if config.changed("nrpe_packet_version"):
132+ update_nrpe()
133
134 if password:
135 update_password(nagiosadmin, password)
136diff --git a/tests/functional/conftest.py b/tests/functional/conftest.py
137index f21d419..2393df5 100644
138--- a/tests/functional/conftest.py
139+++ b/tests/functional/conftest.py
140@@ -218,8 +218,16 @@ def series(request):
141 async def relatives(model, series):
142 nrpe = "nrpe"
143 nrpe_name = "nrpe-{}".format(series)
144+ nrpe_channel = "latest/stable"
145+ if series == "xenial":
146+ nrpe_channel = "latest/beta"
147 nrpe_app = await model.deploy(
148- "ch:" + nrpe, application_name=nrpe_name, series=series, config={}, num_units=0
149+ "ch:" + nrpe,
150+ application_name=nrpe_name,
151+ channel=nrpe_channel,
152+ series=series,
153+ config={},
154+ num_units=0,
155 )
156
157 mysql = "percona-cluster"

Subscribers

People subscribed via source and target branches

to all changes: