blob: 2bfa403d0afc59195a917e3cf2f2b56401d55c66 (
plain)
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
|
"""Integration test for the set_hostname module.
This module specify two tests: One updates only the hostname and the other
one updates the hostname and fqdn of the system. For both of these tests
we will check is the changes requested by the user data are being respected
after the system is boot.
(This is ported from
``tests/cloud_tests/testcases/modules/set_hostname.yaml`` and
``tests/cloud_tests/testcases/modules/set_hostname_fqdn.yaml``.)"""
import pytest
USER_DATA_HOSTNAME = """\
#cloud-config
hostname: cloudinit2
"""
USER_DATA_FQDN = """\
#cloud-config
manage_etc_hosts: true
hostname: cloudinit1
fqdn: cloudinit2.i9n.cloud-init.io
"""
@pytest.mark.ci
class TestHostname:
@pytest.mark.user_data(USER_DATA_HOSTNAME)
def test_hostname(self, client):
hostname_output = client.execute("hostname")
assert "cloudinit2" in hostname_output.strip()
@pytest.mark.user_data(USER_DATA_FQDN)
def test_hostname_and_fqdn(self, client):
hostname_output = client.execute("hostname")
assert "cloudinit1" in hostname_output.strip()
fqdn_output = client.execute("hostname --fqdn")
assert "cloudinit2.i9n.cloud-init.io" in fqdn_output.strip()
host_output = client.execute("grep ^127 /etc/hosts")
assert '127.0.1.1 {} {}'.format(
fqdn_output, hostname_output) in host_output
assert '127.0.0.1 localhost' in host_output
|