Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jenkins: Resilient VirtualBox VM and test directory cleanup #5584

Merged
merged 4 commits into from
Oct 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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