Browse Source

fix(TEST MULTINIC): shellcheck

master
Harald Hoyer 3 years ago committed by Harald Hoyer
parent
commit
c864f8938c
  1. 0
      test/TEST-50-MULTINIC/.shchkdir
  2. 122
      test/TEST-50-MULTINIC/client-init.sh
  3. 2
      test/TEST-50-MULTINIC/create-root.sh
  4. 48
      test/TEST-50-MULTINIC/server-init.sh
  5. 71
      test/TEST-50-MULTINIC/test.sh

0
test/TEST-50-MULTINIC/.shchkdir

122
test/TEST-50-MULTINIC/client-init.sh

@ -1,126 +1,20 @@ @@ -1,126 +1,20 @@
#!/bin/sh
getcmdline() {
while read -r _line || [ -n "$_line" ]; do
printf "%s" "$_line"
done < /proc/cmdline
}
. /lib/dracut-lib.sh

_dogetarg() {
local _o _val _doecho
unset _val
unset _o
unset _doecho
CMDLINE=$(getcmdline)

for _o in $CMDLINE; do
if [ "${_o%%=*}" = "${1%%=*}" ]; then
if [ -n "${1#*=}" -a "${1#*=*}" != "${1}" ]; then
# if $1 has a "=<value>", we want the exact match
if [ "$_o" = "$1" ]; then
_val="1"
unset _doecho
fi
continue
fi

if [ "${_o#*=}" = "$_o" ]; then
# if cmdline argument has no "=<value>", we assume "=1"
_val="1"
unset _doecho
continue
fi

_val="${_o#*=}"
_doecho=1
fi
done
if [ -n "$_val" ]; then
[ "x$_doecho" != "x" ] && echo "$_val"
return 0
fi
return 1
}

getarg() {
local _deprecated _newoption
while [ $# -gt 0 ]; do
case $1 in
-d)
_deprecated=1
shift
;;
-y)
if _dogetarg $2 > /dev/null; then
if [ "$_deprecated" = "1" ]; then
[ -n "$_newoption" ] && warn "Kernel command line option '$2' is deprecated, use '$_newoption' instead." || warn "Option '$2' is deprecated."
fi
echo 1
return 0
fi
_deprecated=0
shift 2
;;
-n)
if _dogetarg $2 > /dev/null; then
echo 0
if [ "$_deprecated" = "1" ]; then
[ -n "$_newoption" ] && warn "Kernel command line option '$2' is deprecated, use '$_newoption=0' instead." || warn "Option '$2' is deprecated."
fi
return 1
fi
_deprecated=0
shift 2
;;
*)
if [ -z "$_newoption" ]; then
_newoption="$1"
fi
if _dogetarg $1; then
if [ "$_deprecated" = "1" ]; then
[ -n "$_newoption" ] && warn "Kernel command line option '$1' is deprecated, use '$_newoption' instead." || warn "Option '$1' is deprecated."
fi
return 0
fi
_deprecated=0
shift
;;
esac
done
return 1
}

getargbool() {
local _b
unset _b
local _default
_default="$1"
shift
_b=$(getarg "$@")
[ $? -ne 0 -a -z "$_b" ] && _b="$_default"
if [ -n "$_b" ]; then
[ $_b = "0" ] && return 1
[ $_b = "no" ] && return 1
[ $_b = "off" ] && return 1
fi
return 0
}

exec > /dev/console 2>&1
set -x
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
strstr() { [ "${1##*"$2"*}" != "$1" ]; }
strglobin() { [ -n "$1" -a -z "${1##*$2*}" ]; }
CMDLINE=$(while read line || [ -n "$line" ]; do echo $line; done < /proc/cmdline)
command -v plymouth > /dev/null 2>&1 && plymouth --quit
exec > /dev/console 2>&1

export TERM=linux
export PS1='initramfs-test:\w\$ '
stty sane
echo "made it to the rootfs! Powering down."
for i in /sys/class/net/*; do
# booting with network-manager module
state=/run/NetworkManager/devices/$(cat $i/ifindex)
grep -q connection-uuid= $state 2> /dev/null || continue
state=/run/NetworkManager/devices/$(cat "$i"/ifindex)
grep -q connection-uuid= "$state" 2> /dev/null || continue
i=${i##*/}
ip link show $i | grep -q master && continue
ip link show "$i" | grep -q master && continue
IFACES+="$i "
done
for i in /run/initramfs/net.*.did-setup; do
@ -136,4 +30,6 @@ done @@ -136,4 +30,6 @@ done
} | dd oflag=direct,dsync of=/dev/sda

getargbool 0 rd.shell && sh -i

sync
poweroff -f

