2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-12-02 23:32:16 +00:00

test(dhcp): a DHCPv6 client with no reservation is told nothing to boot

Sequential discovery over IPv6 starts with a node xCAT has never seen. It has
no DUID in the dhcp6duid table, so kea_node_reservations6 writes no reservation
for it, and option 59 (bootfile-url) is written only inside a reservation. The
subnet carries a dynamicrange, so Kea answers the node with an address and no
boot file.

Measured on xcat88-mn: an unknown client took 2001:db8:188::1000 from the pool,
and the running kea-dhcp6.conf held no client-classes at all.

dhcp6_boot_client_classes.t asserts that render_dhcp6_config carries
client-classes, that _render_subnet6 scopes a class to its subnet, and that the
class builder names a loader per architecture from option 61. Without the fix
10 of its 11 assertions fail.

dhcp_kea_plugin_intent.t gains four assertions on the wiring: that
kea_subnet6_intent carries the classes and evaluates them only for its own
subnet. Emptying the class list in kea_subnet6_intent fails those four and no
other test in the file.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
Daniel Hilst
2026-11-07 19:15:10 -03:00
parent f38c6cd33d
commit 03129cf654
2 changed files with 112 additions and 0 deletions
@@ -0,0 +1,91 @@
#!/usr/bin/perl
# A DHCPv6 client with no reservation must still be told what to boot.
#
# Sequential discovery starts with a node xCAT has never seen: it has no DUID in the dhcp6duid
# table and no reservation, so kea_node_reservations6 writes nothing for it. The subnet has a
# dynamicrange, so Kea answers it with an address -- measured on xcat88-mn, where an unknown
# client took 2001:db8:188::1000 from the pool. What it never gets is option 59, bootfile-url,
# because that option is written only inside a reservation. The node boots nothing and
# seq_discovery_ipv6 fails before it powers the node on.
#
# DHCPv4 solves this with client classes keyed on option 93, the client system architecture, each
# naming a boot file. RFC 5970 gives DHCPv6 the same registry in option 61 and the boot file URL
# in option 59, so the same shape works. Two things were missing:
#
# render_dhcp6_config dropped client-classes entirely. render_dhcp4_config renders them.
# _render_subnet6 dropped the additional-class list. _render_subnet4 renders it.
#
# So classes could not reach the config even once something built them.
use strict;
use warnings;
use Test::More tests => 11;
use FindBin;
use lib "$FindBin::Bin/../../perl-xCAT";
use JSON;
require xCAT::DHCP::Backend::Kea;
require xCAT::DHCP::BootPolicy;
my $backend = xCAT::DHCP::Backend::Kea->new( kea_version => '3.0.1' );
# --- the renderer must carry classes into Dhcp6 -------------------------------------------------
my $json = decode_json(
$backend->render_dhcp6_config({
interfaces => ['eth1'],
subnets => [ { id => 10001, subnet => '2001:db8:188::/64',
additional_client_classes => ['xcat-uefi6-x64'] } ],
'client-classes' => [
{ name => 'xcat-uefi6-x64',
test => 'option[61].hex == 0x0007',
'option-data' => [ { name => 'bootfile-url', data => 'tftp://[2001:db8:188::1]/x' } ] },
],
})
);
ok( exists $json->{Dhcp6}{'client-classes'},
'render_dhcp6_config emits client-classes' )
or diag 'Dhcp6 keys: ' . join( ' ', sort keys %{ $json->{Dhcp6} } );
is( scalar @{ $json->{Dhcp6}{'client-classes'} || [] }, 1, 'it keeps the one class it was given' );
is( $json->{Dhcp6}{'client-classes'}[0]{name}, 'xcat-uefi6-x64', 'with its name' );
is( $json->{Dhcp6}{'client-classes'}[0]{test}, 'option[61].hex == 0x0007',
'and its option 61 architecture test' );
is( $json->{Dhcp6}{'client-classes'}[0]{'option-data'}[0]{name}, 'bootfile-url',
'and the bootfile-url it supplies' );
# Kea 3.0.1 takes the modern spelling, the same choice _render_subnet4 already makes.
my $sn = $json->{Dhcp6}{subnet6}[0];
is_deeply( $sn->{'evaluate-additional-classes'}, ['xcat-uefi6-x64'],
'_render_subnet6 scopes the class to the subnet that named it' );
# --- the classes themselves ---------------------------------------------------------------------
my $host = '[2001:db8:188::1]';
# An eval, not a bare call: a missing sub would end the file and the assertions below would report
# nothing at all. Absent builder and wrong classes must both read as a failure here.
sub classes6 {
my (%opts) = @_;
my $out = eval { xCAT::DHCP::BootPolicy->kea_client_classes6(%opts) };
return $out && ref($out) eq 'ARRAY' ? $out : [];
}
my $classes = classes6( uri_host => $host, ipxe_uefi => 1, tftpdir => '/tftpboot' );
my ($x64) = grep { $_->{test} =~ /0x0007/ } @$classes;
ok( $x64, 'an x86_64 UEFI class is built' );
is( $x64 && $x64->{'option-data'}[0]{data},
"tftp://$host/xcat/ipxe/x86_64-sb/snponly-shim.efi",
'it hands the signed iPXE shim, the same first stage a reserved node gets' );
my ($aa) = grep { $_->{test} =~ /0x000b/ } @$classes;
is( $aa && $aa->{'option-data'}[0]{data}, "tftp://$host/boot/grub2/grub2.aarch64",
'aarch64 gets its grub2 loader' );
my ($rv) = grep { $_->{test} =~ /0x001b/ } @$classes;
is( $rv && $rv->{'option-data'}[0]{data}, "tftp://$host/boot/grub2/grub2.riscv64",
'riscv64 gets its grub2 loader' );
# Naming a file the TFTP server does not have costs the client a timeout it cannot diagnose, which
# is the reason the DHCPv4 classes check the loader before naming it.
my $no_loader = classes6( uri_host => $host, ipxe_uefi => 0, tftpdir => '/tftpboot' );
is( scalar( grep { $_->{test} =~ /0x0007/ } @$no_loader ), 0,
'with no iPXE shim on disk the x86_64 class is left out rather than pointing at nothing' );
+21
View File
@@ -266,6 +266,27 @@ my %network_entry = (
is_deeply( [ grep { /^xcat-ipxe-net-/ } @{ $subnet->{additional_client_classes} } ], [],
'without the upstream loader on this server, the Kea subnet names no network script' );
# The DHCPv6 subnet answers an unknown client the same way, with option 59 instead of a boot
# file name. Without these a node being discovered gets a pool address and nothing to boot,
# which is where seq_discovery_ipv6 stops: the DUID cannot be reserved before it is known.
my %entry6 = ( net => '2001:db8:188::/64', mgtifname => 'eth1', mask => '64',
dynamicrange => '2001:db8:188::1000-2001:db8:188::1fff' );
my $subnet6 = xCAT_plugin::dhcp::kea_subnet6_intent( \%entry6, 'eth1', 0, 10001 );
my %classes6 = map { $_->{name} => $_ } @{ $subnet6->{client_classes} || [] };
ok( $classes6{'xcat-aarch64-6-10001'},
'the Kea DHCPv6 subnet carries boot classes for an unreserved client' )
or diag 'classes: ' . join( ' ', sort keys %classes6 );
is( $classes6{'xcat-aarch64-6-10001'} && $classes6{'xcat-aarch64-6-10001'}{'option-data'}[0]{name},
'bootfile-url', 'and each one supplies bootfile-url, which is option 59' );
is( $classes6{'xcat-aarch64-6-10001'} && $classes6{'xcat-aarch64-6-10001'}{'option-data'}[0]{data},
'tftp://[2001:db8::1]/boot/grub2/grub2.aarch64',
'naming the management node facing this network, bracketed for a URL' );
is_deeply(
[ grep { /^xcat-aarch64-6/ } @{ $subnet6->{additional_client_classes} || [] } ],
['xcat-aarch64-6-10001'],
'and the class is evaluated only for the subnet it was built for',
);
local *xCAT_plugin::dhcp::kea_ipxe_loader_flags = sub { return ( ipxe_bios => 1, ipxe_uefi => 1 ); };
$subnet = xCAT_plugin::dhcp::kea_subnet4_intent( $nettab, '10.0.0.0', '255.255.255.0', 'eth0', 0, 1, 80 );
%classes = map { $_->{name} => $_ } @{ $subnet->{client_classes} };