Merge ~rjschwei/cloud-init:baseNetConfTestSUSE into cloud-init:master

Proposed by Robert Schweikert on 2017-11-15
Status: Merged
Approved by: Scott Moser on 2017-12-21
Approved revision: 14a7b2e6d1a6ccdd488d1bf0b53fc5903d5e01cb
Merged at revision: 25ddc98e8dcd37272825f7044cf4487e3ade126b
Proposed branch: ~rjschwei/cloud-init:baseNetConfTestSUSE
Merge into: cloud-init:master
Diff against target: 84 lines (+46/-3)
1 file modified
tests/unittests/test_distros/test_netconfig.py (+46/-3)
Reviewer Review Type Date Requested Status
Chad Smith 2017-11-15 Approve on 2017-12-20
Server Team CI bot continuous-integration Approve on 2017-12-09
cloud-init commiters 2017-12-09 Pending
Review via email: mp+333772@code.launchpad.net

Description of the Change

It's a start a basic test for network configuration on openSUSE & SLES

To post a comment you must log in.

FAILED: Continuous integration, rev:8ac72b3d6c9188114685c5e0ecdd84a23faf4dd5
https://jenkins.ubuntu.com/server/job/cloud-init-ci/496/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    FAILED: MAAS Compatability Testing

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/496/rebuild

review: Needs Fixing (continuous-integration)

FAILED: Continuous integration, rev:70a8e1d54ee7b3e4aad085321612e6bc7a723ace
https://jenkins.ubuntu.com/server/job/cloud-init-ci/501/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    FAILED: MAAS Compatability Testing

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/501/rebuild

review: Needs Fixing (continuous-integration)
Chad Smith (chad.smith) wrote :

man those exist stacks are stinking in that file. I would prefer if we could move more to either the wrap_and_call approach for handling multiple mock of FileSystemMockingTestCase with patchOS patchUtil calls

here's a pastebin of your test reworked with FilesystemMockingTestCase
http://paste.ubuntu.com/26142306/

Chad Smith (chad.smith) wrote :

Thanks for this Robert, I marked it work in progress just so it pops back up to top of review queue when you get a chance to look over or respond my patch suggestion. I think longterm we'll do a bit of cleanup of all the nested mocks etc where possible and use eiter FileSystemMockingTestCase or wrap_and_call mocking function.

Please just tick "Needs review' when this branch or discussion is ready for more eyes,

review: Needs Information
Chad Smith (chad.smith) wrote :

Also the Needs Fixing from CI is something that was fixed in master after this branch so a 'git fetch master' 'git rebase master' should fix that too.

Robert Schweikert (rjschwei) wrote :

Thanks Chad, and thanks for re-working the test, it is much nicer now.

PASSED: Continuous integration, rev:14a7b2e6d1a6ccdd488d1bf0b53fc5903d5e01cb
https://jenkins.ubuntu.com/server/job/cloud-init-ci/608/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/608/rebuild

review: Approve (continuous-integration)
Scott Moser (smoser) wrote :

I think if we re-factor the code just a bit we can make this much easier to test.

Heres an example:
  http://paste.ubuntu.com/26164253/

The result then is that we can test 'write_network_from_eni' by simply calling:
 tmpd = self.temp_dir()
 devs = write_network_from_eni("your_eni_blob", target=tmpd)
 self.assertEqual(expected_files_in_tmpd, dir2dict(self.tempd))

There are some comments inline, but I think if you go this route its easier to get
test coverage.

Robert Schweikert (rjschwei) wrote :

Sorry, I think I am missing something in the bigger picture.

My goal was to add a basic test such that network configuration doesn't break again. This is/was intended to be a crutch until we can get openSUSE/SUSE moved to the sysconfig-renderer concept.

It is/was my impression that _write_network() is supposed to go away. Sorry but I am missing the point where using the method as a redirector moves us into the direction where _write_network() gets eliminated. But as I said maybe I am missing the bigger picture and _write_network() will live forever more, in which case I think we should drop the warning that is written to the log file if the code goes down that path.

Anyway, I am somewhat confused.

