libvm: factor out helpers to start httpd

This will be used in other tests. Plus, it makes it much nicer to use.

Closes: #1053
Approved by: cgwalters
This commit is contained in:
Jonathan Lebon 2017-10-13 13:20:10 +00:00 committed by Atomic Bot
parent dbceb2aa51
commit e5e9f1f0b8
2 changed files with 32 additions and 19 deletions

View File

@ -393,3 +393,31 @@ vm_assert_journal_has_content() {
assert_file_has_content tmp-journal.txt "$@"
rm -f tmp-journal.txt
}
# $1 - service name
# $2 - dir to serve
# $3 - port to serve on
vm_start_httpd() {
local name=$1; shift
local dir=$1; shift
local port=$1; shift
# CentOS systemd is too old for -p WorkingDirectory
vm_cmd systemd-run --unit $name sh -c \
"'cd $dir && python -m SimpleHTTPServer $port'"
# NB: the EXIT trap is used by libtest, but not the ERR trap
trap "vm_stop_httpd $name" ERR
set -E # inherit trap
# Ideally systemd-run would support .socket units or something
vm_cmd 'while ! curl --head http://127.0.0.1:8888 &>/dev/null; do sleep 1; done'
}
# $1 - service name
vm_stop_httpd() {
local name=$1; shift
vm_cmd systemctl stop $name
set +E
trap - ERR
}

View File

@ -158,29 +158,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
start_http_repo() {
# CentOS systemd is too old for -p WorkingDirectory
vm_cmd systemd-run --unit vmcheck-httpd sh -c \
"'cd /tmp && python -m SimpleHTTPServer 8888'"
# Ideally systemd-run would support .socket units or something
vm_cmd /bin/bash -c "'while ! curl --head http://127.0.0.1:8888 1>/dev/null 2>/dev/null; do sleep 0.1; done'"
cat > vmcheck-http.repo << EOF
vm_start_httpd vmcheck /tmp 8888
cat > vmcheck-http.repo << EOF
[vmcheck-http]
name=vmcheck-http
baseurl=http://localhost:8888/vmcheck/yumrepo
gpgcheck=0
EOF
vm_send /etc/yum.repos.d vmcheck-http.repo
}
vm_send /etc/yum.repos.d vmcheck-http.repo
stop_http_repo() {
vm_cmd systemctl stop vmcheck-httpd.service
}
# NB: the EXIT trap is used by libtest, but not the ERR trap
trap stop_http_repo ERR
set -E # inherit trap
start_http_repo
vm_rpmostree cleanup -rpmb
vm_cmd rm -f /etc/yum.repos.d/vmcheck.repo
vm_build_rpm_repo_mode skip refresh-md-old-pkg
@ -197,6 +183,5 @@ vm_rpmostree refresh-md -f
if ! vm_rpmostree install -C refresh-md-new-pkg --dry-run; then
assert_not_reached "failed to dry-run install new pkg from cached rpmmd?"
fi
set +E
stop_http_repo
vm_stop_httpd vmcheck
echo "ok refresh-md and --cache-only"