Merge ~xavpaice/charm-nrpe:update_tests into charm-nrpe:master

Proposed by Xav Paice
Status: Merged
Approved by: Paul Goins
Approved revision: aa9e5a7b9d45feb6f31b5644ad567596ff82bdd3
Merged at revision: 7fad0fa1d121742315e426446ac2411f9ec529f1
Proposed branch: ~xavpaice/charm-nrpe:update_tests
Merge into: charm-nrpe:master
Diff against target: 290 lines (+67/-67)
10 files modified
Makefile (+1/-1)
hooks/nrpe_helpers.py (+36/-24)
hooks/services.py (+5/-5)
metadata.yaml (+0/-1)
mod/charmhelpers (+1/-1)
tests/functional/tests/bundles/bionic.yaml (+4/-4)
tests/functional/tests/bundles/focal.yaml (+7/-6)
tests/functional/tests/bundles/xenial.yaml (+4/-4)
tests/functional/tests/nrpe_tests.py (+8/-20)
tests/functional/tests/tests.yaml (+1/-1)
Reviewer Review Type Date Requested Status
Paul Goins Approve
Celia Wang Approve
🤖 prod-jenkaas-bootstack (community) continuous-integration Approve
Review via email: mp+406421@code.launchpad.net

Commit message

Improvements to functional testing

* Remove Trusty support
* Add functional tests for Focal
* charmhelpers update
* Lint fixes

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
🤖 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
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
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
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)
Revision history for this message
Celia Wang (ziyiwang) wrote :

lgtm

review: Approve
Revision history for this message
Paul Goins (vultaire) wrote :

Interesting. Took a bit to understand why things got changed from MySQL to RMQ, but I think I got it.

LGTM, +1

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

