Merge ~ziyiwang/juju-lint:lp1851485 into juju-lint:master

Proposed by Celia Wang
Status: Rejected
Rejected by: Haw Loeung
Proposed branch: ~ziyiwang/juju-lint:lp1851485
Merge into: juju-lint:master
Diff against target: 206 lines (+182/-0)
2 files modified
contrib/includes/bindings.yaml (+137/-0)
jujulint/lint.py (+45/-0)
Reviewer Review Type Date Requested Status
James Troup (community) Needs Fixing
Review via email: mp+412782@code.launchpad.net

Commit message

    Add bindings check
    1). only check principal charms
    2). if bindings are not explicitly set (which means the bindings are
        default value "alpha"), print warning message
    LP: #1851485

To post a comment you must log in.
Revision history for this message
Celia Wang (ziyiwang) wrote :

Test result:

(juju-lint-test) ziyiwang@selkie:~$ juju-lint -t openstack ../telefonica-func-211202.yaml -c contrib/includes/bindings.yaml
2021-12-03 08:47:24 [INFO] juju-lint version 1.0.2.dev57+gbded6f9.d20211204 starting...
 * Config directory: /home/ziyiwang/.config/juju-lint
 * Rules file: contrib/includes/bindings.yaml
 * Log level: info

2021-12-03 08:47:24 [INFO] [../telefonica-func-211202.yaml] Linting manual file...
2021-12-03 08:47:25 [WARNING] [../telefonica-func-211202.yaml] [manual/manual] Binding for application ubuntu-controllers-stub has not been set.

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
James Troup (elmo) wrote :

As discussed; please retry this without coding the list of principle vs subordinate into the YAML - we should be able to determine that from the Juju data in status/bundle. Thanks.

review: Needs Fixing

Unmerged commits

a692176... by Celia Wang

Add bindings check
1). only check principal charms
2). if bindings are not explicitly set (which means the bindings are
    default value "alpha"), print warning message
