From 0ae8b2f5d1fda34f1efa50de8defd127a7907576 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Fri, 8 Aug 2014 19:18:42 +0000 Subject: merge: These are the changes from the freebsd-static-networking branch. --- tests/unittests/test_distros/test_netconfig.py | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'tests') diff --git a/tests/unittests/test_distros/test_netconfig.py b/tests/unittests/test_distros/test_netconfig.py index 9763b14b..96379025 100644 --- a/tests/unittests/test_distros/test_netconfig.py +++ b/tests/unittests/test_distros/test_netconfig.py @@ -173,3 +173,39 @@ NETWORKING=yes ''' self.assertCfgEquals(expected_buf, str(write_buf)) self.assertEquals(write_buf.mode, 0644) + + def test_simple_write_freebsd(self): + fbsd_distro = self._get_distro('freebsd') + util_mock = self.mocker.replace(util.write_file, + spec=False, passthrough=False) + exists_mock = self.mocker.replace(os.path.isfile, + spec=False, passthrough=False) + + exists_mock(mocker.ARGS) + self.mocker.count(0, None) + self.mocker.result(False) + + write_bufs = {} + + def replace_write(filename, content, mode=0644, omode="wb"): + buf = WriteBuffer() + buf.mode = mode + buf.omode = omode + buf.write(content) + write_bufs[filename] = buf + + util_mock(mocker.ARGS) + self.mocker.call(replace_write) + self.mocker.replay() + fbsd_distro.apply_network(BASE_NET_CFG, False) + + self.assertIn('/etc/rc.conf', write_bufs) + write_buf = write_bufs['/etc/rc.conf'] + expected_buf = ''' +ifconfig_eth0="192.168.1.5 netmask 255.255.255.0" +ifconfig_eth1="DHCP" +defaultrouter="192.168.1.254" +''' + self.assertCfgEquals(expected_buf, str(write_buf)) + self.assertEquals(write_buf.mode, 0644) + -- cgit v1.2.3 From 5fbdb88b843bfa3b5fb2c454219779b9889cf787 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Thu, 28 Aug 2014 17:50:24 +0000 Subject: fix: Make sure this freebsd test succeeds on all platforms (harlowja). --- tests/unittests/test_distros/test_netconfig.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests') diff --git a/tests/unittests/test_distros/test_netconfig.py b/tests/unittests/test_distros/test_netconfig.py index 96379025..ed997a1d 100644 --- a/tests/unittests/test_distros/test_netconfig.py +++ b/tests/unittests/test_distros/test_netconfig.py @@ -180,12 +180,17 @@ NETWORKING=yes spec=False, passthrough=False) exists_mock = self.mocker.replace(os.path.isfile, spec=False, passthrough=False) + load_mock = self.mocker.replace(util.load_file, + spec=False, passthrough=False) exists_mock(mocker.ARGS) self.mocker.count(0, None) self.mocker.result(False) write_bufs = {} + read_bufs = { + '/etc/rc.conf': '', + } def replace_write(filename, content, mode=0644, omode="wb"): buf = WriteBuffer() @@ -194,8 +199,24 @@ NETWORKING=yes buf.write(content) write_bufs[filename] = buf + def replace_read(fname, read_cb=None, quiet=False): + if fname not in read_bufs: + if fname in write_bufs: + return str(write_bufs[fname]) + raise IOError("%s not found" % fname) + else: + if fname in write_bufs: + return str(write_bufs[fname]) + return read_bufs[fname] + util_mock(mocker.ARGS) self.mocker.call(replace_write) + self.mocker.count(0, None) + + load_mock(mocker.ARGS) + self.mocker.call(replace_read) + self.mocker.count(0, None) + self.mocker.replay() fbsd_distro.apply_network(BASE_NET_CFG, False) -- cgit v1.2.3