From ca9afc0935e4ee1b290011724c0641993c0e9e34 Mon Sep 17 00:00:00 2001 From: Judit Novak Date: Fri, 28 Jul 2023 16:10:20 +0200 Subject: [PATCH] Deleting cert before pushing new ones (#182) --- lib/charms/mongodb/v0/mongodb_tls.py | 1 + src/charm.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/charms/mongodb/v0/mongodb_tls.py b/lib/charms/mongodb/v0/mongodb_tls.py index 2c31519be..b9ead22cc 100644 --- a/lib/charms/mongodb/v0/mongodb_tls.py +++ b/lib/charms/mongodb/v0/mongodb_tls.py @@ -192,6 +192,7 @@ def _on_certificate_available(self, event: CertificateAvailableEvent) -> None: logger.info("Restarting mongod with TLS enabled.") + self.charm.delete_tls_certificate_from_workload() self.charm.push_tls_certificate_to_workload() self.charm.unit.status = MaintenanceStatus("enabling TLS") self.charm.restart_mongod_service() diff --git a/src/charm.py b/src/charm.py index 9f6bbdf84..98d2a09c2 100755 --- a/src/charm.py +++ b/src/charm.py @@ -1001,7 +1001,10 @@ def delete_tls_certificate_from_workload(self) -> None: Config.TLS.INT_CA_FILE, Config.TLS.INT_PEM_FILE, ]: - container.remove_path(f"{Config.CONF_DIR}/{file}") + try: + container.remove_path(f"{Config.CONF_DIR}/{file}") + except PathError as err: + logger.debug("Path unavailable: %s (%s)", file, str(err)) def get_hostname_for_unit(self, unit: Unit) -> str: """Create a DNS name for a MongoDB unit.