summaryrefslogtreecommitdiffstats
path: root/xci/scripts/vm/start-new-vm.sh
diff options
context:
space:
mode:
authorMarkos Chandras <mchandras@suse.de>2017-10-05 17:28:35 +0100
committerMarkos Chandras <mchandras@suse.de>2017-10-09 08:50:56 +0100
commit5ea389f23fb6053855e4840baf6c7c8e0f4b8f99 (patch)
tree08f2f521be72bbea065f9d9f3441047346a5d130 /xci/scripts/vm/start-new-vm.sh
parenta94f0eb1448e98ef2fed6677595d206cc8298bde (diff)
xci: scripts: start-new-vm.sh: Add option to clean VM on failure
Sometimes we may want to remove the clean VM in case of failure. This is mostly true for CI tests because developers do not normally have access to the deployed VMs to debug problems since they can easily recreate the same environment using this script. If they ever want direct access to the slaves then that option can easily be turned off and retrigger the job. In the meantime, this patch allows slaves to free resources when a job fails instead of keeping the broken tests around. Change-Id: I07d56661e45fc64e1ec0db7a359522e4ebd2891a Signed-off-by: Markos Chandras <mchandras@suse.de>
Diffstat (limited to 'xci/scripts/vm/start-new-vm.sh')
-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 a1f4080e..5112cf40 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 )