Merge "[baremetal] Fixup pike deployment (2)"
[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 #FIXME Should be removed once upstream patch get merged
31 salt -C 'kvm*' group.add libvirtd
32 wait_for 5 "salt -C 'kvm*' state.sls libvirt"
33
34 salt -C 'kvm* or cmp*' state.apply salt
35 wait_for 10 "! salt -C 'kvm*' state.sls salt.control | " \
36   "tee /dev/stderr | grep -Fq 'Not connected'"
37
38 vcp_nodes=$(salt --out yaml 'kvm01*' pillar.get salt:control:cluster:internal:node | \
39             awk '/\s+\w+:$/ {gsub(/:$/, "*"); print $1}')
40
41 # Check all vcp nodes are available
42 rc=1
43 attempt=0
44 total_attempts=50
45 while [ $rc -ne 0 ] && [ ${attempt} -lt ${total_attempts} ]; do
46   rc=0
47   for node in $vcp_nodes; do
48     salt "$node" test.ping 2>/dev/null || { rc=$?; break; };
49   done
50   sleep 5
51   ((attempt+=1))
52 done
53
54 wait_for 10 "salt -C '* and not cfg01* and not mas01*' saltutil.sync_all"
55 wait_for 10 "salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' state.apply salt"
56 wait_for 10 "! salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' state.apply linux,ntp | " \
57   "tee /dev/stderr | grep -Fq 'Not connected'"
58
59 wait_for 10 "salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' ssh.set_auth_key ${SUDO_USER} \
60   $(awk 'NR==1{print $2}' "$(eval echo "~${SUDO_USER}/.ssh/authorized_keys")")"
61
62 # Disable proxy dhcp routes after installation
63 salt -C 'prx*' file.write /etc/dhcp/dhclient-enter-hooks.d/no-default-route \
64   args='unset new_routers'
65 salt -C 'prx*' system.reboot
66 wait_for 30 "! salt -C 'prx*' test.ping | " \
67   "tee /dev/stderr | grep -Fq 'Not connected'"
68
69 salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' pkg.upgrade refresh=False