]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
tests/system/framework/roles/shadow.py: implement binding for `newusers`
authorIker Pedrosa <ipedrosa@redhat.com>
Fri, 8 Aug 2025 14:22:16 +0000 (16:22 +0200)
committerSerge Hallyn <serge@hallyn.com>
Fri, 5 Dec 2025 22:35:36 +0000 (16:35 -0600)
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
tests/system/framework/roles/shadow.py

index 39cbb35b7600fb048847631a7167b51f05caf7bd..f6b7481b6f4f04d788fc1d4d5dc021f4addf1e29 100644 (file)
@@ -142,3 +142,27 @@ class Shadow(BaseLinuxRole[ShadowHost]):
         self.host.discard_file("/etc/shadow")
 
         return cmd
+
+    def newusers(self, *args, users_data: str | None = None) -> ProcessResult:
+        """
+        Update or create new users in batch.
+
+        Updates or creates multiple users by reading account information in passwd
+        format. If `users_data` is provided, it's passed via stdin and takes
+        precedence; otherwise, the command reads from a file specified in `args`.
+        """
+        if users_data:
+            cmd_args = " ".join(args)
+            self.logger.info(f"Creating users from stdin on {self.host.hostname}")
+            cmd = self.host.conn.run(f"echo '{users_data}' | newusers {cmd_args}", log_level=ProcessLogLevel.Error)
+        else:
+            args_dict = self._parse_args(args)
+            self.logger.info(f'Creating users from "{args_dict["name"]}" on {self.host.hostname}')
+            cmd = self.host.conn.run("newusers " + args[0], log_level=ProcessLogLevel.Error)
+
+        self.host.discard_file("/etc/passwd")
+        self.host.discard_file("/etc/shadow")
+        self.host.discard_file("/etc/group")
+        self.host.discard_file("/etc/gshadow")
+
+        return cmd