From de40430b13f4767a32ade1d738494b96da90cbc4 Mon Sep 17 00:00:00 2001 From: Dario Faccin <35623244+dariofaccin@users.noreply.github.com> Date: Wed, 24 Apr 2024 16:53:39 +0200 Subject: [PATCH] fix: handle charm status only from CollectStatus event callback (#174) --- src/charm.py | 3 +-- tests/unit/test_charm.py | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/charm.py b/src/charm.py index e4ddc46c..91247c82 100755 --- a/src/charm.py +++ b/src/charm.py @@ -106,8 +106,7 @@ def __init__(self, *args): self.unit.set_ports(PROMETHEUS_PORT) try: self._charm_config: CharmConfig = CharmConfig.from_charm(charm=self) - except CharmConfigInvalidError as exc: - self.model.unit.status = BlockedStatus(exc.msg) + except CharmConfigInvalidError: return self._kubernetes_multus = KubernetesMultusCharmLib( charm=self, diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index 626a4d26..3c1c53ac 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -99,6 +99,7 @@ def test_given_bad_config_when_config_changed_then_status_is_blocked(self, patch ] self.harness.update_config(key_values={"dnn": ""}) self.harness.begin() + self.harness.evaluate_status() self.assertEqual( self.harness.model.unit.status, @@ -118,6 +119,7 @@ def test_given_empty_upf_mode_when_config_changed_then_status_is_blocked(self, p ] self.harness.update_config(key_values={"upf-mode": ""}) self.harness.begin() + self.harness.evaluate_status() self.assertEqual( self.harness.model.unit.status, @@ -139,6 +141,7 @@ def test_given_unsupported_upf_mode_when_config_changed_then_status_is_blocked( ] self.harness.update_config(key_values={"upf-mode": "unsupported"}) self.harness.begin() + self.harness.evaluate_status() self.assertEqual( self.harness.model.unit.status, @@ -162,6 +165,7 @@ def test_given_upf_mode_set_to_dpdk_but_other_required_configs_not_set_when_conf ] self.harness.update_config(key_values={"cni-type": "vfioveth", "upf-mode": "dpdk"}) self.harness.begin() + self.harness.evaluate_status() self.assertEqual( self.harness.model.unit.status, @@ -187,6 +191,7 @@ def test_given_upf_mode_set_to_dpdk_and_hugepages_enabled_but_mac_addresses_of_a ] self.harness.update_config(key_values={"cni-type": "vfioveth", "upf-mode": "dpdk"}) self.harness.begin() + self.harness.evaluate_status() self.assertEqual( self.harness.model.unit.status, @@ -219,6 +224,7 @@ def test_given_upf_mode_set_to_dpdk_and_hugepages_enabled_but_access_interface_m } ) self.harness.begin() + self.harness.evaluate_status() self.assertEqual( self.harness.model.unit.status, @@ -251,6 +257,7 @@ def test_given_upf_mode_set_to_dpdk_and_hugepages_enabled_but_core_interface_mac } ) self.harness.begin() + self.harness.evaluate_status() self.assertEqual( self.harness.model.unit.status, @@ -298,6 +305,8 @@ def test_given_default_config_with_interfaces_zero_mtu_sizes_when_network_attach } ) self.harness.begin() + self.harness.evaluate_status() + self.assertEqual( self.harness.model.unit.status, BlockedStatus(