2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-29 22:02:20 +00:00

test(xcat-core): capture the missing Kea relayed subnet and the empty EL8 NIC dump

Two non-gating cases fail on the EL x86_64 CI cells. These tests capture both defects before
the fixes land.

makedhcp_remote_network fails on EL10 and passes on EL8 and EL9, where the DHCP backend is
ISC. The new case in dhcp_kea_plugin_intent.t asks kea_build_dhcp4_intent for one relayed
network and one local network, and holds down both subnets and their interface binding.

confignetwork_secondarynic_nicextraparams_updatenode fails on EL8 only.
nic_cfg_show_backend_file.bats drives "nic_cfg.sh show" with nmcli stubbed, for an
ifcfg-backed connection and for a keyfile-backed one.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
(cherry picked from commit 11d6a20d3d56d12d7c3c0e9eda3645c86a1264b6)
This commit is contained in:
Daniel Hilst
2026-10-02 13:47:07 -03:00
parent 5952dc04a2
commit 28f0e3f2ac
2 changed files with 179 additions and 0 deletions
@@ -0,0 +1,99 @@
#!/usr/bin/env bats
#
# nic_cfg.sh show must dump the file NetworkManager actually keeps the connection in.
#
# Regression: nm_show looked for a keyfile under /etc/NetworkManager/system-connections and
# dumped nothing when it found none. On EL8 the ifcfg-rh plugin owns an xCAT connection and
# writes /etc/sysconfig/network-scripts/ifcfg-xcat-<nic>, which is where configeth puts an
# extra param such as CONNECTED_MODE. So confignetwork_secondarynic_nicextraparams_updatenode
# read a dump with no extra params in it and failed on EL8 while passing on EL9 and EL10.
#
# nmcli and systemctl are stubbed, so no NetworkManager is needed and nothing on the host is
# read or written.
load 'helpers/shell_source'
UUID=4f99157f-c20a-4a05-bb48-f073abbf027a
setup()
{
SCRIPT="$(require_repo_file 'xCAT-test/autotest/testcase/commoncmd/nic_cfg.sh')"
BIN="${BATS_TEST_TMPDIR}/bin"
mkdir -p "$BIN"
printf '#!/bin/sh\nexit 0\n' >"$BIN/systemctl"
chmod 0755 "$BIN/systemctl"
export PATH="$BIN:$PATH"
}
# Write an nmcli that answers for one connection kept in $1, reporting $2 as 802-3-ethernet.mtu.
stub_nmcli()
{
local file="$1" ethernet_mtu="$2"
cat >"$BIN/nmcli" <<EOF
#!/bin/sh
args="\$*"
case "\$args" in
"-t -f NAME,DEVICE connection show --active") echo "xcat-ens4:ens4" ;;
"-t -f NAME,DEVICE connection show") echo "xcat-ens4:ens4" ;;
"-g connection.uuid connection show xcat-ens4") echo "${UUID}" ;;
"-t -f UUID,FILENAME connection show") echo "${UUID}:${file}" ;;
"-g ipv4.method connection show xcat-ens4") echo "manual" ;;
"-g ipv4.addresses connection show xcat-ens4") echo "11.1.0.100/16" ;;
"-g 802-3-ethernet.mtu connection show xcat-ens4") echo "${ethernet_mtu}" ;;
*) echo "unexpected nmcli \$args" >&2; exit 1 ;;
esac
EOF
chmod 0755 "$BIN/nmcli"
}
@test "an ifcfg-backed connection has its ifcfg file dumped" {
local ifcfg="${BATS_TEST_TMPDIR}/ifcfg-xcat-ens4"
cat >"$ifcfg" <<'EOF'
DEVICE=ens4
BOOTPROTO=none
IPADDR=11.1.0.100
PREFIX=16
CONNECTED_MODE=yes
EOF
stub_nmcli "$ifcfg" ""
run "$SCRIPT" show ens4
[ "$status" -eq 0 ]
[[ "$output" == *"NAME=xcat-ens4"* ]]
[[ "$output" == *"IPADDR=11.1.0.100"* ]]
[[ "$output" == *"CONNECTED_MODE=yes"* ]]
}
@test "an ifcfg-backed connection reports the MTU the ifcfg file names" {
local ifcfg="${BATS_TEST_TMPDIR}/ifcfg-xcat-ens4"
printf 'DEVICE=ens4\nMTU=1496\n' >"$ifcfg"
stub_nmcli "$ifcfg" ""
run "$SCRIPT" show ens4
[ "$status" -eq 0 ]
[[ "$output" == *"MTU=1496"* ]]
}
@test "a keyfile-backed connection still has its keyfile dumped" {
local keyfile="${BATS_TEST_TMPDIR}/xcat-ens4.nmconnection"
cat >"$keyfile" <<EOF
[connection]
id=xcat-ens4
uuid=${UUID}
[ethernet]
mtu=1496
[user]
xcat.CONNECTED_MODE=yes
EOF
stub_nmcli "$keyfile" "1496"
run "$SCRIPT" show ens4
[ "$status" -eq 0 ]
[[ "$output" == *"MTU=1496"* ]]
[[ "$output" == *"xcat.CONNECTED_MODE=yes"* ]]
}
+80
View File
@@ -114,6 +114,30 @@ require xCAT::DHCP::Backend::Kea;
sub close { return; }
}
{
# Several networks, answered per net and mask, so a test can tell one subnet from
# another. DHCPKeaIntentNetTable answers every query with the same row.
package DHCPKeaIntentMultiNetTable;
sub new {
my ( $class, @entries ) = @_;
return bless { entries => [@entries] }, $class;
}
sub getAllAttribs {
my ($self) = @_;
return map { { %{$_} } } @{ $self->{entries} };
}
sub getAttribs {
my ( $self, $criteria ) = @_;
foreach my $entry ( @{ $self->{entries} } ) {
next unless $entry->{net} eq $criteria->{net};
next unless $entry->{mask} eq $criteria->{mask};
return { %{$entry} };
}
return;
}
sub close { return; }
}
my %network_entry = (
net => '10.0.0.0',
mask => '255.255.255.0',
@@ -1827,4 +1851,60 @@ foreach my $case (@invalid_mac_cases) {
'syncing the node client classes with no noderes or mac table does not die' ) or diag($@);
}
{
# A network whose mgtifname is "!remote!<nic>" is reached through a relay agent, so
# site.dhcpinterfaces never names it and %activenics never carries a "!remote!" key.
# Without a subnet4 of its own, subnet_id_for_ip finds nothing for a node on that
# network and makedhcp writes no reservation (makedhcp_remote_network).
my %local_net = (
net => '10.0.0.0',
mask => '255.255.255.0',
mgtifname => 'eth0',
dynamicrange => '10.0.0.100-10.0.0.150',
domain => 'cluster.test',
tftpserver => '<xcatmaster>',
);
my %relayed_net = (
net => '100.100.100.0',
mask => '255.255.255.0',
mgtifname => '!remote!eth0',
domain => 'cluster.test',
tftpserver => '<xcatmaster>',
);
no warnings 'redefine';
local *xCAT::NetworkUtils::thishostisnot = sub { return 0; };
local *xCAT_plugin::dhcp::kea_ipv4_routes = sub {
return (
[ '10.0.0.0', 'eth0', '255.255.255.0', '' ],
[ '100.100.100.0', '!remote!eth0', '255.255.255.0', '' ],
);
};
local *xCAT_plugin::dhcp::kea_boot_client_classes = sub { return []; };
local *xCAT_plugin::dhcp::kea_option_defs = sub { return []; };
local *xCAT_plugin::dhcp::kea_global_option_data = sub { return []; };
local *xCAT_plugin::dhcp::kea_dhcp_lease_time = sub { return 43200; };
local *xCAT_plugin::dhcp::kea_control_agent_enabled = sub { return 0; };
local $xCAT::Table::networks =
DHCPKeaIntentMultiNetTable->new( \%local_net, \%relayed_net );
my $intent = xCAT_plugin::dhcp::kea_build_dhcp4_intent(
bless( {}, 'DHCPKeaIntentBackend' ), { eth0 => 1 }
);
is_deeply(
[
map { [ $_->{subnet}, exists $_->{interface} ? $_->{interface} : undef ] }
sort { $a->{subnet} cmp $b->{subnet} } @{ $intent->{subnets} }
],
[ [ '10.0.0.0/24', 'eth0' ], [ '100.100.100.0/24', undef ] ],
'the relayed network gets a subnet, and it names no local interface'
);
is_deeply(
$intent->{interfaces}, ['eth0'],
'the relay marker is not served as an interface'
);
}
done_testing();