Change successfully merged at revision 7fad0fa1d121742315e426446ac2411f9ec529f1

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/Makefile b/Makefile
2index a9ecf3e..c576977 100644
3--- a/Makefile
4+++ b/Makefile
5@@ -38,7 +38,7 @@ submodules-update:
6 @echo "Pulling latest updates for submodules"
7 @git submodule update --init --recursive --remote --merge
8
9-build:
10+build: submodules-update
11 @echo "Building charm to base directory ${CHARM_BUILD_DIR}/${CHARM_NAME}"
12 @-git rev-parse --abbrev-ref HEAD > ./repo-info
13 @-git describe --always > ./version
14diff --git a/hooks/nrpe_helpers.py b/hooks/nrpe_helpers.py
15index e4b51fd..80f1541 100644
16--- a/hooks/nrpe_helpers.py
17+++ b/hooks/nrpe_helpers.py
18@@ -381,30 +381,10 @@ class SubordinateCheckDefinitions(dict):
19
20 def __init__(self):
21 """Set dict values."""
22- procs = self.proc_count()
23-
24- if hookenv.config("procs") == "auto":
25- proc_thresholds = "-k -w {} -c {}".format(
26- 25 * procs + 100, 50 * procs + 100
27- )
28- else:
29- proc_thresholds = hookenv.config("procs")
30-
31- if hookenv.config("load") == "auto":
32- # Give 1min load alerts higher thresholds than 15 min load alerts
33- warn_multipliers = (4, 2, 1)
34- crit_multipliers = (8, 4, 2)
35- load_thresholds = ("-w %s -c %s") % (
36- ",".join([str(m * procs) for m in warn_multipliers]),
37- ",".join([str(m * procs) for m in crit_multipliers]),
38- )
39- else:
40- load_thresholds = hookenv.config("load")
41-
42- if hookenv.config("disk_root"):
43- disk_root_thresholds = hookenv.config("disk_root") + " -p / "
44- else:
45- disk_root_thresholds = ""
46+ self.procs = self.proc_count()
47+ load_thresholds = self._get_load_thresholds()
48+ proc_thresholds = self._get_proc_thresholds()
49+ disk_root_thresholds = self._get_disk_root_thresholds()
50
51 pkg_plugin_dir = "/usr/lib/nagios/plugins/"
52 local_plugin_dir = "/usr/local/lib/nagios/plugins/"
53@@ -562,6 +542,38 @@ class SubordinateCheckDefinitions(dict):
54 check["cmd_name"] += sub_postfix
55 self["checks"].append(check)
56
57+ def _get_proc_thresholds(self):
58+ """Return suitable processor thresholds."""
59+ if hookenv.config("procs") == "auto":
60+ proc_thresholds = "-k -w {} -c {}".format(
61+ 25 * self.procs + 100, 50 * self.procs + 100
62+ )
63+ else:
64+ proc_thresholds = hookenv.config("procs")
65+ return proc_thresholds
66+
67+ def _get_load_thresholds(self):
68+ """Return suitable load thresholds."""
69+ if hookenv.config("load") == "auto":
70+ # Give 1min load alerts higher thresholds than 15 min load alerts
71+ warn_multipliers = (4, 2, 1)
72+ crit_multipliers = (8, 4, 2)
73+ load_thresholds = ("-w %s -c %s") % (
74+ ",".join([str(m * self.procs) for m in warn_multipliers]),
75+ ",".join([str(m * self.procs) for m in crit_multipliers]),
76+ )
77+ else:
78+ load_thresholds = hookenv.config("load")
79+ return load_thresholds
80+
81+ def _get_disk_root_thresholds(self):
82+ """Return suitable disk thresholds."""
83+ if hookenv.config("disk_root"):
84+ disk_root_thresholds = hookenv.config("disk_root") + " -p / "
85+ else:
86+ disk_root_thresholds = ""
87+ return disk_root_thresholds
88+
89 def proc_count(self):
90 """Return number number of processing units."""
91 return int(subprocess.check_output(["nproc", "--all"]))
92diff --git a/hooks/services.py b/hooks/services.py
93index 6a14c50..792877b 100644
94--- a/hooks/services.py
95+++ b/hooks/services.py
96@@ -72,16 +72,16 @@ def manage():
97 )
98 manager.manage()
99 if nrpe_utils.has_consumer():
100- revision = ''
101- if os.path.exists('version'):
102- with open('version') as f:
103+ revision = ""
104+ if os.path.exists("version"):
105+ with open("version") as f:
106 line = f.readline().strip()
107 # We only want the first 8 characters, that's enough to tell
108 # which version of the charm we're using.
109 if len(line) > 8:
110- revision = ' (source version/commit {}...)'.format(line[:8])
111+ revision = " (source version/commit {}...)".format(line[:8])
112 else:
113- revision = ' (source version/commit {})'.format(line)
114+ revision = " (source version/commit {})".format(line)
115 status_set("active", "Ready{}".format(revision))
116 else:
117 status_set("blocked", "Nagios server not configured or related")
118diff --git a/metadata.yaml b/metadata.yaml
119index 4ed43fb..e3b05f5 100644
120--- a/metadata.yaml
121+++ b/metadata.yaml
122@@ -30,4 +30,3 @@ series:
123 - bionic
124 - focal
125 - xenial
126- - trusty
127diff --git a/mod/charmhelpers b/mod/charmhelpers
128index 6565024..d1f9515 160000
129--- a/mod/charmhelpers
130+++ b/mod/charmhelpers
131@@ -1 +1 @@
132-Subproject commit 6565024e5ef761d020a1cba20b8b09d62603325d
133+Subproject commit d1f9515001237601e4a39aeb443b180137069f25
134diff --git a/tests/functional/tests/bundles/bionic.yaml b/tests/functional/tests/bundles/bionic.yaml
135index 5bb178e..1f68afe 100644
136--- a/tests/functional/tests/bundles/bionic.yaml
137+++ b/tests/functional/tests/bundles/bionic.yaml
138@@ -1,13 +1,13 @@
139 series: bionic
140 applications:
141- mysql:
142- charm: cs:percona-cluster
143+ rabbitmq-server:
144+ charm: cs:rabbitmq-server
145 num_units: 1
146 nagios:
147 charm: cs:nagios
148 num_units: 1
149 relations:
150- - - mysql:nrpe-external-master
151+ - - rabbitmq-server:nrpe-external-master
152 - nrpe:nrpe-external-master
153 - - nrpe:monitors
154- - nagios:monitors
155\ No newline at end of file
156+ - nagios:monitors
157diff --git a/tests/functional/tests/bundles/trusty.yaml b/tests/functional/tests/bundles/focal.yaml
158similarity index 59%
159rename from tests/functional/tests/bundles/trusty.yaml
160rename to tests/functional/tests/bundles/focal.yaml
161index 8fe247d..606e891 100644
162--- a/tests/functional/tests/bundles/trusty.yaml
163+++ b/tests/functional/tests/bundles/focal.yaml
164@@ -1,13 +1,14 @@
165-series: trusty
166+series: focal
167 applications:
168- mysql:
169- charm: cs:mysql
170+ rabbitmq-server:
171+ charm: cs:rabbitmq-server
172 num_units: 1
173 nagios:
174- charm: cs:~llama-charmers-next/nagios
175+ charm: cs:nagios
176 num_units: 1
177+ series: bionic
178 relations:
179- - - mysql:nrpe-external-master
180+ - - rabbitmq-server:nrpe-external-master
181 - nrpe:nrpe-external-master
182 - - nrpe:monitors
183- - nagios:monitors
184\ No newline at end of file
185+ - nagios:monitors
186diff --git a/tests/functional/tests/bundles/xenial.yaml b/tests/functional/tests/bundles/xenial.yaml
187index 168be0e..e6176e1 100644
188--- a/tests/functional/tests/bundles/xenial.yaml
189+++ b/tests/functional/tests/bundles/xenial.yaml
190@@ -1,13 +1,13 @@
191 series: xenial
192 applications:
193- mysql:
194- charm: cs:percona-cluster
195+ rabbitmq-server:
196+ charm: cs:rabbitmq-server
197 num_units: 1
198 nagios:
199 charm: cs:nagios
200 num_units: 1
201 relations:
202- - - mysql:nrpe-external-master
203+ - - rabbitmq-server:nrpe-external-master
204 - nrpe:nrpe-external-master
205 - - nrpe:monitors
206- - nagios:monitors
207\ No newline at end of file
208+ - nagios:monitors
209diff --git a/tests/functional/tests/nrpe_tests.py b/tests/functional/tests/nrpe_tests.py
210index f887fdb..de138ea 100644
211--- a/tests/functional/tests/nrpe_tests.py
212+++ b/tests/functional/tests/nrpe_tests.py
213@@ -5,7 +5,6 @@ import unittest
214 import yaml
215
216 import zaza.model as model
217-from zaza.utilities import juju as juju_utils
218
219
220 class TestBase(unittest.TestCase):
221@@ -32,17 +31,6 @@ class TestNrpe(TestBase):
222 "Verify the nrpe checks are created and have the required content..."
223 )
224
225- check_mysql_content = (
226- "command[check_mysql]=/usr/local/lib/nagios/plugins/check_systemd.py mysql"
227- )
228- machine = list(juju_utils.get_machines_for_application("mysql"))[0]
229- machine_series = juju_utils.get_machine_series(machine)
230-
231- if machine_series == "trusty":
232- check_mysql_content = (
233- "command[check_mysql]=/usr/lib/nagios/plugins/check_mysql -u nagios"
234- )
235-
236 nrpe_checks = {
237 "check_conntrack.cfg":
238 "command[check_conntrack]=/usr/local/lib/nagios/plugins/"
239@@ -52,9 +40,9 @@ class TestNrpe(TestBase):
240 "check_load.cfg": "command[check_load]=/usr/lib/nagios/plugins/check_load",
241 "check_mem.cfg":
242 "command[check_mem]=/usr/local/lib/nagios/plugins/check_mem.pl",
243- "check_mysql.cfg": check_mysql_content,
244- "check_mysql_proc.cfg": "command[check_mysql_proc]=/usr/lib/nagios/plugins/"
245- "check_procs -c 1:1 -C mysqld",
246+ "check_rabbitmq.cfg":
247+ "command[check_rabbitmq]="
248+ "/usr/local/lib/nagios/plugins/check_rabbitmq.py",
249 "check_swap_activity.cfg":
250 "command[check_swap_activity]="
251 "/usr/local/lib/nagios/plugins/check_swap_activity",
252@@ -206,20 +194,20 @@ class TestNrpe(TestBase):
253
254 def test_05_netlinks(self):
255 """Check netlinks checks are applied."""
256- netlinks = "- eth0 mtu:9000 speed:10000"
257+ netlinks = "- ens3 mtu:9000 speed:10000"
258 model.set_application_config(self.application_name, {"netlinks": netlinks})
259 model.block_until_all_units_idle()
260- cmd = "cat /etc/nagios/nrpe.d/check_netlinks_eth0.cfg"
261+ cmd = "cat /etc/nagios/nrpe.d/check_netlinks_ens3.cfg"
262 line = (
263- "command[check_netlinks_eth0]=/usr/local/lib/nagios/plugins/"
264- "check_netlinks.py -i eth0 -m 9000 -s 1000"
265+ "command[check_netlinks_ens3]=/usr/local/lib/nagios/plugins/"
266+ "check_netlinks.py -i ens3 -m 9000 -s 1000"
267 )
268 result = model.run_on_unit(self.lead_unit_name, cmd)
269 code = result.get("Code")
270 if code != "0":
271 logging.warning(
272 "Unable to find nrpe check at "
273- "/etc/nagios/nrpe.d/check_netlinks_eth0.cfg"
274+ "/etc/nagios/nrpe.d/check_netlinks_ens3.cfg"
275 )
276 raise model.CommandRunFailed(cmd, result)
277 content = result.get("Stdout")
278diff --git a/tests/functional/tests/tests.yaml b/tests/functional/tests/tests.yaml
279index 1c39d87..640c3d2 100644
280--- a/tests/functional/tests/tests.yaml
281+++ b/tests/functional/tests/tests.yaml
282@@ -1,7 +1,7 @@
283 charm_name: nrpe
284 gate_bundles:
285- - trusty
286 - xenial
287 - bionic
288+ - focal
289 tests:
290 - tests.nrpe_tests.TestNrpe

Subscribers

People subscribed via source and target branches

to all changes: