From 3389c1ccd105ebddda9e0e30a97afcdaa32a5a21 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Wed, 28 Oct 2026 02:41:44 -0300 Subject: [PATCH] test(dhcp): the ISC DHCPv6 reservation of a node is not checked for a boot file The DHCPv6 half of makedhcp had no test for the boot file, the DHCPv6 service or the sysconfig file, so a node could be given its reserved address with nothing to load and the suite stayed green. The test drives the ISC path of makedhcp and asserts that every DHCPv6 host it creates carries a bootfile-url naming the grub2 loader, that a node with netboot=xnba gets none, that the DHCPv6 daemon is restarted, and that a missing /etc/sysconfig/dhcpd6 is not reported as an error. The harness now names the operating system instead of reading the host it runs on. Both sysconfig branches depend on it, so without this the test exercised whichever branch the build host happened to take, and the error assertion passed with the defect in place. It also stubs restartservice, which the harness previously let through to the services of the build host. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/unit/dhcp_dhcpv6_duid.t | 55 +++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/xCAT-test/unit/dhcp_dhcpv6_duid.t b/xCAT-test/unit/dhcp_dhcpv6_duid.t index 0c35820159..c4ce6bf36c 100644 --- a/xCAT-test/unit/dhcp_dhcpv6_duid.t +++ b/xCAT-test/unit/dhcp_dhcpv6_duid.t @@ -169,13 +169,26 @@ print {$fh} "#xCAT generated dhcp configuration\n", "subnet 192.0.2.0 netmask 255.255.255.0 {\n", "} # 192.0.2.0/255.255.255.0 subnet_end\n"; close($fh) or die "Cannot close $conf: $!"; +our @restarted; +# The OS that makedhcp believes it runs on. Without this the sysconfig decisions follow the +# host the suite runs on, and the branch under test is whichever that host happens to take. +our $osver = 'rhels9.4'; + sub isc_commands { my (@wanted) = @_; my @sessions; @errors = @warnings = (); + @restarted = (); no warnings 'redefine'; + # Without this the test restarts the dhcp services of the host it runs on. + local *xCAT::Utils::restartservice = sub { + shift if @_ && defined( $_[0] ) && $_[0] eq 'xCAT::Utils'; + push @restarted, $_[0]; + return 0; + }; local @DUIDTable::networks = ( { net => '2001:db8:176::', mask => '/64', mgtifname => 'eth0' } ); local *xCAT::DHCP::Backend::new_backend = sub { return bless {}, 'DUIDISCBackend'; }; + local *xCAT::Utils::osver = sub { return $osver; }; local *xCAT::Utils::isServiceNode = sub { return 0; }; local *xCAT::Utils::isLinux = sub { return 1; }; local *xCAT::Utils::isFIPS = sub { return 0; }; @@ -561,4 +574,46 @@ sub isc_hosts { 'Kea: a node with no duid attribute is still reported' ); } +# ---- The DHCPv6 reservation names the boot file (RFC 5970 option 59) ------------------------------ +# Without the option the firmware takes the reserved address and has nothing to load. EDK2 then +# reports "PXE-E21: Remote boot cancelled" and falls through to the next boot entry, which reads +# like a DHCP failure although the address was granted. +{ + local %DUIDTable::rows = node_rows(%settings); + my $sessions = isc_commands(@nodes); + my $v6 = $sessions->[1] // ''; + + my @urls = $v6 =~ m{dhcp6\.bootfile-url\s*\\?"?(tftp:[^"\\;]+)}g; + my @hosts = sort keys %{ isc_hosts($v6) }; + diag( "hosts created: " . scalar(@hosts) . " (@hosts), urls: " . scalar(@urls) ); + is( scalar(@urls), scalar(@hosts), 'ISC: every DHCPv6 host that is created gets a boot file URL' ); + is( $urls[0], "tftp://[2001:db8:176::1]/boot/grub2/grub2-$nodes[0]", + 'ISC: the URL brackets the IPv6 boot server and names the node loader' ); + + # ISC runs DHCPv6 as a second daemon, so restarting dhcpd alone leaves it stopped or + # holding the previous configuration. The node then gets no address at all. + is( scalar( grep { $_ eq 'dhcp6' } @restarted ), 1, + 'ISC: makedhcp restarts the DHCPv6 daemon, which is a service of its own' ); + + # No EL or openEuler dhcp package ships /etc/sysconfig/dhcpd6, and dhcpd6 does not need + # it: ISC dhcpd listens on the interfaces its subnet declarations name. Only an OS outside + # the DHCPD_INTERFACE family reaches this decision, so the OS is named here. + { + local $osver = 'openeuler24.03'; + isc_commands(@nodes); + unlike( join( ' ', @errors ), qr{/etc/sysconfig/dhcpd6}, + 'ISC: a missing /etc/sysconfig/dhcpd6 is not reported as an error' ); + } + + # A node that cannot netboot over IPv6 must get no URL: only the grub2 loaders read one. + local %DUIDTable::rows = node_rows(%settings); + $DUIDTable::rows{noderes}{ $nodes[0] }{netboot} = 'xnba'; + my $mixed = isc_commands(@nodes)->[1] // ''; + my @mixed_urls = $mixed =~ m{dhcp6\.bootfile-url\s*\\?"?(tftp:[^"\\;]+)}g; + my @mixed_hosts = sort keys %{ isc_hosts($mixed) }; + is( scalar(@mixed_urls), scalar(@mixed_hosts) - 1, 'ISC: an xnba node gets no DHCPv6 boot file URL' ); + unlike( join( '', @mixed_urls ), qr/\Q$nodes[0]\E/, + 'ISC: the URL that is left belongs to the grub2 nodes' ); +} + done_testing();