summaryrefslogtreecommitdiff
path: root/tests/unittests/test_datasource/test_azure.py
diff options
context:
space:
mode:
authorJames Falcon <james.falcon@canonical.com>2021-11-22 16:56:41 -0600
committerGitHub <noreply@github.com>2021-11-22 16:56:41 -0600
commit31daf6670aeeba1d452c70bc0d4d04139652be36 (patch)
treee892ab1389fdcd36c77ea985711b09e5d113dcdb /tests/unittests/test_datasource/test_azure.py
parent1343584dc03c50c80eabb8199c4e7d0d6fb4bd56 (diff)
downloadvyos-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_datasource/test_azure.py')
-rw-r--r--tests/unittests/test_datasource/test_azure.py13
1 files changed, 3 insertions, 10 deletions
diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py
index cbc9665d..d0274049 100644
--- a/tests/unittests/test_datasource/test_azure.py
+++ b/tests/unittests/test_datasource/test_azure.py
@@ -1789,9 +1789,8 @@ scbus-1 on xpt0 bus 0
config_driver=True)
@mock.patch(MOCKPATH + 'net.get_interfaces', autospec=True)
- @mock.patch(MOCKPATH + 'util.is_FreeBSD')
def test_blacklist_through_distro(
- self, m_is_freebsd, m_net_get_interfaces):
+ self, m_net_get_interfaces):
"""Verify Azure DS updates blacklist drivers in the distro's
networking object."""
odata = {'HostName': "myhost", 'UserName': "myuser"}
@@ -1805,7 +1804,6 @@ scbus-1 on xpt0 bus 0
self.assertEqual(distro.networking.blacklist_drivers,
dsaz.BLACKLIST_DRIVERS)
- m_is_freebsd.return_value = False
distro.networking.get_interfaces_by_mac()
m_net_get_interfaces.assert_called_with(
blacklist_drivers=dsaz.BLACKLIST_DRIVERS)
@@ -3219,7 +3217,6 @@ class TestPreprovisioningPollIMDS(CiTestCase):
@mock.patch(MOCKPATH + 'DataSourceAzure._report_ready', mock.MagicMock())
@mock.patch(MOCKPATH + 'subp.subp', mock.MagicMock())
@mock.patch(MOCKPATH + 'util.write_file', mock.MagicMock())
-@mock.patch(MOCKPATH + 'util.is_FreeBSD')
@mock.patch('cloudinit.sources.helpers.netlink.'
'wait_for_media_disconnect_connect')
@mock.patch('cloudinit.net.dhcp.EphemeralIPv4Network', autospec=True)
@@ -3236,10 +3233,8 @@ class TestAzureDataSourcePreprovisioning(CiTestCase):
def test_poll_imds_returns_ovf_env(self, m_request,
m_dhcp, m_net,
- m_media_switch,
- m_is_bsd):
+ m_media_switch):
"""The _poll_imds method should return the ovf_env.xml."""
- m_is_bsd.return_value = False
m_media_switch.return_value = None
m_dhcp.return_value = [{
'interface': 'eth9', 'fixed-address': '192.168.2.9',
@@ -3268,10 +3263,8 @@ class TestAzureDataSourcePreprovisioning(CiTestCase):
def test__reprovision_calls__poll_imds(self, m_request,
m_dhcp, m_net,
- m_media_switch,
- m_is_bsd):
+ m_media_switch):
"""The _reprovision method should call poll IMDS."""
- m_is_bsd.return_value = False
m_media_switch.return_value = None
m_dhcp.return_value = [{
'interface': 'eth9', 'fixed-address': '192.168.2.9',