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