2
test/TEST-50-MULTINIC/create-root.sh

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
#!/bin/sh
# don't let udev and this script step on eachother's toes
for x in 64-lvm.rules 70-mdadm.rules 99-mount-rules; do
> "/etc/udev/rules.d/$x"
: > "/etc/udev/rules.d/$x"
done
rm -f -- /etc/lvm/lvm.conf
udevadm control --reload

48
test/TEST-50-MULTINIC/server-init.sh

@ -4,7 +4,7 @@ set -x @@ -4,7 +4,7 @@ set -x
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
export TERM=linux
export PS1='nfstest-server:\w\$ '
echo > /dev/watchdog
echo : > /dev/watchdog
stty sane
echo "made it to the rootfs!"
echo server > /proc/sys/kernel/hostname
@ -13,10 +13,10 @@ wait_for_if_link() { @@ -13,10 +13,10 @@ wait_for_if_link() {
local cnt=0
local li
while [ $cnt -lt 600 ]; do
li=$(ip -o link show dev $1 2> /dev/null)
li=$(ip -o link show dev "$1" 2> /dev/null)
[ -n "$li" ] && return 0
if [[ $2 ]]; then
li=$(ip -o link show dev $2 2> /dev/null)
li=$(ip -o link show dev "$2" 2> /dev/null)
[ -n "$li" ] && return 0
fi
sleep 0.1
@ -29,7 +29,7 @@ wait_for_if_up() { @@ -29,7 +29,7 @@ wait_for_if_up() {
local cnt=0
local li
while [ $cnt -lt 200 ]; do
li=$(ip -o link show up dev $1)
li=$(ip -o link show up dev "$1")
[ -n "$li" ] && return 0
sleep 0.1
cnt=$((cnt + 1))
@ -49,52 +49,54 @@ wait_for_route_ok() { @@ -49,52 +49,54 @@ wait_for_route_ok() {
}

linkup() {
wait_for_if_link $1 2> /dev/null && ip link set $1 up 2> /dev/null && wait_for_if_up $1 2> /dev/null
wait_for_if_link "$1" 2> /dev/null && ip link set "$1" up 2> /dev/null && wait_for_if_up "$1" 2> /dev/null
}

wait_for_if_link eth0 ens2

> /dev/watchdog
: > /dev/watchdog
ip addr add 127.0.0.1/8 dev lo
linkup lo
ip link set dev eth0 name ens2
ip addr add 192.168.50.1/24 dev ens2
linkup ens2

> /dev/watchdog
: > /dev/watchdog
modprobe af_packet
> /dev/watchdog
: > /dev/watchdog
modprobe sunrpc
> /dev/watchdog
: > /dev/watchdog
mount -t rpc_pipefs sunrpc /var/lib/nfs/rpc_pipefs
> /dev/watchdog
: > /dev/watchdog
[ -x /sbin/portmap ] && portmap
> /dev/watchdog
: > /dev/watchdog
mkdir -p /run/rpcbind
[ -x /sbin/rpcbind ] && rpcbind
> /dev/watchdog
: > /dev/watchdog
modprobe nfsd
> /dev/watchdog
: > /dev/watchdog
mount -t nfsd nfsd /proc/fs/nfsd
> /dev/watchdog
: > /dev/watchdog
exportfs -r
> /dev/watchdog
: > /dev/watchdog
rpc.nfsd
> /dev/watchdog
: > /dev/watchdog
rpc.mountd
> /dev/watchdog
: > /dev/watchdog
rpc.idmapd -S
> /dev/watchdog
: > /dev/watchdog
exportfs -r
> /dev/watchdog
> /var/lib/dhcpd/dhcpd.leases
> /dev/watchdog
: > /dev/watchdog

: > /var/lib/dhcpd/dhcpd.leases

: > /dev/watchdog
chmod 777 /var/lib/dhcpd/dhcpd.leases
> /dev/watchdog
: > /dev/watchdog
dhcpd -d -cf /etc/dhcpd.conf -lf /var/lib/dhcpd/dhcpd.leases &
echo "Serving NFS mounts"
while :; do
[ -n "$(jobs -rp)" ] && echo > /dev/watchdog
[ -n "$(jobs -rp)" ] && echo : > /dev/watchdog
sleep 10
done
mount -n -o remount,ro /

71
test/TEST-50-MULTINIC/test.sh

@ -8,6 +8,7 @@ else @@ -8,6 +8,7 @@ else
OMIT_NETWORK="network-manager"
fi

# shellcheck disable=SC2034
TEST_DESCRIPTION="root filesystem on NFS with multiple nics with $USE_NETWORK"

KVERSION=${KVERSION-$(uname -r)}
@ -20,12 +21,11 @@ run_server() { @@ -20,12 +21,11 @@ run_server() {
# Start server first
echo "MULTINIC TEST SETUP: Starting DHCP/NFS server"

$testdir/run-qemu \
"$testdir"/run-qemu \
-drive format=raw,index=0,media=disk,file="$TESTDIR"/server.ext3 \
-net socket,listen=127.0.0.1:12350 \
-net nic,macaddr=52:54:01:12:34:56,model=e1000 \
${SERIAL:+-serial "$SERIAL"} \
${SERIAL:--serial file:"$TESTDIR"/server.log} \
-serial "${SERIAL:-"file:$TESTDIR/server.log"}" \
-watchdog i6300esb -watchdog-action poweroff \
-append "panic=1 systemd.crash_reboot loglevel=7 root=LABEL=dracut rootfstype=ext3 rw console=ttyS0,115200n81 selinux=0" \
-initrd "$TESTDIR"/initramfs.server \
@ -65,11 +65,11 @@ client_test() { @@ -65,11 +65,11 @@ client_test() {
return 1
fi

$testdir/run-qemu -drive format=raw,index=0,media=disk,file="$TESTDIR"/client.img \
"$testdir"/run-qemu -drive format=raw,index=0,media=disk,file="$TESTDIR"/client.img \
-net socket,connect=127.0.0.1:12350 \
-net nic,macaddr=52:54:00:12:34:$mac1,model=e1000 \
-net nic,macaddr=52:54:00:12:34:$mac2,model=e1000 \
-net nic,macaddr=52:54:00:12:34:$mac3,model=e1000 \
-net nic,macaddr=52:54:00:12:34:"$mac1",model=e1000 \
-net nic,macaddr=52:54:00:12:34:"$mac2",model=e1000 \
-net nic,macaddr=52:54:00:12:34:"$mac3",model=e1000 \
-netdev hubport,id=n1,hubid=1 \
-netdev hubport,id=n2,hubid=2 \
-device e1000,netdev=n1,mac=52:54:00:12:34:98 \
@ -79,8 +79,8 @@ client_test() { @@ -79,8 +79,8 @@ client_test() {
-initrd "$TESTDIR"/initramfs.testing

{
read OK
read IFACES
read -r OK
read -r IFACES
} < "$TESTDIR"/client.img

if [[ $OK != "OK" ]]; then
@ -178,26 +178,28 @@ test_setup() { @@ -178,26 +178,28 @@ test_setup() {

kernel=$KVERSION
(
mkdir -p $TESTDIR/overlay/source
mkdir -p "$TESTDIR"/overlay/source
# shellcheck disable=SC2030
export initdir=$TESTDIR/overlay/source
. $basedir/dracut-init.sh
# shellcheck disable=SC1090
. "$basedir"/dracut-init.sh

(
cd "$initdir"
cd "$initdir" || exit
mkdir -p -- dev sys proc run var/run etc tmp var/lib/{dhcpd,rpcbind}
mkdir -p -- var/lib/nfs/{v4recovery,rpc_pipefs}
chmod 777 -- var/lib/rpcbind var/lib/nfs
)

for _f in modules.builtin.bin modules.builtin; do
[[ $srcmods/$_f ]] && break
[[ -f $srcmods/$_f ]] && break
done || {
dfatal "No modules.builtin.bin and modules.builtin found!"
return 1
}

for _f in modules.builtin.bin modules.builtin modules.order; do
[[ $srcmods/$_f ]] && inst_simple "$srcmods/$_f" "/lib/modules/$kernel/$_f"
[[ -f $srcmods/$_f ]] && inst_simple "$srcmods/$_f" "/lib/modules/$kernel/$_f"
done

inst_multiple sh ls shutdown poweroff stty cat ps ln ip \
@ -245,10 +247,13 @@ test_setup() { @@ -245,10 +247,13 @@ test_setup() {

# Make client root inside server root
(
# shellcheck disable=SC2030
# shellcheck disable=SC2031
export initdir=$TESTDIR/overlay/source/nfs/client
. $basedir/dracut-init.sh
# shellcheck disable=SC1090
. "$basedir"/dracut-init.sh
(
cd "$initdir"
cd "$initdir" || exit
mkdir -p dev sys proc etc run
mkdir -p var/lib/nfs/rpc_pipefs
mkdir -p root usr/bin usr/lib usr/lib64 usr/sbin
@ -257,12 +262,18 @@ test_setup() { @@ -257,12 +262,18 @@ test_setup() {
done
)
inst_multiple sh shutdown poweroff stty cat ps ln ip \
mount dmesg mkdir cp ping grep ls dd
mount dmesg mkdir cp ping grep ls dd sync
for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
[[ -f ${_terminfodir}/l/linux ]] && break
done
inst_multiple -o "${_terminfodir}"/l/linux
inst_simple /etc/os-release

inst_simple "${basedir}/modules.d/99base/dracut-lib.sh" "/lib/dracut-lib.sh"
inst_binary "${basedir}/dracut-util" "/usr/bin/dracut-util"
ln -s dracut-util "${initdir}/usr/bin/dracut-getarg"
ln -s dracut-util "${initdir}/usr/bin/dracut-getargs"

inst ./client-init.sh /sbin/init
inst /etc/nsswitch.conf /etc/nsswitch.conf
inst /etc/passwd /etc/passwd
@ -286,8 +297,11 @@ test_setup() { @@ -286,8 +297,11 @@ test_setup() {

# second, install the files needed to make the root filesystem
(
# shellcheck disable=SC2030
# shellcheck disable=SC2031
export initdir=$TESTDIR/overlay
. $basedir/dracut-init.sh
# shellcheck disable=SC1090
. "$basedir"/dracut-init.sh
inst_multiple sfdisk mkfs.ext3 poweroff cp umount sync dd
inst_hook initqueue 01 ./create-root.sh
inst_hook initqueue/finished 01 ./finished-false.sh
@ -297,24 +311,26 @@ test_setup() { @@ -297,24 +311,26 @@ test_setup() {
# create an initramfs that will create the target root filesystem.
# We do it this way so that we do not risk trashing the host mdraid
# devices, volume groups, encrypted partitions, etc.
$basedir/dracut.sh -l -i $TESTDIR/overlay / \
"$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \
-m "bash udev-rules base rootfs-block fs-lib kernel-modules fs-lib qemu" \
-d "piix ide-gd_mod ata_piix ext3 sd_mod" \
--nomdadmconf \
--no-hostonly-cmdline -N \
-f $TESTDIR/initramfs.makeroot $KVERSION || return 1
-f "$TESTDIR"/initramfs.makeroot "$KVERSION" || return 1

# Invoke KVM and/or QEMU to actually create the target filesystem.
$testdir/run-qemu \
-drive format=raw,index=0,media=disk,file=$TESTDIR/server.ext3 \
"$testdir"/run-qemu \
-drive format=raw,index=0,media=disk,file="$TESTDIR"/server.ext3 \
-append "root=/dev/dracut/root rw rootfstype=ext3 quiet console=ttyS0,115200n81 selinux=0" \
-initrd $TESTDIR/initramfs.makeroot || return 1
grep -U --binary-files=binary -F -m 1 -q dracut-root-block-created $TESTDIR/server.ext3 || return 1
-initrd "$TESTDIR"/initramfs.makeroot || return 1
grep -U --binary-files=binary -F -m 1 -q dracut-root-block-created "$TESTDIR"/server.ext3 || return 1
rm -fr "$TESTDIR"/overlay

# Make an overlay with needed tools for the test harness
(
# shellcheck disable=SC2031
export initdir="$TESTDIR"/overlay
# shellcheck disable=SC1090
. "$basedir"/dracut-init.sh
inst_multiple poweroff shutdown
inst_hook shutdown-emergency 000 ./hard-off.sh
@ -324,7 +340,7 @@ test_setup() { @@ -324,7 +340,7 @@ test_setup() {
)

# Make server's dracut image
$basedir/dracut.sh \
"$basedir"/dracut.sh \
-l -i "$TESTDIR"/overlay / \
-m "dash udev-rules base rootfs-block fs-lib debug kernel-modules watchdog qemu" \
-d "af_packet piix ide-gd_mod ata_piix ext3 sd_mod nfsv2 nfsv3 nfsv4 nfs_acl nfs_layout_nfsv41_files nfsd e1000 i6300esb ib700wdt" \
@ -332,7 +348,7 @@ test_setup() { @@ -332,7 +348,7 @@ test_setup() {
-f "$TESTDIR"/initramfs.server "$KVERSION" || return 1

# Make client's dracut image
$basedir/dracut.sh \
"$basedir"/dracut.sh \
-l -i "$TESTDIR"/overlay / \
-o "plymouth ${OMIT_NETWORK}" \
-a "debug ${USE_NETWORK}" \
@ -343,7 +359,7 @@ test_setup() { @@ -343,7 +359,7 @@ test_setup() {

kill_server() {
if [[ -s "$TESTDIR"/server.pid ]]; then
kill -TERM -- $(cat "$TESTDIR"/server.pid)
kill -TERM -- "$(cat "$TESTDIR"/server.pid)"
rm -f -- "$TESTDIR"/server.pid
fi
}
@ -352,4 +368,5 @@ test_cleanup() { @@ -352,4 +368,5 @@ test_cleanup() {
kill_server
}

# shellcheck disable=SC1090
. "$testdir"/test-functions

Loading…
Cancel
Save