diff --git a/xCAT-server/lib/xcat/plugins/dhcp.pm b/xCAT-server/lib/xcat/plugins/dhcp.pm index aa2a7b8c78..2a5b3f337f 100644 --- a/xCAT-server/lib/xcat/plugins/dhcp.pm +++ b/xCAT-server/lib/xcat/plugins/dhcp.pm @@ -4491,7 +4491,8 @@ sub dhcp6_bootfile_url_for_node return unless $netboot && ($netboot eq 'grub2' || $netboot eq 'grub2-http' - || $netboot eq 'grub2-tftp'); + || $netboot eq 'grub2-tftp' + || $netboot eq 'ipxe'); my $server = dhcp6_boot_server_for_node($node, $peer, $nrent); return unless $server; @@ -4499,12 +4500,27 @@ sub dhcp6_bootfile_url_for_node my $uri_host = xCAT::NetworkUtils->format_uri_host($server); return unless $uri_host; + my $boot_tftpdir = ( ( $nrent && $nrent->{tftpdir} ) || $tftpdir ); + + if ($netboot eq 'ipxe') { + # The firmware that solicits over DHCPv6 is UEFI, so the UEFI loader is the only one + # such a client can ask for. The iPXE build xCAT ships reports dhcpv6 and ipv6, which + # the xnba loader does not, so xnba still gets no option 59. + my $loader = xCAT::DHCP::BootPolicy->x86_loader( method => 'ipxe' )->{uefi}; + return unless $loader; + + # Naming a file the TFTP server does not have costs the client a timeout it cannot + # diagnose, which is why the Kea client classes check the loader the same way. + return if defined $boot_tftpdir && !-e "$boot_tftpdir/$loader"; + return "tftp://$uri_host/$loader"; + } + # grub2_node_loader is the one place the boot file name of a grub2 node is chosen, so # an aarch64 node gets the .efi name its firmware requests over IPv6 as well as IPv4. my $loader = xCAT::DHCP::BootPolicy->grub2_node_loader( node => $node, arch => $ntent && $ntent->{arch}, - tftpdir => ( ( $nrent && $nrent->{tftpdir} ) || $tftpdir ), + tftpdir => $boot_tftpdir, ); return "tftp://$uri_host/boot/grub2/$loader"; } diff --git a/xCAT-test/unit/dhcp_dhcpv6_duid.t b/xCAT-test/unit/dhcp_dhcpv6_duid.t index be3584437c..c7ad58ab00 100644 --- a/xCAT-test/unit/dhcp_dhcpv6_duid.t +++ b/xCAT-test/unit/dhcp_dhcpv6_duid.t @@ -13,6 +13,8 @@ use lib "$FindBin::Bin/../../xCAT-server/lib"; use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; use lib "$FindBin::Bin/../../perl-xCAT"; +use File::Basename qw(dirname); +use File::Path qw(make_path); use File::Temp qw(tempdir); use JSON (); use Test::More; @@ -266,6 +268,39 @@ sub isc_hosts { 'ISC: an xnba node gets no bootfile-url' ); } +# ---- An ipxe node gets the UEFI loader over DHCPv6 ------------------------------------------- +# The firmware that solicits over DHCPv6 is UEFI, and the iPXE build xCAT ships reports dhcpv6 +# and ipv6 where the xnba loader does not. Without option 59 such a node takes the reserved +# address and has nothing to load. +{ + local %DUIDTable::rows = node_rows(%settings); + + my $present = tempdir( CLEANUP => 1 ); + my $loader = 'xcat/ipxe/x86_64-sb/snponly-shim.efi'; + make_path( dirname("$present/$loader") ); + open( my $fh, '>', "$present/$loader" ) or die "cannot write the loader: $!"; + print {$fh} "loader\n"; + close($fh); + my $absent = tempdir( CLEANUP => 1 ); + + $DUIDTable::rows{noderes}{cn02} = + { netboot => 'ipxe', tftpserver => '2001:db8:176::1', tftpdir => $present }; + $DUIDTable::rows{noderes}{cn03} = + { netboot => 'ipxe', tftpserver => '2001:db8:176::1', tftpdir => $absent }; + + my $config = empty_config(); + my %kea = map { $_->{hostname} => $_ } @{ kea_reservations( $config, 'cn02', 'cn03' ) }; + + my ($with) = grep { $_->{name} eq 'bootfile-url' } @{ $kea{cn02}{'option-data'} || [] }; + is( $with && $with->{data}, "tftp://[2001:db8:176::1]/$loader", + 'an ipxe node gets the UEFI loader from the bracketed IPv6 server' ); + + # Naming a file the TFTP server does not have costs the client a timeout it cannot + # diagnose, so no option is better than a wrong one. + my ($without) = grep { $_->{name} eq 'bootfile-url' } @{ $kea{cn03}{'option-data'} || [] }; + is( $without, undef, 'an ipxe node whose loader is not on disk gets no bootfile-url' ); +} + # ---- Each backend builds the DUID that mac.duid selects -------------------------------------------- { local %DUIDTable::rows = node_rows(%settings);