summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRobert Schweikert <rjschwei@suse.com>2017-11-15 16:03:24 -0500
committerScott Moser <smoser@ubuntu.com>2017-12-20 21:37:02 -0500
commit25ddc98e8dcd37272825f7044cf4487e3ade126b (patch)
tree80ed70c69338742be4e0ee696828595bd9b3ab3b /tests
parentb05b9972d20ec3ea699d1691b67314d04e852d2f (diff)
downloadvyos-cloud-init-25ddc98e8dcd37272825f7044cf4487e3ade126b.tar.gz
vyos-cloud-init-25ddc98e8dcd37272825f7044cf4487e3ade126b.zip
SUSE: Add a basic test of network config rendering.
This simply increases test coverage in rendering of network config for SUSE and SLES.
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/test_distros/test_netconfig.py49
1 files changed, 46 insertions, 3 deletions
diff --git a/tests/unittests/test_distros/test_netconfig.py b/tests/unittests/test_distros/test_netconfig.py
index 8d0b2634..1c2e45fe 100644
--- a/tests/unittests/test_distros/test_netconfig.py
+++ b/tests/unittests/test_distros/test_netconfig.py
@@ -2,6 +2,8 @@
import os
from six import StringIO
+import stat
+from textwrap import dedent
try:
from unittest import mock
@@ -12,13 +14,12 @@ try:
except ImportError:
from contextlib2 import ExitStack
-from cloudinit.tests.helpers import TestCase
-
from cloudinit import distros
from cloudinit.distros.parsers.sys_conf import SysConf
from cloudinit import helpers
from cloudinit.net import eni
from cloudinit import settings
+from cloudinit.tests.helpers import FilesystemMockingTestCase
from cloudinit import util
@@ -175,7 +176,7 @@ class WriteBuffer(object):
return self.buffer.getvalue()
-class TestNetCfgDistro(TestCase):
+class TestNetCfgDistro(FilesystemMockingTestCase):
frbsd_ifout = """\
hn0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
@@ -771,4 +772,46 @@ ifconfig_vtnet0="DHCP"
self.assertCfgEquals(expected_buf, str(write_buf))
self.assertEqual(write_buf.mode, 0o644)
+ def test_simple_write_opensuse(self):
+ """Opensuse network rendering writes appropriate sysconfg files."""
+ tmpdir = self.tmp_dir()
+ self.patchOS(tmpdir)
+ self.patchUtils(tmpdir)
+ distro = self._get_distro('opensuse')
+
+ distro.apply_network(BASE_NET_CFG, False)
+
+ lo_path = os.path.join(tmpdir, 'etc/sysconfig/network/ifcfg-lo')
+ eth0_path = os.path.join(tmpdir, 'etc/sysconfig/network/ifcfg-eth0')
+ eth1_path = os.path.join(tmpdir, 'etc/sysconfig/network/ifcfg-eth1')
+ expected_cfgs = {
+ lo_path: dedent('''
+ STARTMODE="auto"
+ USERCONTROL="no"
+ FIREWALL="no"
+ '''),
+ eth0_path: dedent('''
+ BOOTPROTO="static"
+ BROADCAST="192.168.1.0"
+ GATEWAY="192.168.1.254"
+ IPADDR="192.168.1.5"
+ NETMASK="255.255.255.0"
+ STARTMODE="auto"
+ USERCONTROL="no"
+ ETHTOOL_OPTIONS=""
+ '''),
+ eth1_path: dedent('''
+ BOOTPROTO="dhcp"
+ STARTMODE="auto"
+ USERCONTROL="no"
+ ETHTOOL_OPTIONS=""
+ ''')
+ }
+ for cfgpath in (lo_path, eth0_path, eth1_path):
+ self.assertCfgEquals(
+ expected_cfgs[cfgpath],
+ util.load_file(cfgpath))
+ file_stat = os.stat(cfgpath)
+ self.assertEqual(0o644, stat.S_IMODE(file_stat.st_mode))
+
# vi: ts=4 expandtab