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 ##############################################################################
10 CI_DEBUG=${CI_DEBUG:-0}; [[ "${CI_DEBUG}" =~ (false|0) ]] || set -x
12 # shellcheck disable=SC1090
13 source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/lib.sh"
15 # Wait for MaaS commissioning/deploy to finish, retry on failure
16 function maas_fixup() {
17 local statuscmd="salt 'mas01*' --out yaml state.apply maas.machines.status"
18 # shellcheck disable=SC2155
19 local ncount=$(salt --out yaml 'mas01*' pillar.get maas:region:machines | \
20 grep -cE '^\s{2}\w+:$')
21 wait_for 180 "${statuscmd} | tee /dev/stderr | " \
22 "grep -Eq '((Deployed|Ready): ${ncount}|status:Failed|status:Allocated)'"
23 # shellcheck disable=SC2155
24 local statusout=$(eval "${statuscmd}")
26 # shellcheck disable=SC2155
27 local fcnodes=$(echo "${statusout}" | \
28 grep -Po '(?<=system_id:)(.*)(?=,status:Failed commissioning)')
29 for node_system_id in ${fcnodes}; do
30 salt -C 'mas01*' state.apply maas.machines.delete \
31 pillar="{'system_id': '${node_system_id}'}"
34 if [ -n "${fcnodes}" ]; then
35 salt -C 'mas01*' state.apply maas.machines
39 # shellcheck disable=SC2155
40 local fdnodes=$(echo "${statusout}" | \
41 grep -Po '(?<=system_id:)(.*)(?=,status:(Failed deployment|Allocated))')
42 for node_system_id in ${fdnodes}; do
43 salt -C 'mas01*' state.apply maas.machines.mark_broken_fixed \
44 pillar="{'system_id': '${node_system_id}'}"
47 if [ -n "${fdnodes}" ]; then
48 salt -C 'mas01*' state.apply maas.machines.deploy
55 # MaaS rack/region controller, node commissioning
56 salt -C 'mas01*' cmd.run "add-apt-repository ppa:maas/stable"
58 salt -C 'mas01*' state.apply linux,salt,openssh,ntp
59 salt -C 'mas01*' state.apply linux.network.interface
60 salt -C 'mas01*' state.apply maas.pxe_nat
61 salt -C 'mas01*' state.apply maas.cluster
62 salt -C 'cfg01*' state.apply maas.pxe_route
64 wait_for 10 "salt -C 'mas01*' state.apply maas.region"
66 salt -C 'mas01*' state.apply maas.machines
67 wait_for 10 maas_fixup
69 # cleanup outdated salt keys
70 salt-key --out yaml | awk '!/^(minions|- cfg01|- mas01)/ {print $2}' | \
71 xargs -I{} salt-key -yd {}
73 # MaaS node deployment
74 salt -C 'mas01*' state.apply maas.machines.deploy
75 wait_for 10 maas_fixup
77 salt -C 'mas01*' pillar.item\
78 maas:region:admin:username \
79 maas:region:admin:password
81 # Check all baremetal nodes are available
85 while [ $rc -ne 0 ] && [ ${attempt} -lt ${total_attempts} ]; do
86 bm_nodes=$(salt --out yaml 'mas01*' pillar.get maas:region:machines | \
87 awk '/^\s+\w+[[:digit:]]+:$/ {gsub(/:$/, "*"); print $1}')
89 for node in $bm_nodes; do
90 salt "$node" test.ping 2>/dev/null || { rc=$?; break; };
96 wait_for 10 "salt -C '* and not cfg01* and not mas01*' saltutil.sync_all"