forked from osism/ansible-collection-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhostname.py
32 lines (23 loc) · 1.04 KB
/
hostname.py
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
from .util.util import get_ansible, get_variable
testinfra_runner, testinfra_hosts = get_ansible()
def test_hostname(host):
# Fetch system's hostname using the 'hostname' command
system_hostname = host.check_output("hostname")
expected_hostname = None
if get_variable(host, "hostname_use_fqdn"):
expected_hostname = get_variable(host, "inventory_hostname")
else:
expected_hostname = get_variable(host, "inventory_hostname").split(".")[0]
assert system_hostname == expected_hostname
def test_hostname_settings(host):
etc_hostname = host.file("/etc/hostname")
assert etc_hostname.exists
assert etc_hostname.user == "root"
assert etc_hostname.group == "root"
assert etc_hostname.mode == 0o644
expected_hostname = None
if get_variable(host, "hostname_use_fqdn"):
expected_hostname = get_variable(host, "inventory_hostname")
else:
expected_hostname = get_variable(host, "inventory_hostname").split(".")[0]
assert etc_hostname.content_string.strip() == expected_hostname