mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-22 18:32:13 +00:00
4509c4bb5d
getzonesfornet in dhcp.pm rounded the prefix itself and passed the rounded value beside a network that still carried its own. getIPv6PrefixLength prefers the embedded prefix, so the rounded value was ignored and no reverse zone was written at all: dhcpd updated no PTR record for a /62 or /126 network and reported nothing. The ddns.pm copy stripped the prefix first and was unaffected, so the previous commit's claim that both copies were fixed was wrong. The zones now come from xCAT::NetworkUtils::getIPv6ReverseZones, which both copies call. A network whose prefix is not a multiple of 4 is covered by the zones of the next nibble -- a /62 by its four /64 zones -- which is what the IPv4 arm does with a /22. Rounding down to the /60 made xCAT answer for three networks it does not own. kea_subnet_id_numeric.t only observes the encoding under the XS backend, and passed 6 of 6 under JSON::PP with the bug in place. It skips unless JSON->backend is the XS one, and the workflow installs libjson-xs-perl so the backend is there. dhcp6_boot_server now reports a substituted boot server, so an unresolvable tftpserver is not silent, and the caller reports a warning that arrives with a server. The routine also moved below grub2_node_loader, whose comment it had separated from it. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
75 lines
2.8 KiB
Perl
75 lines
2.8 KiB
Perl
#!/usr/bin/env perl
|
|
#
|
|
# Kea rejects a reservation whose subnet-id arrives as a JSON string, so every Control Agent
|
|
# update falls back to a full server restart.
|
|
#
|
|
# The cause is Perl aliasing: the dedupe key in live_upsert_reservations read the subnet-id of
|
|
# each reservation through an aliased $_, and reading a numeric scalar in string context attaches
|
|
# a string form to it. The reservation body is encoded from the same scalar afterwards.
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use FindBin;
|
|
use lib "$FindBin::Bin/../../perl-xCAT";
|
|
|
|
use Test::More;
|
|
|
|
# Only the XS backend keeps the string form that an aliased $_ attaches to the scalar. Under
|
|
# JSON::PP every assertion here passes with the bug in place, so the test skips unless the
|
|
# backend that Kea.pm will use is the XS one. The workflow installs libjson-xs-perl.
|
|
use JSON ();
|
|
BEGIN {
|
|
plan skip_all => 'the JSON backend is ' . JSON->backend . ', which does not keep the string form'
|
|
unless JSON->backend =~ /XS/;
|
|
}
|
|
plan tests => 6;
|
|
|
|
use xCAT::DHCP::Backend::Kea;
|
|
|
|
# Drive the real sub and encode the captured payload with the backend's own encoder, which is
|
|
# what the HTTP path uses. Asserting on the Perl value would pass with the bug in place.
|
|
sub upsert {
|
|
my (@args) = @_;
|
|
my @payloads;
|
|
my $backend = xCAT::DHCP::Backend::Kea->new(
|
|
control_agent_handler => sub {
|
|
my ($payload) = @_;
|
|
push @payloads, $payload;
|
|
return { ok => 1, result => 0, response => { result => 0 } };
|
|
},
|
|
);
|
|
my $result = $backend->live_upsert_reservations(@args);
|
|
my @adds = grep { $_->{command} eq 'reservation-add' } @payloads;
|
|
return ( $result, $backend, \@adds );
|
|
}
|
|
|
|
my $reservation = {
|
|
'subnet-id' => 1,
|
|
duid => '00:04:aa:bb',
|
|
'ip-addresses' => ['2001:db8::20'],
|
|
hostname => 'node20',
|
|
};
|
|
|
|
my ( $result, $backend, $adds ) = upsert( [$reservation], service => ['dhcp6'] );
|
|
ok( !$result->{error}, 'the upsert reaches the Control Agent handler' );
|
|
is( scalar(@$adds), 1, 'one reservation-add is sent' );
|
|
|
|
my $body = $backend->encode_config( $adds->[0] );
|
|
like( $body, qr/"subnet-id"\s*:\s*1\b/,
|
|
'the reservation body encodes subnet-id as a JSON number' );
|
|
unlike( $body, qr/"subnet-id"\s*:\s*"1"/,
|
|
'the reservation body does not encode subnet-id as a JSON string, which Kea rejects' );
|
|
|
|
# The dedupe key is built over the stale list as well, so a stale entry reads the same scalar a
|
|
# second time.
|
|
my $stale = { 'subnet-id' => 1, duid => '00:04:cc:dd' };
|
|
( $result, $backend, $adds ) = upsert(
|
|
[ { %$reservation } ],
|
|
service => ['dhcp6'],
|
|
stale_reservations => [$stale],
|
|
);
|
|
ok( !$result->{error}, 'the upsert succeeds with a stale reservation to delete' );
|
|
like( $backend->encode_config( $adds->[0] ), qr/"subnet-id"\s*:\s*1\b/,
|
|
'subnet-id stays a JSON number when the dedupe key also reads a stale reservation' );
|