2016-06-21 19:37:02 +03:00
#!/bin/bash
set -euo pipefail
2016-06-24 23:40:20 +03:00
. ${ commondir } /libvm.sh
2017-03-11 01:43:23 +03:00
LOG = ${ LOG :- vmcheck .log }
LOG = $( realpath $LOG )
# NB: allow JOURNAL_LOG to be empty, which means we never
# fetch it
JOURNAL_LOG = ${ JOURNAL_LOG -vmcheck-journal.txt }
if [ -n " $JOURNAL_LOG " ] ; then
JOURNAL_LOG = $( realpath $JOURNAL_LOG )
fi
2016-07-15 20:30:56 +03:00
# create ssh-config if needed and export cmds
vm_setup
2016-06-21 19:37:02 +03:00
# stand up ssh connection and sanity check that it all works
2016-11-22 06:22:51 +03:00
if ! vm_ssh_wait 30; then
2016-06-21 19:37:02 +03:00
echo "ERROR: A running VM is required for 'make vmcheck'."
exit 1
fi
2016-11-14 20:07:43 +03:00
echo "VM is running."
2016-07-04 18:39:40 +03:00
# just error out if we're unlocked -- we use the current deployment as the
# fallback between each test, so we need to be sure it's in a state that works.
# also, the user might have forgotten that these tests are somewhat destructive
# and thus would wipe out unlocked changes, hotfix or not.
2016-06-29 00:23:53 +03:00
unlocked_cur = $( vm_get_booted_deployment_info unlocked)
if [ [ $unlocked_cur != none ] ] ; then
echo "ERROR: VM is unlocked."
exit 1
fi
# remember the csum we're currently on and tag it so that ostree doesn't wipe it
csum_orig = $( vm_get_booted_csum)
vm_cmd ostree rev-parse $csum_orig & > /dev/null # validate
vm_cmd ostree refs vmcheck_orig --delete
vm_cmd ostree refs $csum_orig --create vmcheck_orig
2017-08-12 02:36:38 +03:00
# reboot onto the vmcheck ref if we're not already on it
origin = $( vm_get_booted_deployment_info origin)
if [ [ $origin != vmcheck ] ] ; then
vm_cmd ostree refs vmcheck --delete
vm_cmd ostree refs vmcheck_orig --create vmcheck
vm_cmd ostree admin deploy vmcheck & >> ${ LOG }
vm_reboot & >> ${ LOG }
fi
2017-02-25 00:28:47 +03:00
# delete whatever tmp refs the previous testsuite runs may have created
2017-10-13 16:22:15 +03:00
vm_cmd ostree refs vmcheck_tmp vmcheck_remote --delete
2017-02-25 00:28:47 +03:00
2016-12-07 23:58:35 +03:00
# we bring our own test repo and test packages, so let's neuter any repo that
# comes with the distro to help speed up rpm-ostree metadata fetching since we
# don't cache it (e.g. on Fedora, it takes *forever* to fetch metadata, which we
# have to do dozens of times throughout the suite)
2017-04-06 04:51:37 +03:00
if ! vm_cmd test -f /etc/yum.repos.d/.vmcheck; then
echo "Neutering /etc/yum.repos.d"
# Move the current one to .bak
vm_cmd mv /etc/yum.repos.d{ ,.bak}
# And create a new one with a .vmcheck as a stamp file so we recognize it
vm_cmd rm /etc/yum.repos.d.tmp -rf
vm_cmd mkdir /etc/yum.repos.d.tmp
vm_cmd touch /etc/yum.repos.d.tmp/.vmcheck
2017-05-19 16:44:57 +03:00
vm_cmd cp -r /etc/yum.repos.d{ .tmp,}
2017-04-06 04:51:37 +03:00
else
echo "Keeping existing vmcheck /etc/yum.repos.d"
fi
2016-12-07 23:58:35 +03:00
2018-01-17 23:54:21 +03:00
# tests expect to run with the default config
# remember the original config, we restore it after the tests
if vm_cmd test -f /etc/rpm-ostreed.conf; then
vm_cmd mv -f /etc/rpm-ostreed.conf{ ,.bak}
fi
vm_cmd cp -f /usr/etc/rpm-ostreed.conf /etc
2017-01-10 19:13:26 +03:00
origdir = $( pwd )
2016-06-21 19:37:02 +03:00
echo -n '' > ${ LOG }
testdir = " $( dirname $( realpath $0 ) ) "
cd $testdir
2016-07-04 18:39:40 +03:00
colour_print( ) {
colour = $1 ; shift
[ ! -t 1 ] || echo -en " \e[ ${ colour } m "
echo -n " $@ "
[ ! -t 1 ] || echo -en "\e[0m"
echo
}
pass_print( ) {
colour_print 32 " $@ " # green
}
fail_print( ) {
colour_print 31 " $@ " # red
}
skip_print( ) {
colour_print 34 " $@ " # blue
}
total = 0
pass = 0
fail = 0
skip = 0
2017-01-11 17:13:20 +03:00
notrun = 0
2016-06-21 19:37:02 +03:00
for tf in $( find . -name 'test-*.sh' | sort) ; do
if [ -n " ${ TESTS + } " ] ; then
tfbn = $( basename " $tf " .sh)
tfbn = " ${ tfbn #test- } "
if [ [ " $TESTS " != *$tfbn * ] ] ; then
2017-01-11 17:13:20 +03:00
let "notrun += 1"
2016-06-21 19:37:02 +03:00
continue
fi
fi
2016-07-04 18:39:40 +03:00
let "total += 1"
2016-06-21 19:37:02 +03:00
bn = $( basename ${ tf } )
printf " Running $bn ...\n "
2016-12-09 01:31:20 +03:00
printf " \n==== ${ bn } ====\n " >> ${ LOG }
2017-03-11 01:43:23 +03:00
vm_cmd logger " vmcheck: running $bn ... "
2016-06-21 19:37:02 +03:00
# do some dirty piping to get some instant feedback and help debugging
if ${ tf } | & tee -a ${ LOG } \
2016-07-14 23:47:35 +03:00
| grep -e '^ok ' --line-buffered \
2016-06-21 19:37:02 +03:00
| xargs -d '\n' -n 1 echo " " ; then
2016-07-04 18:39:40 +03:00
pass_print " PASS: $bn "
2016-07-15 03:10:47 +03:00
echo "PASS" >> ${ LOG }
2016-07-04 18:39:40 +03:00
let "pass += 1"
2016-06-21 19:37:02 +03:00
else
if test $? = 77; then
2016-07-04 18:39:40 +03:00
skip_print " SKIP: $bn "
2016-07-15 03:10:47 +03:00
echo "SKIP" >> ${ LOG }
2016-07-04 18:39:40 +03:00
let "skip += 1"
2016-06-21 19:37:02 +03:00
else
2016-07-04 18:39:40 +03:00
fail_print " FAIL: $bn "
2016-07-15 03:10:47 +03:00
echo "FAIL" >> ${ LOG }
2016-07-04 18:39:40 +03:00
let "fail += 1"
2016-06-21 19:37:02 +03:00
fi
fi
2016-06-29 00:23:53 +03:00
2017-03-11 01:43:23 +03:00
vm_cmd logger " vmcheck: finished $bn ... "
2017-04-06 04:51:37 +03:00
if test -n " ${ VMCHECK_DEBUG :- } " ; then
echo "VMCHECK_DEBUG is set, skipping restoration of original deployment"
break
fi
2017-03-11 01:43:23 +03:00
2017-05-09 21:27:29 +03:00
# nuke all vmcheck and vmcheck_tmp refs and recreate vmcheck from orig
echo "Restoring original vmcheck commit" >> ${ LOG }
2017-10-13 16:22:15 +03:00
vm_cmd ostree refs vmcheck vmcheck_tmp vmcheck_remote --delete
2017-05-09 21:27:29 +03:00
vm_cmd ostree refs vmcheck_orig --create vmcheck & >> ${ LOG }
2018-01-17 23:54:21 +03:00
# restore the default config
vm_cmd cp -f /usr/etc/rpm-ostreed.conf /etc/
2016-06-29 00:23:53 +03:00
# go back to the original vmcheck deployment if needed
2018-01-17 23:54:21 +03:00
origin_cur = $( vm_get_booted_deployment_info origin)
2016-06-29 00:23:53 +03:00
csum_cur = $( vm_get_booted_csum)
unlocked_cur = $( vm_get_booted_deployment_info unlocked)
2017-07-04 20:06:53 +03:00
live_csum = $( vm_get_booted_deployment_info live-replaced)
2018-01-17 23:54:21 +03:00
if [ [ $origin_cur != vmcheck ] ] || \
[ [ $csum_orig != $csum_cur ] ] || \
2017-07-04 20:06:53 +03:00
[ [ $unlocked_cur != none ] ] || \
[ -n " ${ live_csum } " ] ; then
2017-05-09 21:27:29 +03:00
# redeploy under the name 'vmcheck' so that tests can
# never modify the vmcheck_orig ref itself
2016-07-04 18:39:40 +03:00
vm_cmd ostree admin deploy vmcheck & >> ${ LOG }
2017-02-24 07:38:26 +03:00
vm_reboot & >> ${ LOG }
2018-01-17 23:54:21 +03:00
else
# make sure we're using the default config vals again
vm_cmd systemctl restart rpm-ostreed
2016-06-29 00:23:53 +03:00
fi
2017-01-10 19:13:26 +03:00
2017-05-09 21:27:29 +03:00
# make sure to clean up any pending & rollback deployments
2017-06-19 17:11:43 +03:00
vm_rpmostree cleanup -b -p -r -m || :
2017-05-19 16:44:57 +03:00
# and put back our tmp repo
vm_cmd rm /etc/yum.repos.d -rf
vm_cmd cp -r /etc/yum.repos.d{ .tmp,}
2017-10-05 22:33:40 +03:00
2017-10-13 16:22:15 +03:00
# and clean up any leftovers from our tmp
osname = $( vm_get_booted_deployment_info osname)
vm_cmd rm -rf /ostree/deploy/$osname /var/tmp/vmcheck
2016-06-21 19:37:02 +03:00
done
2017-04-06 04:51:37 +03:00
2016-12-07 23:58:35 +03:00
# put back the original yum repos
2017-04-06 04:51:37 +03:00
if test -z " ${ VMCHECK_DEBUG :- } " ; then
if vm_cmd test -f /etc/yum.repos.d/.vmcheck; then
echo "Restoring original /etc/yum.repos.d"
vm_cmd rm -rf /etc/yum.repos.d
vm_cmd mv /etc/yum.repos.d{ .bak,}
fi
fi
2016-12-07 23:58:35 +03:00
2018-01-17 23:54:21 +03:00
# put back the original config if any
vm_cmd rm -f /etc/rpm-ostreed.conf
if vm_cmd test -f /etc/rpm-ostreed.conf.bak; then
vm_cmd mv /etc/rpm-ostreed.conf{ .bak,}
fi
2017-01-10 19:13:26 +03:00
# Gather post-failure system logs if necessary
ALL_LOGS = $LOG
2017-03-11 01:43:23 +03:00
if [ ${ fail } -ne 0 ] && [ -n " $JOURNAL_LOG " ] ; then
./fetch-journal.sh
ALL_LOGS = " $ALL_LOGS $JOURNAL_LOG "
2017-01-10 19:13:26 +03:00
fi
2016-07-14 23:47:35 +03:00
# tear down ssh connection if needed
if $SSH -O check & >/dev/null; then
$SSH -O exit & >/dev/null
fi
2016-06-21 19:37:02 +03:00
2016-07-04 18:39:40 +03:00
[ ${ fail } -eq 0 ] && printer = pass || printer = fail
${ printer } _print " TOTAL: $total PASS: $pass SKIP: $skip FAIL: $fail "
2017-01-11 17:13:20 +03:00
if test ${ notrun } -gt 0; then
echo " NOTICE: Skipped ${ notrun } tests not matching \" ${ TESTS } \" "
fi
2017-01-10 19:13:26 +03:00
echo " See ${ ALL_LOGS } for more information. "
2016-07-04 18:39:40 +03:00
[ ${ fail } -eq 0 ]