]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
tests/system/framework/roles/shadow.py: implement binding for `chgpasswd`
authorIker Pedrosa <ipedrosa@redhat.com>
Wed, 10 Sep 2025 14:53:02 +0000 (16:53 +0200)
committerSerge Hallyn <serge@hallyn.com>
Wed, 25 Mar 2026 02:33:15 +0000 (21:33 -0500)
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
tests/system/framework/roles/shadow.py

index 5cfa10de3e7cb59433c9e63270a80f56cae584c1..0a31e0140dee51f3af420cd38a9becca3158161c 100644 (file)
@@ -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