summaryrefslogtreecommitdiff
path: root/tests/unittests/test_distros/test_arch.py
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2017-07-24 17:18:22 -0400
committerScott Moser <smoser@brickies.net>2017-08-01 12:10:06 -0400
commit512145cd16b0dfa0cbbe8a20d732e6f2d943b869 (patch)
treeeeef845119faf75ba406bd0df9ce0bc8dd8f01ab /tests/unittests/test_distros/test_arch.py
parente586fe35a692b7519000005c8024ebd2bcbc82e0 (diff)
downloadvyos-cloud-init-512145cd16b0dfa0cbbe8a20d732e6f2d943b869.tar.gz
vyos-cloud-init-512145cd16b0dfa0cbbe8a20d732e6f2d943b869.zip
archlinux: Fix bug with empty dns, do not render 'lo' devices.
If no dns nameservers were provided a stack trace would occur. The changes here add some unit tests for the arch distro. Also avoids rendering an 'lo' interface. LP: #1663045 LP: #1706593
Diffstat (limited to 'tests/unittests/test_distros/test_arch.py')
-rw-r--r--tests/unittests/test_distros/test_arch.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/unittests/test_distros/test_arch.py b/tests/unittests/test_distros/test_arch.py
new file mode 100644
index 00000000..3d4c9a70
--- /dev/null
+++ b/tests/unittests/test_distros/test_arch.py
@@ -0,0 +1,45 @@
+# This file is part of cloud-init. See LICENSE file for license information.
+
+from cloudinit.distros.arch import _render_network
+from cloudinit import util
+
+from ..helpers import (CiTestCase, dir2dict)
+
+from . import _get_distro
+
+
+class TestArch(CiTestCase):
+
+ def test_get_distro(self):
+ distro = _get_distro("arch")
+ hostname = "myhostname"
+ hostfile = self.tmp_path("hostfile")
+ distro._write_hostname(hostname, hostfile)
+ self.assertEqual(hostname + "\n", util.load_file(hostfile))
+
+
+class TestRenderNetwork(CiTestCase):
+ def test_basic_static(self):
+ """Just the most basic static config.
+
+ note 'lo' should not be rendered as an interface."""
+ entries = {'eth0': {'auto': True,
+ 'dns-nameservers': ['8.8.8.8'],
+ 'bootproto': 'static',
+ 'address': '10.0.0.2',
+ 'gateway': '10.0.0.1',
+ 'netmask': '255.255.255.0'},
+ 'lo': {'auto': True}}
+ target = self.tmp_dir()
+ devs = _render_network(entries, target=target)
+ files = dir2dict(target, prefix=target)
+ self.assertEqual(['eth0'], devs)
+ self.assertEqual(
+ {'/etc/netctl/eth0': '\n'.join([
+ "Address=10.0.0.2/255.255.255.0",
+ "Connection=ethernet",
+ "DNS=('8.8.8.8')",
+ "Gateway=10.0.0.1",
+ "IP=static",
+ "Interface=eth0", ""]),
+ '/etc/resolv.conf': 'nameserver 8.8.8.8\n'}, files)