From 8e02cff47522d046030df8c9d50be9129b50a2bd Mon Sep 17 00:00:00 2001 From: Iker Pedrosa Date: Mon, 31 Mar 2025 17:49:22 +0200 Subject: [PATCH] tests/: implement feature detection Implement a general function to detect features in shadow host. Apparently, musl doesn't provide `getent gshadow`, but shadow still needs it to check for several group attributes. Thus, check whether it exists in the host, and if it does run it. If not, let's just skip that part of the test. Link: Signed-off-by: Iker Pedrosa Reviewed-by: Dan Lavu --- tests/system/framework/hosts/shadow.py | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/system/framework/hosts/shadow.py b/tests/system/framework/hosts/shadow.py index 1fb656b63..2a0ca3e5d 100644 --- a/tests/system/framework/hosts/shadow.py +++ b/tests/system/framework/hosts/shadow.py @@ -42,6 +42,9 @@ class ShadowHost(BaseHost, BaseLinuxHost): ] """Files to verify for mismatch.""" + self._features: dict[str, bool] | None = None + """Features supported by the host.""" + def pytest_setup(self) -> None: super().pytest_setup() @@ -61,6 +64,34 @@ class ShadowHost(BaseHost, BaseLinuxHost): """ raise NotImplementedError("Stopping shadow service is not implemented.") + @property + def features(self) -> dict[str, bool]: + """ + Features supported by the host. + """ + if self._features is not None: + return self._features + + self.logger.info(f"Detecting shadow features on {self.hostname}") + result = self.conn.run( + """ + set -ex + + getent gshadow > /dev/null 2>&1 && echo "gshadow" || : + """, + log_level=ProcessLogLevel.Error, + ) + + # Set default values + self._features = { + "gshadow": False, + } + + self._features.update({k: True for k in result.stdout_lines}) + self.logger.info("Detected features:", extra={"data": {"Features": self._features}}) + + return self._features + def backup(self) -> Any: """ Backup all shadow data. -- 2.47.2