Skip to content

Commit

Permalink
fix: move to Blocked state when Multus is disabled (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
dariofaccin authored Jan 3, 2024
1 parent 6649241 commit b4f41eb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ def _on_config_changed(self, event: EventBase):
if not self._hugepages_are_available():
self.unit.status = BlockedStatus("Not enough HugePages available")
return
if not self._kubernetes_multus.multus_is_available():
self.unit.status = BlockedStatus("Multus is not installed or enabled")
return
if invalid_configs := self._get_invalid_configs():
self.unit.status = BlockedStatus(
f"The following configurations are not valid: {invalid_configs}"
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ def test_given_cpu_supporting_required_hugepages_instructions_when_hugepages_ena
patch_list.side_effect = [
[Node(status=NodeStatus(allocatable={"hugepages-1Gi": "3Gi"}))],
[],
[],
]

self.harness.update_config(key_values={"enable-hugepages": True})
Expand Down Expand Up @@ -833,6 +834,7 @@ def test_given_hugepages_not_available_then_hugepages_available_when_update_stat
[Node(status=NodeStatus(allocatable={"hugepages-1Gi": "1Gi"}))],
[Node(status=NodeStatus(allocatable={"hugepages-1Gi": "2Gi"}))],
[],
[],
]

self.harness.update_config(key_values={"enable-hugepages": True})
Expand All @@ -848,6 +850,27 @@ def test_given_hugepages_not_available_then_hugepages_available_when_update_stat
WaitingStatus("Waiting for bessd container to be ready"),
)

@patch("charm.check_output")
@patch("lightkube.core.client.GenericSyncClient", new=Mock)
@patch(f"{MULTUS_LIBRARY_PATH}.KubernetesMultusCharmLib.multus_is_available")
@patch(f"{HUGEPAGES_LIBRARY_PATH}.KubernetesHugePagesPatchCharmLib.is_patched")
def test_given_multus_disabled_then_enabled_when_update_status_then_status_is_active(
self, patch_hugepages_is_patched, patch_multus_available, patched_check_output
):
patch_hugepages_is_patched.return_value = True
patch_multus_available.side_effect = [False, True]
patched_check_output.return_value = b"Flags: avx2 ssse3 fma cx16 rdrand pdpe1gb"
self.harness.charm.on.update_status.emit()
self.assertEqual(
self.harness.model.unit.status, BlockedStatus("Multus is not installed or enabled")
)
self.harness.charm.on.update_status.emit()

self.assertEqual(
self.harness.model.unit.status,
WaitingStatus("Waiting for bessd container to be ready"),
)

@patch(f"{HUGEPAGES_LIBRARY_PATH}.KubernetesHugePagesPatchCharmLib.is_patched")
def test_given_default_config_when_network_attachment_definitions_from_config_is_called_then_no_interface_mtu_specified_in_nad( # noqa: E501
self,
Expand Down

0 comments on commit b4f41eb

Please sign in to comment.