From 63f545a6f4c07990d52664c6544d14e8c8eb3cfa Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 9 Mar 2018 14:52:12 -0500 Subject: [PATCH] tests: Replace some more libvm bits with Ansible `vm_cmdfile()` was clearly calling out for this. I also replaced `vm_send()` calls. Closes: #1298 Approved by: jlebon --- tests/common/libvm.sh | 57 ++++++++++------------------- tests/vmcheck/test-autoupdate.sh | 10 ++--- tests/vmcheck/test-basic.sh | 23 +++++++----- tests/vmcheck/test-download-only.sh | 14 ++++--- tests/vmcheck/test-livefs.sh | 21 +++++------ 5 files changed, 56 insertions(+), 69 deletions(-) diff --git a/tests/common/libvm.sh b/tests/common/libvm.sh index aed3c808..91c2794b 100644 --- a/tests/common/libvm.sh +++ b/tests/common/libvm.sh @@ -84,16 +84,6 @@ vm_cmd() { $SSH "$@" } -# Copy argument (usually shell script) to VM, execute it there -vm_cmdfile() { - local bin=$1 - chmod a+x ${bin} - local bn=$(basename ${bin}) - $SCP $1 $VM:/root/${bn} - $SSH /root/${bn} -} - - # Delete anything which we might change between runs vm_clean_caches() { vm_cmd rm /ostree/repo/refs/heads/rpmostree/pkg/* -rf @@ -105,15 +95,6 @@ vm_rpmostree() { vm_cmd env ASAN_OPTIONS=detect_leaks=false rpm-ostree "$@" } -# copy files to a directory in the vm -# - $1 target directory -# - $2.. files & dirs to copy -vm_send() { - local dir=$1; shift - vm_cmd mkdir -p $dir - $SCP -r "$@" $VM:$dir -} - # copy the test repo to the vm # $1 - repo file mode: nogpgcheck (default), gpgcheck, skip (don't send) vm_send_test_repo() { @@ -142,7 +123,10 @@ EOF echo 'gpgcheck=0' >> vmcheck.repo fi - vm_send /etc/yum.repos.d vmcheck.repo + vm_ansible_inline < wait.sh < \${tmpf} - if grep -q -e "${regex}" \${tmpf}; then - exit 0 - else - cat \${tmpf} - sleep 1 - fi -done -echo "timed out after 60s" 1>&2 -journalctl -u rpm-ostreed --after-cursor "${from_cursor}" | tail -100 -exit 1 + vm_ansible_inline < \${tmpf} + if grep -q -e "${regex}" \${tmpf}; then + exit 0 + else + cat \${tmpf} + sleep 1 + fi + done + echo "timed out after 60s" 1>&2 + journalctl -u rpm-ostreed --after-cursor "${from_cursor}" | tail -100 + exit 1 EOF - vm_cmdfile wait.sh } vm_assert_journal_has_content() { diff --git a/tests/vmcheck/test-autoupdate.sh b/tests/vmcheck/test-autoupdate.sh index ca6ebafd..67ff1571 100755 --- a/tests/vmcheck/test-autoupdate.sh +++ b/tests/vmcheck/test-autoupdate.sh @@ -127,12 +127,12 @@ vm_start_httpd ostree_server $REMOTE_OSTREE 8888 change_policy() { policy=$1; shift - vm_cmd cp /usr/etc/rpm-ostreed.conf /etc - cat > tmp.sh << EOF -echo -e "[Daemon]\nAutomaticUpdatePolicy=$policy" > /etc/rpm-ostreed.conf + vm_ansible_inline < /etc/rpm-ostreed.conf + rpm-ostree reload EOF - vm_cmdfile tmp.sh - vm_rpmostree reload } vm_rpmostree cleanup -m diff --git a/tests/vmcheck/test-basic.sh b/tests/vmcheck/test-basic.sh index 506d6498..6778ca98 100755 --- a/tests/vmcheck/test-basic.sh +++ b/tests/vmcheck/test-basic.sh @@ -45,10 +45,11 @@ echo "ok jsonpath" # and logging in through SSH is an easy way to achieve that. if ! vm_cmd getent passwd testuser; then vm_ansible_inline < - useradd testuser && - mkdir -pm 0700 /home/testuser/.ssh && - cp -a /root/.ssh/authorized_keys /home/testuser/.ssh && +- shell: | + set -euo pipefail + useradd testuser + mkdir -pm 0700 /home/testuser/.ssh + cp -a /root/.ssh/authorized_keys /home/testuser/.ssh chown -R testuser:testuser /home/testuser/.ssh EOF fi @@ -183,13 +184,15 @@ echo "ok script output prefixed in journal" # local repos are always cached, so let's start up an http server for the same # vmcheck repo vm_start_httpd vmcheck /tmp 8888 -cat > vmcheck-http.repo << EOF -[vmcheck-http] -name=vmcheck-http -baseurl=http://localhost:8888/vmcheck/yumrepo -gpgcheck=0 +vm_ansible_inline < vmcheck-http.repo << EOF -[vmcheck-http] -name=vmcheck-http -baseurl=http://localhost:8888/vmcheck/yumrepo -gpgcheck=0 +vm_ansible_inline <t.sh<vmcheck/${dummy_file_to_modify}.new && mv vmcheck/${dummy_file_to_modify}{.new,} -$@ -ostree commit -b vmcheck --tree=dir=vmcheck --link-checkout-speedup -rm vmcheck -rf + vm_ansible_inline <vmcheck/${dummy_file_to_modify}.new && mv vmcheck/${dummy_file_to_modify}{.new,} + $@ + ostree commit -b vmcheck --tree=dir=vmcheck --link-checkout-speedup + rm vmcheck -rf EOF - vm_cmdfile t.sh } generate_upgrade # And remove the pending deployment so that our origin is now the booted