Skip to content

Commit

Permalink
reprovision all VM in local environment when running run_w_clean target
Browse files Browse the repository at this point in the history
  • Loading branch information
nqb committed Nov 25, 2021
1 parent f07218b commit 362bad0
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions t/venom/test-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,41 +78,44 @@ run() {
run_tests
}

# Start with or without VM
start_vm() {
local vm=$1
local dotfile_path=$2
if [ -e "${dotfile_path}/machines/${vm}/libvirt/id" ]; then
echo "Machine $vm already exists"
machine_uuid=$(cat ${dotfile_path}/machines/${vm}/libvirt/id)
echo "Starting $vm using libvirt, provisioning using Ansible (without Vagrant)"
virsh -c qemu:///system start --domain $machine_uuid
# let time for the VM to boot before using ansible
sleep 60
( cd ${VAGRANT_DIR}; \
ansible-playbook site.yml -l $vm )
else
echo "Machine $vm doesn't exist, start and provision with Vagrant"
( cd ${VAGRANT_DIR} ; \
VAGRANT_DOTFILE_PATH=${dotfile_path} \
vagrant up \
${vm} \
${VAGRANT_UP_OPTS} )
fi
}

start_and_provision_pf_vm() {
local vm_names=${@:-vmname}
log_subsection "Start and provision $vm_names"
log_subsection "Start and provision PacketFence $vm_names"
for vm in ${vm_names}; do
start_vm ${vm} ${VAGRANT_PF_DOTFILE_PATH}
done

( cd ${VAGRANT_DIR} ; \
VAGRANT_DOTFILE_PATH=${VAGRANT_PF_DOTFILE_PATH} \
vagrant up \
${vm_names} \
${VAGRANT_UP_OPTS} )
}

start_and_provision_other_vm() {
local vm_names=${@:-vmname}
log_subsection "Start and provision $vm_names"

for vm in ${vm_names}; do
if [ -e "${VAGRANT_COMMON_DOTFILE_PATH}/machines/${vm}/libvirt/id" ]; then
echo "Machine $vm already exists"
machine_uuid=$(cat ${VAGRANT_COMMON_DOTFILE_PATH}/machines/${vm}/libvirt/id)
# hack to overcome the fact that node01 doesn't have IP address after first provisioning
# vagrant up will fail
echo "Starting $vm using libvirt, provisioning using Ansible (without Vagrant)"
virsh -c qemu:///system start --domain $machine_uuid
# let time for the VM to boot before using ansible
sleep 60
( cd ${VAGRANT_DIR}; \
ansible-playbook site.yml -l $vm )
else
echo "Machine $vm doesn't exist, start and provision with Vagrant"
( cd ${VAGRANT_DIR} ; \
VAGRANT_DOTFILE_PATH=${VAGRANT_COMMON_DOTFILE_PATH} \
vagrant up \
${vm} \
${VAGRANT_UP_OPTS} )
fi
start_vm ${vm} ${VAGRANT_COMMON_DOTFILE_PATH}
done
}

Expand Down

0 comments on commit 362bad0

Please sign in to comment.