diff options
author | James Falcon <james.falcon@canonical.com> | 2021-11-22 16:56:41 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-22 16:56:41 -0600 |
commit | 31daf6670aeeba1d452c70bc0d4d04139652be36 (patch) | |
tree | e892ab1389fdcd36c77ea985711b09e5d113dcdb /tests/unittests/test_distros | |
parent | 1343584dc03c50c80eabb8199c4e7d0d6fb4bd56 (diff) | |
download | vyos-cloud-init-31daf6670aeeba1d452c70bc0d4d04139652be36.tar.gz vyos-cloud-init-31daf6670aeeba1d452c70bc0d4d04139652be36.zip |
testing: monkeypatch system_info call in unit tests (SC-533) (#1117)
testing: monkeypatch system_info call in unit tests
system_info can make calls that read or write from the filesystem, which
should require special mocking. It is also decorated with 'lru_cache',
which means test authors often don't realize they need to be mocking.
Also, we don't actually want the results from the user's local
machine, so monkeypatching it across all tests should be reasonable.
Additionally, moved some of 'system_info` into a helper function to
reduce the surface area of the monkeypatch, added tests for the new
function (and fixed a bug as a result), and removed related mocks that
should be no longer needed.
Diffstat (limited to 'tests/unittests/test_distros')
-rw-r--r-- | tests/unittests/test_distros/test_netconfig.py | 7 | ||||
-rw-r--r-- | tests/unittests/test_distros/test_user_data_normalize.py | 2 |
2 files changed, 4 insertions, 5 deletions
diff --git a/tests/unittests/test_distros/test_netconfig.py b/tests/unittests/test_distros/test_netconfig.py index d09e46af..e4eba179 100644 --- a/tests/unittests/test_distros/test_netconfig.py +++ b/tests/unittests/test_distros/test_netconfig.py @@ -241,8 +241,6 @@ class TestNetCfgDistroBase(FilesystemMockingTestCase): def setUp(self): super(TestNetCfgDistroBase, self).setUp() self.add_patch('cloudinit.util.system_is_snappy', 'm_snappy') - self.add_patch('cloudinit.util.system_info', 'm_sysinfo') - self.m_sysinfo.return_value = {'dist': ('Distro', '99.1', 'Codename')} def _get_distro(self, dname, renderers=None): cls = distros.fetch(dname) @@ -783,7 +781,10 @@ class TestNetCfgDistroArch(TestNetCfgDistroBase): """), } - with mock.patch('cloudinit.util.is_FreeBSD', return_value=False): + with mock.patch( + 'cloudinit.net.netplan.get_devicelist', + return_value=[] + ): self._apply_and_verify(self.distro.apply_network_config, V1_NET_CFG, expected_cfgs=expected_cfgs.copy(), diff --git a/tests/unittests/test_distros/test_user_data_normalize.py b/tests/unittests/test_distros/test_user_data_normalize.py index fa48410a..50c86942 100644 --- a/tests/unittests/test_distros/test_user_data_normalize.py +++ b/tests/unittests/test_distros/test_user_data_normalize.py @@ -26,8 +26,6 @@ class TestUGNormalize(TestCase): def setUp(self): super(TestUGNormalize, self).setUp() self.add_patch('cloudinit.util.system_is_snappy', 'm_snappy') - self.add_patch('cloudinit.util.system_info', 'm_sysinfo') - self.m_sysinfo.return_value = {'dist': ('Distro', '99.1', 'Codename')} def _make_distro(self, dtype, def_user=None): cfg = dict(settings.CFG_BUILTIN) |