From 66520c968c4cc2d53ea7d07c6adadaa6a9e5a0d8 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Thu, 5 Nov 2026 09:39:41 -0300 Subject: [PATCH] test(xcat-core): a netboot=ipxe node with no loader gets no boot file and no warning dhcp6_bootfile_url_for_node drops the DHCPv6 boot file when the UEFI loader is not under the tftpdir of the node, and says nothing. makedhcp exits 0, the reservation is written with its address and its DUID, and the node then sits at a firmware timeout with no line on the management node that names the file it was looking for. upstream_loader_warnings does not cover this. It reads the SITE TFTP directory, and it runs on makedhcp -n and makedhcp -a only, so a node that carries its own noderes.tftpdir is never examined and makedhcp warns about nothing at all. dhcp_dhcpv6_duid.t now asserts the warning reaches the caller for the node whose loader is absent, exactly once, attributed to the node and naming the full path. The node in the same run whose loader is present must not be reported. dhcp_ipxe_readiness.t asserts the decision itself for a present loader, an absent one, a trailing slash on the directory, and the three inputs that are not a missing file. These assertions fail on this tree: the three in dhcp_dhcpv6_duid.t report nothing in the collected warnings, while the assertion that the boot file is absent, and the control on the node whose loader is present, both still pass. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/unit/dhcp_dhcpv6_duid.t | 12 +++++++++ xCAT-test/unit/dhcp_ipxe_readiness.t | 38 ++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/xCAT-test/unit/dhcp_dhcpv6_duid.t b/xCAT-test/unit/dhcp_dhcpv6_duid.t index ff48a59cc4..107425adbe 100644 --- a/xCAT-test/unit/dhcp_dhcpv6_duid.t +++ b/xCAT-test/unit/dhcp_dhcpv6_duid.t @@ -358,6 +358,18 @@ sub isc_hosts { # diagnose, so no option is better than a wrong one. my ($without) = grep { $_->{name} eq 'bootfile-url' } @{ $kea{cn01}{'option-data'} || [] }; is( $without, undef, 'an ipxe node whose loader is not on disk gets no bootfile-url' ); + + # BUT IT MUST NOT BE SILENT. makedhcp exits 0 either way, so a node with no boot file and no + # warning reaches a firmware timeout and no log on the management node says why. The warning + # names the path that was looked for, because the node carries its own noderes.tftpdir and + # the reader cannot derive it from the site value. + my @loader = grep { /snponly-shim\.efi/ } @warnings; + is( scalar @loader, 1, 'the absent loader is reported exactly once for the node' ); + like( $loader[0], qr/\Qcn01:\E/, 'the warning is attributed to the node' ); + like( $loader[0], qr{\Q$absent/$loader\E}, + 'and names the full path that was looked for, which is the node tftpdir and not the site one' ); + is( scalar( grep { /\Q$present\E/ } @warnings ), 0, + 'and the node whose loader IS on disk is not reported' ); } # ---- Each backend builds the DUID that mac.duid selects -------------------------------------------- diff --git a/xCAT-test/unit/dhcp_ipxe_readiness.t b/xCAT-test/unit/dhcp_ipxe_readiness.t index 97c664cdbd..b49386d0dd 100644 --- a/xCAT-test/unit/dhcp_ipxe_readiness.t +++ b/xCAT-test/unit/dhcp_ipxe_readiness.t @@ -54,4 +54,42 @@ $warnings = warnings_for( tree_with( $bios, $uefi, $payload, 'xcat/xnba/nets/x', is( scalar @$warnings, 1, 'a directory under xcat/ipxe/nets is not a network boot script' ); like( $warnings->[0], qr{xcat/ipxe/nets has no network boot script}, 'so the network scripts are still missing' ); +# ---- A NODE whose own loader is missing, which upstream_loader_warnings cannot see ----------- +# upstream_loader_warnings reads the SITE TFTP directory and runs on makedhcp -n and -a only. A +# node carries its own noderes.tftpdir, and makedhcp never calls it at all, so +# dhcp6_bootfile_url_for_node dropped the DHCPv6 boot file with nothing said anywhere: makedhcp +# exited 0 and the node sat at a firmware timeout. +my $ready = tree_with($uefi); +my @none = xCAT::DHCP::BootPolicy->dhcp6_missing_loader_warning( + node => "cn01", tftpdir => $ready, loader => $uefi ); +is( scalar @none, 0, "a node whose loader is on disk gets no warning" ); + +my $missing_dir = tree_with(); +my ($warning) = xCAT::DHCP::BootPolicy->dhcp6_missing_loader_warning( + node => "cn01", tftpdir => $missing_dir, loader => $uefi ); +like( $warning, qr{\Q$missing_dir/$uefi\E}, + "a node whose loader is absent gets a warning naming the FULL PATH it looked for" ); +like( $warning, qr{\bcn01\b}, "... and the node, so a per-node tftpdir is attributable" ); +like( $warning, qr/no DHCPv6 boot file/, + "... and the consequence, which is the thing the silence hid" ); +like( $warning, qr/ipxe-xcat/, "... and the package that supplies the loader" ); + +# A trailing slash on the tftpdir must not double in the path, or the warning names a file that +# never existed and the reader looks in the wrong place. +($warning) = xCAT::DHCP::BootPolicy->dhcp6_missing_loader_warning( + node => "cn01", tftpdir => "$missing_dir/", loader => $uefi ); +like( $warning, qr{\Q$missing_dir/$uefi\E}, "a trailing slash on the TFTP directory is dropped" ); +unlike( $warning, qr{//}, "... and no doubled separator is left in the path" ); + +# No tftpdir and no loader are not a missing file. dhcp6_bootfile_url_for_node keeps the boot +# file in both cases, so a warning here would be a false alarm on every such node. +for my $case ( [ "an unset tftpdir", { tftpdir => undef, loader => $uefi } ], + [ "an empty tftpdir", { tftpdir => "", loader => $uefi } ], + [ "an unset loader", { tftpdir => $missing_dir, loader => undef } ] ) +{ + my @quiet = xCAT::DHCP::BootPolicy->dhcp6_missing_loader_warning( + node => "cn01", %{ $case->[1] } ); + is( scalar @quiet, 0, "$case->[0] is not reported as a missing loader" ); +} + done_testing();