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

fix(azure): handle unexpected exceptions during obtain_lease() #6092

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions cloudinit/sources/DataSourceAzure.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,12 @@ def _setup_ephemeral_networking(
),
host_only=True,
)
except FileNotFoundError as error:
report_diagnostic_event(
"File not found during DHCP %r" % error,
logger_func=LOG.error,
)
raise error
except subp.ProcessExecutionError as error:
# udevadm settle, ip link set dev eth0 up, etc.
report_diagnostic_event(
Expand Down
19 changes: 19 additions & 0 deletions tests/unittests/sources/test_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3424,6 +3424,25 @@ def test_basic_setup_without_wireserver_opt(
assert azure_ds._wireserver_endpoint == "168.63.129.16"
assert azure_ds._ephemeral_dhcp_ctx.iface == lease["interface"]

def test_no_retry_missing_driver(
self,
azure_ds,
caplog,
mock_ephemeral_dhcp_v4
):
mock_ephemeral_dhcp_v4.return_value.obtain_lease.side_effect = [
FileNotFoundError
]

with pytest.raises(FileNotFoundError):
azure_ds._setup_ephemeral_networking()

assert (
mock_ephemeral_dhcp_v4.return_value.mock_calls
== [mock.call.obtain_lease()]
)
assert "File not found during DHCP" in caplog.text

def test_no_retry_missing_dhclient_error(
self,
azure_ds,
Expand Down
Loading