summaryrefslogtreecommitdiff
path: root/tests/unittests/test_datasource/test_gce.py
diff options
context:
space:
mode:
authorJames Falcon <james.falcon@canonical.com>2021-12-02 08:51:26 -0600
committerGitHub <noreply@github.com>2021-12-02 08:51:26 -0600
commitcf38c2cbc5875813fbb9858f45e5b95789b7ffea (patch)
treec345dc97de1c17488fe6c27697f48f0febae6de6 /tests/unittests/test_datasource/test_gce.py
parenta1cf55e5e6331b9b3a4f9ceb412dd14c78abb5ea (diff)
downloadvyos-cloud-init-cf38c2cbc5875813fbb9858f45e5b95789b7ffea.tar.gz
vyos-cloud-init-cf38c2cbc5875813fbb9858f45e5b95789b7ffea.zip
Move GCE metadata fetch to init-local (SC-502) (#1122)
GCE currently fetches metadata after network has come up. There's no reason we can't fetch at init-local time, so update GCE to fetch at init-local time to be more performant and consistent with other datasources.
Diffstat (limited to 'tests/unittests/test_datasource/test_gce.py')
-rw-r--r--tests/unittests/test_datasource/test_gce.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/unittests/test_datasource/test_gce.py b/tests/unittests/test_datasource/test_gce.py
index 80b38f9e..1d91b301 100644
--- a/tests/unittests/test_datasource/test_gce.py
+++ b/tests/unittests/test_datasource/test_gce.py
@@ -360,5 +360,29 @@ class TestDataSourceGCE(test_helpers.HttprettyTestCase):
self.ds.publish_host_keys(hostkeys)
m_readurl.assert_has_calls(readurl_expected_calls, any_order=True)
+ @mock.patch(
+ "cloudinit.sources.DataSourceGCE.EphemeralDHCPv4",
+ autospec=True,
+ )
+ @mock.patch(
+ "cloudinit.sources.DataSourceGCE.DataSourceGCELocal.fallback_interface"
+ )
+ def test_local_datasource_uses_ephemeral_dhcp(self, _m_fallback, m_dhcp):
+ _set_mock_metadata()
+ ds = DataSourceGCE.DataSourceGCELocal(
+ sys_cfg={}, distro=None, paths=None
+ )
+ ds._get_data()
+ assert m_dhcp.call_count == 1
+
+ @mock.patch(
+ "cloudinit.sources.DataSourceGCE.EphemeralDHCPv4",
+ autospec=True,
+ )
+ def test_datasource_doesnt_use_ephemeral_dhcp(self, m_dhcp):
+ _set_mock_metadata()
+ ds = DataSourceGCE.DataSourceGCE(sys_cfg={}, distro=None, paths=None)
+ ds._get_data()
+ assert m_dhcp.call_count == 0
# vi: ts=4 expandtab