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
diff --git a/src/charm.py b/src/charm.py
index c5f5c59..addd9bc 100755
--- a/src/charm.py
+++ b/src/charm.py
@@ -654,6 +654,10 @@ class LandscapeServerCharm(CharmBase):
654 self.unit.status = MaintenanceStatus("Configuring HAProxy")654 self.unit.status = MaintenanceStatus("Configuring HAProxy")
655 haproxy_ssl_cert = event.relation.data[event.unit]["ssl_cert"]655 haproxy_ssl_cert = event.relation.data[event.unit]["ssl_cert"]
656656
657 # Sometimes the data has not been encoded propery in the HA charm
658 if haproxy_ssl_cert.startswith("b'"):
659 haproxy_ssl_cert = haproxy_ssl_cert.strip('b').strip("'")
660
657 if haproxy_ssl_cert != "DEFAULT":661 if haproxy_ssl_cert != "DEFAULT":
658 # If DEFAULT, cert is being managed by a third party,662 # If DEFAULT, cert is being managed by a third party,
659 # possibly a subordinate charm.663 # possibly a subordinate charm.
diff --git a/tests/test_charm.py b/tests/test_charm.py
index 0b1477d..d904212 100644
--- a/tests/test_charm.py
+++ b/tests/test_charm.py
@@ -809,6 +809,29 @@ class TestCharm(unittest.TestCase):
809 self.assertIsInstance(status, WaitingStatus)809 self.assertIsInstance(status, WaitingStatus)
810 write_cert_mock.assert_called_once_with("FANCYNEWCERT")810 write_cert_mock.assert_called_once_with("FANCYNEWCERT")
811811
812 def test_website_relation_changed_strip_b_char(self):
813 self.harness.charm._update_haproxy_connection = Mock()
814 mock_event = Mock()
815 mock_event.relation.data = {
816 mock_event.unit: {"ssl_cert": "b'FANCYNEWCERT'"},
817 self.harness.charm.unit: {
818 "private-address": "test",
819 "public-address": "test2",
820 },
821 }
822
823 with patch.multiple(
824 "charm",
825 write_ssl_cert=DEFAULT,
826 update_service_conf=DEFAULT,
827 ) as mocks:
828 write_cert_mock = mocks["write_ssl_cert"]
829 self.harness.charm._website_relation_changed(mock_event)
830
831 status = self.harness.charm.unit.status
832 self.assertIsInstance(status, WaitingStatus)
833 write_cert_mock.assert_called_once_with("FANCYNEWCERT")
834
812 @patch("charm.update_service_conf")835 @patch("charm.update_service_conf")
813 def test_on_config_changed_no_smtp_change(self, _):836 def test_on_config_changed_no_smtp_change(self, _):
814 self.harness.charm._update_ready_status = Mock()837 self.harness.charm._update_ready_status = Mock()

Subscribers

People subscribed via source and target branches

to all changes: