2 # shellcheck disable=SC2155,SC2015
3 ##############################################################################
4 # Copyright (c) 2018 Mirantis Inc., Enea AB and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
11 # Library of common shell functions used by build/deploy scripts, states etc.
15 # Execute in a subshell to prevent local variable override during recursion
17 local total_attempts=$1; shift
20 echo -e "\n[wait_for] Waiting for cmd to return success: ${cmdstr}"
21 # shellcheck disable=SC2034
22 for attempt in $(seq "${total_attempts}"); do
23 echo "[wait_for] Attempt ${attempt}/${total_attempts%.*} for: ${cmdstr}"
24 if [ "${total_attempts%.*}" = "${total_attempts}" ]; then
25 eval "${cmdstr}" && echo "[wait_for] OK: ${cmdstr}" && return 0 || true
27 ! (eval "${cmdstr}" || echo 'No response') |& tee /dev/stderr | \
28 grep -Eq '(Not connected|No response)' && \
29 echo "[wait_for] OK: ${cmdstr}" && return 0 || true
33 echo "[wait_for] ERROR: Failed after max attempts: ${cmdstr}"
38 function cleanup_uefi {
39 # Clean up Ubuntu boot entry if cfg01, kvm nodes online from previous deploy
40 local cmd_str="ssh ${SSH_OPTS} ${SSH_SALT}"
41 ping -c 1 -w 1 "${SALT_MASTER}" || return 0
42 [ ! "$(hostname)" = 'cfg01' ] || cmd_str='eval'
43 # NOTE: Targeting nodes by hostname is fragile and should be refactored to
44 # also cover corner cases like noha scenarios on AArch64 baremetal's 'ctl01'
45 ${cmd_str} "sudo salt -C 'kvm* or cmp*' cmd.run \
46 \"which efibootmgr > /dev/null 2>&1 && \
47 efibootmgr | grep -oP '(?<=Boot)[0-9]+(?=.*ubuntu)' | \
48 xargs -I{} efibootmgr --delete-bootnum --bootnum {}; \
49 rm -rf /boot/efi/*\"" || true
52 function get_nova_compute_pillar_data {
53 local value=$(salt -C 'I@nova:compute and *01*' pillar.get _param:"${1}" --out yaml | cut -d ' ' -f2)
54 if [ "${value}" != "''" ]; then