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
1diff --git a/contrib/includes/base.yaml b/contrib/includes/base.yaml
2index da558a3..bc39a46 100644
3--- a/contrib/includes/base.yaml
4+++ b/contrib/includes/base.yaml
5@@ -29,6 +29,7 @@ subordinates:
6 host-suffixes: [host, physical, guest]
7 container-suffixes: [lxd, container]
8 exceptions: [nagios]
9+ allow-multiple: true # There can be multiple nrpe units, see LP#1855858
10 ntp:
11 # You don't want NTP in a container dueling with ntp in the host
12 where: host only
13diff --git a/jujulint/lint.py b/jujulint/lint.py
14index f680370..58ce1f1 100755
15--- a/jujulint/lint.py
16+++ b/jujulint/lint.py
17@@ -150,8 +150,6 @@ class Linter:
18 if "units" not in app_d:
19 return
20 for unit in app_d["units"]:
21- # juju_status = app_d["units"][unit]["juju-status"]
22- # workload_status = app_d["units"][unit]["workload-status"]
23 if "subordinates" in app_d["units"][unit]:
24 subordinates = app_d["units"][unit]["subordinates"].keys()
25 subordinates = [i.split("/")[0] for i in subordinates]
26@@ -162,8 +160,11 @@ class Linter:
27 self.model.subs_on_machines.setdefault(machine, set())
28 for sub in subordinates:
29 if sub in self.model.subs_on_machines[machine]:
30- self.model.duelling_subs.setdefault(sub, set())
31- self.model.duelling_subs[sub].add(machine)
32+ charm = self.model.app_to_charm[sub]
33+ allow_multiple = self.lint_rules['subordinates'][charm].get("allow-multiple")
34+ if not allow_multiple:
35+ self.model.duelling_subs.setdefault(sub, set())
36+ self.model.duelling_subs[sub].add(machine)
37 self.model.subs_on_machines[machine].add(sub)
38 self.model.subs_on_machines[machine] = (
39 set(subordinates) | self.model.subs_on_machines[machine]
40diff --git a/tests/test_jujulint.py b/tests/test_jujulint.py
41index 2494c28..c74c550 100644
42--- a/tests/test_jujulint.py
43+++ b/tests/test_jujulint.py
44@@ -280,6 +280,61 @@ class TestLinter:
45 assert errors[0]["machines"] == "0"
46 assert errors[0]["subordinate"] == "ntp"
47
48+ def test_subordinate_duplicates_allow(self, linter, juju_status):
49+ """
50+ Test the subordinate option "allow-multiple".
51+
52+ Setting it to true will skip the duplicate check for subordinates
53+ """
54+ template_status = {
55+ "juju-status": {"current": "idle"},
56+ "workload-status": {"current": "active"},
57+ }
58+
59+ # Drop the fixture ntp rule and add the nrpe rule with allowing duplicates
60+ linter.lint_rules["subordinates"].pop("ntp")
61+ linter.lint_rules["subordinates"]["nrpe"] = {
62+ "where": "container aware",
63+ "host-suffixes": "[host, physical, guest]",
64+ "allow-multiple": True,
65+ }
66+
67+ # Add a nrpe-host subordinate application
68+ linter.lint_rules["known charms"].append("nrpe")
69+ juju_status["applications"]["nrpe-host"] = {
70+ "application-status": {"current": "active"},
71+ "charm": "cs:nrpe-74",
72+ "charm-name": "nrpe",
73+ "relations": {"juju-info": ["ubuntu", "ubuntu2"]},
74+ }
75+
76+ # Add a nrpe-host subordinate unit to the 'ubuntu' app
77+ juju_status["applications"]["ubuntu"]["units"]["ubuntu/0"]["subordinates"] = {
78+ "nrpe-host/0": template_status
79+ }
80+
81+ # Add a second 'ubuntu' app with nrpe subordinate
82+ juju_status["applications"]["ubuntu2"] = {
83+ "application-status": {"current": "active"},
84+ "charm": "cs:ubuntu-18",
85+ "charm-name": "ubuntu",
86+ "relations": {"juju-info": ["ntp", "nrpe-host"]},
87+ "units": {
88+ "ubuntu2/0": {
89+ "juju-status": {"current": "idle"},
90+ "machine": "0",
91+ "subordinates": {"nrpe-host/1": template_status},
92+ "workload-status": {"current": "active"},
93+ }
94+ },
95+ }
96+
97+ linter.do_lint(juju_status)
98+
99+ # Since we allow duplicates there should be no errors
100+ errors = linter.output_collector["errors"]
101+ assert not errors
102+
103 def test_ops_subordinate_metal_only1(self, linter, juju_status):
104 """
105 Test that missing ops subordinate charms are detected.
106@@ -305,7 +360,9 @@ class TestLinter:
107 linter.lint_rules["subordinates"]["hw-health"] = {"where": "metal only"}
108
109 # Turn machine "0" into a "VM"
110- juju_status["machines"]["0"]["hardware"] = "tags=virtual availability-zone=rack-1"
111+ juju_status["machines"]["0"][
112+ "hardware"
113+ ] = "tags=virtual availability-zone=rack-1"
114 linter.do_lint(juju_status)
115
116 errors = linter.output_collector["errors"]

Subscribers

People subscribed via source and target branches