mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-26 12:22:15 +00:00
fix(xcat-core): restart a NIC when only its MTU changes
A network object that declares mtu=1496 leaves the NIC on its old MTU. After "updatenode <node> -P confignetwork" the connection profile says 1496 and "ip link" says 1500. The new profile is not the active one either, so a query of the NIC reports the MTU of the connection it replaced. configeth chooses between writing the configuration files and also restarting the NIC. It compares the addresses the node has against the addresses the networks table declares, and it sets the flag for nicextraparams. An MTU change is in neither test, so bool_restart_flag stays 0 whenever the NIC is up and xcat_history_important already names it. The files are written, nmcli adds the connection, and the "nmcli con reload; nmcli con up" that activates it never runs. Compare the MTU as well, in xcat_nic_mtu_changed in xcatlib.sh, and set bool_restart_flag when it differs. A network that declares no MTU is unchanged, as is a NIC whose MTU cannot be read. The case that covers this is confignetwork_secondarynic_updatenode. It fails on EL8 and EL9 and passes on EL10, where /etc/sysconfig/network-scripts does not exist, so xcat_history_important is never written and every run takes the restart path. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> (cherry picked from commit bde80e46ce15f6831fe49dda644f193f5d2e5b97)
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# xcat_nic_mtu_changed is the decision configeth makes when it has to choose between writing
|
||||
# the configuration files and also restarting the NIC. Its address comparison cannot see an
|
||||
# MTU change, so a run that changes nothing else left the NIC on its old MTU: the profile said
|
||||
# 1496 and `ip link` still said 1500 (confignetwork_secondarynic_updatenode on EL8 and EL9).
|
||||
#
|
||||
# `ip` is stubbed, so nothing on the host is read.
|
||||
|
||||
load 'helpers/shell_source'
|
||||
|
||||
setup()
|
||||
{
|
||||
LIB="$(require_repo_file 'xCAT/postscripts/xcatlib.sh')"
|
||||
BIN="${BATS_TEST_TMPDIR}/bin"
|
||||
mkdir -p "$BIN"
|
||||
export PATH="$BIN:$PATH"
|
||||
}
|
||||
|
||||
# Write an `ip` that reports $1 as the line for `ip link show dev <nic>`.
|
||||
stub_ip()
|
||||
{
|
||||
printf '#!/bin/sh\nprintf "%%s\\n" "%s"\n' "$1" >"$BIN/ip"
|
||||
chmod 0755 "$BIN/ip"
|
||||
}
|
||||
|
||||
stub_ip_absent_device()
|
||||
{
|
||||
printf '#!/bin/sh\necho "Device does not exist" >&2\nexit 1\n' >"$BIN/ip"
|
||||
chmod 0755 "$BIN/ip"
|
||||
}
|
||||
|
||||
@test "a wanted MTU different from the live one is a change" {
|
||||
stub_ip "3: ens4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000"
|
||||
. "$LIB"
|
||||
run xcat_nic_mtu_changed ens4 1496
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "a wanted MTU equal to the live one is not a change" {
|
||||
stub_ip "3: ens4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1496 qdisc fq_codel state UP group default qlen 1000"
|
||||
. "$LIB"
|
||||
run xcat_nic_mtu_changed ens4 1496
|
||||
[ "$status" -ne 0 ]
|
||||
}
|
||||
|
||||
@test "a network that declares no MTU is not a change" {
|
||||
stub_ip "3: ens4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000"
|
||||
. "$LIB"
|
||||
run xcat_nic_mtu_changed ens4 ""
|
||||
[ "$status" -ne 0 ]
|
||||
run xcat_nic_mtu_changed ens4 default
|
||||
[ "$status" -ne 0 ]
|
||||
}
|
||||
|
||||
@test "a NIC whose MTU cannot be read is not a change" {
|
||||
stub_ip_absent_device
|
||||
. "$LIB"
|
||||
run xcat_nic_mtu_changed ens4 1496
|
||||
[ "$status" -ne 0 ]
|
||||
}
|
||||
@@ -1564,7 +1564,20 @@ else
|
||||
bool_restart_flag=1
|
||||
bool_modify_flag=1
|
||||
fi
|
||||
|
||||
|
||||
#The restart below is what hands a changed MTU to the running NIC.
|
||||
if [ $bool_restart_flag -eq 0 ];then
|
||||
for str_mtu_wanted in "${array_nic_mtu[@]}"
|
||||
do
|
||||
if xcat_nic_mtu_changed "$str_nic_name" "$str_mtu_wanted"; then
|
||||
log_info "configeth on $NODE: $str_nic_name mtu changes to $str_mtu_wanted."
|
||||
bool_restart_flag=1
|
||||
bool_modify_flag=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ $bool_restart_flag = 0 ];then
|
||||
#add the new defined ip
|
||||
old_ifs=$IFS
|
||||
|
||||
@@ -61,6 +61,24 @@ function hashget(){
|
||||
eval echo "\$${str_hashname}"
|
||||
}
|
||||
|
||||
# True when the live MTU of NIC $1 differs from the MTU $2 the networks table declares.
|
||||
# A wanted value that is empty or not a number means the network declares no MTU.
|
||||
xcat_nic_mtu_changed()
|
||||
{
|
||||
local nic="$1"
|
||||
local wanted="$2"
|
||||
local live
|
||||
|
||||
[ -n "$nic" ] || return 1
|
||||
case "$wanted" in
|
||||
''|*[!0-9]*) return 1 ;;
|
||||
esac
|
||||
|
||||
live=$(ip link show dev "$nic" 2>/dev/null | sed -n 's/.*[[:space:]]mtu[[:space:]]\{1,\}\([0-9]\{1,\}\).*/\1/p' | head -1)
|
||||
[ -n "$live" ] || return 1
|
||||
[ "$live" != "$wanted" ]
|
||||
}
|
||||
|
||||
# Match the OSVER forms currently used by EL9+ postscript paths.
|
||||
xcat_is_el9_or_later()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user