From f8b701f2980d5d56e6b93541ec1c39d9e65d602b Mon Sep 17 00:00:00 2001 From: Mehdi Bendriss Date: Tue, 10 Sep 2024 17:36:49 +0100 Subject: [PATCH] Increase swappiness max and fix cast (#434) ## Issue This PR increases the max allowed for swappiness and fixes an erroneous string to string comparison Manually tested on: AWS EC2 --- lib/charms/opensearch/v0/opensearch_distro.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/charms/opensearch/v0/opensearch_distro.py b/lib/charms/opensearch/v0/opensearch_distro.py index 702f81002..f042da7ec 100644 --- a/lib/charms/opensearch/v0/opensearch_distro.py +++ b/lib/charms/opensearch/v0/opensearch_distro.py @@ -455,26 +455,26 @@ def normalize_allocation_exclusions(exclusions: Union[List[str], Set[str], str]) def missing_sys_requirements(self) -> List[str]: """Checks the system requirements.""" - def apply(prop: str, value: str) -> bool: + def apply(prop: str, value: int) -> bool: """Apply a sysctl value and check if it was set.""" try: self._run_cmd(f"sysctl -w {prop}={value}") - return self._run_cmd(f"sysctl -n {prop}") == value + return int(self._run_cmd(f"sysctl -n {prop}")) == value except OpenSearchCmdError: return False missing_requirements = [] - prop, val = "vm.max_map_count", "262144" - if self._run_cmd(f"sysctl -n {prop}") < val and not apply(prop, val): + prop, val = "vm.max_map_count", 262144 + if int(self._run_cmd(f"sysctl -n {prop}")) < val and not apply(prop, val): missing_requirements.append(f"{prop} should be at least {val}") - prop, val = "vm.swappiness", "0" - if self._run_cmd(f"sysctl -n {prop}") > val and not apply(prop, val): - missing_requirements.append(f"{prop} should be {val}") + prop, val = "vm.swappiness", 1 + if int(self._run_cmd(f"sysctl -n {prop}")) > val and not apply(prop, 0): + missing_requirements.append(f"{prop} should be at most 1") - prop, val = "net.ipv4.tcp_retries2", "5" - if self._run_cmd(f"sysctl -n {prop}") > val and not apply(prop, val): + prop, val = "net.ipv4.tcp_retries2", 5 + if int(self._run_cmd(f"sysctl -n {prop}")) > val and not apply(prop, val): missing_requirements.append(f"{prop} should be at most {val}") return missing_requirements