From b2008bd7a2b3aa373d0e966596d3713acc6f67bb Mon Sep 17 00:00:00 2001 From: Chad Smith Date: Fri, 21 Jul 2023 21:41:52 +0000 Subject: [PATCH] tests: avoid leaks into host system checking of ovs-vsctl cmd Mock out the `which` checks for presence of ovs-vsctl cmd on system. This prevents test leaks which eventually call subp ovs-vsctl commands. --- tests/unittests/test_net.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py index edf8c4382ff..f0663481393 100644 --- a/tests/unittests/test_net.py +++ b/tests/unittests/test_net.py @@ -4291,11 +4291,16 @@ def test_device_driver_v2( } self.assertEqual(expected, network_cfg) + @mock.patch("cloudinit.net.openvswitch_is_installed", return_value=False) @mock.patch("cloudinit.net.sys_dev_path") @mock.patch("cloudinit.net.read_sys_net") @mock.patch("cloudinit.net.get_devicelist") def test_device_driver( - self, mock_get_devicelist, mock_read_sys_net, mock_sys_dev_path + self, + mock_get_devicelist, + mock_read_sys_net, + mock_sys_dev_path, + _ovs_is_installed, ): devices = { "eth0": { @@ -4375,11 +4380,16 @@ def test_device_driver( ] self.assertEqual(", ".join(expected_rule) + "\n", contents.lstrip()) + @mock.patch("cloudinit.net.openvswitch_is_installed", return_value=False) @mock.patch("cloudinit.net.sys_dev_path") @mock.patch("cloudinit.net.read_sys_net") @mock.patch("cloudinit.net.get_devicelist") def test_hv_netvsc_vf_filter( - self, mock_get_devicelist, mock_read_sys_net, mock_sys_dev_path + self, + mock_get_devicelist, + mock_read_sys_net, + mock_sys_dev_path, + _ovs_installed, ): devices = { "eth1": { @@ -6556,6 +6566,7 @@ class TestNetplanNetRendering: ) @mock.patch("cloudinit.net.util.get_cmdline", return_value="root=myroot") @mock.patch("cloudinit.net.netplan._clean_default") + @mock.patch("cloudinit.net.openvswitch_is_installed", return_value=False) @mock.patch("cloudinit.net.sys_dev_path") @mock.patch("cloudinit.net.read_sys_net") @mock.patch("cloudinit.net.get_devicelist") @@ -6564,6 +6575,7 @@ def test_render( mock_get_devicelist, mock_read_sys_net, mock_sys_dev_path, + _openvswitch_is_installed, mock_clean_default, m_get_cmdline, m_renderer_features,