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 "$@"
}
# 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 <<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
@ -391,24 +375,23 @@ vm_get_journal_cursor() {
vm_wait_content_after_cursor() {
from_cursor=$1; shift
regex=$1; shift
cat > wait.sh <<EOF
#!/usr/bin/bash
set -xeuo pipefail
tmpf=\$(mktemp /var/tmp/journal.XXXXXX)
for x in \$(seq 60); do
journalctl -u rpm-ostreed --after-cursor "${from_cursor}" > \${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 <<EOF
- shell: |
set -xeuo pipefail
tmpf=\$(mktemp /var/tmp/journal.XXXXXX)
for x in \$(seq 60); do
journalctl -u rpm-ostreed --after-cursor "${from_cursor}" > \${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() {

View File

@ -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 <<EOF
- shell: |
cp /usr/etc/rpm-ostreed.conf /etc
echo -e "[Daemon]\nAutomaticUpdatePolicy=$policy" > /etc/rpm-ostreed.conf
rpm-ostree reload
EOF
vm_cmdfile tmp.sh
vm_rpmostree reload
}
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.
if ! vm_cmd getent passwd testuser; then
vm_ansible_inline <<EOF
- shell: >
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 <<EOF
- copy:
content: |
[vmcheck-http]
name=vmcheck-http
baseurl=http://localhost:8888/vmcheck/yumrepo
gpgcheck=0
dest: /etc/yum.repos.d/vmcheck-http.repo
EOF
vm_send /etc/yum.repos.d vmcheck-http.repo
vm_rpmostree cleanup -rpmb
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_start_httpd vmcheck /tmp 8888
vm_rpmostree cleanup -m
cat > vmcheck-http.repo << EOF
[vmcheck-http]
name=vmcheck-http
baseurl=http://localhost:8888/vmcheck/yumrepo
gpgcheck=0
vm_ansible_inline <<EOF
- copy:
content: |
[vmcheck-http]
name=vmcheck-http
baseurl=http://localhost:8888/vmcheck/yumrepo
gpgcheck=0
dest: /etc/yum.repos.d/vmcheck-http.repo
EOF
vm_send /etc/yum.repos.d vmcheck-http.repo
osname=$(vm_get_booted_deployment_info osname)
# 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}
generate_upgrade() {
# Create a modified vmcheck commit
cat >t.sh<<EOF
#!/bin/bash
set -xeuo pipefail
cd /ostree/repo/tmp
rm vmcheck -rf
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,}
$@
ostree commit -b vmcheck --tree=dir=vmcheck --link-checkout-speedup
rm vmcheck -rf
vm_ansible_inline <<EOF
- shell: |
set -xeuo pipefail
cd /ostree/repo/tmp
rm vmcheck -rf
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,}
$@
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