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.0 "salt -C 'kvm*' state.sls libvirt"
32 salt -C 'kvm* or cmp*' state.apply salt
33 wait_for 10.0 "salt -C 'kvm*' state.sls salt.control"
35 vcp_nodes=$(salt --out yaml 'kvm01*' pillar.get salt:control:cluster:internal:node | \
36 awk '/\s+\w+:$/ {gsub(/:$/, "*"); print $1}')
38 # Check all vcp nodes are available
42 while [ $rc -ne 0 ] && [ ${attempt} -lt ${total_attempts} ]; do
44 for node in $vcp_nodes; do
45 salt "$node" test.ping 2>/dev/null || { rc=$?; break; };
51 wait_for 10.0 "salt -C '* and not cfg01* and not mas01*' saltutil.sync_all"
53 # Propagate APT proxy config created by curtin on baremetal nodes to VCP VMs
54 APT_CONF_D_CURTIN='/etc/apt/apt.conf.d/90curtin-aptproxy'
55 salt -C 'kvm01*' cp.push "${APT_CONF_D_CURTIN}"
56 cd /srv/salt/env/prd/maas/files && ln -sf \
57 /var/cache/salt/master/minions/kvm01.*/files/${APT_CONF_D_CURTIN}
58 salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' cp.get_file \
59 "salt://maas/files/$(basename "${APT_CONF_D_CURTIN}")" "${APT_CONF_D_CURTIN}"
61 wait_for 10 "salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' state.apply salt"
62 wait_for 10.0 "salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' state.apply linux,ntp"
64 wait_for 10 "salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' ssh.set_auth_key ${SUDO_USER} \
65 $(awk 'NR==1{print $2}' "$(eval echo "~${SUDO_USER}/.ssh/authorized_keys")")"
67 # Disable proxy dhcp routes after installation
68 salt -C 'prx*' file.write /etc/dhcp/dhclient-enter-hooks.d/no-default-route \
69 args='unset new_routers'
70 salt -C 'prx*' system.reboot
71 wait_for 30.0 "salt -C 'prx*' test.ping"
73 salt -C 'E@^(?!cfg01|mas01|kvm|cmp00).*' pkg.upgrade refresh=False