From: Iker Pedrosa Date: Wed, 10 Sep 2025 14:53:02 +0000 (+0200) Subject: tests/system/framework/roles/shadow.py: implement binding for `chgpasswd` X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e313ffd591803be7bb672aec66148663c3a3eb11;p=thirdparty%2Fshadow.git tests/system/framework/roles/shadow.py: implement binding for `chgpasswd` Signed-off-by: Iker Pedrosa --- diff --git a/tests/system/framework/roles/shadow.py b/tests/system/framework/roles/shadow.py index 5cfa10de3..0a31e0140 100644 --- a/tests/system/framework/roles/shadow.py +++ b/tests/system/framework/roles/shadow.py @@ -454,3 +454,27 @@ class Shadow(BaseLinuxRole[ShadowHost]): self.host.discard_file("/etc/gshadow") return cmd + + def chgpasswd(self, *args, passwords_data: str | None = None, file: str | None = None) -> ProcessResult: + """ + Update group passwords in batch. + + Updates group passwords in batch by reading groupname:password pairs. + If `passwords_data` is provided, this data is used to simulate an interactive prompt. + Otherwise, the command reads from a file specified in `file`. + """ + cmd_args = " ".join(args) + + if passwords_data: + self.logger.info(f"Running chgpasswd interactively on {self.host.hostname}") + cmd = self.host.conn.run( + f"echo '{passwords_data}' | chgpasswd {cmd_args}", log_level=ProcessLogLevel.Error + ) + else: + self.logger.info(f"Running chgpasswd from file on {self.host.hostname}") + cmd = self.host.conn.run(f"chgpasswd {cmd_args} < {file}", log_level=ProcessLogLevel.Error) + + self.host.discard_file("/etc/group") + self.host.discard_file("/etc/gshadow") + + return cmd