Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
holmanb committed Apr 2, 2024
1 parent aec9035 commit 0ef7ea8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
9 changes: 8 additions & 1 deletion cloudinit/net/dhcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,15 @@ def parse_dhcpcd_lease(lease_dump: str, interface: str) -> Dict:
if "=" in a
]
)
if not lease:
msg = (
"No valid DHCP lease configuration "
"found in dhcpcd lease: %r"
)
LOG.error(msg, lease_dump)
raise InvalidDHCPLeaseFileError(msg % lease_dump)
except ValueError as error:
LOG.error("Error parsing dhcpcd lease: %r", error)
LOG.error("Error parsing dhcpcd lease: %r", lease_dump)
raise InvalidDHCPLeaseFileError from error

# this is expected by cloud-init's code
Expand Down
17 changes: 10 additions & 7 deletions tests/unittests/net/test_dhcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,13 +1202,6 @@ def test_parse_lease_dump(self):
@pytest.mark.parametrize(
"lease, parsed",
(
pytest.param(
"""
fail
""",
{},
id="lease_has_no_keys",
),
pytest.param(
"""
Expand Down Expand Up @@ -1250,6 +1243,7 @@ def test_parse_lease_dump_resilience(self, lease, parsed):
with mock.patch("cloudinit.net.dhcp.util.load_binary_file"):
Dhcpcd.parse_dhcpcd_lease(dedent(lease), "eth0")


def test_parse_lease_dump_fails(self):
def _raise():
raise ValueError()
Expand All @@ -1261,6 +1255,15 @@ def _raise():
with mock.patch("cloudinit.net.dhcp.util.load_binary_file"):
Dhcpcd.parse_dhcpcd_lease(lease, "eth0")

with pytest.raises(InvalidDHCPLeaseFileError):
with mock.patch("cloudinit.net.dhcp.util.load_binary_file"):
lease = dedent(
"""
fail
"""
)
Dhcpcd.parse_dhcpcd_lease(lease, "eth0")

@pytest.mark.parametrize(
"lease_file, option_245",
(
Expand Down

0 comments on commit 0ef7ea8

Please sign in to comment.