diff --git a/xCAT-genesis-scripts/usr/bin/doxcat b/xCAT-genesis-scripts/usr/bin/doxcat index 0779158165..8636887321 100755 --- a/xCAT-genesis-scripts/usr/bin/doxcat +++ b/xCAT-genesis-scripts/usr/bin/doxcat @@ -238,6 +238,18 @@ genesis_nic_has_global_v6() { ip -6 -o addr show dev "$nic" 2>/dev/null | grep -v 'scope link' | grep -q inet6 } +genesis_nic_has_global_v4() { + local nic="$1" + ip -4 -o addr show dev "$nic" 2>/dev/null | grep -v 'scope link' | grep -q inet +} + +# xcatd is reached over whichever family the provisioning network serves, so net init is over +# when the boot nic holds an address of either one. +genesis_nic_has_address() { + local nic="$1" + genesis_nic_has_global_v4 "$nic" || genesis_nic_has_global_v6 "$nic" +} + # Wait for one nic to hold a routable IPv6 address. Returns non-zero after the last try, which # on an IPv4-only network is every time. genesis_wait_nic_v6() { @@ -417,10 +429,10 @@ else gripeiter=101 logger -s -t $log_label -p local4.info "Acquiring network addresses.." - while ! ip -4 -o a show dev $bootnic|grep -v 'scope link'|grep -q inet; do + while ! genesis_nic_has_address "$bootnic"; do sleep 0.1 if [ $gripeiter = 1 ]; then - logger -s -t $log_label -p local4.info "It seems to be taking a while to acquire an IPv4 address, you may want to check spanning tree..." + logger -s -t $log_label -p local4.info "It seems to be taking a while to acquire an address, you may want to check spanning tree..." fi gripeiter=$((gripeiter-1)) done @@ -432,9 +444,13 @@ touch /tmp/netinitted openssl genrsa -out /etc/xcat/certkey.pem 4096 > /dev/null 2>&1 & -logger -s -t $log_label -p local4.info "Acquired IPv4 address on $bootnic" - -ip -4 -o a show dev $bootnic|grep -v 'scope link'|grep -v 'dynamic'|awk '{print $4}' +if genesis_nic_has_global_v4 "$bootnic"; then + logger -s -t $log_label -p local4.info "Acquired IPv4 address on $bootnic" + ip -4 -o addr show dev $bootnic|grep -v 'scope link'|grep -v 'dynamic'|awk '{print $4}' +else + logger -s -t $log_label -p local4.info "Acquired IPv6 address on $bootnic" + ip -6 -o addr show dev $bootnic|grep -v 'scope link'|awk '{print $4}' +fi if [ -e /usr/sbin/ntpd ]; then logger -s -t $log_label -p local4.info "Starting ntpd..." diff --git a/xCAT-test/bats/genesis_secondary_dhcp6_order.bats b/xCAT-test/bats/genesis_secondary_dhcp6_order.bats index bea823d78f..b9b5fb583b 100644 --- a/xCAT-test/bats/genesis_secondary_dhcp6_order.bats +++ b/xCAT-test/bats/genesis_secondary_dhcp6_order.bats @@ -63,3 +63,11 @@ dhcp6_nics() [ "$status" -eq 0 ] [ "$output" = 2 ] } + +@test "the boot nic finishes net init with an IPv6 address and no IPv4 address" { + # The provisioning network of an IPv6 cell declares no IPv4 pool, so no IPv4 address can + # arrive. doxcat has to go on with the address it has, or Genesis never reaches xcatd. + : >"$fixture/addrs4/boot0" + printf '2: boot0 inet6 2001:db8:188::20/64 scope global\n' >"$fixture/addrs6/boot0" + boot_genesis +} diff --git a/xCAT-test/bats/helpers/doxcat_sandbox.bash b/xCAT-test/bats/helpers/doxcat_sandbox.bash index 2abe3dc9d7..b909bad2ef 100644 --- a/xCAT-test/bats/helpers/doxcat_sandbox.bash +++ b/xCAT-test/bats/helpers/doxcat_sandbox.bash @@ -9,7 +9,7 @@ setup_doxcat() local utility fips library fips=$(repo_path xCAT-genesis-scripts/usr/lib/xcat/fips.sh) [ -r "$fips" ] - mkdir -p "$fixture"/{etc/ssh,etc/pki/tls,real,links,addrs,addrs6} + mkdir -p "$fixture"/{etc/ssh,etc/pki/tls,real,links,addrs,addrs4,addrs6} # chmod is in this list because doxcat runs it: the sandbox has no /usr/bin on PATH, so a # command that is missing here is a command that silently does nothing under test. doxcat's # chmod of the sshd privilege separation directory was not exercised until it was added. @@ -56,10 +56,15 @@ case "$*" in '-o addr show dev '*) [ ! -e "/run/fixture/addrs/$5.fail" ] || exit 19 cat "/run/fixture/addrs/$5" ;; - '-6 -o addr show dev '*) + '-6 -o a show dev '*|'-6 -o addr show dev '*) [ ! -e "/run/fixture/addrs6/$6.fail" ] || exit 19 cat "/run/fixture/addrs6/$6" ;; - '-4 -o a show dev '*) printf '2: %s inet 192.0.2.20/24 scope global\n' "$6" ;; + '-4 -o a show dev '*|'-4 -o addr show dev '*) + if [ -e "/run/fixture/addrs4/$6" ]; then + cat "/run/fixture/addrs4/$6" + else + printf '2: %s inet 192.0.2.20/24 scope global\n' "$6" + fi ;; *) printf 'unexpected ip %s\n' "$*" >&2; exit 97 ;; esac SH