1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
import logging
def host_does_not_have_user(ctx, username=None):
assert_ne = globals()["assert_ne"]
qemu = ctx["qemu"]
output, exit = qemu.ssh(["getent", "passwd", username])
assert_ne(exit, 0)
def host_has_user(ctx, username=None):
assert_eq = globals()["assert_eq"]
qemu = ctx["qemu"]
output, exit = qemu.ssh(["getent", "passwd", username])
assert_eq(exit, 0)
output = output.decode("UTF8")
assert f"\n{username}:" in output
def host_user_has_shell(ctx, username=None, shell=None):
assert_eq = globals()["assert_eq"]
qemu = ctx["qemu"]
output, exit = qemu.ssh(["getent", "passwd", username])
assert_eq(exit, 0)
for line in output.decode("UTF8").splitlines():
if line.startswith(f"{username}:"):
logging.debug(f"host_user_has_shell: line={line!r}")
assert line.endswith(f":{shell}")
|