LP: #1851485

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/contrib/includes/bindings.yaml b/contrib/includes/bindings.yaml
2new file mode 100644
3index 0000000..85905c3
4--- /dev/null
5+++ b/contrib/includes/bindings.yaml
6@@ -0,0 +1,137 @@
7+openstack mandatory: &openstack-mandatory-charms
8+ - ceilometer
9+ - ceph-mon
10+ - ceph-osd
11+ - cinder
12+ - glance
13+ - heat
14+ - keystone
15+ - neutron-api
16+ - nova-cloud-controller
17+ - nova-compute
18+ - openstack-dashboard
19+
20+openstack mandatory deps: &openstack-mandatory-deps
21+ - haproxy
22+ - memcached
23+ - percona-cluster
24+ - rabbitmq-server
25+
26+openstack optional charms: &openstack-optional-charms
27+ - aodh
28+ - barbican
29+ - barbican-vault
30+ - ceph-fs
31+ - ceph-radosgw
32+ - cinder-backup
33+ - designate
34+ - designate-bind
35+ - easyrsa
36+ - etcd
37+ - glance-simplestreams-sync
38+ - glance-sync-slave
39+ - gnocchi
40+ - ironic-api
41+ - ironic-conductor
42+ - manila
43+ - manila-ganesha
44+ - manila-dashboard
45+ - mongodb # Optional since Gnocchi
46+ - neutron-gateway
47+ - neutron-api-plugin-ironic
48+ - octavia
49+ - octavia-dashboard
50+ - octavia-diskimage-retrofit
51+ - placement
52+ - swift-proxy
53+ - swift-storage
54+ - vault
55+
56+cisco-aci-charms: &cisco-aci-charms
57+ - neutron-api-plugin-aci
58+ - openstack-dashboard-plugin-gbp
59+
60+ovn-charms: &ovn-charms
61+ - ovn-central
62+ - ovn-chassis
63+ - neutron-api-plugin-ovn
64+
65+masakari-charms: &masakari-charms
66+ - masakari
67+ - masakari-monitors
68+ - pacemaker-remote
69+
70+trilio-charms: &trilio-charms
71+ - trilio-dm-api
72+ - trilio-horizon-plugin
73+ - trilio-data-mover
74+ - trilio-wlm
75+
76+operations mandatory: &operations-mandatory-charms
77+ - elasticsearch
78+ - grafana
79+ - graylog
80+ - landscape-server
81+ - nagios
82+ - prometheus2
83+
84+operations optional: &operations-optional-charms
85+ - infra-node
86+ - cloudstats
87+ - juju-lint
88+
89+operations openstack mandatory: &operations-openstack-mandatory-charms
90+ - openstack-service-checks
91+ - prometheus-openstack-exporter
92+
93+operations kubernetes mandatory: &operations-kubernetes-mandatory-charms
94+ - kubernetes-service-checks
95+
96+operations mandatory dependencies: &operations-mandatory-deps
97+ - postgresql
98+
99+kubernetes mandatory: &kubernetes-mandatory-charms
100+ - containerd
101+ - kubeapi-load-balancer
102+ - kubernetes-master
103+ - kubernetes-worker
104+
105+kubernetes optional charms: &kubernetes-optional-charms
106+ - calico
107+ - canal
108+ - coredns
109+ - easyrsa
110+ - etcd
111+ - flannel
112+ - kubernetes-dashboard
113+ - openstack-integrator
114+ - vsphere-integrator
115+
116+operations principal charms: &operations-principal-charms
117+ - *operations-kubernetes-mandatory-charms
118+ - *operations-mandatory-charms
119+ - *operations-mandatory-deps
120+ - *operations-optional-charms
121+ - *operations-openstack-mandatory-charms
122+
123+openstack principal charms: &openstack-principal-charms
124+ - *openstack-mandatory-charms
125+ - *openstack-mandatory-deps
126+ - *openstack-optional-charms
127+ - *cisco-aci-charms
128+ - *ovn-charms
129+ - *masakari-charms
130+ - *trilio-charms
131+
132+kubernetes principal charms: &kubernetes-principal-charms
133+ - *kubernetes-mandatory-charms
134+ - *kubernetes-optional-charms
135+
136+principal charms: &principal-charms
137+ - ubuntu
138+ - *openstack-principal-charms
139+ - *operations-principal-charms
140+ - *kubernetes-principal-charms
141+
142+endpoints:
143+ - *principal-charms
144diff --git a/jujulint/lint.py b/jujulint/lint.py
145index a59d66a..0b92464 100755
146--- a/jujulint/lint.py
147+++ b/jujulint/lint.py
148@@ -420,6 +420,48 @@ class Linter:
149 lint_rules,
150 )
151
152+ def check_binding(self, app_name, binding, rule):
153+ """Check application against provided rule."""
154+ for check_op, check_value in rule.items():
155+ if check_op == "neq":
156+ for endpoint_name, endpoint_value in binding.items():
157+ if check_value == endpoint_value:
158+ self._log_with_header(
159+ "Binding {} for application {} has not been set.".format(
160+ endpoint_name,
161+ app_name,
162+ ),
163+ level=logging.WARN,
164+ )
165+ else:
166+ self._log_with_header(
167+ "Application {} has unknown check operation for {}: {}.".format(
168+ app_name,
169+ rule,
170+ check_op,
171+ ),
172+ level=logging.WARN,
173+ )
174+
175+ def check_bindings(self, applications):
176+ """Check application bindings in the model."""
177+ for application in applications.keys():
178+ # look for config rules for this application
179+ lint_rules = []
180+
181+ charm_name = utils.extract_charm_name(applications[application]["charm"])
182+ if "endpoints" in self.lint_rules:
183+ if charm_name in self.lint_rules["endpoints"]:
184+ lint_rules = dict([("neq", "alpha")])
185+
186+ if lint_rules:
187+ if "bindings" in applications[application]:
188+ self.check_binding(
189+ application,
190+ applications[application]["bindings"],
191+ lint_rules,
192+ )
193+
194 def check_subs(self, machines_data):
195 """Check the subordinates in the model."""
196 all_or_nothing = set()
197@@ -1021,6 +1063,9 @@ class Linter:
198 # Check configuration
199 self.check_configuration(parsed_yaml[applications])
200
201+ # Check bindings
202+ self.check_bindings(parsed_yaml[applications])
203+
204 # Then map out subordinates to applications
205 for app in parsed_yaml[applications]:
206 self.process_subordinates(parsed_yaml[applications][app], app)

Subscribers

People subscribed via source and target branches