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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
import logging
def host_has_package_installed(ctx, package=None):
assert_eq = globals()["assert_eq"]
qemu = ctx["qemu"]
output, exit = qemu.ssh(["dpkg", "--status", package])
assert_eq(exit, 0)
installed = False
for line in output.decode("UTF8").splitlines():
if line.startswith("Status:") and " installed" in line:
installed = True
break
assert installed
def host_directory_is_empty(ctx, pathname=None):
assert_eq = globals()["assert_eq"]
qemu = ctx["qemu"]
output, exit = qemu.ssh(["find", "/etc/apt/sources.list.d"])
assert_eq(exit, 0)
for line in output.decode("UTF8").splitlines():
assert "/etc/apt/sources.list.d/" not in line
def host_hostname_is(ctx, hostname=None):
assert_eq = globals()["assert_eq"]
qemu = ctx["qemu"]
output, exit = qemu.ssh(["hostname"])
assert_eq(exit, 0)
actual = output.decode("UTF8").splitlines()[-1]
assert_eq(actual, hostname)
def host_hostname_has_address(ctx, hostname=None, addr=None):
assert_eq = globals()["assert_eq"]
logging.debug(f"host_hostname_has_address:")
qemu = ctx["qemu"]
output, exit = qemu.ssh(["cat", "/etc/hosts"])
assert_eq(exit, 0)
logging.debug(f" /etc/hosts: {output!r}")
actual = output.decode("UTF8")
logging.debug(f" /etc/hosts: {actual!r}")
wordlines = [line.split() for line in actual.splitlines()]
matches = [words for words in wordlines if len(words) == 2 and words[1] == hostname]
logging.debug(f" matches: {matches!r}")
assert_eq(matches, [[addr, hostname]])
|