From 0467496724b8875a5ba5fa95d07740aa51f6c780 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 8 Nov 2020 09:32:29 +0200 Subject: feat(unix_users): allow a user to be added to extra groups --- roles/unix_users/subplot.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'roles/unix_users/subplot.py') diff --git a/roles/unix_users/subplot.py b/roles/unix_users/subplot.py index 7bf921d..05330fd 100644 --- a/roles/unix_users/subplot.py +++ b/roles/unix_users/subplot.py @@ -14,7 +14,7 @@ def host_has_user(ctx, username=None): output, exit = qemu.ssh(["getent", "passwd", username]) assert_eq(exit, 0) output = output.decode("UTF8") - assert f"\n{username}:" in output + assert f"{username}:" in output def host_user_has_shell(ctx, username=None, shell=None): @@ -46,3 +46,14 @@ def host_user_has_authorized_keys_containing(ctx, username=None, substring=None) assert_eq(exit, 0) output = output.decode("UTF8") assert substring in output + + +def host_user_is_in_group(ctx, username=None, group=None): + assert_eq = globals()["assert_eq"] + qemu = ctx["qemu"] + output, exit = qemu.ssh(["sudo", "-u", username, "groups"]) + assert_eq(exit, 0) + output = output.decode("UTF8") + groups = output.split() + logging.debug(f"host_user_is_in_group: groups={groups}") + assert group in groups -- cgit v1.2.1