From 435ba5abd3b337252081883ca0a85aa98fd255bb Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sun, 8 Nov 2026 12:57:38 -0300 Subject: [PATCH] test(xcat-core): sequential discovery cannot resolve or match an IPv6 node nodediscover.pm decides two things with IPv4-only code, and sequential discovery over IPv6 stops at each of them. It gates the MAC record on inet_aton($node), so a node whose only address is IPv6 fails and process_request returns "Can not resolve IP for the matching node". update_discovery_data runs after every such early return, so no discoverydata row is written and makedhcp never runs. Measured on xcat88-mn: tabdump discoverydata empty after a full seq_discovery_ipv6 run. It then matches a NIC behind if ($ip =~ /\d+\.\d+\.\d+\.\d+/). The OpenEmbedded image sends address=${ipv4_address:-$ipv6_address}, so over IPv6 the NIC record carries the v6 address, the branch is skipped, $localnic stays 0 and process_request returns "No nic found in deploy network". The three tests ask xCAT::DiscoveryUtils for the two decisions and for the hostname tag of an IPv6 NIC. Each holds an IPv4 case down as well, because every green discovery cell depends on that path being unchanged. All three fail on this commit. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/unit/discovery_hosttag_ipv6_nic.t | 40 +++++++++++++++++++ xCAT-test/unit/discovery_nic_network_key.t | 35 ++++++++++++++++ .../unit/discovery_node_address_usable.t | 30 ++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 xCAT-test/unit/discovery_hosttag_ipv6_nic.t create mode 100644 xCAT-test/unit/discovery_nic_network_key.t create mode 100644 xCAT-test/unit/discovery_node_address_usable.t diff --git a/xCAT-test/unit/discovery_hosttag_ipv6_nic.t b/xCAT-test/unit/discovery_hosttag_ipv6_nic.t new file mode 100644 index 0000000000..ff8eb7707b --- /dev/null +++ b/xCAT-test/unit/discovery_hosttag_ipv6_nic.t @@ -0,0 +1,40 @@ +#!/usr/bin/perl +# The hostname tag for a discovered IPv6 NIC. +# +# The IPv4 path asks gethosttag, which reads an A record and my_if_netmap -- netstat -rn, which +# prints IPv4 routes only. So the decision for an IPv6 nic is made from the addresses themselves: +# a nic in the same network as the node's own address IS the node, and that is what sets +# $localnic and stops process_request returning "No nic found in deploy network". +use strict; +use warnings; +use Test::More tests => 6; +use FindBin; +use lib "$FindBin::Bin/../../perl-xCAT"; + +require xCAT::DiscoveryUtils; + +can_ok( 'xCAT::DiscoveryUtils', 'hosttag_for_ipv6_nic' ); + +my %used; +is( xCAT::DiscoveryUtils::hosttag_for_ipv6_nic( + 'seqdisc1', '2001:db8:188::21', 'eth0', '2001:db8:188::31', 64, \%used ), + 'seqdisc1', 'a nic in the network of the node is the node itself' ); + +is( xCAT::DiscoveryUtils::hosttag_for_ipv6_nic( + 'seqdisc1', '2001:db8:188::21', 'eth1', '2001:db8:99::31', 64, \%used ), + undef, 'a nic on another network is not the node' ); + +# The v4 path owns a v4 nic; this helper must not answer for one. +is( xCAT::DiscoveryUtils::hosttag_for_ipv6_nic( + 'seqdisc1', '2001:db8:188::21', 'eth0', '192.168.88.31', 24, \%used ), + undef, 'an IPv4 nic is left to the IPv4 path' ); + +is( xCAT::DiscoveryUtils::hosttag_for_ipv6_nic( + 'seqdisc1', undef, 'eth0', '2001:db8:188::31', 64, \%used ), + undef, 'with no address for the node there is nothing to compare' ); + +# A second nic on the node's own network must not claim the node's name twice. +my %taken = ( seqdisc1 => 1 ); +is( xCAT::DiscoveryUtils::hosttag_for_ipv6_nic( + 'seqdisc1', '2001:db8:188::21', 'eth2', '2001:db8:188::32', 64, \%taken ), + 'seqdisc1-eth2', 'a second nic on that network takes an interface-qualified name' ); diff --git a/xCAT-test/unit/discovery_nic_network_key.t b/xCAT-test/unit/discovery_nic_network_key.t new file mode 100644 index 0000000000..ca533cd1ae --- /dev/null +++ b/xCAT-test/unit/discovery_nic_network_key.t @@ -0,0 +1,35 @@ +#!/usr/bin/perl +# Which network a discovered NIC is on, for either address family. +# +# nodediscover.pm computed this with unpack("N", inet_aton($ip)) behind an +# if ($ip =~ /\d+\.\d+\.\d+\.\d+/) gate, so a NIC reported as 2001:db8:188::31/64 skipped the +# branch entirely, $localnic stayed 0 and process_request returned "No nic found in deploy +# network". The OpenEmbedded image sends address=${ipv4_address:-$ipv6_address}, so over IPv6 the +# NIC record carries the v6 address. +use strict; +use warnings; +use Test::More tests => 8; +use FindBin; +use lib "$FindBin::Bin/../../perl-xCAT"; + +require xCAT::DiscoveryUtils; + +can_ok( 'xCAT::DiscoveryUtils', 'nic_network_key' ); + +# IPv4 must come out byte-for-byte as the old arithmetic did. +is( xCAT::DiscoveryUtils::nic_network_key( '10.0.0.212', 8 ), '10.0.0.0', + 'an IPv4 nic keys on its network, as before' ); +is( xCAT::DiscoveryUtils::nic_network_key( '192.168.88.21', 24 ), '192.168.88.0', + 'and at a /24' ); + +is( xCAT::DiscoveryUtils::nic_network_key( '2001:db8:188::31', 64 ), '2001:db8:188::', + 'an IPv6 nic keys on its network' ); +# A prefix that is not a whole number of bytes must mask bits, not bytes. +is( xCAT::DiscoveryUtils::nic_network_key( '2001:db8:188:1::5', 60 ), '2001:db8:188::', + 'a /60 masks within the fourth group' ); +is( xCAT::DiscoveryUtils::nic_network_key( '2001:db8:188:1::5', 64 ), '2001:db8:188:1::', + 'and the same address at /64 is a different network' ); + +is( xCAT::DiscoveryUtils::nic_network_key( 'not-an-address', 64 ), undef, + 'a value that is no address keys nothing' ); +is( xCAT::DiscoveryUtils::nic_network_key( undef, 64 ), undef, 'and neither does no address' ); diff --git a/xCAT-test/unit/discovery_node_address_usable.t b/xCAT-test/unit/discovery_node_address_usable.t new file mode 100644 index 0000000000..21e58d2d96 --- /dev/null +++ b/xCAT-test/unit/discovery_node_address_usable.t @@ -0,0 +1,30 @@ +#!/usr/bin/perl +# A discovered node must be resolvable before its MAC is recorded. +# +# nodediscover.pm gated that on inet_aton($node), which answers only for IPv4. A node whose only +# address is IPv6 -- the pool node of seq_discovery_ipv6 carries ip=2001:db8:188::21 -- failed the +# gate, so process_request logged "Can not resolve IP for the matching node" and returned. +# update_discovery_data runs after every one of those early returns, so no discoverydata row was +# written, no mac was set and makedhcp never ran. Measured: tabdump discoverydata empty on +# xcat88-mn after a full seq_discovery_ipv6 run. +use strict; +use warnings; +use Test::More tests => 7; +use FindBin; +use lib "$FindBin::Bin/../../perl-xCAT"; + +require xCAT::DiscoveryUtils; + +can_ok( 'xCAT::DiscoveryUtils', 'discovery_address_usable' ); + +is( xCAT::DiscoveryUtils::discovery_address_usable('2001:db8:188::21'), 1, + 'an IPv6 address is usable, which is the whole defect' ); +is( xCAT::DiscoveryUtils::discovery_address_usable('192.168.88.21'), 1, + 'an IPv4 address stays usable -- every green discovery cell depends on this' ); +is( xCAT::DiscoveryUtils::discovery_address_usable(undef), 0, 'no address is not usable' ); +is( xCAT::DiscoveryUtils::discovery_address_usable(''), 0, 'an empty address is not usable' ); +is( xCAT::DiscoveryUtils::discovery_address_usable('seqdisc1'), 0, + 'a name that never resolved is not an address' ); +# A link-local carries a scope and names no node on the provisioning network. +is( xCAT::DiscoveryUtils::discovery_address_usable('fe80::1%eth0'), 0, + 'a scoped link-local is not usable' );