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 ##############################################################################
11 CI_DEBUG=${CI_DEBUG:-0}; [[ "${CI_DEBUG}" =~ (false|0) ]] || set -x
12 ERASE_ENV=${ERASE_ENV:-0}
14 source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/globals.sh"
15 source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/lib.sh"
17 bm_nodes=$(salt --out yaml 'mas01*' pillar.get maas:region:machines | \
18 awk '/^\s+\w+[[:digit:]]+:$/ {gsub(/:$/, "*"); printf "%s ", $1}')
20 # Optionally destroy MaaS machines from a previous run
21 if [ "${ERASE_ENV}" -gt 1 ]; then
23 for node_hostname in ${bm_nodes//\*/}; do
24 salt -C 'mas01*' maasng.delete_machine "${node_hostname}" || true
28 # MaaS rack/region controller, node commissioning
29 wait_for 10.0 "salt -C 'mas01*' state.apply linux,salt,openssh,ntp,iptables"
30 salt -C 'mas01*' state.apply maas.cluster
32 wait_for 10 "salt -C 'mas01*' state.apply maas.region"
34 if [ -n "${bm_nodes}" ]; then
35 salt -C 'mas01*' state.apply maas.machines
38 # cleanup outdated salt keys
40 salt-key --out yaml | awk '!/^(minions|- cfg01|- mas01)/ {print $2}' | \
41 xargs --no-run-if-empty -I{} salt-key -yd {}
43 # MaaS node deployment
44 if [ -n "${bm_nodes}" ]; then
45 notify "[NOTE] MaaS operations might take a long time, please be patient" 2
46 salt -C 'mas01*' state.apply maas.machines.wait_for_ready_or_deployed
47 salt -C 'mas01*' state.apply maas.machines.storage
48 salt -C 'mas01*' state.apply maas.machines.deploy
49 salt -C 'mas01*' state.apply maas.machines.wait_for_deployed
52 # Check all baremetal nodes are available
53 wait_for 10.0 "(for n in ${bm_nodes}; do salt \${n} test.ping 2>/dev/null || exit; done)"
55 wait_for 10.0 "salt -C '* and not cfg01* and not mas01*' saltutil.sync_all"