From 32492f09f440cfb36e7dc8c242d6547493f89607 Mon Sep 17 00:00:00 2001 From: Dario Faccin Date: Tue, 12 Dec 2023 15:09:54 +0100 Subject: [PATCH] Check for allocatable resources instead of capacity --- src/charm.py | 7 ++++++- tests/unit/test_charm.py | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/charm.py b/src/charm.py index e160c066..09df9c76 100755 --- a/src/charm.py +++ b/src/charm.py @@ -807,11 +807,16 @@ def _cpu_is_compatible_for_hugepages(self) -> bool: @staticmethod def _hugepages_are_available() -> bool: + """Checks whether HugePages are available in the K8S nodes. + + Returns: + bool: Whether HugePages are available in the K8S nodes + """ client = Client() nodes = client.list(Node) if not nodes: return False - return all([node.status.capacity.get("hugepages-1Gi", "0") >= "2Gi" for node in nodes]) + return all([node.status.allocatable.get("hugepages-1Gi", "0") >= "2Gi" for node in nodes]) def _get_access_nad_config(self) -> Dict[Any, Any]: """Get access interface NAD config. diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index 18ebb6e2..14e7bce4 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -791,7 +791,7 @@ def test_given_cpu_supporting_required_hugepages_instructions_when_hugepages_ena ): patch_hugepages_is_patched.return_value = False patched_check_output.return_value = b"Flags: avx2 ssse3 fma cx16 rdrand pdpe1gb" - patch_list.return_value = [Node(status=NodeStatus(capacity={"hugepages-1Gi": "3Gi"}))] + patch_list.return_value = [Node(status=NodeStatus(allocatable={"hugepages-1Gi": "3Gi"}))] self.harness.update_config(key_values={"enable-hugepages": True}) @@ -806,7 +806,7 @@ def test_given_cpu_supporting_required_hugepages_instructions_and_not_available_ ): patch_hugepages_is_patched.return_value = False patched_check_output.return_value = b"Flags: avx2 ssse3 fma cx16 rdrand pdpe1gb" - patch_list.return_value = [Node(status=NodeStatus(capacity={"hugepages-1Gi": "1Gi"}))] + patch_list.return_value = [Node(status=NodeStatus(allocatable={"hugepages-1Gi": "1Gi"}))] self.harness.update_config(key_values={"enable-hugepages": True})