Skip to content

Commit

Permalink
test: cleanup ginkgo loop vgs
Browse files Browse the repository at this point in the history
gingko lvm_utils creates some loop devices and vgs, which are not
cleanup in some cases (eg: test failures).
furthermore, even between test cases, leftovers are causing subsequent
tests to fails, but that's another matter that needs fixing.
also ensure make clean cleans these up

Signed-off-by: Tiago Castro <[email protected]>
  • Loading branch information
tiagolobocastro committed Jan 7, 2025
1 parent 1ba667d commit 4645464
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ clean:
@echo "--> Cleaning Directory" ;
go clean -testcache
rm -rf bin
CLEANUP_ONLY=1 ./ci/ci-test.sh
chmod -R u+w ${GOPATH}/bin/${CSI_DRIVER} 2>/dev/null || true
chmod -R u+w ${GOPATH}/pkg/* 2>/dev/null || true
rm -rf ${GOPATH}/bin/${CSI_DRIVER}
Expand Down
29 changes: 22 additions & 7 deletions ci/ci-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ CRDS_TO_DELETE_ON_CLEANUP="lvmnodes.local.openebs.io lvmsnapshots.local.openebs.

# Clean up generated resources for successive tests.
cleanup_loopdev() {
sudo losetup -l | grep '(deleted)' | awk '{print $1}' \
losetup -l | grep '(deleted)' | awk '{print $1}' \
| while IFS= read -r disk
do
sudo losetup -d "${disk}"
Expand All @@ -36,24 +36,39 @@ cleanup_foreign_lvmvg() {
cleanup_loopdev
}

# Clean up loop devices and vgs created by the ginkgo lvm_utils.go
cleanup_ginkgo_loop_lvm() {
for device in $(losetup -l -J | jq -r '.loopdevices[]|select(."back-file" | startswith("/tmp/openebs_lvm_localpv_disk_"))' | jq -r '.name'); do
echo "Found stale loop device: $device"

sudo "$(which vgremove)" -y --select="pv_name=$device" || :
sudo losetup -d "$device" 2>/dev/null || :
done
}

cleanup() {
set +e

echo "Cleaning up test resources"

cleanup_foreign_lvmvg
cleanup_ginkgo_loop_lvm

if kubectl get nodes 2>/dev/null; then
kubectl delete pvc -n "$OPENEBS_NAMESPACE" lvmpv-pvc
kubectl delete -f "${SNAP_CLASS}"

kubectl delete pvc -n "$OPENEBS_NAMESPACE" lvmpv-pvc
kubectl delete -f "${SNAP_CLASS}"
helm uninstall lvm-localpv -n "$OPENEBS_NAMESPACE" || true
kubectl delete crds "$CRDS_TO_DELETE_ON_CLEANUP"
fi

helm uninstall lvm-localpv -n "$OPENEBS_NAMESPACE" || true
kubectl delete crds "$CRDS_TO_DELETE_ON_CLEANUP"
set -e
# always return true
return 0
}
# trap "cleanup 2>/dev/null" EXIT
[ -n "${CLEANUP_ONLY}" ] && cleanup 2>/dev/null && exit 0
[ -n "${RESET}" ] && cleanup 2>/dev/null
[ -n "${CLEANUP_ONLY}" ] && cleanup && exit 0
[ -n "${RESET}" ] && cleanup


# setup a foreign lvm to test
Expand Down

0 comments on commit 4645464

Please sign in to comment.