tests/libvm: Handle transient service already existing

We would error out when trying to start the transient httpd service if
it already exists, e.g. from a previous test.

Depending on how we exit, the `vm_stop_httpd` trap for the previous test
might not have been able to kick in. I think this happens when we exit
using `fatal`, which just does an `exit 1`. It's not strictly an error,
so doesn't trip the `ERR` handler.

Let's just go the extra mile and explicitly delete transient services if
they already exist.

Closes: #1284
Approved by: cgwalters
This commit is contained in:
Jonathan Lebon 2018-03-01 17:31:13 +00:00 committed by Atomic Bot
parent a05a21edd3
commit b54b8744b9

View File

@ -415,6 +415,11 @@ vm_start_httpd() {
local dir=$1; shift
local port=$1; shift
# just nuke the service of the same name if it exists and is also transient
if vm_cmd systemctl show $name | grep -q UnitFileState=transient; then
vm_cmd systemctl stop $name
fi
# CentOS systemd is too old for -p WorkingDirectory
vm_cmd systemd-run --unit $name sh -c \
"'cd $dir && python -m SimpleHTTPServer $port'"