diff options
author | Pavel Raiskup <praiskup@redhat.com> | 2014-11-04 14:03:51 +0100 |
---|---|---|
committer | Pavel Raiskup <praiskup@redhat.com> | 2014-11-04 14:03:51 +0100 |
commit | b602b6772d364c40399f751b45206d6a2fe7ccb7 (patch) | |
tree | 4ef8feac3394411ae45aa81c95d1639372f03f10 /controller | |
parent | 347e150a7bc60a1ed019877f2ae4cf2a3e51d22c (diff) | |
download | postgresql-setup-tests-b602b6772d364c40399f751b45206d6a2fe7ccb7.tar.gz postgresql-setup-tests-b602b6772d364c40399f751b45206d6a2fe7ccb7.tar.xz postgresql-setup-tests-b602b6772d364c40399f751b45206d6a2fe7ccb7.zip |
controller: shutdown VM when run was successful
New script 'dtf-return-machine' returns the VM to OpenStack based
on its public IP. In future, this may be abstracted to any VM
provider (or VM pool or whatever), but that requires also some
IP <=> VM mapping shared between dtf-get-machine and
dtf-return-machine.
* controller/.gitignore: Ignore new scripts.
* controller/Makefile.am: Build new scripts.
* controller/bin/dtf-return-machine.in: New script for VM
* deletion.
* controller/libexec/dtf-nova.in: New wrapper around 'nova'
command, showing only data output where fields are separated by
tabulator.
* controller/share/dtf-controller/ansible/playbooks/fedora.yml:
Finally call dtf-return-machine after successful test run.
Diffstat (limited to 'controller')
-rw-r--r-- | controller/.gitignore | 2 | ||||
-rw-r--r-- | controller/Makefile.am | 11 | ||||
-rw-r--r-- | controller/bin/dtf-get-machine.in | 1 | ||||
-rw-r--r-- | controller/bin/dtf-return-machine.in | 45 | ||||
-rw-r--r-- | controller/libexec/dtf-nova.in | 11 | ||||
-rw-r--r-- | controller/share/dtf-controller/ansible/playbooks/fedora.yml | 2 |
6 files changed, 70 insertions, 2 deletions
diff --git a/controller/.gitignore b/controller/.gitignore index aec98c7..316b505 100644 --- a/controller/.gitignore +++ b/controller/.gitignore @@ -8,7 +8,9 @@ dtf.sh dtf-commit-results dtf-controller dtf-get-machine +dtf-nova dtf-result-stats +dtf-return-machine dtf-run-remote generated-vars.yml Makefile diff --git a/controller/Makefile.am b/controller/Makefile.am index 80ecb63..d4d16a9 100644 --- a/controller/Makefile.am +++ b/controller/Makefile.am @@ -1,6 +1,7 @@ bin_SCRIPTS = \ bin/dtf-run-remote \ bin/dtf-get-machine \ + bin/dtf-return-machine \ bin/dtf-controller sysconf_DATA = etc/dtf.sh @@ -9,7 +10,9 @@ pkgdata_DATA = ./share/dtf-controller/parse_credsfile libexec_SCRIPTS = libexec/dtf-wait-for-ssh \ libexec/dtf-commit-results \ - libexec/dtf-result-stats + libexec/dtf-result-stats \ + libexec/dtf-nova + ansiblevarsdir = $(pkgdatadir)/ansible/vars ansibleplaybooksdir = $(pkgdatadir)/ansible/playbooks @@ -35,12 +38,18 @@ libexec/dtf-commit-results: libexec/dtf-commit-results.in .dep libexec/dtf-result-stats: libexec/dtf-result-stats.in .dep $(INSTANTIATE_SCRIPT) +libexec/dtf-nova: libexec/dtf-nova.in .dep + $(INSTANTIATE_SCRIPT) + bin/dtf-run-remote: bin/dtf-run-remote.in .dep $(INSTANTIATE_SCRIPT) bin/dtf-get-machine: bin/dtf-get-machine.in .dep $(INSTANTIATE_SCRIPT) +bin/dtf-return-machine: bin/dtf-return-machine.in .dep + $(INSTANTIATE_SCRIPT) + bin/dtf-controller: bin/dtf-controller.in .dep $(INSTANTIATE_SCRIPT) diff --git a/controller/bin/dtf-get-machine.in b/controller/bin/dtf-get-machine.in index 54a3253..0c51f11 100644 --- a/controller/bin/dtf-get-machine.in +++ b/controller/bin/dtf-get-machine.in @@ -26,6 +26,7 @@ Options: --distro-version=VERSION E.g. 20 for Fedora 20 --openstack-instance=ID --name=NAME Name of the machine + --quite Print only the VM IP address to stdout EOHELP test -n "$1" && exit "$1" } diff --git a/controller/bin/dtf-return-machine.in b/controller/bin/dtf-return-machine.in new file mode 100644 index 0000000..799a1f4 --- /dev/null +++ b/controller/bin/dtf-return-machine.in @@ -0,0 +1,45 @@ +#!/bin/bash + +. "@sysconfdir@/dtf.sh" || exit 1 +opt_openstack_instance="$DTF_OPENSTACK_DEFAULT_ID" + +die() { echo "$@" ; exit 1 ; } + +longopts="openstack-instance:" +ARGS=$(getopt -o "" -l "help,$longopts" -n "$0" -- "$@") \ + || exit 1 +eval set -- "$ARGS" +while true; do + case "$1" in + --openstack-instance) + opt=$(sed -e 's/^--//' -e 's/[^[a-zA-Z0-9]/_/g'<<<"$1") + eval "opt_$opt=\"${2,,}\"" + shift 2 + ;; + --) + shift + break; + ;; + *) + echo >&2 "programmer mistake" + exit 1 + ;; + esac +done + +test -z "$opt_openstack_instance" && die "no openstack intance ID used" +. "@pkgdatadir@/parse_credsfile" "$opt_openstack_instance" || exit 1 + +IP="$1" + +test -z "$IP" && die "no IP passed" + +NOVACMD="@libexecdir@/dtf-nova" + +$NOVACMD list --fields 'networks' | \ + while IFS=" " read id networks; do + if [[ "$networks" == *$IP* ]]; then + nova delete "$id" + exit $? + fi + done diff --git a/controller/libexec/dtf-nova.in b/controller/libexec/dtf-nova.in new file mode 100644 index 0000000..e4a7791 --- /dev/null +++ b/controller/libexec/dtf-nova.in @@ -0,0 +1,11 @@ +#!/bin/bash + +set -o pipefail + +# Remove the boxing around raw nova output data +nova "$@" | sed \ + -e '1,3d' \ + -e '$d' \ + -e 's/^| //' \ + -e 's/[[:space:]]*|$//' \ + -e 's/[[:space:]]*|[[:space:]]*/\t/g' diff --git a/controller/share/dtf-controller/ansible/playbooks/fedora.yml b/controller/share/dtf-controller/ansible/playbooks/fedora.yml index 1d49671..ea39e70 100644 --- a/controller/share/dtf-controller/ansible/playbooks/fedora.yml +++ b/controller/share/dtf-controller/ansible/playbooks/fedora.yml @@ -51,5 +51,5 @@ - include: "{{ config_ansibleplaybooksdir }}/include/download-results.yml" - name: stop the vm - shell: echo "not implemented yet" + local_action: shell "{{ config_bindir }}/dtf-return-machine" {{ inventory_hostname }} when: test_result.rc == 0 |