Skip to content

Commit

Permalink
fix: handle charm status only from CollectStatus event callback (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
dariofaccin authored Apr 24, 2024
1 parent 99d1ed2 commit de40430
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit de40430

Please sign in to comment.