Extract the dbus based interactions with dnsmasq so that it can be mocked in tests.
Signed-off-by: Stefan Lendl <s.le...@proxmox.com> Reviewed-by: Max Carrara <m.carr...@proxmox.com> Tested-by: Max Carrara <m.carr...@proxmox.com> --- src/PVE/Network/SDN/Dhcp/Dnsmasq.pm | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm index 5a227ba..c14f5d7 100644 --- a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm +++ b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm @@ -38,6 +38,17 @@ sub ethers_file { return "$DNSMASQ_CONFIG_ROOT/$dhcpid/ethers"; } +sub update_lease { + my ($dhcpid, $ip4, $mac) = @_; + #update lease as ip could still be associated to an old removed mac + my $bus = Net::DBus->system(); + my $dnsmasq = $bus->get_service("uk.org.thekelleys.dnsmasq.$dhcpid"); + my $manager = $dnsmasq->get_object("/uk/org/thekelleys/dnsmasq","uk.org.thekelleys.dnsmasq.$dhcpid"); + + my @hostname = unpack("C*", "*"); + $manager->AddDhcpLease($ip4, $mac, \@hostname, undef, 0, 0, 0) if $ip4; +} + sub add_ip_mapping { my ($class, $dhcpid, $macdb, $mac, $ip4, $ip6) = @_; @@ -107,16 +118,7 @@ sub add_ip_mapping { my $service_name = "dnsmasq\@$dhcpid"; systemctl_service('reload', $service_name) if $reload; - - #update lease as ip could still be associated to an old removed mac - my $bus = Net::DBus->system(); - my $dnsmasq = $bus->get_service("uk.org.thekelleys.dnsmasq.$dhcpid"); - my $manager = $dnsmasq->get_object("/uk/org/thekelleys/dnsmasq","uk.org.thekelleys.dnsmasq.$dhcpid"); - - my @hostname = unpack("C*", "*"); - $manager->AddDhcpLease($ip4, $mac, \@hostname, undef, 0, 0, 0) if $ip4; -# $manager->AddDhcpLease($ip6, $mac, \@hostname, undef, 0, 0, 0) if $ip6; - + update_lease($dhcpid, $ip4, $mac); } sub configure_subnet { -- 2.44.0 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel