Merge ~silverdrake11/landscape-charm:strip_cert into landscape-charm:main

Proposed by Kevin Nasto
Status: Merged
Merged at revision: 123e2885f1392c6420b44beb12ee78e816df969e
Proposed branch: ~silverdrake11/landscape-charm:strip_cert
Merge into: landscape-charm:main
Diff against target: 49 lines (+27/-0)
2 files modified
src/charm.py (+4/-0)
tests/test_charm.py (+23/-0)
Reviewer Review Type Date Requested Status
Mitch Burton Approve
Review via email: mp+455010@code.launchpad.net

Commit message

Remove b char from haproxy cert

Description of the change

Sometimes landscape server throws an error from base64 improper chars like b' originating from the ha charm config value

To post a comment you must log in.
Revision history for this message
Mitch Burton (mitchburton) wrote :

LGTM. I don't have the luck to be able to regularly reproduce this, but the change is non-disruptive enough that I'm okay with that.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/charm.py b/src/charm.py
2index c5f5c59..addd9bc 100755
3--- a/src/charm.py
4+++ b/src/charm.py
5@@ -654,6 +654,10 @@ class LandscapeServerCharm(CharmBase):
6 self.unit.status = MaintenanceStatus("Configuring HAProxy")
7 haproxy_ssl_cert = event.relation.data[event.unit]["ssl_cert"]
8
9+ # Sometimes the data has not been encoded propery in the HA charm
10+ if haproxy_ssl_cert.startswith("b'"):
11+ haproxy_ssl_cert = haproxy_ssl_cert.strip('b').strip("'")
12+
13 if haproxy_ssl_cert != "DEFAULT":
14 # If DEFAULT, cert is being managed by a third party,
15 # possibly a subordinate charm.
16diff --git a/tests/test_charm.py b/tests/test_charm.py
17index 0b1477d..d904212 100644
18--- a/tests/test_charm.py
19+++ b/tests/test_charm.py
20@@ -809,6 +809,29 @@ class TestCharm(unittest.TestCase):
21 self.assertIsInstance(status, WaitingStatus)
22 write_cert_mock.assert_called_once_with("FANCYNEWCERT")
23
24+ def test_website_relation_changed_strip_b_char(self):
25+ self.harness.charm._update_haproxy_connection = Mock()
26+ mock_event = Mock()
27+ mock_event.relation.data = {
28+ mock_event.unit: {"ssl_cert": "b'FANCYNEWCERT'"},
29+ self.harness.charm.unit: {
30+ "private-address": "test",
31+ "public-address": "test2",
32+ },
33+ }
34+
35+ with patch.multiple(
36+ "charm",
37+ write_ssl_cert=DEFAULT,
38+ update_service_conf=DEFAULT,
39+ ) as mocks:
40+ write_cert_mock = mocks["write_ssl_cert"]
41+ self.harness.charm._website_relation_changed(mock_event)
42+
43+ status = self.harness.charm.unit.status
44+ self.assertIsInstance(status, WaitingStatus)
45+ write_cert_mock.assert_called_once_with("FANCYNEWCERT")
46+
47 @patch("charm.update_service_conf")
48 def test_on_config_changed_no_smtp_change(self, _):
49 self.harness.charm._update_ready_status = Mock()

Subscribers

People subscribed via source and target branches

to all changes: