summaryrefslogtreecommitdiffstats
path: root/xci
diff options
context:
space:
mode:
authorMarkos Chandras <mchandras@suse.de>2017-10-10 08:44:57 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-10-10 08:44:57 +0000
commit2c7f7d08e42a26f046fd8d745ccbf7caefd56547 (patch)
tree9e87c59c7f6abdbbe1e2a1b5ec8d9dbcb04527d3 /xci
parent9bbaa9d219e77b53db8cbbd0df21581790e53f9f (diff)
parent5ea389f23fb6053855e4840baf6c7c8e0f4b8f99 (diff)
Merge "xci: scripts: start-new-vm.sh: Add option to clean VM on failure"
Diffstat (limited to 'xci')
-rwxr-xr-xxci/scripts/vm/start-new-vm.sh15
1 files changed, 15 insertions, 0 deletions
diff --git a/xci/scripts/vm/start-new-vm.sh b/xci/scripts/vm/start-new-vm.sh
index 5273a778..96ce17e1 100755
--- a/xci/scripts/vm/start-new-vm.sh
+++ b/xci/scripts/vm/start-new-vm.sh
@@ -15,6 +15,10 @@ set -e
# executed on a CI or not.
export JENKINS_HOME="${JENKINS_HOME:-${HOME}}"
+# Set this option to destroy the VM on failures. This is helpful when we
+# don't want to preserve the VM for debugging purposes.
+export XCI_KEEP_CLEAN_VM_ON_FAILURES=${XCI_KEEP_CLEAN_VM_ON_FAILURES:-true}
+
export DEFAULT_XCI_TEST=${DEFAULT_XCI_TEST:-false}
# JIT Build of OS image to load on the clean VM
export XCI_BUILD_CLEAN_VM_OS=${XCI_BUILD_CLEAN_VM_OS:-true}
@@ -24,6 +28,15 @@ export XCI_UPDATE_CLEAN_VM_OS=${XCI_UPDATE_CLEAN_VM_OS:-false}
grep -q -i ^Y$ /sys/module/kvm_intel/parameters/nested || { echo "Nested virtualization is not enabled but it's needed for XCI to work"; exit 1; }
+destroy_vm_on_failures() {
+ local exit_err=${xci_error:-130}
+ if ! ${XCI_KEEP_CLEAN_VM_ON_FAILURES}; then
+ sudo virsh destroy ${VM_NAME}_xci_vm
+ sudo virsh undefine ${VM_NAME}_xci_vm
+ fi
+ exit $exit_err
+}
+
usage() {
echo """
$0 <distro>
@@ -181,6 +194,8 @@ sudo virt-install -n ${VM_NAME} --memory ${MEMORY} --vcpus ${NCPUS} --cpu ${CPU}
--import --disk=${OS_IMAGE_FILE},cache=unsafe --network network=${NETWORK} \
--graphics none --hvm --noautoconsole
+trap destroy_vm_on_failures EXIT
+
_retries=30
while [[ $_retries -ne 0 ]]; do
_ip=$(sudo virsh domifaddr ${VM_NAME} | grep -o --colour=never 192.168.140.[[:digit:]]* | cat )