2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-19 17:02:15 +00:00
Files
xcat-core/xCAT-test/unit/networkutils_linklocal_preference.t
T
Daniel Hilst 21359734b2 test(xcat-core): cover the dual-stack DHCPv6 boot server on a management node
makedhcp_dhcpv6_boot_intent declares a node with no tftpserver, so it measures only the
<xcatmaster> path. A dual-stack node keeps an IPv4 tftpserver, and that is the path on which
makedhcp exited 1 and dropped the boot URL.

makedhcp_dhcpv6_dual_stack_boot_server declares a grub2 node with an IPv6 address and an IPv4
tftpserver, then asserts that makedhcp exits 0, that Kea accepts the configuration, and that the
bootfile-url names the IPv6 address of the management node facing the node. Both values are
compared exactly, so a dropped option and a wrong authority each fail.

The test addresses move to the documentation ranges at the same time. The three networkutils
tests carried a link-local address read off a lab NIC, and dhcp_kea_plugin_intent.t carried two
addresses from the management network. They are fixtures that nothing dials, so this only keeps
the internal topology out of the upstream tree.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-27 05:35:23 -03:00

111 lines
4.1 KiB
Perl

#!/usr/bin/env perl
# A management node resolves its own name to every address on it, and a
# link-local address is usually first. xcatconfig writes that answer into
# site.master and site.nameservers, which reach every node through DHCP, DNS
# and the kernel command line, so a link-local address there is unusable: a
# node on another link cannot reach it, and the %zone form is not a literal any
# consumer accepts.
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../../perl-xCAT";
use Test::More;
use xCAT::NetworkUtils;
my @cases = (
[ 'a global IPv6 address outranks a link-local one',
[ 'fe80::5054:ff:fe12:3456', '2001:db8::50' ],
'2001:db8::50',
],
[ 'an IPv4 address outranks a link-local IPv6 address',
[ 'fe80::5054:ff:fe12:3456', '192.0.2.154' ],
'192.0.2.154',
],
[ 'the zone identifier is removed from the address that is returned',
[ 'fe80::5054:ff:fe12:3456%mgmt0' ],
'fe80::5054:ff:fe12:3456',
],
[ 'a link-local address is still returned when it is the only one',
[ 'fe80::1%eth0' ],
'fe80::1',
],
[ 'an IPv4 link-local address outranks nothing but another link-local',
[ '169.254.1.1', '192.0.2.154' ],
'192.0.2.154',
],
[ 'the first address wins when none is link-local',
[ '2001:db8::50', '192.0.2.154' ],
'2001:db8::50',
],
[ 'order is kept among link-local addresses',
[ 'fe80::2', 'fe80::3' ],
'fe80::2',
],
);
foreach my $case (@cases) {
my ( $why, $addresses, $expected ) = @{$case};
my @ordered = xCAT::NetworkUtils->prefer_routable_addresses( @{$addresses} );
is( $ordered[0], $expected, $why );
}
is_deeply(
[ xCAT::NetworkUtils->prefer_routable_addresses(
'fe80::1%eth0', '192.0.2.154', 'fe80::2', '2001:db8::50' ) ],
[ '192.0.2.154', '2001:db8::50', 'fe80::1', 'fe80::2' ],
'every routable address comes before every link-local one, order kept inside each group'
);
is_deeply( [ xCAT::NetworkUtils->prefer_routable_addresses() ],
[], 'an empty list stays empty' );
# getipaddr reaches the resolver through one of two code paths, and only the
# Socket6 one runs on a management node that has Socket6 installed. Both order
# their results, so both are covered here. Socket6::getaddrinfo answers a flat
# list of five-element records, so the records move and their elements do not.
{
no warnings 'once', 'redefine';
local *Socket6::NI_NUMERICHOST = sub { 1 };
local *Socket6::getnameinfo = sub {
my %address_of = (
PACKED_LINKLOCAL => 'fe80::5054:ff:fe12:3456',
PACKED_GLOBAL => '2001:db8::50',
PACKED_V4 => '192.0.2.154',
PACKED_BROKEN => undef,
);
return ( $address_of{ $_[0] } );
};
my @flat = (
10, 1, 6, 'PACKED_LINKLOCAL', 'linklocal.example',
2, 1, 6, 'PACKED_V4', 'v4.example',
10, 1, 6, 'PACKED_GLOBAL', 'global.example',
);
my @ordered = xCAT::NetworkUtils::_socket6_addrinfo_routable_first(@flat);
is( scalar(@ordered), 15, 'every record survives the reorder' );
is_deeply( [ @ordered[ 3, 8, 13 ] ],
[ 'PACKED_V4', 'PACKED_GLOBAL', 'PACKED_LINKLOCAL' ],
'the link-local record moves behind both routable records' );
is_deeply( [ @ordered[ 0 .. 4 ] ],
[ 2, 1, 6, 'PACKED_V4', 'v4.example' ],
'the five elements of a record stay with that record' );
my @with_broken = xCAT::NetworkUtils::_socket6_addrinfo_routable_first(
10, 1, 6, 'PACKED_BROKEN', 'broken.example',
10, 1, 6, 'PACKED_GLOBAL', 'global.example',
);
is( $with_broken[3], 'PACKED_GLOBAL',
'a record whose address cannot be read goes last, not first' );
is_deeply( [ xCAT::NetworkUtils::_socket6_addrinfo_routable_first( 1, 2, 3 ) ],
[ 1, 2, 3 ],
'a list that is not a whole number of records is returned untouched' );
}
is_deeply(
[ xCAT::NetworkUtils->prefer_routable_addresses( undef, '', '192.0.2.154' ) ],
['192.0.2.154'], 'undef and empty entries are dropped' );
done_testing();