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/makehosts_dual_stack.t
T
Daniel Hilst 2811c2761d fix(xcat-core): the byte-order warning cannot be silenced, and a delete keeps one family
makedhcp reported a vpd.uuid that looks byte-swapped for duid=firmware and duid=canonical as
well as for a node with no duid attribute. Setting duid is the remedy the message names, so the
message could not be silenced except by a literal DUID. The check reads the version field, which
also reports a UUID that does not follow RFC 4122. It is now reported only for a node with no
duid attribute, and makedhcp.8 says so.

delnode removed only the lines of the family of the address it was given. A node whose address
changed from IPv4 to IPv6 kept its old A record, and makedhcp then wrote a DHCPv4 reservation
with a boot file for a node whose only address was IPv6. The family filter stays on the update
path, which is what keeps both records of a dual-stack node.

dhcp_dhcpv6_duid.t asserts that each duid value silences the report and that the default still
makes it. makehosts_dual_stack.t asserts a family change followed by a delete. Reverting either
fix fails exactly one assertion in each file.

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

67 lines
3.2 KiB
Perl

#!/usr/bin/env perl
#
# A dual-stack node has an A line and an AAAA line in /etc/hosts under one node name, and that is
# the only way to give it both records through makehosts and makedns. The node index recorded node
# names for IPv6 lines as well as IPv4 ones, and addnode overwrites the first match and blanks every
# other one, so running makehosts for a node with an IPv4 hosts.ip deleted its IPv6 line.
#
# A node name now matches only lines of the family being written. The reason the index records node
# names at all -- so a node that CHANGES address does not leave a second entry -- still holds, and
# is asserted here per family.
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../../perl-xCAT";
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
use Test::More tests => 13;
require "$FindBin::Bin/../../xCAT-server/lib/xcat/plugins/hosts.pm";
my $pkg = 'xCAT_plugin::hosts';
no strict 'refs';
my $set = \&{"${pkg}::_set_host_lines"};
my $match = \&{"${pkg}::_matching_host_indexes"};
use strict 'refs';
# A dual-stack node: both families under one name.
$set->([ "192.0.2.10 node01\n", "2001:db8::10 node01\n" ]);
my @v4 = $match->('node01', '192.0.2.10');
is(scalar(@v4), 1, 'writing the IPv4 address matches one line');
is($v4[0], 0, 'and it is the IPv4 line, so the IPv6 line is not blanked');
my @v6 = $match->('node01', '2001:db8::10');
is(scalar(@v6), 1, 'writing the IPv6 address matches one line');
is($v6[0], 1, 'and it is the IPv6 line, so the IPv4 line is not blanked');
# The reason the node index exists: a node that changes address must not leave a second entry.
$set->([ "192.0.2.10 node01\n", "2001:db8::10 node01\n" ]);
my @moved4 = $match->('node01', '192.0.2.99');
is(scalar(@moved4), 1, 'an IPv4 address change still matches the old IPv4 line');
is($moved4[0], 0, 'so makehosts replaces it instead of adding a second entry');
my @moved6 = $match->('node01', '2001:db8::99');
is(scalar(@moved6), 1, 'an IPv6 address change still matches the old IPv6 line');
is($moved6[0], 1, 'so the IPv6 entry is replaced, not duplicated');
# A name that is not in the file matches nothing, so the matcher is not simply permissive.
is(scalar($match->('node99', '192.0.2.99')), 0, 'an unknown node matches no line');
# A DELETE takes every family. The filter above keeps the other record during an update; applied
# to a delete it left the old record behind when the address of a node changed family, and
# makedhcp then wrote a DHCPv4 reservation for a node whose only address was IPv6.
no strict 'refs';
my $del = \&{"${pkg}::delnode"};
use strict 'refs';
$set->([ "192.0.2.10 node01\n", "2001:db8::10 node01\n", "192.0.2.11 node02\n" ]);
is(scalar($match->('node01', '2001:db8::10', all_families => 1)), 2,
'a delete matches the lines of both families');
# The address of the node changed from IPv4 to IPv6, and then the node is deleted. _set_host_line
# maintains the index, so a line that no longer matches is a line that was removed.
$del->('node01', '2001:db8::10');
is(scalar($match->('node01', '192.0.2.10')), 0, 'the IPv4 record of the deleted node is gone');
is(scalar($match->('node01', '2001:db8::10')), 0, 'the IPv6 record of the deleted node is gone');
is(scalar($match->('node02', '192.0.2.11')), 1, 'and the other node still has its line');