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_net.py | |
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_net.py')
-rw-r--r-- | tests/unittests/test_net.py | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py index 094450b4..57edc89a 100644 --- a/tests/unittests/test_net.py +++ b/tests/unittests/test_net.py @@ -5373,21 +5373,20 @@ class TestNetRenderers(CiTestCase): priority=['sysconfig', 'eni']) @mock.patch("cloudinit.net.sysconfig.available_sysconfig") - @mock.patch("cloudinit.util.get_linux_distro") - def test_sysconfig_available_uses_variant_mapping(self, m_distro, m_avail): + @mock.patch("cloudinit.util.system_info") + def test_sysconfig_available_uses_variant_mapping(self, m_info, m_avail): m_avail.return_value = True - distro_values = [ - ('opensuse', '', ''), - ('opensuse-leap', '', ''), - ('opensuse-tumbleweed', '', ''), - ('sles', '', ''), - ('centos', '', ''), - ('eurolinux', '', ''), - ('fedora', '', ''), - ('redhat', '', ''), + variants = [ + 'suse', + 'centos', + 'eurolinux', + 'fedora', + 'rhel', ] - for (distro_name, distro_version, flavor) in distro_values: - m_distro.return_value = (distro_name, distro_version, flavor) + for distro_name in variants: + m_info.return_value = { + "variant": distro_name + } if hasattr(util.system_info, "cache_clear"): util.system_info.cache_clear() result = sysconfig.available() |