docker build: Update saltstack repo URL, locale
[fuel.git] / mcp / config / states / maas
1 #!/bin/bash -e
2 # shellcheck disable=SC1090
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 ##############################################################################
10
11 CI_DEBUG=${CI_DEBUG:-0}; [[ "${CI_DEBUG}" =~ (false|0) ]] || set -x
12 ERASE_ENV=${ERASE_ENV:-0}
13
14 source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/globals.sh"
15 source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/lib.sh"
16
17 bm_nodes=$(salt --out yaml 'mas01*' pillar.get maas:region:machines | \
18            awk '/^\s+\w+[[:digit:]]+:$/ {gsub(/:$/, "*"); printf "%s ", $1}')
19
20 wait_for 60.0 "salt --out yaml -C 'mas01*' service.status maas-fixup | fgrep -q 'false'"
21
22 # Optionally destroy MaaS machines from a previous run
23 if [ "${ERASE_ENV}" -gt 1 ]; then
24   cleanup_uefi
25   for node_hostname in ${bm_nodes//\*/}; do
26     salt -C 'mas01*' maasng.delete_machine "${node_hostname}" || true
27   done
28 fi
29
30 # MaaS rack/region controller, node commissioning
31 wait_for 10.0 "salt -C 'mas01*' state.apply salt,iptables"
32 salt -C 'mas01*' state.apply maas.cluster
33
34 wait_for 10 "salt -C 'mas01*' state.apply maas.region"
35
36 if [ -n "${bm_nodes}" ]; then
37   salt -C 'mas01*' state.apply maas.machines
38 fi
39
40 # cleanup outdated salt keys
41 sleep 30
42 salt-key --out yaml | awk '!/^(minions|- cfg01|- mas01)/ {print $2}' | \
43   xargs --no-run-if-empty -I{} salt-key -yd {}
44
45 # MaaS node deployment
46 if [ -n "${bm_nodes}" ]; then
47   notify "[NOTE] MaaS operations might take a long time, please be patient" 2
48   salt -C 'mas01*' state.apply maas.machines.wait_for_ready_or_deployed
49   salt -C 'mas01*' state.apply maas.machines.storage
50   salt -C 'mas01*' state.apply maas.machines.deploy
51   salt -C 'mas01*' state.apply maas.machines.wait_for_deployed
52 fi
53
54 # Check all baremetal nodes are available
55 wait_for 10.0 "(for n in ${bm_nodes}; do salt \${n} test.ping 2>/dev/null || exit; done)"
56
57 wait_for 10.0 "salt -C '* and not cfg01* and not mas01*' saltutil.sync_all"