From 65eb9c53b90be1b4396677a585dfa2a7f174e31c Mon Sep 17 00:00:00 2001 From: saltiyazan Date: Wed, 12 Jun 2024 12:36:43 +0400 Subject: [PATCH] chore: Fetches lates version of the lego client lib (#169) --- lib/charms/lego_base_k8s/v0/lego_client.py | 17 +++++++++++++++-- tests/unit/test_charm.py | 10 ++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/charms/lego_base_k8s/v0/lego_client.py b/lib/charms/lego_base_k8s/v0/lego_client.py index bd6c919..299ccb6 100644 --- a/lib/charms/lego_base_k8s/v0/lego_client.py +++ b/lib/charms/lego_base_k8s/v0/lego_client.py @@ -95,7 +95,7 @@ def _plugin_config(self): # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 8 +LIBPATCH = 9 logger = logging.getLogger(__name__) @@ -144,7 +144,7 @@ def _on_collect_status(self, event: CollectStatusEvent) -> None: BlockedStatus(err) ) return - event.add_status(ActiveStatus()) + event.add_status(ActiveStatus(self._get_certificate_fulfillment_status())) def _sync_certificates(self, event: EventBase) -> None: """Go through all the certificates relations and handle outstanding requests.""" @@ -278,6 +278,19 @@ def _generate_signed_certificate(self, csr: str, relation_id: int): relation_id=relation_id, ) + def _get_certificate_fulfillment_status(self) -> str: + """Return the status message reflecting how many certificate requests are still pending.""" + outstanding_requests_num = len( + self.tls_certificates.get_outstanding_certificate_requests() + ) + total_requests_num = len( + self.tls_certificates.get_requirer_csrs() + ) + fulfilled_certs = total_requests_num - outstanding_requests_num + return ( + f"{fulfilled_certs}/{total_requests_num} certificate requests are fulfilled" + ) + @property def _cmd(self) -> List[str]: """Command to run to get the certificate. diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index 056018d..25eae05 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -26,7 +26,10 @@ def test_given_email_is_valid_when_config_changed_then_status_is_active(self): } ) self.harness.evaluate_status() - self.assertEqual(self.harness.model.unit.status, ActiveStatus()) + self.assertEqual( + self.harness.model.unit.status, + ActiveStatus("0/0 certificate requests are fulfilled"), + ) def test_given_email_is_invalid_when_config_changed_then_status_is_blocked(self): self.harness.update_config( @@ -85,7 +88,10 @@ def test_optional_config_provided_then_status_is_active(self): } ) self.harness.evaluate_status() - self.assertEqual(self.harness.model.unit.status, ActiveStatus()) + self.assertEqual( + self.harness.model.unit.status, + ActiveStatus("0/0 certificate requests are fulfilled"), + ) def test_optional_config_provided_then_plugin_config_is_correct(self): self.harness.update_config(