[AArch64] vcp: Fix up vcp_nodes awk query conflict
[fuel.git] / mcp / config / states / virtual_control_plane
1 #!/bin/bash -e
2 ##############################################################################
3 # Copyright (c) 2017 Mirantis Inc., Enea AB and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 CI_DEBUG=${CI_DEBUG:-0}; [[ "${CI_DEBUG}" =~ (false|0) ]] || set -x
11 ERASE_ENV=${ERASE_ENV:-0}
12
13 # shellcheck disable=SC1090
14 source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/lib.sh"
15
16 # Optionally destroy VCP VMs from a previous run
17 if [ "${ERASE_ENV}" -eq 1 ]; then
18     kvm_vms=$(salt --out yaml 'kvm*' virt.list_domains | \
19               sed -e 's/- //g' -e 's/:.*$//g')
20     for line in ${kvm_vms}; do
21         if [[ "${line}" =~ ^kvm ]]; then
22             kvm_node=${line}
23         elif [ -n "${kvm_node}" ]; then
24             salt "${kvm_node}" virt.purge dirs=True "${line}" || true
25         fi
26     done
27 fi
28
29 # KVM libvirt first, VCP deployment
30 if salt -C 'kvm*' match.grain 'cpuarch:aarch64' \
31   --out yaml --static | grep -q -e 'true' ; then
32   wait_for 5.0 "salt -C 'G@cpuarch:aarch64 and kvm*' state.sls armband"
33 fi
34 wait_for 5.0 "salt -C 'kvm*' state.sls libvirt"
35
36 salt -C 'kvm* or cmp*' state.apply salt
37 wait_for 10.0 "salt -C 'kvm*' state.sls salt.control"
38
39 vcp_nodes=$(salt --out yaml 'kvm01*' pillar.get salt:control:cluster:internal:node | \
40             awk '/\s+\w+[[:digit:]]+:$/ {gsub(/:$/, "*"); printf "%s ", $1}')
41
42 # Check all vcp nodes are available
43 wait_for 25.0 "(for n in ${vcp_nodes}; do salt \${n} test.ping 2>/dev/null || exit; done)"
44
45 wait_for 10.0 "salt -C '* and not cfg01* and not mas01*' saltutil.sync_all"
46
47 # Propagate APT proxy config created by curtin on baremetal nodes to VCP VMs
48 APT_CONF_D_CURTIN='/etc/apt/apt.conf.d/90curtin-aptproxy'
49 salt -C 'kvm01*' cp.push "${APT_CONF_D_CURTIN}"
50 cd /srv/salt/env/prd/maas/files && ln -sf \
51   /var/cache/salt/master/minions/kvm01.*/files/${APT_CONF_D_CURTIN}
52 salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' cp.get_file \
53   "salt://maas/files/$(basename "${APT_CONF_D_CURTIN}")" "${APT_CONF_D_CURTIN}"
54
55 wait_for 10.0 "salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' state.apply salt"
56 wait_for 10.0 "salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' state.apply linux,ntp"
57
58 wait_for 10.0 "salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' ssh.set_auth_key ${SUDO_USER} \
59   $(awk 'NR==1{print $2}' "$(eval echo "~${SUDO_USER}/.ssh/authorized_keys")")"
60
61 salt -C 'prx*' system.reboot
62 wait_for 30.0 "salt -C 'prx*' test.ping"
63
64 salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' pkg.upgrade refresh=False dist_upgrade=True