diff options
author | Igor Galić <me+github@igalic.co> | 2019-11-25 23:10:50 +0100 |
---|---|---|
committer | Chad Smith <chad.smith@canonical.com> | 2019-11-25 15:10:50 -0700 |
commit | 2a135c4a421af47f5bd511e89e385a72f62bde33 (patch) | |
tree | 9abda1673b01fa4838874adb3a8551282552d984 /tests | |
parent | aa935aefd2a01e792a397a28a915f0e029aeaed6 (diff) | |
download | vyos-cloud-init-2a135c4a421af47f5bd511e89e385a72f62bde33.tar.gz vyos-cloud-init-2a135c4a421af47f5bd511e89e385a72f62bde33.zip |
FreeBSD: fix for get_linux_distro() and lru_cache (#59)
Since `is_FreeBSD()` is used a lot, which uses `system_info()`, which uses `get_linux_distro()` we add caching, by decorating the following functions with `@lru_cache`:
- get_architecture()
- _lsb_release()
- is_FreeBSD
- get_linux_distro
- system_info()
- _get_cmdline()
Since [functools](https://docs.python.org/3/library/functools.html) only exists in Python 3, only python 3 will benefit from this improvement. For python 2, our shim is just a pass-thru. Too bad, but, also… https://pythonclock.org/
The main motivation here was, at first, to cache more, following the style of _lsb_release.
That is now consolidated under this very same roof.
LP: #1815030
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unittests/test_net.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py index 0f45dc38..01119e0a 100644 --- a/tests/unittests/test_net.py +++ b/tests/unittests/test_net.py @@ -4576,6 +4576,7 @@ class TestNetRenderers(CiTestCase): priority=['sysconfig', 'eni']) @mock.patch("cloudinit.net.renderers.netplan.available") + @mock.patch("cloudinit.net.renderers.sysconfig.available") @mock.patch("cloudinit.net.renderers.sysconfig.available_sysconfig") @mock.patch("cloudinit.net.renderers.sysconfig.available_nm") @mock.patch("cloudinit.net.renderers.eni.available") @@ -4583,14 +4584,16 @@ class TestNetRenderers(CiTestCase): def test_sysconfig_selected_on_sysconfig_enabled_distros(self, m_distro, m_eni, m_sys_nm, m_sys_scfg, + m_sys_avail, m_netplan): """sysconfig only selected on specific distros (rhel/sles).""" # Ubuntu with Network-Manager installed - m_eni.return_value = False # no ifupdown (ifquery) - m_sys_scfg.return_value = False # no sysconfig/ifup/ifdown - m_sys_nm.return_value = True # network-manager is installed - m_netplan.return_value = True # netplan is installed + m_eni.return_value = False # no ifupdown (ifquery) + m_sys_scfg.return_value = False # no sysconfig/ifup/ifdown + m_sys_nm.return_value = True # network-manager is installed + m_netplan.return_value = True # netplan is installed + m_sys_avail.return_value = False # no sysconfig on Ubuntu m_distro.return_value = ('ubuntu', None, None) self.assertEqual('netplan', renderers.select(priority=None)[0]) @@ -4598,7 +4601,8 @@ class TestNetRenderers(CiTestCase): m_eni.return_value = False # no ifupdown (ifquery) m_sys_scfg.return_value = False # no sysconfig/ifup/ifdown m_sys_nm.return_value = True # network-manager is installed - m_netplan.return_value = False # netplan is not installed + m_netplan.return_value = False # netplan is not installed + m_sys_avail.return_value = True # sysconfig is available on centos m_distro.return_value = ('centos', None, None) self.assertEqual('sysconfig', renderers.select(priority=None)[0]) @@ -4606,7 +4610,8 @@ class TestNetRenderers(CiTestCase): m_eni.return_value = False # no ifupdown (ifquery) m_sys_scfg.return_value = False # no sysconfig/ifup/ifdown m_sys_nm.return_value = True # network-manager is installed - m_netplan.return_value = False # netplan is not installed + m_netplan.return_value = False # netplan is not installed + m_sys_avail.return_value = True # sysconfig is available on opensuse m_distro.return_value = ('opensuse', None, None) self.assertEqual('sysconfig', renderers.select(priority=None)[0]) @@ -4625,6 +4630,8 @@ class TestNetRenderers(CiTestCase): ] for (distro_name, distro_version, flavor) in distro_values: m_distro.return_value = (distro_name, distro_version, flavor) + if hasattr(util.system_info, "cache_clear"): + util.system_info.cache_clear() result = sysconfig.available() self.assertTrue(result) |