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
This commit is contained in:
Colin Walters 2018-03-09 14:52:12 -05:00 committed by Atomic Bot
parent bb86912de9
commit 63f545a6f4
5 changed files with 56 additions and 69 deletions

View File

@ -84,16 +84,6 @@ vm_cmd() {
$SSH "$@" $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 # Delete anything which we might change between runs
vm_clean_caches() { vm_clean_caches() {
vm_cmd rm /ostree/repo/refs/heads/rpmostree/pkg/* -rf 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 "$@" 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 # copy the test repo to the vm
# $1 - repo file mode: nogpgcheck (default), gpgcheck, skip (don't send) # $1 - repo file mode: nogpgcheck (default), gpgcheck, skip (don't send)
vm_send_test_repo() { vm_send_test_repo() {
@ -142,7 +123,10 @@ EOF
echo 'gpgcheck=0' >> vmcheck.repo echo 'gpgcheck=0' >> vmcheck.repo
fi fi
vm_send /etc/yum.repos.d vmcheck.repo vm_ansible_inline <<EOF
- file: path=/etc/yum.repos.d state=directory
- copy: src=$(pwd)/vmcheck.repo dest=/etc/yum.repos.d
EOF
} }
# wait until ssh is available on the vm # wait until ssh is available on the vm
@ -391,24 +375,23 @@ vm_get_journal_cursor() {
vm_wait_content_after_cursor() { vm_wait_content_after_cursor() {
from_cursor=$1; shift from_cursor=$1; shift
regex=$1; shift regex=$1; shift
cat > wait.sh <<EOF vm_ansible_inline <<EOF
#!/usr/bin/bash - shell: |
set -xeuo pipefail set -xeuo pipefail
tmpf=\$(mktemp /var/tmp/journal.XXXXXX) tmpf=\$(mktemp /var/tmp/journal.XXXXXX)
for x in \$(seq 60); do for x in \$(seq 60); do
journalctl -u rpm-ostreed --after-cursor "${from_cursor}" > \${tmpf} journalctl -u rpm-ostreed --after-cursor "${from_cursor}" > \${tmpf}
if grep -q -e "${regex}" \${tmpf}; then if grep -q -e "${regex}" \${tmpf}; then
exit 0 exit 0
else else
cat \${tmpf} cat \${tmpf}
sleep 1 sleep 1
fi fi
done done
echo "timed out after 60s" 1>&2 echo "timed out after 60s" 1>&2
journalctl -u rpm-ostreed --after-cursor "${from_cursor}" | tail -100 journalctl -u rpm-ostreed --after-cursor "${from_cursor}" | tail -100
exit 1 exit 1
EOF EOF
vm_cmdfile wait.sh
} }
vm_assert_journal_has_content() { vm_assert_journal_has_content() {

View File

@ -127,12 +127,12 @@ vm_start_httpd ostree_server $REMOTE_OSTREE 8888
change_policy() { change_policy() {
policy=$1; shift policy=$1; shift
vm_cmd cp /usr/etc/rpm-ostreed.conf /etc vm_ansible_inline <<EOF
cat > tmp.sh << EOF - shell: |
echo -e "[Daemon]\nAutomaticUpdatePolicy=$policy" > /etc/rpm-ostreed.conf cp /usr/etc/rpm-ostreed.conf /etc
echo -e "[Daemon]\nAutomaticUpdatePolicy=$policy" > /etc/rpm-ostreed.conf
rpm-ostree reload
EOF EOF
vm_cmdfile tmp.sh
vm_rpmostree reload
} }
vm_rpmostree cleanup -m vm_rpmostree cleanup -m

View File

@ -45,10 +45,11 @@ echo "ok jsonpath"
# and logging in through SSH is an easy way to achieve that. # and logging in through SSH is an easy way to achieve that.
if ! vm_cmd getent passwd testuser; then if ! vm_cmd getent passwd testuser; then
vm_ansible_inline <<EOF vm_ansible_inline <<EOF
- shell: > - shell: |
useradd testuser && set -euo pipefail
mkdir -pm 0700 /home/testuser/.ssh && useradd testuser
cp -a /root/.ssh/authorized_keys /home/testuser/.ssh && mkdir -pm 0700 /home/testuser/.ssh
cp -a /root/.ssh/authorized_keys /home/testuser/.ssh
chown -R testuser:testuser /home/testuser/.ssh chown -R testuser:testuser /home/testuser/.ssh
EOF EOF
fi 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 # local repos are always cached, so let's start up an http server for the same
# vmcheck repo # vmcheck repo
vm_start_httpd vmcheck /tmp 8888 vm_start_httpd vmcheck /tmp 8888
cat > vmcheck-http.repo << EOF vm_ansible_inline <<EOF
[vmcheck-http] - copy:
name=vmcheck-http content: |
baseurl=http://localhost:8888/vmcheck/yumrepo [vmcheck-http]
gpgcheck=0 name=vmcheck-http
baseurl=http://localhost:8888/vmcheck/yumrepo
gpgcheck=0
dest: /etc/yum.repos.d/vmcheck-http.repo
EOF EOF
vm_send /etc/yum.repos.d vmcheck-http.repo
vm_rpmostree cleanup -rpmb vm_rpmostree cleanup -rpmb
vm_cmd rm -f /etc/yum.repos.d/vmcheck.repo vm_cmd rm -f /etc/yum.repos.d/vmcheck.repo

View File

@ -35,13 +35,15 @@ set -x
vm_build_rpm_repo_mode skip foobar vm_build_rpm_repo_mode skip foobar
vm_start_httpd vmcheck /tmp 8888 vm_start_httpd vmcheck /tmp 8888
vm_rpmostree cleanup -m vm_rpmostree cleanup -m
cat > vmcheck-http.repo << EOF vm_ansible_inline <<EOF
[vmcheck-http] - copy:
name=vmcheck-http content: |
baseurl=http://localhost:8888/vmcheck/yumrepo [vmcheck-http]
gpgcheck=0 name=vmcheck-http
baseurl=http://localhost:8888/vmcheck/yumrepo
gpgcheck=0
dest: /etc/yum.repos.d/vmcheck-http.repo
EOF EOF
vm_send /etc/yum.repos.d vmcheck-http.repo
osname=$(vm_get_booted_deployment_info osname) osname=$(vm_get_booted_deployment_info osname)
# use the var through /sysroot/ to make sure we always get hardlinks # use the var through /sysroot/ to make sure we always get hardlinks

View File

@ -145,18 +145,17 @@ fi
vm_cmd test -f /${dummy_file_to_modify} vm_cmd test -f /${dummy_file_to_modify}
generate_upgrade() { generate_upgrade() {
# Create a modified vmcheck commit # Create a modified vmcheck commit
cat >t.sh<<EOF vm_ansible_inline <<EOF
#!/bin/bash - shell: |
set -xeuo pipefail set -xeuo pipefail
cd /ostree/repo/tmp cd /ostree/repo/tmp
rm vmcheck -rf rm vmcheck -rf
ostree checkout vmcheck vmcheck --fsync=0 ostree checkout vmcheck vmcheck --fsync=0
(date; echo "JUST KIDDING DO WHATEVER") >vmcheck/${dummy_file_to_modify}.new && mv vmcheck/${dummy_file_to_modify}{.new,} (date; echo "JUST KIDDING DO WHATEVER") >vmcheck/${dummy_file_to_modify}.new && mv vmcheck/${dummy_file_to_modify}{.new,}
$@ $@
ostree commit -b vmcheck --tree=dir=vmcheck --link-checkout-speedup ostree commit -b vmcheck --tree=dir=vmcheck --link-checkout-speedup
rm vmcheck -rf rm vmcheck -rf
EOF EOF
vm_cmdfile t.sh
} }
generate_upgrade generate_upgrade
# And remove the pending deployment so that our origin is now the booted # And remove the pending deployment so that our origin is now the booted