3 local total_attempts=$1; shift
6 echo "[NOTE] Waiting for cmd to return success: ${cmdstr}"
7 for attempt in $(seq "${total_attempts}"); do
8 eval "${cmdstr}" && break || true
9 echo -n '.'; sleep "${sleep_time}"
13 # Wait for MaaS commissioning/deploy to finish, retry on failure
14 function maas_fixup() {
15 local statuscmd="salt 'mas01*' --out yaml state.apply maas.machines.status"
16 wait_for 180 "${statuscmd} | tee /dev/stderr | " \
17 "grep -Eq '((Deployed|Ready): 5|status:Failed|status:Allocated)'"
18 local statusout=$(eval "${statuscmd}")
20 local fcnodes=$(echo "${statusout}" | \
21 grep -Po '(?<=system_id:)(.*)(?=,status:Failed commissioning)')
22 for node_system_id in ${fcnodes}; do
23 salt -C 'mas01*' state.apply maas.machines.delete \
24 pillar="{'system_id': '${node_system_id}'}"
26 if [ -n "${fcnodes}" ]; then
27 salt -C 'mas01*' state.apply maas.machines
31 local fdnodes=$(echo "${statusout}" | \
32 grep -Po '(?<=system_id:)(.*)(?=,status:(Failed deployment|Allocated))')
33 for node_system_id in ${fdnodes}; do
34 salt -C 'mas01*' state.apply maas.machines.mark_broken_fixed \
35 pillar="{'system_id': '${node_system_id}'}"
37 if [ -n "${fdnodes}" ]; then
38 salt -C 'mas01*' state.apply maas.machines.deploy
45 # MaaS rack/region controller, node commissioning
46 salt -C 'mas01*' cmd.run "add-apt-repository ppa:maas/stable"
48 salt -C 'mas01*' state.apply linux,salt,openssh,ntp
49 salt -C 'mas01*' state.apply linux.network.interface
50 salt -C 'mas01*' state.apply maas.pxe_nat
51 salt -C 'mas01*' state.apply maas.cluster
52 salt -C 'cfg01*' cmd.run \
53 "route add -net 192.168.11.0/24 gw ${MAAS_IP:-192.168.10.3}"
55 wait_for 10 "salt -C 'mas01*' state.apply maas.region"
57 salt -C 'mas01*' state.apply maas.machines
58 wait_for 10 maas_fixup
60 # cleanup outdated salt keys
61 salt-key --out yaml | awk '!/^(minions|- cfg01|- mas01)/ {print $2}' | \
62 xargs -I{} salt-key -yd {}
64 # MaaS node deployment
65 salt -C 'mas01*' state.apply maas.machines.deploy
66 wait_for 10 maas_fixup
68 salt -C 'mas01*' pillar.item\
69 maas:region:admin:username \
70 maas:region:admin:password
72 # KVM, compute node prereqs (libvirt first), VCP deployment
73 salt -C '* and not cfg01* and not mas01*' saltutil.sync_all
75 salt -C 'kvm*' pkg.install bridge-utils
76 salt -C 'kvm*' state.apply linux.network
77 salt -C 'kvm*' system.reboot
78 wait_for 90 "! salt '*' test.ping | tee /dev/stderr | fgrep -q 'Not connected'"
80 salt -C '* and not cfg01* and not mas01*' state.apply linux,ntp
82 salt -C 'kvm*' state.sls libvirt
84 salt -C '* and not cfg01* and not mas01*' state.apply salt
85 salt -C 'kvm*' saltutil.sync_all
86 salt -C 'kvm*' state.sls salt.control
88 vcp_nodes=$(salt --out yaml 'kvm01*' pillar.get salt:control:cluster:internal:node | \
89 awk '/\s+\w+:$/ {gsub(/:$/, "*"); print $1}')
91 # Check all vcp nodes are available
93 while [ $rc -ne 0 ]; do
95 for node in $vcp_nodes; do
96 salt "$node" test.ping 2>/dev/null || { rc=$?; break; };
101 wait_for 10 "salt -C '* and not cfg01* and not mas01*' ssh.set_auth_key ${SUDO_USER} \
102 $(awk 'NR==1{print $2}' $(eval echo ~${SUDO_USER}/.ssh/authorized_keys))"
104 wait_for 10 "salt -C '* and not cfg01* and not mas01*' saltutil.sync_all"
105 wait_for 10 "salt -C '* and not cfg01* and not mas01*' state.apply salt"
106 wait_for 10 "salt -C '* and not cfg01* and not mas01*' state.apply linux,ntp"