Scott Moser (smoser) wrote :

Robert,
I'm sorry for the confusion. I was reading this purely "on its own".

I think the re-factor makes it considerably easier to test, and thus is useful even if the point is only getting tests for somethign that will be replaced.

Chad pointed out to me that using the module level defines as defaults for the function call does not really make testing easier as those values not mockable. so consider this paste instead. Chad let me know if I understood you wrong.

 http://paste.ubuntu.com/26166233/

Chad Smith (chad.smith) wrote :

Scott, understood. This refactor makes sense, we can do it either as a part of this branch landing, or you can point me at a trivial followup afterward that we can land right after

Chad Smith (chad.smith) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/tests/unittests/test_distros/test_netconfig.py b/tests/unittests/test_distros/test_netconfig.py
2index 8d0b263..9a62b71 100644
3--- a/tests/unittests/test_distros/test_netconfig.py
4+++ b/tests/unittests/test_distros/test_netconfig.py
5@@ -2,6 +2,8 @@
6
7 import os
8 from six import StringIO
9+import stat
10+from textwrap import dedent
11
12 try:
13 from unittest import mock
14@@ -12,13 +14,12 @@ try:
15 except ImportError:
16 from contextlib2 import ExitStack
17
18-from cloudinit.tests.helpers import TestCase
19-
20 from cloudinit import distros
21 from cloudinit.distros.parsers.sys_conf import SysConf
22 from cloudinit import helpers
23 from cloudinit.net import eni
24 from cloudinit import settings
25+from cloudinit.tests.helpers import FilesystemMockingTestCase
26 from cloudinit import util
27
28
29@@ -175,7 +176,7 @@ class WriteBuffer(object):
30 return self.buffer.getvalue()
31
32
33-class TestNetCfgDistro(TestCase):
34+class TestNetCfgDistro(FilesystemMockingTestCase):
35
36 frbsd_ifout = """\
37 hn0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
38@@ -771,4 +772,46 @@ ifconfig_vtnet0="DHCP"
39 self.assertCfgEquals(expected_buf, str(write_buf))
40 self.assertEqual(write_buf.mode, 0o644)
41
42+ def test_simple_write_oopensuse(self):
43+ """Opensuse network rendering writes appropriate sysconfg files."""
44+ tmpdir = self.tmp_dir()
45+ self.patchOS(tmpdir)
46+ self.patchUtils(tmpdir)
47+ distro = self._get_distro('opensuse')
48+
49+ distro.apply_network(BASE_NET_CFG, False)
50+
51+ lo_path = os.path.join(tmpdir, 'etc/sysconfig/network/ifcfg-lo')
52+ eth0_path = os.path.join(tmpdir, 'etc/sysconfig/network/ifcfg-eth0')
53+ eth1_path = os.path.join(tmpdir, 'etc/sysconfig/network/ifcfg-eth1')
54+ expected_cfgs = {
55+ lo_path: dedent('''
56+ STARTMODE="auto"
57+ USERCONTROL="no"
58+ FIREWALL="no"
59+ '''),
60+ eth0_path: dedent('''
61+ BOOTPROTO="static"
62+ BROADCAST="192.168.1.0"
63+ GATEWAY="192.168.1.254"
64+ IPADDR="192.168.1.5"
65+ NETMASK="255.255.255.0"
66+ STARTMODE="auto"
67+ USERCONTROL="no"
68+ ETHTOOL_OPTIONS=""
69+ '''),
70+ eth1_path: dedent('''
71+ BOOTPROTO="dhcp"
72+ STARTMODE="auto"
73+ USERCONTROL="no"
74+ ETHTOOL_OPTIONS=""
75+ ''')
76+ }
77+ for cfgpath in (lo_path, eth0_path, eth1_path):
78+ self.assertCfgEquals(
79+ expected_cfgs[cfgpath],
80+ util.load_file(cfgpath))
81+ file_stat = os.stat(cfgpath)
82+ self.assertEqual(0o644, stat.S_IMODE(file_stat.st_mode))
83+
84 # vi: ts=4 expandtab

Subscribers

People subscribed via source and target branches