summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoshua Harlow <jxharlow@godaddy.com>2016-09-15 14:46:14 -0700
committerScott Moser <smoser@brickies.net>2016-12-02 16:23:38 -0500
commitf6d5dc486776019e0799f95f8d1982be8fba4da5 (patch)
tree63151c94cfc8a3afca15a2aa791a7b952bcbbc48 /tests
parent3ac34f5325edf7f1212cd0b6a3d1cfe2ed45a63b (diff)
downloadvyos-cloud-init-f6d5dc486776019e0799f95f8d1982be8fba4da5.tar.gz
vyos-cloud-init-f6d5dc486776019e0799f95f8d1982be8fba4da5.zip
Replace usage of sys_netdev_info with read_sys_net
I've seen cases of unable to read from files as well as the existing os errors so catch io error and skip by using the smarter read_sys_net instead. LP: #1625766
Diffstat (limited to 'tests')
-rwxr-xr-x[-rw-r--r--]tests/unittests/test_net.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index 780e4ad6..789c78b2 100644..100755
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -445,7 +445,7 @@ pre-down route del -net 10.0.0.0 netmask 255.0.0.0 gw 11.0.0.1 metric 3 || true
}
-def _setup_test(tmp_dir, mock_get_devicelist, mock_sys_netdev_info,
+def _setup_test(tmp_dir, mock_get_devicelist, mock_read_sys_net,
mock_sys_dev_path):
mock_get_devicelist.return_value = ['eth1000']
dev_characteristics = {
@@ -458,10 +458,12 @@ def _setup_test(tmp_dir, mock_get_devicelist, mock_sys_netdev_info,
}
}
- def netdev_info(name, field):
- return dev_characteristics[name][field]
+ def fake_read(devname, path, translate=None,
+ on_enoent=None, on_keyerror=None,
+ on_einval=None):
+ return dev_characteristics[devname][path]
- mock_sys_netdev_info.side_effect = netdev_info
+ mock_read_sys_net.side_effect = fake_read
def sys_dev_path(devname, path=""):
return tmp_dir + devname + "/" + path
@@ -477,15 +479,15 @@ def _setup_test(tmp_dir, mock_get_devicelist, mock_sys_netdev_info,
class TestSysConfigRendering(TestCase):
@mock.patch("cloudinit.net.sys_dev_path")
- @mock.patch("cloudinit.net.sys_netdev_info")
+ @mock.patch("cloudinit.net.read_sys_net")
@mock.patch("cloudinit.net.get_devicelist")
def test_default_generation(self, mock_get_devicelist,
- mock_sys_netdev_info,
+ mock_read_sys_net,
mock_sys_dev_path):
tmp_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, tmp_dir)
_setup_test(tmp_dir, mock_get_devicelist,
- mock_sys_netdev_info, mock_sys_dev_path)
+ mock_read_sys_net, mock_sys_dev_path)
network_cfg = net.generate_fallback_config()
ns = network_state.parse_net_config_data(network_cfg,
@@ -534,15 +536,15 @@ USERCTL=no
class TestEniNetRendering(TestCase):
@mock.patch("cloudinit.net.sys_dev_path")
- @mock.patch("cloudinit.net.sys_netdev_info")
+ @mock.patch("cloudinit.net.read_sys_net")
@mock.patch("cloudinit.net.get_devicelist")
def test_default_generation(self, mock_get_devicelist,
- mock_sys_netdev_info,
+ mock_read_sys_net,
mock_sys_dev_path):
tmp_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, tmp_dir)
_setup_test(tmp_dir, mock_get_devicelist,
- mock_sys_netdev_info, mock_sys_dev_path)
+ mock_read_sys_net, mock_sys_dev_path)
network_cfg = net.generate_fallback_config()
ns = network_state.parse_net_config_data(network_cfg,