v1 -> v2:
1. selftest: kill VM reliably - use $_jobs instead of `echo $_jobs` to iterate jobs - fix format issue 2. selftest: Make test_base_image depends on EXTRA_RPMS (new)
Coiby Xu (3): selftest: fix the error of misplacing double quotes selftest: kill VM reliably selftest: Make test_base_image depends on EXTRA_RPMS
tests/Makefile | 2 +- tests/scripts/run-test.sh | 14 ++++++++++---- tests/scripts/test-lib.sh | 3 +-- tests/scripts/testcases/nfs-kdump/0-server.sh | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-)
Signed-off-by: Coiby Xu coxu@redhat.com --- tests/scripts/testcases/nfs-kdump/0-server.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/scripts/testcases/nfs-kdump/0-server.sh b/tests/scripts/testcases/nfs-kdump/0-server.sh index 41a0212..cf54e70 100755 --- a/tests/scripts/testcases/nfs-kdump/0-server.sh +++ b/tests/scripts/testcases/nfs-kdump/0-server.sh @@ -17,7 +17,7 @@ on_build() { img_run_cmd "systemctl enable dnsmasq"
img_run_cmd 'echo DEVICE="eth0" > /etc/sysconfig/network-scripts/ifcfg-eth0' - img_run_cmd 'echo BOOTPROTO="none >> /etc/sysconfig/network-scripts/ifcfg-eth0"' + img_run_cmd 'echo BOOTPROTO="none" >> /etc/sysconfig/network-scripts/ifcfg-eth0' img_run_cmd 'echo ONBOOT="yes" >> /etc/sysconfig/network-scripts/ifcfg-eth0' img_run_cmd 'echo PREFIX="24" >> /etc/sysconfig/network-scripts/ifcfg-eth0' img_run_cmd 'echo IPADDR="192.168.77.1" >> /etc/sysconfig/network-scripts/ifcfg-eth0'
qemu is launched in nested subprocess and can't be killed by simply killing the job ids,
PID Command 2269634 │ ├─ sshd: root [priv] 2269637 │ │ └─ sshd: root@pts/0 2269638 │ │ └─ -bash 2269744 │ │ └─ make test-run V=1 2273117 │ │ └─ /bin/bash /root/kexec-tools-300/tests/scripts/run-test.sh 2273712 │ │ ├─ /bin/bash /root/kexec-tools-300/tests/scripts/run-test.sh 2273714 │ │ │ └─ /bin/bash /root/kexec-tools-300/tests/scripts/run-test.sh 2273737 │ │ │ └─ timeout --foreground 10m /root/kexec-tools-300/tests/scripts/run-qemu -nodefaults -nographic -smp 2 -m 768M -monitor no 2273738 │ │ │ └─ /usr/bin/qemu-system-x86_64 -enable-kvm -cpu host -nodefaults -nographic -smp 2 -m 768M -monitor none -serial stdio 2273746 │ │ │ ├─ /usr/bin/qemu-system-x86_64 -enable-kvm -cpu host -nodefaults -nographic -smp 2 -m 768M -monitor none -serial std 2273797 │ │ ├─ /bin/bash /root/kexec-tools-300/tests/scripts/run-test.sh 2273798 │ │ │ └─ /bin/bash /root/kexec-tools-300/tests/scripts/run-test.sh 2273831 │ │ │ └─ timeout --foreground 10m /root/kexec-tools-300/tests/scripts/run-qemu -nodefaults -nographic -smp 2 -m 768M -monitor no 2273832 │ │ │ └─ /usr/bin/qemu-system-x86_64 -enable-kvm -cpu host -nodefaults -nographic -smp 2 -m 768M -monitor none -serial stdio 2273840 │ │ │ ├─ /usr/bin/qemu-system-x86_64 -enable-kvm -cpu host -nodefaults -nographic -smp 2 -m 768M -monitor none -serial std
This patch will kill qemu by killing all the children of the job id.
Signed-off-by: Coiby Xu coxu@redhat.com --- tests/scripts/run-test.sh | 14 ++++++++++---- tests/scripts/test-lib.sh | 3 +-- 2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/tests/scripts/run-test.sh b/tests/scripts/run-test.sh index a68504d..4889ed9 100755 --- a/tests/scripts/run-test.sh +++ b/tests/scripts/run-test.sh @@ -1,9 +1,15 @@ #!/bin/bash
_kill_all_jobs() { - local _jobs=$(jobs -r -p) - - [ -n "$_jobs" ] && kill $_jobs + local _jobs=$(jobs -r -p) + local _job + + if [ -n "$_jobs" ]; then + for _job in $_jobs + do + kill $(pstree $_job -p -a -l | cut -d, -f2 | cut -d' ' -f1) + done + fi }
trap ' @@ -121,7 +127,7 @@ for test_case in $testcases; do
[ $? -ne 0 ] && ret=$(expr $ret + 1) results[$test_case]="$res" - + _kill_all_jobs echo -e "-------- Test finished: $test_case $res --------" for script in $scripts; do script="$testdir/$script" diff --git a/tests/scripts/test-lib.sh b/tests/scripts/test-lib.sh index f8a2249..8b24b2a 100644 --- a/tests/scripts/test-lib.sh +++ b/tests/scripts/test-lib.sh @@ -146,8 +146,7 @@ watch_test_outputs() { ret=$?
if [ $ret -ne 255 ]; then - # Test finished, kill VMs - kill $(jobs -p) + # Test finished break 2 fi done
test_base_image should depend on EXTRA_RPMS so it gets rebuild when EXTRA_RPMS changes.
Fixes: commit bbc064f9582080124a4acc41f7e33e21c4f18a4f ("selftest: add EXTRA_RPMs so dracut RPMs can be installed onto the image to run the tests") Signed-off-by: Coiby Xu coxu@redhat.com --- tests/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/Makefile b/tests/Makefile index 4e9c55f..8fb38c7 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -67,7 +67,7 @@ $(BUILD_ROOT)/inst-base-image: $(BUILD_ROOT)/base-image $(BUILD_ROOT)/inst-base-image \ $(TEST_ROOT)/scripts/build-scripts/base-image.sh
-$(TEST_ROOT)/output/test-base-image: $(BUILD_ROOT)/inst-base-image $(KEXEC_TOOLS_RPM) $(KEXEC_TOOLS_TEST_SRC) +$(TEST_ROOT)/output/test-base-image: $(BUILD_ROOT)/inst-base-image $(KEXEC_TOOLS_RPM) $(KEXEC_TOOLS_TEST_SRC) $(EXTRA_RPMS) @echo "Building test base image" mkdir -p $(TEST_ROOT)/output $(TEST_ROOT)/scripts/build-image.sh \