diff --git a/xCAT-test/bats/nic_cfg_show_backend_file.bats b/xCAT-test/bats/nic_cfg_show_backend_file.bats new file mode 100644 index 0000000000..7896316a7e --- /dev/null +++ b/xCAT-test/bats/nic_cfg_show_backend_file.bats @@ -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-, 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" <&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" < [@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!" 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 => '', + ); + my %relayed_net = ( + net => '100.100.100.0', + mask => '255.255.255.0', + mgtifname => '!remote!eth0', + domain => 'cluster.test', + tftpserver => '', + ); + + 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();