mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-08-03 07:57:00 +00:00
test(dhcp): cover Kea reservation regeneration
(cherry picked from commit 3bc24cf08f)
This commit is contained in:
committed by
github-actions[bot]
parent
1817ef78c9
commit
a7dd708136
@@ -329,6 +329,96 @@ my $deleted = $backend->delete_reservations( $reservation_config, { 'hw-address'
|
||||
is( scalar @$deleted, 1, 'reservation delete returns deleted reservation' );
|
||||
is( scalar @{ $reservation_config->{Dhcp4}{subnet4}[0]{reservations} }, 0, 'reservation is removed from config' );
|
||||
|
||||
my $existing_dhcp4 = {
|
||||
Dhcp4 => {
|
||||
subnet4 => [
|
||||
{
|
||||
id => 1,
|
||||
subnet => '10.20.0.0/24',
|
||||
reservations => [
|
||||
{
|
||||
'hw-address' => '00:11:22:33:44:66',
|
||||
'ip-address' => '10.20.0.12',
|
||||
hostname => 'node20',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id => 2,
|
||||
subnet => '10.30.0.0/24',
|
||||
reservations => [
|
||||
{
|
||||
'hw-address' => '00:11:22:33:44:77',
|
||||
'ip-address' => '10.30.0.12',
|
||||
hostname => 'removed-node',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
my $regenerated_dhcp4 = {
|
||||
subnets => [
|
||||
{
|
||||
id => 9,
|
||||
subnet => '10.20.0.0/24',
|
||||
},
|
||||
],
|
||||
};
|
||||
$backend->preserve_reservations( $existing_dhcp4, $regenerated_dhcp4 );
|
||||
is_deeply(
|
||||
$regenerated_dhcp4->{subnets}[0]{reservations},
|
||||
$existing_dhcp4->{Dhcp4}{subnet4}[0]{reservations},
|
||||
'regeneration preserves IPv4 reservations in the matching subnet'
|
||||
);
|
||||
is(
|
||||
scalar @{ $regenerated_dhcp4->{subnets}[0]{reservations} },
|
||||
1,
|
||||
'regeneration drops reservations for removed IPv4 subnets'
|
||||
);
|
||||
is(
|
||||
$regenerated_dhcp4->{subnets}[0]{id},
|
||||
9,
|
||||
'regeneration does not copy the old IPv4 subnet id'
|
||||
);
|
||||
|
||||
my $existing_dhcp6 = {
|
||||
Dhcp6 => {
|
||||
subnet6 => [
|
||||
{
|
||||
id => 10001,
|
||||
subnet => '2001:db8:20::/64',
|
||||
reservations => [
|
||||
{
|
||||
duid => '00:04:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff',
|
||||
'ip-addresses' => ['2001:db8:20::12'],
|
||||
hostname => 'node20-v6',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
my $regenerated_dhcp6 = {
|
||||
subnets => [
|
||||
{
|
||||
id => 10009,
|
||||
subnet => '2001:db8:20::/64',
|
||||
},
|
||||
],
|
||||
};
|
||||
$backend->preserve_reservations( $existing_dhcp6, $regenerated_dhcp6 );
|
||||
is_deeply(
|
||||
$regenerated_dhcp6->{subnets}[0]{reservations},
|
||||
$existing_dhcp6->{Dhcp6}{subnet6}[0]{reservations},
|
||||
'regeneration preserves IPv6 reservations in the matching subnet'
|
||||
);
|
||||
is(
|
||||
$regenerated_dhcp6->{subnets}[0]{id},
|
||||
10009,
|
||||
'regeneration does not copy the old IPv6 subnet id'
|
||||
);
|
||||
|
||||
my $hookdir = tempdir(CLEANUP => 1);
|
||||
my $hook = "$hookdir/libdhcp_host_cmds.so";
|
||||
open(my $hookfh, '>', $hook) or die "Unable to create fake hook: $!";
|
||||
|
||||
Reference in New Issue
Block a user