Merge ~aluria/charm-grafana:bug/1975622 into charm-grafana:master

Proposed by Alvaro Uria
Status: Merged
Approved by: Alvaro Uria
Approved revision: 1c4d877e86b603136fd6891898006476e8bb7786
Merged at revision: 29f5405151e2450c34389336754f5c8697f492d7
Proposed branch: ~aluria/charm-grafana:bug/1975622
Merge into: charm-grafana:master
Diff against target: 156 lines (+68/-19)
4 files modified
src/templates/ldap.toml.j2 (+4/-2)
src/tests/functional/tests/test_grafana.py (+1/-1)
src/tests/unit/test_grafana.py (+16/-16)
src/tests/unit/test_templates.py (+47/-0)
Reviewer Review Type Date Requested Status
Peter Sabaini (community) Approve
🤖 prod-jenkaas-bootstack continuous-integration Needs Fixing
BootStack Reviewers Pending
Review via email: mp+423367@code.launchpad.net

Commit message

LP#1975622 LDAP config rendered non-string values with quotes

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
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :

A CI job is currently in progress. A follow up comment will be added when it completes.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alvaro Uria (aluria) wrote :

After a git-push --force, it seems jenkaas did not update the results of the build [1], in this MP.

All tests passed, and since the MP only affected lint/unittests, I think it is good to go.

1. https://jenkins.canonical.com/bootstack/job/lp-charm-test-functest/833/console

Revision history for this message
Peter Sabaini (peter-sabaini) wrote :

Lgtm, 1 minor yakshaving comment :-)

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

Change successfully merged at revision 29f5405151e2450c34389336754f5c8697f492d7

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/templates/ldap.toml.j2 b/src/templates/ldap.toml.j2
index bbf0d27..a47819d 100644
--- a/src/templates/ldap.toml.j2
+++ b/src/templates/ldap.toml.j2
@@ -1,6 +1,6 @@
1[[servers]]1[[servers]]
2host = "{{ host }}"2host = "{{ host }}"
3port = {{ port }} 3port = {{ port }}
4bind_dn = "{{ config.ldap_user }}"4bind_dn = "{{ config.ldap_user }}"
5bind_password = "{{ config.ldap_password }}"5bind_password = "{{ config.ldap_password }}"
6{% if ssl or config.ldap_server_ca -%}6{% if ssl or config.ldap_server_ca -%}
@@ -20,8 +20,10 @@ search_filter = "(cn=%s)"
20{% for key, value in ldap_options.items() -%}20{% for key, value in ldap_options.items() -%}
21{% if key == 'group_search_base_dns' -%}21{% if key == 'group_search_base_dns' -%}
22group_search_base_dns = ["{{ value }}"]22group_search_base_dns = ["{{ value }}"]
23{% else -%}23{% elif value is string -%}
24{{ key }} = "{{ value }}"24{{ key }} = "{{ value }}"
25{% else -%}
26{{ key }} = {{ value }}
25{% endif -%}27{% endif -%}
26{% endfor -%}28{% endfor -%}
27{% endif -%}29{% endif -%}
diff --git a/src/tests/functional/tests/test_grafana.py b/src/tests/functional/tests/test_grafana.py
index 69746e3..fb3286e 100644
--- a/src/tests/functional/tests/test_grafana.py
+++ b/src/tests/functional/tests/test_grafana.py
@@ -304,7 +304,7 @@ class CharmOperationTest(BaseGrafanaTest):
304304
305 def chk(dashes):305 def chk(dashes):
306 marker_dashes = [d for d in dashes if "FunctionalTestMarker" in d["title"]]306 marker_dashes = [d for d in dashes if "FunctionalTestMarker" in d["title"]]
307 return len(dashes) >= 1 and len(marker_dashes) == 1307 return len(dashes) >= 1 and len(marker_dashes) >= 1
308308
309 dashes = self.get_and_check_dashboards(chk)309 dashes = self.get_and_check_dashboards(chk)
310 self.assertTrue(chk(dashes))310 self.assertTrue(chk(dashes))
diff --git a/src/tests/unit/test_grafana.py b/src/tests/unit/test_grafana.py
index f15c9e9..e8da3f7 100644
--- a/src/tests/unit/test_grafana.py
+++ b/src/tests/unit/test_grafana.py
@@ -171,12 +171,12 @@ class GrafanaTestCase(unittest.TestCase):
171 {"dashboard": {"title": "[juju-foo-app] test-title"}, "folderId": 0},171 {"dashboard": {"title": "[juju-foo-app] test-title"}, "folderId": 0},
172 )172 )
173173
174 @mock.patch("charmhelpers.core.hookenv.charm_dir", auto_spec=True)174 @mock.patch("charmhelpers.core.hookenv.charm_dir", autospec=True)
175 @mock.patch("reactive.grafana.templating.render", auto_spec=True)175 @mock.patch("reactive.grafana.templating.render", autospec=True)
176 @mock.patch("reactive.grafana.hookenv.config", auto_spec=True)176 @mock.patch("reactive.grafana.hookenv.config", autospec=True)
177 @mock.patch("reactive.grafana.hookenv.unit_public_ip", auto_spec=True)177 @mock.patch("reactive.grafana.hookenv.unit_public_ip", autospec=True)
178 @mock.patch("reactive.grafana.hookenv.unit_private_ip", auto_spec=True)178 @mock.patch("reactive.grafana.hookenv.unit_private_ip", autospec=True)
179 @mock.patch("subprocess.check_call", auto_spec=True)179 @mock.patch("subprocess.check_call", autospec=True)
180 def test_request_certificate(180 def test_request_certificate(
181 self,181 self,
182 mock_check_call,182 mock_check_call,
@@ -217,12 +217,12 @@ class GrafanaTestCase(unittest.TestCase):
217217
218 @mock.patch("os.makedirs")218 @mock.patch("os.makedirs")
219 @mock.patch("subprocess.check_call")219 @mock.patch("subprocess.check_call")
220 @mock.patch.object(grafana_reactive.templating, "render", auto_spec=True)220 @mock.patch.object(grafana_reactive.templating, "render", autospec=True)
221 @mock.patch.object(grafana_reactive, "check_ports", auto_spec=True)221 @mock.patch.object(grafana_reactive, "check_ports", autospec=True)
222 @mock.patch.object(grafana_reactive, "render", auto_spec=True)222 @mock.patch.object(grafana_reactive, "render", autospec=True)
223 @mock.patch.object(grafana_reactive, "get_install_source", auto_spec=True)223 @mock.patch.object(grafana_reactive, "get_install_source", autospec=True)
224 @mock.patch.object(grafana, "config", auto_spec=True)224 @mock.patch.object(grafana, "config", autospec=True)
225 @mock.patch("reactive.grafana.hookenv.config", auto_spec=True)225 @mock.patch("reactive.grafana.hookenv.config", autospec=True)
226 def test_setting_ssl_via_juju_config(226 def test_setting_ssl_via_juju_config(
227 self,227 self,
228 mock_config,228 mock_config,
@@ -325,9 +325,9 @@ class GrafanaTestCase(unittest.TestCase):
325 @mock.patch("sqlite3.connect")325 @mock.patch("sqlite3.connect")
326 @mock.patch("os.chmod")326 @mock.patch("os.chmod")
327 @mock.patch("charmhelpers.core.host.chownr")327 @mock.patch("charmhelpers.core.host.chownr")
328 @mock.patch.object(grafana_reactive, "data_path", auto_spec=True)328 @mock.patch.object(grafana_reactive, "data_path", autospec=True)
329 @mock.patch("charmhelpers.core.host.owner")329 @mock.patch("charmhelpers.core.host.owner")
330 @mock.patch.object(grafana_reactive, "get_install_source", auto_spec=True)330 @mock.patch.object(grafana_reactive, "get_install_source", autospec=True)
331 def test_db_connection_snap(331 def test_db_connection_snap(
332 self,332 self,
333 mock_install_source,333 mock_install_source,
@@ -350,9 +350,9 @@ class GrafanaTestCase(unittest.TestCase):
350 @mock.patch("sqlite3.connect")350 @mock.patch("sqlite3.connect")
351 @mock.patch("os.chmod")351 @mock.patch("os.chmod")
352 @mock.patch("charmhelpers.core.host.chownr")352 @mock.patch("charmhelpers.core.host.chownr")
353 @mock.patch.object(grafana_reactive, "data_path", auto_spec=True)353 @mock.patch.object(grafana_reactive, "data_path", autospec=True)
354 @mock.patch("charmhelpers.core.host.owner")354 @mock.patch("charmhelpers.core.host.owner")
355 @mock.patch.object(grafana_reactive, "get_install_source", auto_spec=True)355 @mock.patch.object(grafana_reactive, "get_install_source", autospec=True)
356 def test_db_connection_apt(356 def test_db_connection_apt(
357 self,357 self,
358 mock_install_source,358 mock_install_source,
diff --git a/src/tests/unit/test_templates.py b/src/tests/unit/test_templates.py
359new file mode 100644359new file mode 100644
index 0000000..e66f763
--- /dev/null
+++ b/src/tests/unit/test_templates.py
@@ -0,0 +1,47 @@
1"""Unit tests module."""
2
3import unittest
4
5from charms.layer.grafana import LDAP_TOML_TMPL
6
7import jinja2
8
9
10class GrafanaTestCaseTemplates(unittest.TestCase):
11 """Unit tests class for Grafana."""
12
13 def test_template_ldap_tom_j2(self):
14 """Test ldap.tom.j2 template."""
15 settings = {
16 "host": "ldap.server.example",
17 "port": 389,
18 "ldap_options": {
19 "start_tls": False,
20 "string_value1": "This is a string",
21 "string_value2": "string_value2_value",
22 },
23 "config": {
24 "ldap_user": "bind_dn_value",
25 "ldap_password": "bind_passw0rd",
26 },
27 }
28 expected = """\
29[[servers]]
30host = "ldap.server.example"
31port = 389
32bind_dn = "bind_dn_value"
33bind_password = "bind_passw0rd"
34use_ssl = false
35search_base_dns = [""]
36
37search_filter = "(cn=%s)"
38start_tls = False
39string_value1 = "This is a string"
40string_value2 = "string_value2_value"
41"""
42 # Note(aluria): charmhelpers.contrib.templating.render fails when running
43 # unit tests in py3.10
44 template_env = jinja2.Environment(loader=jinja2.FileSystemLoader("templates"))
45 template = template_env.get_template(LDAP_TOML_TMPL)
46 content = template.render(settings)
47 self.assertEqual(expected, content)

Subscribers

People subscribed via source and target branches

to all changes: