From 95bbecafce85c55df67f413a9170652bd74bf68d Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Thu, 5 Nov 2026 16:56:24 -0300 Subject: [PATCH] test(xcat-core): nothing asserts that the DUID the Genesis image sends is reserved The OpenEmbedded Genesis image ships one NetworkManager configuration, 10-xcat-genesis.conf, and it sets ipv6.dhcp-duid=ll. The image therefore sends the DUID-LL of the provisioning NIC. makedhcp reserves the two DUID-UUID orders that EDK2 and iPXE send, or a DUID-LL when mac.duid asks for one, and the two forms are exclusive. No test says which identities one node needs, so a reservation set that answers the firmware and the loader and not the image passes. The new block renders the Kea DHCPv6 reservations of a netboot=ipxe node and asserts the DUIDs, which client keeps the address and the hostname, and the boot file URL of each. It asserts the same node on ISC DHCP and through makedhcp -d, and that mac.duid=ll, a literal DUID and the DHCPv4 reservations are unchanged. Ten assertions fail on this commit: the DUID-LL is reserved nowhere. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/unit/dhcp_dhcpv6_duid.t | 124 ++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/xCAT-test/unit/dhcp_dhcpv6_duid.t b/xCAT-test/unit/dhcp_dhcpv6_duid.t index 107425adbe..60f7c1c7d7 100644 --- a/xCAT-test/unit/dhcp_dhcpv6_duid.t +++ b/xCAT-test/unit/dhcp_dhcpv6_duid.t @@ -77,6 +77,11 @@ require( repo_path('xCAT-server/lib/xcat/plugins/dhcp.pm') ); package DUIDISCBackend; sub name { return 'isc'; } + + # The IPv4 reservations are rendered to prove that nothing on that path changed, so the + # subnet of an address is answered without a configuration to look it up in. + package DUIDKeaV4Backend; + sub subnet_id_for_ip { return 1; } } my $uuid = '12345678-1234-4bcd-9876-1234567890ab'; @@ -983,4 +988,123 @@ is( xCAT_plugin::dhcp::radvd_needs_restart( 0, 1 ), 0, 'an unchanged file with t 'ISC: that host is given the boot script' ); } +# ---- The Genesis image is a third client, and it sends a DUID-LL ---------------------------- +# The OpenEmbedded Genesis image ships one NetworkManager file, 10-xcat-genesis.conf, and its +# whole DHCPv6 identity policy is ipv6.dhcp-duid=ll. So the image sends the DUID-LL of the +# provisioning NIC, which matches neither order of vpd.uuid, and a node reserved for its UUID +# alone gets no answer once Genesis runs. The DUID-LL is derived from the MAC, so it is reserved +# beside the two UUID orders instead of in place of them: one node, three clients. +{ + local %DUIDTable::rows = node_rows(%settings); + + my $present = tempdir( CLEANUP => 1 ); + my $shim = 'xcat/ipxe/x86_64-sb/snponly-shim.efi'; + make_path( dirname("$present/$shim") ); + open( my $fh, '>', "$present/$shim" ) or die "cannot write the loader: $!"; + print {$fh} "loader\n"; + close($fh); + + # cn01 takes the firmware order, cn04 holds a DUID of its own and cn13 asks for ll. All three + # chainload, so the two that keep one reservation keep it because of mac.duid and not because + # iPXE is absent. + foreach my $node (qw(cn01 cn04 cn13)) { + $DUIDTable::rows{noderes}{$node} = + { netboot => 'ipxe', tftpserver => '2001:db8:176::1', tftpdir => $present }; + } + + is( $mac{cn01}, '02:00:00:00:01:21', 'the MAC that the DUID-LL of the chainloading node is built from' ); + is( $mac{cn02}, '02:00:00:00:01:22', 'and the MAC of the node that the firmware boots directly' ); + my $ll_cn01 = '00:03:00:01:02:00:00:00:01:21'; + my $ll_cn02 = '00:03:00:01:02:00:00:00:01:22'; + + my $shim_url = "tftp://[2001:db8:176::1]/$shim"; + my $script_url = 'http://[2001:db8:176::1]/tftpboot/xcat/ipxe/nodes/cn01.uefi'; + + my $config = empty_config(); + my @cn01 = @{ kea_reservations( $config, 'cn01' ) }; + is_deeply( [ map { $_->{duid} } @cn01 ], [ $firmware, $canonical, $ll_cn01 ], + 'an ipxe node is reserved for the firmware order, the RFC 4122 order, and the DUID-LL' ); + + # Kea refuses a second reservation for one address, and _reservation_matches treats a shared + # hostname as the same reservation, so only the first client carries either. + is_deeply( $cn01[0]->{'ip-addresses'}, [ $address{cn01} ], 'the first client keeps the address' ); + is( $cn01[0]->{hostname}, 'cn01', '... and the hostname' ); + is( scalar( grep { defined $_->{hostname} || $_->{'ip-addresses'} } @cn01 ), 1, + 'and no other client of the node carries either' ); + + my @option = map { + my ($found) = grep { $_->{name} eq 'bootfile-url' } @{ $_->{'option-data'} || [] }; + $found; + } @cn01; + is( scalar( grep { $_ && $_->{'always-send'} } @option ), 3, + 'each of the three clients is sent a boot file URL whether it asks for one or not' ); + is( $option[0] && $option[0]->{data}, $shim_url, 'the firmware is given the UEFI shim' ); + is( $option[1] && $option[1]->{data}, $script_url, 'iPXE is given the boot script instead' ); + is( $option[2] && $option[2]->{data}, $shim_url, + 'and the Genesis client the same file as the firmware' ); + + # The Genesis image boots whatever loaded it, so a node that the firmware boots directly + # sends the DUID-LL as well. It never runs iPXE, so the RFC 4122 order is left out. + my @cn02 = @{ kea_reservations( $config, 'cn02' ) }; + is_deeply( [ map { $_->{duid} } @cn02 ], + [ '00:04:78:56:34:12:34:12:cd:4b:98:76:12:34:56:78:90:ac', $ll_cn02 ], + 'a grub2 node is reserved for its firmware and for Genesis, and not for iPXE' ); + is_deeply( $cn02[0]->{'ip-addresses'}, [ $address{cn02} ], + 'the firmware of that node still keeps its address' ); + is( $cn02[1]->{hostname}, undef, 'and the Genesis client of it holds none' ); + + # mac.duid names one client and one DUID. Neither value is built from vpd.uuid, so there is + # no second order to derive and nothing to add: the node answers as the operator said. + my @cn13 = @{ kea_reservations( $config, 'cn13' ) }; + is( scalar(@cn13), 1, 'a node that asks for ll keeps the single reservation it asked for' ); + is( $cn13[0]->{duid}, $ll_cn13, '... keyed on the DUID-LL' ); + is_deeply( $cn13[0]->{'ip-addresses'}, [ $address{cn13} ], '... which keeps the address' ); + + my @cn04 = @{ kea_reservations( $config, 'cn04' ) }; + is( scalar(@cn04), 1, 'a node with a DUID of its own keeps a single reservation too' ); + is( $cn04[0]->{duid}, $literal, '... keyed on that DUID, as given' ); + + # makedhcp -d removes a reservation by what it is keyed on, so a delete that does not name + # the DUID-LL leaves that entry behind with the boot file of a node it removed. + my %matched = map { ( $_->{duid} || '' ) => 1 } + @{ xCAT_plugin::dhcp::kea_reservation_matches_for_nodes( ['cn01'] ) }; + ok( $matched{$ll_cn01}, 'makedhcp -d of an ipxe node names its DUID-LL as well' ); + my %grub2 = map { ( $_->{duid} || '' ) => 1 } + @{ xCAT_plugin::dhcp::kea_reservation_matches_for_nodes( ['cn02'] ) }; + ok( $grub2{$ll_cn02}, 'and of a grub2 node names the DUID-LL it reserved' ); + + # ISC DHCP gives one address to one host, so the Genesis client is a host of its own there. + my $sessions = isc_commands( 'cn01', 'cn02' ); + my $hosts = isc_hosts( $sessions->[1] // '' ); + is( $hosts->{'cn01-genesis'}, $ll_cn01, + 'ISC: the Genesis client of an ipxe node is a host keyed on the DUID-LL' ); + is( $hosts->{'cn01-ipxe'}, $canonical, '... beside the host of iPXE' ); + is( $hosts->{cn01}, $firmware, '... and the host of the firmware' ); + is( $hosts->{'cn02-genesis'}, $ll_cn02, 'ISC: a grub2 node gets that host as well' ); + is( $hosts->{'cn02-ipxe'}, undef, '... and no host for a client it never runs' ); + + my $removed = ''; + open( my $session, '>', \$removed ) or die "Cannot open an omshell buffer: $!"; + xCAT_plugin::dhcp::delnode6( 'cn01', $session ); + close($session); + like( $removed, qr/^set name = "cn01-genesis"\nopen\nremove\n/m, + 'ISC: makedhcp -d removes the host of the Genesis client' ); + like( $removed, qr/^set name = "cn01-ipxe"\nopen\nremove\n/m, '... and the host of iPXE' ); + + # No IPv4 behaviour changes. A DUID identifies a DHCPv6 client, so a DHCPv4 reservation is + # keyed on the hardware address of the NIC whatever mac.duid holds. + { + local $resolve{cn01} = { 4 => '192.0.2.21', 6 => $address{cn01} }; + no warnings 'redefine'; + local *xCAT_plugin::dhcp::next_server_for_node = sub { return ( '192.0.2.1', '192.0.2.1' ); }; + local *xCAT_plugin::dhcp::kea_boot_for_node = sub { return {}; }; + use warnings 'redefine'; + my $v4 = xCAT_plugin::dhcp::kea_build_node_reservations( + bless( {}, 'DUIDKeaV4Backend' ), {}, ['cn01'] ); + is_deeply( [ map { $_->{'hw-address'} } @$v4 ], [ $mac{cn01} ], + 'the node keeps its one IPv4 reservation, keyed on its MAC' ); + ok( !grep( { $_->{duid} } @$v4 ), 'and no DUID reaches a DHCPv4 reservation' ); + } +} + done_testing();