ci/deploy.sh: maas: cleanup_uefi on env erase 93/49793/1
authorAlexandru Avadanii <Alexandru.Avadanii@enea.com>
Sat, 9 Dec 2017 01:39:33 +0000 (02:39 +0100)
committerAlexandru Avadanii <Alexandru.Avadanii@enea.com>
Sat, 30 Dec 2017 23:58:17 +0000 (23:58 +0000)
Running `ci/deploy.sh -EE` should also perform an UEFI boot option
cleanup, otherwise we risk booting the previously installed OS.

While at it, reduce delay between nodes removal and fix a rare failure
for `-EE` when no nodes are defined in MaaS.

Change-Id: I789ffd3e22545921216f7d5ee3509c76354542eb
Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
(cherry picked from commit 15173a83dba08729e62da277b9165677323675d8)

mcp/config/states/maas
mcp/scripts/lib.sh

index 24cefe8..9ad0538 100755 (executable)
@@ -1,4 +1,5 @@
 #!/bin/bash -e
+# shellcheck disable=SC1090,SC2155
 ##############################################################################
 # Copyright (c) 2017 Mirantis Inc., Enea AB and others.
 # All rights reserved. This program and the accompanying materials
 CI_DEBUG=${CI_DEBUG:-0}; [[ "${CI_DEBUG}" =~ (false|0) ]] || set -x
 ERASE_ENV=${ERASE_ENV:-0}
 
-# shellcheck disable=SC1090
+source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/globals.sh"
 source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/lib.sh"
 
 # Wait for MaaS commissioning/deploy to finish, retry on failure
 function maas_fixup() {
   local statuscmd="salt 'mas01*' --out yaml state.apply maas.machines.status"
-  # shellcheck disable=SC2155
   local ncount=$(salt --out yaml 'mas01*' pillar.get maas:region:machines | \
     grep -cE '^\s{2}\w+:$')
   wait_for 180 "${statuscmd} | tee /dev/stderr | " \
     "grep -Eq '((Deployed|Ready): ${ncount}|status: (Failed|Allocated))'"
-  # shellcheck disable=SC2155
   local statusout=$(eval "${statuscmd}")
 
-  # shellcheck disable=SC2155
   local fcnodes=$(echo "${statusout}" | \
     grep -Pzo 'status: Failed commissioning\n\s+system_id: \K.+\n')
   for node_system_id in ${fcnodes}; do
@@ -37,7 +35,6 @@ function maas_fixup() {
     return 1
   fi
 
-  # shellcheck disable=SC2155
   local fdnodes=$(echo "${statusout}" | \
     grep -Pzo 'status: (Failed deployment|Allocated)\n\s+system_id: \K.+\n')
   for node_system_id in ${fdnodes}; do
@@ -55,12 +52,13 @@ function maas_fixup() {
 
 # Optionally destroy MaaS machines from a previous run
 if [ "${ERASE_ENV}" -gt 1 ]; then
-  dnodes=$(salt 'mas01*' --out yaml state.apply maas.machines.status | \
-    grep -Pzo '\s+system_id: \K.+\n')
+  set +e; dnodes=$(salt 'mas01*' --out yaml state.apply maas.machines.status | \
+    grep -Pzo '\s+system_id: \K.+\n'); set -e
+  cleanup_uefi
   for node_system_id in ${dnodes}; do
     salt -C 'mas01*' state.apply maas.machines.delete \
       pillar="{'system_id': '${node_system_id}'}"
-    sleep 30
+    sleep 10
   done
 fi
 
index 93ee59d..cafa7d5 100644 (file)
@@ -37,8 +37,9 @@ function get_base_image {
 
 function cleanup_uefi {
   # Clean up Ubuntu boot entry if cfg01, kvm nodes online from previous deploy
-  # shellcheck disable=SC2086
-  ssh ${SSH_OPTS} "${SSH_SALT}" "sudo salt -C 'kvm* or cmp*' cmd.run \
+  local cmd_str="ssh ${SSH_OPTS} ${SSH_SALT}"
+  [ ! "$(hostname)" = 'cfg01' ] || cmd_str='eval'
+  ${cmd_str} "sudo salt -C 'kvm* or cmp*' cmd.run \
     \"which efibootmgr > /dev/null 2>&1 && \
     efibootmgr | grep -oP '(?<=Boot)[0-9]+(?=.*ubuntu)' | \
     xargs -I{} efibootmgr --delete-bootnum --bootnum {}; \