summaryrefslogtreecommitdiff
path: root/tests/unittests/test_distros
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2018-02-02 11:11:36 -0700
committerChad Smith <chad.smith@canonical.com>2018-02-02 11:11:36 -0700
commit78013bc65030421699b5feb66bc8b7a205abfbc0 (patch)
tree2ebf7111129f4aaf8a833ba6d226d4513ed59388 /tests/unittests/test_distros
parent192261fe38a32edbd1f605ba25bbb6f4822a0720 (diff)
parentf7deaf15acf382d62554e2b1d70daa9a9109d542 (diff)
downloadvyos-cloud-init-78013bc65030421699b5feb66bc8b7a205abfbc0.tar.gz
vyos-cloud-init-78013bc65030421699b5feb66bc8b7a205abfbc0.zip
merge from master at 17.2-30-gf7deaf15
Diffstat (limited to 'tests/unittests/test_distros')
-rw-r--r--tests/unittests/test_distros/test_create_users.py7
-rw-r--r--tests/unittests/test_distros/test_netconfig.py52
2 files changed, 51 insertions, 8 deletions
diff --git a/tests/unittests/test_distros/test_create_users.py b/tests/unittests/test_distros/test_create_users.py
index aa13670a..5670904a 100644
--- a/tests/unittests/test_distros/test_create_users.py
+++ b/tests/unittests/test_distros/test_create_users.py
@@ -7,7 +7,11 @@ from cloudinit.tests.helpers import (TestCase, mock)
class MyBaseDistro(distros.Distro):
# MyBaseDistro is here to test base Distro class implementations
- def __init__(self, name="basedistro", cfg={}, paths={}):
+ def __init__(self, name="basedistro", cfg=None, paths=None):
+ if not cfg:
+ cfg = {}
+ if not paths:
+ paths = {}
super(MyBaseDistro, self).__init__(name, cfg, paths)
def install_packages(self, pkglist):
@@ -42,7 +46,6 @@ class MyBaseDistro(distros.Distro):
@mock.patch("cloudinit.distros.util.subp")
class TestCreateUser(TestCase):
def setUp(self):
- super(TestCase, self).setUp()
self.dist = MyBaseDistro()
def _useradd2call(self, args):
diff --git a/tests/unittests/test_distros/test_netconfig.py b/tests/unittests/test_distros/test_netconfig.py
index c4bd11bc..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
@@ -188,9 +189,6 @@ hn0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
status: active
"""
- def setUp(self):
- super(TestNetCfgDistro, self).setUp()
-
def _get_distro(self, dname, renderers=None):
cls = distros.fetch(dname)
cfg = settings.CFG_BUILTIN
@@ -774,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