tests/libvm: use rsync and add yumrepo mode

I've been lazy about actually using using rsync instead of scp when
copying new RPMs over to the VM. We do this here. Also make
`vm_send_test_repo` take a mode argument that allows callers to
completely skip the sending of the repo file itself. This will be needed
for the `makecache` test, in which we *don't* want the repo to be local.
It looks cleaner anyway for the gpgcheck use case as well.

Closes: #1035
Approved by: cgwalters
This commit is contained in:
Jonathan Lebon 2017-10-05 19:29:57 +00:00 committed by Atomic Bot
parent 4442a0c362
commit dc08ebda0e
2 changed files with 29 additions and 14 deletions

View File

@ -36,15 +36,19 @@ vm_setup() {
export SCP="scp $sshopts" export SCP="scp $sshopts"
} }
# rsync wrapper that sets up authentication
vm_raw_rsync() {
local rsyncopts="ssh -o User=root"
if [ -f ${topsrcdir}/ssh-config ]; then
rsyncopts="$rsyncopts -F '${topsrcdir}/ssh-config'"
fi
rsync -az --no-owner --no-group -e "$rsyncopts" "$@"
}
vm_rsync() { vm_rsync() {
if ! test -f .vagrant/using_sshfs; then if ! test -f .vagrant/using_sshfs; then
pushd ${topsrcdir} pushd ${topsrcdir}
local rsyncopts="ssh -o User=root" vm_raw_rsync --exclude .git/ . $VM:/var/roothome/sync
if [ -f ssh-config ]; then
rsyncopts="$rsyncopts -F ssh-config"
fi
rsync -az --no-owner --no-group -e "$rsyncopts" \
--exclude .git/ . $VM:/var/roothome/sync
popd popd
fi fi
} }
@ -99,10 +103,14 @@ vm_send() {
} }
# 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)
vm_send_test_repo() { vm_send_test_repo() {
gpgcheck=${1:-0} mode=${1:-nogpgcheck}
vm_cmd rm -rf /tmp/vmcheck vm_raw_rsync --delete ${test_tmpdir}/yumrepo $VM:/tmp/vmcheck
vm_send /tmp/vmcheck ${test_tmpdir}/yumrepo
if [[ $mode == skip ]]; then
return
fi
cat > vmcheck.repo << EOF cat > vmcheck.repo << EOF
[test-repo] [test-repo]
@ -110,12 +118,13 @@ name=test-repo
baseurl=file:///tmp/vmcheck/yumrepo baseurl=file:///tmp/vmcheck/yumrepo
EOF EOF
if [ $gpgcheck -eq 1 ]; then if [[ $mode == gpgcheck ]]; then
cat >> vmcheck.repo <<EOF cat >> vmcheck.repo <<EOF
gpgcheck=1 gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-25-primary gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-25-primary
EOF EOF
else else
assert_streq "$mode" nogpgcheck
echo "Enabling vmcheck.repo without GPG" echo "Enabling vmcheck.repo without GPG"
echo 'gpgcheck=0' >> vmcheck.repo echo 'gpgcheck=0' >> vmcheck.repo
fi fi
@ -333,12 +342,19 @@ vm_assert_status_jq() {
# Like build_rpm, but also sends it to the VM # Like build_rpm, but also sends it to the VM
vm_build_rpm() { vm_build_rpm() {
build_rpm "$@" build_rpm "$@"
vm_send_test_repo 0 # XXX use rsync vm_send_test_repo
}
# Like vm_build_rpm but takes a yumrepo mode
vm_build_rpm_repo_mode() {
mode=$1; shift
build_rpm "$@"
vm_send_test_repo $mode
} }
vm_build_selinux_rpm() { vm_build_selinux_rpm() {
build_selinux_rpm "$@" build_selinux_rpm "$@"
vm_send_test_repo 0 # XXX use rsync vm_send_test_repo
} }
vm_get_journal_cursor() { vm_get_journal_cursor() {

View File

@ -29,8 +29,7 @@ vm_clean_caches
# make sure the package is not already layered # make sure the package is not already layered
vm_assert_layered_pkg foo absent vm_assert_layered_pkg foo absent
vm_build_rpm foo version 4.5 release 6 vm_build_rpm_repo_mode gpgcheck foo version 4.5 release 6
vm_send_test_repo 1 # resend repo with gpg checking on
if vm_rpmostree pkg-add foo-4.5 2>err.txt; then if vm_rpmostree pkg-add foo-4.5 2>err.txt; then
assert_not_reached "Installed unsigned package" assert_not_reached "Installed unsigned package"
fi fi