Merge ~jfguedez/juju-lint:bug/1855858 into juju-lint:master

Proposed by Jose Guedez
Status: Merged
Approved by: James Troup
Approved revision: 831ecc2e13a21b1e431a6ec8f57e588b3318f4fb
Merged at revision: 3b85de9d81bf29c7769febd0a60c7a41fc424a34
Proposed branch: ~jfguedez/juju-lint:bug/1855858
Merge into: juju-lint:master
Prerequisite: ~jfguedez/juju-lint:bug/1903973
Diff against target: 116 lines (+64/-5)
3 files modified
contrib/includes/base.yaml (+1/-0)
jujulint/lint.py (+5/-4)
tests/test_jujulint.py (+58/-1)
Reviewer Review Type Date Requested Status
Edin S (community) Approve
Juju Lint maintainers Pending
Review via email: mp+408861@code.launchpad.net

Commit message

Add the "allow-multiple" condition for subordinates

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
Edin S (exsdev) :
review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 3b85de9d81bf29c7769febd0a60c7a41fc424a34

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/contrib/includes/base.yaml b/contrib/includes/base.yaml
index da558a3..bc39a46 100644
--- a/contrib/includes/base.yaml
+++ b/contrib/includes/base.yaml
@@ -29,6 +29,7 @@ subordinates:
29 host-suffixes: [host, physical, guest]29 host-suffixes: [host, physical, guest]
30 container-suffixes: [lxd, container]30 container-suffixes: [lxd, container]
31 exceptions: [nagios]31 exceptions: [nagios]
32 allow-multiple: true # There can be multiple nrpe units, see LP#1855858
32 ntp:33 ntp:
33 # You don't want NTP in a container dueling with ntp in the host34 # You don't want NTP in a container dueling with ntp in the host
34 where: host only35 where: host only
diff --git a/jujulint/lint.py b/jujulint/lint.py
index f680370..58ce1f1 100755
--- a/jujulint/lint.py
+++ b/jujulint/lint.py
@@ -150,8 +150,6 @@ class Linter:
150 if "units" not in app_d:150 if "units" not in app_d:
151 return151 return
152 for unit in app_d["units"]:152 for unit in app_d["units"]:
153 # juju_status = app_d["units"][unit]["juju-status"]
154 # workload_status = app_d["units"][unit]["workload-status"]
155 if "subordinates" in app_d["units"][unit]:153 if "subordinates" in app_d["units"][unit]:
156 subordinates = app_d["units"][unit]["subordinates"].keys()154 subordinates = app_d["units"][unit]["subordinates"].keys()
157 subordinates = [i.split("/")[0] for i in subordinates]155 subordinates = [i.split("/")[0] for i in subordinates]
@@ -162,8 +160,11 @@ class Linter:
162 self.model.subs_on_machines.setdefault(machine, set())160 self.model.subs_on_machines.setdefault(machine, set())
163 for sub in subordinates:161 for sub in subordinates:
164 if sub in self.model.subs_on_machines[machine]:162 if sub in self.model.subs_on_machines[machine]:
165 self.model.duelling_subs.setdefault(sub, set())163 charm = self.model.app_to_charm[sub]
166 self.model.duelling_subs[sub].add(machine)164 allow_multiple = self.lint_rules['subordinates'][charm].get("allow-multiple")
165 if not allow_multiple:
166 self.model.duelling_subs.setdefault(sub, set())
167 self.model.duelling_subs[sub].add(machine)
167 self.model.subs_on_machines[machine].add(sub)168 self.model.subs_on_machines[machine].add(sub)
168 self.model.subs_on_machines[machine] = (169 self.model.subs_on_machines[machine] = (
169 set(subordinates) | self.model.subs_on_machines[machine]170 set(subordinates) | self.model.subs_on_machines[machine]
diff --git a/tests/test_jujulint.py b/tests/test_jujulint.py
index 2494c28..c74c550 100644
--- a/tests/test_jujulint.py
+++ b/tests/test_jujulint.py
@@ -280,6 +280,61 @@ class TestLinter:
280 assert errors[0]["machines"] == "0"280 assert errors[0]["machines"] == "0"
281 assert errors[0]["subordinate"] == "ntp"281 assert errors[0]["subordinate"] == "ntp"
282282
283 def test_subordinate_duplicates_allow(self, linter, juju_status):
284 """
285 Test the subordinate option "allow-multiple".
286
287 Setting it to true will skip the duplicate check for subordinates
288 """
289 template_status = {
290 "juju-status": {"current": "idle"},
291 "workload-status": {"current": "active"},
292 }
293
294 # Drop the fixture ntp rule and add the nrpe rule with allowing duplicates
295 linter.lint_rules["subordinates"].pop("ntp")
296 linter.lint_rules["subordinates"]["nrpe"] = {
297 "where": "container aware",
298 "host-suffixes": "[host, physical, guest]",
299 "allow-multiple": True,
300 }
301
302 # Add a nrpe-host subordinate application
303 linter.lint_rules["known charms"].append("nrpe")
304 juju_status["applications"]["nrpe-host"] = {
305 "application-status": {"current": "active"},
306 "charm": "cs:nrpe-74",
307 "charm-name": "nrpe",
308 "relations": {"juju-info": ["ubuntu", "ubuntu2"]},
309 }
310
311 # Add a nrpe-host subordinate unit to the 'ubuntu' app
312 juju_status["applications"]["ubuntu"]["units"]["ubuntu/0"]["subordinates"] = {
313 "nrpe-host/0": template_status
314 }
315
316 # Add a second 'ubuntu' app with nrpe subordinate
317 juju_status["applications"]["ubuntu2"] = {
318 "application-status": {"current": "active"},
319 "charm": "cs:ubuntu-18",
320 "charm-name": "ubuntu",
321 "relations": {"juju-info": ["ntp", "nrpe-host"]},
322 "units": {
323 "ubuntu2/0": {
324 "juju-status": {"current": "idle"},
325 "machine": "0",
326 "subordinates": {"nrpe-host/1": template_status},
327 "workload-status": {"current": "active"},
328 }
329 },
330 }
331
332 linter.do_lint(juju_status)
333
334 # Since we allow duplicates there should be no errors
335 errors = linter.output_collector["errors"]
336 assert not errors
337
283 def test_ops_subordinate_metal_only1(self, linter, juju_status):338 def test_ops_subordinate_metal_only1(self, linter, juju_status):
284 """339 """
285 Test that missing ops subordinate charms are detected.340 Test that missing ops subordinate charms are detected.
@@ -305,7 +360,9 @@ class TestLinter:
305 linter.lint_rules["subordinates"]["hw-health"] = {"where": "metal only"}360 linter.lint_rules["subordinates"]["hw-health"] = {"where": "metal only"}
306361
307 # Turn machine "0" into a "VM"362 # Turn machine "0" into a "VM"
308 juju_status["machines"]["0"]["hardware"] = "tags=virtual availability-zone=rack-1"363 juju_status["machines"]["0"][
364 "hardware"
365 ] = "tags=virtual availability-zone=rack-1"
309 linter.do_lint(juju_status)366 linter.do_lint(juju_status)
310367
311 errors = linter.output_collector["errors"]368 errors = linter.output_collector["errors"]

Subscribers

People subscribed via source and target branches