Merge "[baremetal] Fix DPDK by running linux.system first" into stable/euphrates
[fuel.git] / mcp / config / states / virtual_control_plane
1 #!/bin/bash -x
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 # shellcheck disable=SC1090
11 source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/lib.sh"
12
13 # KVM, compute node prereqs (libvirt first), VCP deployment
14 salt -C 'kvm*' pkg.install bridge-utils
15 salt -C 'kvm*' state.apply linux.network
16 salt -C 'cmp*' state.apply linux.system
17 salt -C 'kvm* or cmp*' system.reboot
18 wait_for 90 "! salt -C 'kvm* or cmp*' test.ping | " \
19   "tee /dev/stderr | grep -Fq 'Not connected'"
20
21 salt -C '* and not cfg01* and not mas01*' state.apply linux,ntp
22
23 salt -C 'kvm*' state.sls libvirt
24
25 salt -C '* and not cfg01* and not mas01*' state.apply salt
26 salt -C 'kvm*' saltutil.sync_all
27 wait_for 10 "! salt -C 'kvm*' state.sls salt.control | " \
28   "tee /dev/stderr | grep -Fq 'Not connected'"
29
30 vcp_nodes=$(salt --out yaml 'kvm01*' pillar.get salt:control:cluster:internal:node | \
31             awk '/\s+\w+:$/ {gsub(/:$/, "*"); print $1}')
32
33 # Check all vcp nodes are available
34 rc=1
35 while [ $rc -ne 0 ]; do
36   rc=0
37   for node in $vcp_nodes; do
38     salt "$node" test.ping 2>/dev/null || { rc=$?; break; };
39   done
40   sleep 5
41 done
42
43 wait_for 10 "salt -C '* and not cfg01* and not mas01*' saltutil.sync_all"
44 wait_for 10 "salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' state.apply salt"
45 wait_for 10 "! salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' state.apply linux,ntp | " \
46   "tee /dev/stderr | grep -Fq 'Not connected'"
47
48 wait_for 10 "salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' ssh.set_auth_key ${SUDO_USER} \
49   $(awk 'NR==1{print $2}' "$(eval echo "~${SUDO_USER}/.ssh/authorized_keys")")"