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
and allow to shutdown all VM without errors using make halt
  • Loading branch information
nqb committed Nov 25, 2021
1 parent f07218b commit f8a031d
Showing 1 changed file with 37 additions and 27 deletions.
64 changes: 37 additions & 27 deletions t/venom/test-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,41 +78,45 @@ 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
echo "Let time to VM to start before provisioning 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 All @@ -134,8 +138,14 @@ run_tests() {

unconfigure() {
log_subsection "Unconfigure virtual machines"
( cd $VAGRANT_DIR ; \
ansible-playbook teardown.yml -l $ANSIBLE_VM_LIST )
# when we call "make halt" without options (localdev)
# no VM are provided
if [ -n "${ANSIBLE_VM_LIST}" ]; then
( cd $VAGRANT_DIR ; \
ansible-playbook teardown.yml -l $ANSIBLE_VM_LIST )
else
echo "No VM detected, nothing to unconfigure"
fi
}

halt() {
Expand Down

0 comments on commit f8a031d

Please sign in to comment.