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
11 ERASE_ENV=${ERASE_ENV:-0}
13 # shellcheck disable=SC1090
14 source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/lib.sh"
16 # Optionally destroy VCP VMs from a previous run
17 if [ "${ERASE_ENV}" -eq 1 ]; then
18 kvm_vms=$(salt --out yaml 'kvm*' virt.list_domains | \
19 sed -e 's/- //g' -e 's/:.*$//g')
20 for line in ${kvm_vms}; do
21 if [[ "${line}" =~ ^kvm ]]; then
23 elif [ -n "${kvm_node}" ]; then
24 salt "${kvm_node}" virt.purge dirs=True "${line}" || true
29 # KVM libvirt first, VCP deployment
30 wait_for 5 "salt -C 'kvm*' state.sls libvirt"
32 salt -C 'kvm* or cmp*' state.apply salt
33 wait_for 10 "! salt -C 'kvm*' state.sls salt.control | " \
34 "tee /dev/stderr | grep -Fq 'Not connected'"
36 vcp_nodes=$(salt --out yaml 'kvm01*' pillar.get salt:control:cluster:internal:node | \
37 awk '/\s+\w+:$/ {gsub(/:$/, "*"); print $1}')
39 # Check all vcp nodes are available
43 while [ $rc -ne 0 ] && [ ${attempt} -lt ${total_attempts} ]; do
45 for node in $vcp_nodes; do
46 salt "$node" test.ping 2>/dev/null || { rc=$?; break; };
52 wait_for 10 "salt -C '* and not cfg01* and not mas01*' saltutil.sync_all"
54 # Propagate APT proxy config created by curtin on baremetal nodes to VCP VMs
55 APT_CONF_D_CURTIN='/etc/apt/apt.conf.d/90curtin-aptproxy'
56 salt -C 'kvm01*' cp.push "${APT_CONF_D_CURTIN}"
57 cd /srv/salt/env/prd/maas/files && ln -sf \
58 /var/cache/salt/master/minions/kvm01.*/files/${APT_CONF_D_CURTIN}
59 salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' cp.get_file \
60 "salt://maas/files/$(basename "${APT_CONF_D_CURTIN}")" "${APT_CONF_D_CURTIN}"
62 wait_for 10 "salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' state.apply salt"
63 wait_for 10 "salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' service.force_reload salt-minion"
64 wait_for 10 "! salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' state.apply linux,ntp | " \
65 "tee /dev/stderr | grep -Eq '(Not connected|No response)'"
67 wait_for 10 "salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' ssh.set_auth_key ${SUDO_USER} \
68 $(awk 'NR==1{print $2}' "$(eval echo "~${SUDO_USER}/.ssh/authorized_keys")")"
70 # Disable proxy dhcp routes after installation
71 salt -C 'prx*' file.write /etc/dhcp/dhclient-enter-hooks.d/no-default-route \
72 args='unset new_routers'
73 salt -C 'prx*' system.reboot
74 wait_for 30 "! salt -C 'prx*' test.ping | " \
75 "tee /dev/stderr | grep -Fq 'Not connected'"
77 salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' pkg.upgrade refresh=False