From 3e4a19ef349cc2f560d96aff77a2ecd760ff4148 Mon Sep 17 00:00:00 2001 From: Katarzyna Treder Date: Mon, 7 Oct 2024 13:15:33 +0200 Subject: [PATCH] Introduce methods for creating or checking if user exists Signed-off-by: Katarzyna Treder --- test_utils/os_utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test_utils/os_utils.py b/test_utils/os_utils.py index bd040fc..9bca157 100644 --- a/test_utils/os_utils.py +++ b/test_utils/os_utils.py @@ -460,3 +460,15 @@ def get_cores_ids_range(numa_node: int): parse_output = re.findall(r'(\d+),(\d+),(?:\d+),(\d+),,', output, re.I) return [element[0] for element in parse_output if int(element[2]) == numa_node] + + +def create_user(username, additional_params=None): + command = "useradd " + if additional_params: + command += "".join([f"-{p} " for p in additional_params]) + command += username + return TestRun.executor.run_expect_success(command) + + +def check_if_user_exists(username): + return TestRun.executor.run(f"id {username}").exit_code == 0