From 7b68a7d7a735fd54b116d50c57ab1d060e21b81c Mon Sep 17 00:00:00 2001 From: Andrew Schoen Date: Mon, 26 Mar 2018 09:56:48 -0500 Subject: [PATCH] scripts: adds a teardown_vagrant_tests method This will collect logs and do any vagrant/libvirt cleanup needed after any jobs fail that were using vagrant vms for testing. Signed-off-by: Andrew Schoen --- scripts/build_utils.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scripts/build_utils.sh b/scripts/build_utils.sh index af0f94b7..66d46b3a 100644 --- a/scripts/build_utils.sh +++ b/scripts/build_utils.sh @@ -719,3 +719,24 @@ collect_ceph_logs() { $VENV/ansible-playbook -vv -i hosts --limit $limit --extra-vars "archive_path=$WORKSPACE/logs" $WORKSPACE/collect-logs.yml fi } + +teardown_vagrant_tests() { + # collect ceph logs and teardown any running vagrant vms + # this also cleans up any lingering livirt networks + scenarios=$(find . | grep vagrant_ssh_config | xargs dirname) + + for scenario in $scenarios; do + cd $scenario + # collect all ceph logs from all test nodes + collect_ceph_logs all + vagrant destroy -f + cd - + done + + # Sometimes, networks may linger around, so we must ensure they are killed: + networks=`sudo virsh net-list --all | grep active | egrep -v "(default|libvirt)" | cut -d ' ' -f 2` + for network in $networks; do + sudo virsh net-destroy $network || true + sudo virsh net-undefine $network || true + done +} -- 2.39.5