From a110e483e8644ab73e69853ea11b6c4c6cfa04b6 Mon Sep 17 00:00:00 2001 From: Ryan Harper Date: Wed, 6 Dec 2017 16:30:22 -0600 Subject: pylint: Update pylint to 1.7.1, run on tests/ and tools and fix complaints. The motivation for this is that a.) 1.7.1 runs with python 3.6 (bionic) b.) we want to run pylint on tests/ and tools for the same reasons that we want to run it on cloudinit/ The changes are described below. - Update tox.ini to invoke pylint v1.7.1. - Modify .pylintrc generated-members ignore mocked object members (m_.*) - Replace "dangerous" params defaulting to {} - Fix up cloud_tests use of platforms - Cast some instance objects to with dict() - Handle python2.7 vs 3+ ConfigParser use of readfp (deprecated) - Update use of assertEqual(, value) to assert(value) - replace depricated assertRegexp -> assertRegex - Remove useless test-class calls to super class - Assign class property accessors a result and use it - Fix missing class member in CepkoResultTests - Fix Cheetah test import --- tests/unittests/test_distros/test_create_users.py | 7 +++++-- tests/unittests/test_distros/test_netconfig.py | 3 --- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tests/unittests/test_distros') 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..8d0b2634 100644 --- a/tests/unittests/test_distros/test_netconfig.py +++ b/tests/unittests/test_distros/test_netconfig.py @@ -188,9 +188,6 @@ hn0: flags=8843 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 -- cgit v1.2.3 From 25ddc98e8dcd37272825f7044cf4487e3ade126b Mon Sep 17 00:00:00 2001 From: Robert Schweikert Date: Wed, 15 Nov 2017 16:03:24 -0500 Subject: SUSE: Add a basic test of network config rendering. This simply increases test coverage in rendering of network config for SUSE and SLES. --- tests/unittests/test_distros/test_netconfig.py | 49 ++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'tests/unittests/test_distros') 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 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 -- cgit v1.2.3