lib.sh: Remove all storage on undefine 39/41339/7
authorAlexandru Avadanii <Alexandru.Avadanii@enea.com>
Thu, 7 Sep 2017 19:55:16 +0000 (21:55 +0200)
committerAlexandru Avadanii <Alexandru.Avadanii@enea.com>
Thu, 7 Sep 2017 22:29:30 +0000 (00:29 +0200)
While executing the deploy script via sudo will raise no issues with
re-using old storage volume files, non-root deploys fail to change
ownership of said files.

Properly clean after ourselves when destroying and undefining VMs.

JIRA: ARMBAND-311

Change-Id: I7fdd269dccbfd5ab5285d852ac7dacfc4dc5ccd7
Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
mcp/scripts/lib.sh

index 1812663..d9b5e63 100644 (file)
@@ -34,7 +34,9 @@ cleanup_vms() {
     virsh destroy "${node}"
   done
   for node in $(virsh list --name --all | grep -P '\w{3}\d{2}'); do
-    virsh undefine --nvram "${node}"
+    virsh domblklist "${node}" | awk '/^.da/ {print $2}' | \
+      xargs --no-run-if-empty -I{} sudo rm -f {}
+    virsh undefine "${node}" --remove-all-storage --nvram
   done
 }
 
@@ -45,6 +47,7 @@ prepare_vms() {
 
   cleanup_vms
   get_base_image "${base_image}" "${image_dir}"
+  # shellcheck disable=SC2016
   envsubst '${SALT_MASTER},${CLUSTER_DOMAIN}' < \
     user-data.template > user-data.sh