Merge ~gabrielcocenza/juju-lint:bug/1979382 into juju-lint:master

Proposed by Gabriel Cocenza
Status: Merged
Approved by: Martin Kalcok
Approved revision: f03505a64ee54531b014d9f4e5e246d5e0094b15
Merged at revision: ca71a604c57b0c9641780b7cfa48d7e3a39d75c0
Proposed branch: ~gabrielcocenza/juju-lint:bug/1979382
Merge into: juju-lint:master
Diff against target: 138 lines (+55/-14)
3 files modified
jujulint/check_spaces.py (+15/-6)
jujulint/lint.py (+2/-1)
tests/test_jujulint.py (+38/-7)
Reviewer Review Type Date Requested Status
Martin Kalcok (community) Approve
Eric Chen Approve
Review via email: mp+426590@code.launchpad.net

Commit message

warning for applications from other model

- added default alpha space binding for applications that are
  present in the bundle, but miss 'bindings' keyword;
- check if both spaces in a endpoint are not from another model
  to add as mismatch;
- warn log for possible multi-model applications that appear on relations.

Closes-Bug: #1979382
Co-authored-by: Vern Hart <email address hidden>

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
Eric Chen (eric-chen) :
review: Approve
Revision history for this message
Martin Kalcok (martin-kalcok) wrote :

LGTM

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

Change successfully merged at revision ca71a604c57b0c9641780b7cfa48d7e3a39d75c0

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/jujulint/check_spaces.py b/jujulint/check_spaces.py
2index 337f9b2..975661d 100644
3--- a/jujulint/check_spaces.py
4+++ b/jujulint/check_spaces.py
5@@ -62,8 +62,8 @@ class SpaceMismatch:
6 """Return a relation object, mapping applications to charms."""
7 app1, endpoint1 = self.endpoint1.split(":")
8 app2, endpoint2 = self.endpoint2.split(":")
9- charm1 = app_to_charm_map[app1]
10- charm2 = app_to_charm_map[app2]
11+ charm1 = app_to_charm_map.get(app1, "")
12+ charm2 = app_to_charm_map.get(app2, "")
13 return Relation(":".join([charm1, endpoint1]), ":".join([charm2, endpoint2]))
14
15
16@@ -97,7 +97,7 @@ def find_space_mismatches(parsed_yaml, debug=False):
17 for relation in relations_list:
18 space1 = get_relation_space(relation.endpoint1, app_spaces)
19 space2 = get_relation_space(relation.endpoint2, app_spaces)
20- if space1 != space2:
21+ if space1 != space2 and all([space1 != "XModel", space2 != "XModel"]):
22 mismatch = SpaceMismatch(
23 relation.endpoint1, space1, relation.endpoint2, space2
24 )
25@@ -119,13 +119,18 @@ def get_application_spaces(application_list, parsed_yaml):
26 """Return a dictionary with app.binding=space mappings."""
27 app_spaces = {}
28 for app in application_list:
29- bindings = parsed_yaml["applications"][app].get('bindings', {})
30+ bindings = parsed_yaml["applications"][app].get("bindings", {})
31+ app_spaces.setdefault(app, {})
32 if not bindings:
33+ # this probably means that is a single space binding. See LP#1949883
34 LOGGER.warning("Application %s is missing explicit bindings", app)
35+ LOGGER.warning("Setting default binding of '%s' to alpha", app)
36+ app_spaces[app][""] = "alpha"
37 continue
38 if not bindings.get(""):
39- LOGGER.warning("Application %s does not define explicit default binding", app)
40- app_spaces[app] = {}
41+ LOGGER.warning(
42+ "Application %s does not define explicit default binding", app
43+ )
44 for name, value in bindings.items():
45 app_spaces[app][name] = value
46 return app_spaces
47@@ -149,4 +154,8 @@ def get_relation_space(endpoint, app_spaces):
48 else:
49 return app_spaces[app][service]
50 else:
51+ LOGGER.warning(
52+ "Multi-model is not supported yet. Please check if '%s' is from another model",
53+ app,
54+ )
55 return "XModel"
56diff --git a/jujulint/lint.py b/jujulint/lint.py
57index 748fc8a..e4afa10 100755
58--- a/jujulint/lint.py
59+++ b/jujulint/lint.py
60@@ -1121,7 +1121,8 @@ class Linter:
61 self._log_with_header(
62 "Relations detected but explicit bindings not found; "
63 "Not specifying explicit bindings may cause problems on models"
64- " with multiple network spaces.", level=logging.WARNING
65+ " with multiple network spaces.",
66+ level=logging.WARNING,
67 )
68 else:
69 self._log_with_header(
70diff --git a/tests/test_jujulint.py b/tests/test_jujulint.py
71index 11cc514..9155ff9 100644
72--- a/tests/test_jujulint.py
73+++ b/tests/test_jujulint.py
74@@ -824,7 +824,7 @@ applications:
75 assert mock_log.call_count == 0
76
77 def test_check_spaces_missing_explicit_bindings(self, linter, mocker):
78- """Test that check_spaces shows warning if some application are missing bindings
79+ """Test that check_spaces shows warning if some application are missing bindings.
80
81 This warning should be triggerred if some applications have bindings and some
82 dont.
83@@ -847,12 +847,13 @@ applications:
84 ],
85 }
86
87- expected_warning = "Application %s is missing explicit bindings"
88+ expected_warning_callings = [
89+ mock.call("Application %s is missing explicit bindings", "prometheus-app"),
90+ mock.call("Setting default binding of '%s' to alpha", "prometheus-app"),
91+ ]
92
93 linter.check_spaces(bundle)
94-
95- logger_mock.warning.assert_called_once_with(expected_warning,
96- app_without_binding)
97+ assert logger_mock.warning.call_args_list == expected_warning_callings
98
99 def test_check_spaces_missing_default_endpoint_binding(self, linter, mocker):
100 """Raise warning if application is missing explicit default binding.
101@@ -888,5 +889,35 @@ applications:
102
103 linter.check_spaces(bundle)
104
105- logger_mock.warning.assert_called_once_with(expected_warning,
106- app_without_default_space)
107+ logger_mock.warning.assert_called_once_with(
108+ expected_warning, app_without_default_space
109+ )
110+
111+ def test_check_spaces_multi_model_warning(self, linter, mocker):
112+ """Test that check_spaces shows warning if some application are from another model."""
113+ logger_mock = mocker.patch.object(check_spaces, "LOGGER")
114+
115+ app_another_model = "prometheus-app"
116+ bundle = {
117+ "applications": {
118+ "telegraf-app": {
119+ "bindings": {
120+ "": "alpha",
121+ "prometheus-client": "alpha",
122+ },
123+ },
124+ },
125+ "relations": [
126+ ["telegraf-app:prometheus-client", "prometheus-app:target"],
127+ ],
128+ }
129+
130+ expected_warning_callings = [
131+ mock.call(
132+ "Multi-model is not supported yet. Please check if '%s' is from another model",
133+ app_another_model,
134+ ),
135+ ]
136+
137+ linter.check_spaces(bundle)
138+ assert logger_mock.warning.call_args_list == expected_warning_callings

Subscribers

People subscribed via source and target branches