Merge ~vultaire/juju-lint:check-spaces-error-handling into juju-lint:master

Proposed by Paul Goins
Status: Merged
Merged at revision: bd5c1aab5603089c7454b5c52771473a64aa1bef
Proposed branch: ~vultaire/juju-lint:check-spaces-error-handling
Merge into: juju-lint:master
Diff against target: 105 lines (+47/-33)
1 file modified
jujulint/lint.py (+47/-33)
Reviewer Review Type Date Requested Status
Alvaro Uria (community) Needs Information
Review via email: mp+420950@code.launchpad.net

Commit message

On exception during check_spaces, eat and log exception

Description of the change

While not an ideal fix, at present the check_spaces code breaks pretty badly in some cases. Seems like it occurs when CMRs are involved.

As a stopgap, eating the exception and logging a warning, so we can at least do a full juju-lint run per normal. We may want to revisit this later though.

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
Alvaro Uria (aluria) :
review: Needs Information

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/jujulint/lint.py b/jujulint/lint.py
2index c1aa3be..404e8b8 100755
3--- a/jujulint/lint.py
4+++ b/jujulint/lint.py
5@@ -25,6 +25,7 @@ import logging
6 import os.path
7 import pprint
8 import re
9+import traceback
10
11 import yaml
12
13@@ -691,38 +692,45 @@ class Linter:
14
15 mismatches = find_space_mismatches(parsed_yaml)
16 for mismatch in mismatches:
17- # By default: treat mismatches as warnings.
18- # If we have a matching enforcement rule, treat as an error.
19- # If we have a matching ignore rule, do not warn.
20- # (Enforcement rules win over ignore rules.)
21- error = False
22- warning = True
23- mismatch_relation = mismatch.get_charm_relation(self.model.app_to_charm)
24-
25- for enforce_endpoint in enforce_endpoints:
26- if enforce_endpoint in mismatch_relation.endpoints:
27- error = True
28- for ignore_endpoint in ignore_endpoints:
29- if ignore_endpoint in mismatch_relation.endpoints:
30- warning = False
31- for enforce_relation in enforce_relations:
32- if enforce_relation == mismatch_relation:
33- error = True
34- for ignore_relation in ignore_relations:
35- if ignore_relation == mismatch_relation:
36- warning = False
37-
38- message = "Space binding mismatch: {}".format(mismatch)
39- if error:
40- self.handle_error({
41- "id": "space-binding-mismatch",
42- "tags": ["mismatch", "space", "binding"],
43- "description": "Unhandled space binding mismatch",
44- "message": message,
45- })
46- elif warning:
47- # DEFAULT: not a critical error, so just warn
48- self._log_with_header(message, level=logging.WARN)
49+ try:
50+ self._handle_space_mismatch(mismatch, enforce_endpoints, enforce_relations, ignore_endpoints, ignore_relations)
51+ except Exception:
52+ # FOR NOW: super quick and dirty
53+ print('Exception caught during space check; please check space by hand. {}'.format(traceback.format_exc()))
54+
55+ def _handle_space_mismatch(self, mismatch, enforce_endpoints, enforce_relations, ignore_endpoints, ignore_relations):
56+ # By default: treat mismatches as warnings.
57+ # If we have a matching enforcement rule, treat as an error.
58+ # If we have a matching ignore rule, do not warn.
59+ # (Enforcement rules win over ignore rules.)
60+ error = False
61+ warning = True
62+ mismatch_relation = mismatch.get_charm_relation(self.model.app_to_charm)
63+
64+ for enforce_endpoint in enforce_endpoints:
65+ if enforce_endpoint in mismatch_relation.endpoints:
66+ error = True
67+ for ignore_endpoint in ignore_endpoints:
68+ if ignore_endpoint in mismatch_relation.endpoints:
69+ warning = False
70+ for enforce_relation in enforce_relations:
71+ if enforce_relation == mismatch_relation:
72+ error = True
73+ for ignore_relation in ignore_relations:
74+ if ignore_relation == mismatch_relation:
75+ warning = False
76+
77+ message = "Space binding mismatch: {}".format(mismatch)
78+ if error:
79+ self.handle_error({
80+ "id": "space-binding-mismatch",
81+ "tags": ["mismatch", "space", "binding"],
82+ "description": "Unhandled space binding mismatch",
83+ "message": message,
84+ })
85+ elif warning:
86+ # DEFAULT: not a critical error, so just warn
87+ self._log_with_header(message, level=logging.WARN)
88
89 def results(self):
90 """Provide results of the linting process."""
91@@ -1080,7 +1088,13 @@ class Linter:
92 # "bindings" *should* be in exported bundles, *unless* no custom bindings exist,
93 # in which case "juju export-bundle" omits them.
94 if "bindings" in list(parsed_yaml[applications].values())[0]:
95- self.check_spaces(parsed_yaml)
96+ #try:
97+ self.check_spaces(parsed_yaml)
98+ #except Exception as e:
99+ # self._log_with_header(
100+ # "Encountered error while checking spaces: {}".format(e),
101+ # level=logging.WARN
102+ # )
103 else:
104 self._log_with_header(
105 "Relations detected but custom bindings not found; "

Subscribers

People subscribed via source and target branches