mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-19 17:02:15 +00:00
d2947a7f69
addnode and delnode find an existing host entry through the host-entry index, and that index indexed node names only for an IPv4 first field and keyed the address on its literal spelling. So makehosts left two entries for one node: changing node01 from 2001:db8::10 to 2001:db8::20 added the second address and kept the first, and an expanded IPv6 entry stayed when the compressed spelling of the same address was added or deleted. The node resolved to a stale address. _host_entry_matches handled both cases and no code called it. It is removed, because a second place that compares an address is how this file reached this state. xCAT::NetworkUtils gains canonical_ip_address, which answers the one spelling every spelling of an address shares. It is built on _pack_ip_address, so it prefers core Socket and falls back to the optional Socket6. The index keys on that answer, and it indexes node names for any first field whose shape is an address. On a host with no parser for IPv6 the canonical form is undefined and the index keys on the literal. An address change written the same way still leaves one entry, through the node name. An equivalent spelling becomes a second entry, which is the limit of what such a host can decide. makehosts_ipv6.t now runs addnode and delnode and reads the host entries they produced. Eight of its 21 assertions fail against the previous index, including the address change and both spelling-equivalence cases. makehosts_index.t stubbed xCAT::NetworkUtils as an empty package. It loads the real module, because the index now reads the canonical address from it. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
167 lines
3.9 KiB
Perl
167 lines
3.9 KiB
Perl
#!/usr/bin/env perl
|
|
use strict;
|
|
use warnings;
|
|
|
|
use FindBin;
|
|
use Test::More;
|
|
|
|
# The real xCAT::NetworkUtils is loaded, because the host-entry index keys on
|
|
# the canonical form of an address and that is where it comes from. The other
|
|
# modules reach the xCAT database and nothing here calls them.
|
|
use lib "$FindBin::Bin/../../perl-xCAT";
|
|
|
|
BEGIN {
|
|
package xCAT::Table;
|
|
$INC{'xCAT/Table.pm'} = __FILE__;
|
|
|
|
package xCAT::TableUtils;
|
|
$INC{'xCAT/TableUtils.pm'} = __FILE__;
|
|
|
|
package xCAT::Utils;
|
|
$INC{'xCAT/Utils.pm'} = __FILE__;
|
|
|
|
package xCAT::MsgUtils;
|
|
$INC{'xCAT/MsgUtils.pm'} = __FILE__;
|
|
}
|
|
|
|
my $source_hosts_plugin =
|
|
"$FindBin::Bin/../../xCAT-server/lib/xcat/plugins/hosts.pm";
|
|
require $source_hosts_plugin;
|
|
|
|
sub set_host_lines
|
|
{
|
|
return xCAT_plugin::hosts::_set_host_lines([@_]);
|
|
}
|
|
|
|
{
|
|
my $lines = set_host_lines(
|
|
"127.0.0.1 localhost\n",
|
|
"# retained comment\n",
|
|
);
|
|
|
|
xCAT_plugin::hosts::addnode(
|
|
undef, 'node01', '10.0.0.1', 'alias1 alias2', 'cluster.test'
|
|
);
|
|
|
|
is_deeply(
|
|
$lines,
|
|
[
|
|
"127.0.0.1 localhost\n",
|
|
"# retained comment\n",
|
|
"10.0.0.1 node01 node01.cluster.test alias1 alias2\n",
|
|
],
|
|
'new host is appended without changing unrelated lines'
|
|
);
|
|
}
|
|
|
|
{
|
|
my $lines = set_host_lines(
|
|
"10.0.0.1 node01 node01.cluster.test oldalias\n",
|
|
"10.0.0.2 other other.cluster.test\n",
|
|
"10.0.0.3 node01 node01.other.test\n",
|
|
);
|
|
|
|
xCAT_plugin::hosts::addnode(
|
|
undef, 'node01', '10.0.0.2', 'newalias', 'cluster.test'
|
|
);
|
|
|
|
is_deeply(
|
|
$lines,
|
|
[
|
|
"10.0.0.2 node01 node01.cluster.test newalias\n",
|
|
'',
|
|
'',
|
|
],
|
|
'first IP or primary-name match is updated and later duplicates are removed'
|
|
);
|
|
}
|
|
|
|
{
|
|
my $lines = set_host_lines(
|
|
"10.0.0.1 node01.cluster.test node01\n",
|
|
);
|
|
|
|
xCAT_plugin::hosts::addnode(
|
|
undef, 'node01', '10.0.0.9', '', 'cluster.test'
|
|
);
|
|
|
|
is(
|
|
$lines->[0],
|
|
"10.0.0.9 node01 node01.cluster.test \n",
|
|
'short node matches an existing FQDN-first entry'
|
|
);
|
|
}
|
|
|
|
{
|
|
my $lines = set_host_lines(
|
|
"10.0.0.1 node01 node01.cluster.test\n",
|
|
);
|
|
|
|
xCAT_plugin::hosts::addnode(
|
|
undef, 'node01-bmc', '10.0.0.1', 'bmc-alias', 'cluster.test', 1
|
|
);
|
|
is(
|
|
$lines->[0],
|
|
"10.0.0.1 node01 node01.cluster.test bmc-alias\n",
|
|
'NIC entry keeps the existing primary node when matching by IP'
|
|
);
|
|
|
|
xCAT_plugin::hosts::addnode(
|
|
undef, 'node01', '10.0.0.9', '', 'cluster.test'
|
|
);
|
|
is(
|
|
$lines->[0],
|
|
"10.0.0.9 node01 node01.cluster.test \n",
|
|
'updated line remains indexed for the next host change'
|
|
);
|
|
}
|
|
|
|
{
|
|
my $lines = set_host_lines(
|
|
"10.0.0.1 node01 node01.cluster.test\n",
|
|
"10.0.0.2 node02 node02.cluster.test\n",
|
|
"10.0.0.3 node01 node01.other.test\n",
|
|
);
|
|
|
|
xCAT_plugin::hosts::delnode('node01', '10.0.0.2', '', 'cluster.test');
|
|
is_deeply(
|
|
$lines,
|
|
['', '', ''],
|
|
'delete removes every IP or primary-name match'
|
|
);
|
|
|
|
xCAT_plugin::hosts::addnode(
|
|
undef, 'node01', '10.0.0.2', '', 'cluster.test'
|
|
);
|
|
is_deeply(
|
|
$lines,
|
|
['', '', '', "10.0.0.2 node01 node01.cluster.test \n"],
|
|
'deleted lines are removed from the indexes before a later append'
|
|
);
|
|
}
|
|
|
|
{
|
|
my $lines = set_host_lines(
|
|
"fe80::1 node01 node01.cluster.test\n",
|
|
"10.0.0.1 \n",
|
|
);
|
|
|
|
xCAT_plugin::hosts::addnode(
|
|
undef, 'node02', 'fe80::1', '', 'cluster.test'
|
|
);
|
|
xCAT_plugin::hosts::addnode(
|
|
undef, 'node03', '10.0.0.1', '', 'cluster.test'
|
|
);
|
|
|
|
is_deeply(
|
|
$lines,
|
|
[
|
|
"fe80::1 node02 node02.cluster.test \n",
|
|
"10.0.0.1 node03 node03.cluster.test \n",
|
|
],
|
|
'IP index handles IPv6 addresses and entries without a primary name'
|
|
);
|
|
}
|
|
|
|
done_testing();
|