Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sources/azure: fix provisioning dhcp timeout to 20 minutes #1394

Merged
merged 1 commit into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cloudinit/sources/DataSourceAzure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
25 changes: 25 additions & 0 deletions tests/unittests/sources/test_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 = (
Expand All @@ -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"}},
Expand Down Expand Up @@ -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)
]
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down