diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py index 81414f92b17..65ed990a483 100755 --- a/cloudinit/sources/DataSourceAzure.py +++ b/cloudinit/sources/DataSourceAzure.py @@ -530,7 +530,7 @@ def crawl_metadata(self): # If we require IMDS metadata, try harder to obtain networking, waiting # for at least 20 minutes. Otherwise only wait 5 minutes. requires_imds_metadata = bool(self._iso_dev) or not ovf_is_accessible - timeout_minutes = 5 if requires_imds_metadata else 20 + timeout_minutes = 20 if requires_imds_metadata else 5 try: self._setup_ephemeral_networking(timeout_minutes=timeout_minutes) except NoDHCPLeaseError: diff --git a/tests/unittests/sources/test_azure.py b/tests/unittests/sources/test_azure.py index 21e2201260e..f9f65c48ce6 100644 --- a/tests/unittests/sources/test_azure.py +++ b/tests/unittests/sources/test_azure.py @@ -49,6 +49,16 @@ def azure_ds(paths): yield dsaz.DataSourceAzure(sys_cfg={}, distro=mock.Mock(), paths=paths) +@pytest.fixture +def mock_wrapping_setup_ephemeral_networking(azure_ds): + with mock.patch.object( + azure_ds, + "_setup_ephemeral_networking", + wraps=azure_ds._setup_ephemeral_networking, + ) as m: + yield m + + @pytest.fixture def mock_azure_helper_readurl(): with mock.patch( @@ -4013,6 +4023,7 @@ def provisioning_setup( mock_util_load_file, mock_util_mount_cb, mock_util_write_file, + mock_wrapping_setup_ephemeral_networking, ): self.azure_ds = azure_ds self.mock_azure_get_metadata_from_fabric = ( @@ -4039,6 +4050,9 @@ def provisioning_setup( self.mock_util_load_file = mock_util_load_file self.mock_util_mount_cb = mock_util_mount_cb self.mock_util_write_file = mock_util_write_file + self.mock_wrapping_setup_ephemeral_networking = ( + mock_wrapping_setup_ephemeral_networking + ) self.imds_md = { "extended": {"compute": {"ppsType": "None"}}, @@ -4095,6 +4109,9 @@ def test_no_pps(self): ] # Verify DHCP is setup once. + assert self.mock_wrapping_setup_ephemeral_networking.mock_calls == [ + mock.call(timeout_minutes=20) + ] assert self.mock_net_dhcp_maybe_perform_dhcp_discovery.mock_calls == [ mock.call(None, dsaz.dhcp_log_cb) ] @@ -4182,6 +4199,10 @@ def test_running_pps(self): ] # Verify DHCP is setup twice. + assert self.mock_wrapping_setup_ephemeral_networking.mock_calls == [ + mock.call(timeout_minutes=20), + mock.call(timeout_minutes=5), + ] assert self.mock_net_dhcp_maybe_perform_dhcp_discovery.mock_calls == [ mock.call(None, dsaz.dhcp_log_cb), mock.call(None, dsaz.dhcp_log_cb), @@ -4301,6 +4322,10 @@ def test_savable_pps(self): ] # Verify DHCP is setup twice. + assert self.mock_wrapping_setup_ephemeral_networking.mock_calls == [ + mock.call(timeout_minutes=20), + mock.call(iface="ethAttached1", timeout_minutes=20), + ] assert self.mock_net_dhcp_maybe_perform_dhcp_discovery.mock_calls == [ mock.call(None, dsaz.dhcp_log_cb), mock.call("ethAttached1", dsaz.dhcp_log_cb),