Skip to content

Commit

Permalink
Alpine: fix location of dhclient leases file (#4782)
Browse files Browse the repository at this point in the history
PR #4683 changes missed Alpine. This PR addresses this.
  • Loading branch information
dermotbradley authored Jan 17, 2024
1 parent 034a5cd commit 5b6d08d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cloudinit/distros/alpine.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class Distro(distros.Distro):
renderer_configs = {
"eni": {"eni_path": network_conf_fn, "eni_header": NETWORK_FILE_HEADER}
}
# Alpine stores dhclient leases at following location:
# /var/lib/dhcp/dhclient.leases
dhclient_lease_directory = "/var/lib/dhcp"
dhclient_lease_file_regex = r"dhclient\.leases"

def __init__(self, name, cfg, paths):
distros.Distro.__init__(self, name, cfg, paths)
Expand Down
24 changes: 23 additions & 1 deletion tests/unittests/net/test_dhcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest
import responses

from cloudinit.distros import amazon, centos, debian, freebsd, rhel
from cloudinit.distros import alpine, amazon, centos, debian, freebsd, rhel
from cloudinit.net.dhcp import (
DHCLIENT_FALLBACK_LEASE_DIR,
InvalidDHCPLeaseFileError,
Expand Down Expand Up @@ -1206,6 +1206,28 @@ def test_get_latest_lease_freebsd(self, *_):
),
)

@mock.patch(
"os.listdir",
return_value=(
"some_file",
# alpine style lease file
"dhclient.leases",
"some_other_file",
),
)
@mock.patch("os.path.getmtime", return_value=123.45)
def test_get_latest_lease_alpine(self, *_):
"""
Test that an alpine style lease has been found
"""
self.assertEqual(
"/var/lib/dhcp/dhclient.leases",
IscDhclient.get_latest_lease(
alpine.Distro.dhclient_lease_directory,
alpine.Distro.dhclient_lease_file_regex,
),
)

@mock.patch(
"os.listdir",
return_value=(
Expand Down

0 comments on commit 5b6d08d

Please sign in to comment.