Skip to content

Commit

Permalink
Merge pull request #5584 from tstromberg/common.sh
Browse files Browse the repository at this point in the history
jenkins: Resilient VirtualBox VM and test directory cleanup
  • Loading branch information
tstromberg authored Oct 10, 2019
2 parents d139781 + 34b6f6d commit 5c6f33b
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions hack/jenkins/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,28 +91,34 @@ if [[ "${procs}" != "" ]]; then
kill -9 ${procs} || true
fi

# Quickly notice misconfigured test roots
mkdir -p "${TEST_ROOT}"

# Cleanup stale test outputs.
echo ""
echo ">> Cleaning up after previous test runs ..."

for stale_dir in ${TEST_ROOT}/*; do
echo "* Cleaning stale test root: ${stale_dir}"

for tunnel in $(find ${stale_dir} -name tunnels.json -type f); do
for entry in $(ls ${TEST_ROOT}); do
echo "* Cleaning stale test path: ${entry}"
for tunnel in $(find ${entry} -name tunnels.json -type f); do
env MINIKUBE_HOME="$(dirname ${tunnel})" ${MINIKUBE_BIN} tunnel --cleanup || true
done

for home in $(find ${stale_dir} -name .minikube -type d); do
env MINIKUBE_HOME="$(dirname ${home})" ${MINIKUBE_BIN} delete || true
sudo rm -Rf "${home}"
for home in $(find ${entry} -name .minikube -type d); do
env MINIKUBE_HOME="$(dirname ${home})" ${MINIKUBE_BIN} delete || true
sudo rm -Rf "${home}"
done

for kconfig in $(find ${stale_dir} -name kubeconfig -type f); do
for kconfig in $(find ${entry} -name kubeconfig -type f); do
sudo rm -f "${kconfig}"
done

rm -f "${stale_dir}/*" || true
rmdir "${stale_dir}" || ls "${stale_dir}"
# Be very specific to avoid accidentally deleting other items, like wildcards or devices
if [[ -d "${entry}" ]]; then
rm -Rf "${entry}" || true
elif [[ -f "${entry}" ]]; then
rm -f "${entry}" || true
fi

done

# sometimes tests left over zombie procs that won't exit
Expand All @@ -134,11 +140,16 @@ if type -P virsh; then
fi

if type -P vboxmanage; then
vboxmanage list vms || true
vboxmanage list vms \
| egrep -o '{.*?}' \
| xargs -I {} sh -c "vboxmanage startvm {} --type emergencystop; vboxmanage unregistervm {} --delete" \
|| true
for guid in $(vboxmanage list vms | egrep -Eo '\{[-a-Z0-9]+\}'); do
echo "- Removing stale VirtualBox VM: $guid"
vboxmanage startvm $guid --type emergencystop || true
vboxmanage unregistervm $guid || true
done

vboxmanage list hostonlyifs \
| grep "^Name:" \
| awk '{ print $2 }' \
| xargs -n1 vboxmanage hostonlyif remove || true

echo ">> VirtualBox VM list after clean up (should be empty):"
vboxmanage list vms || true
Expand Down

0 comments on commit 5c6f33b

Please sign in to comment.