]> git.apps.os.sepia.ceph.com Git - ceph-build.git/commitdiff
scripts: adds a teardown_vagrant_tests method
authorAndrew Schoen <aschoen@redhat.com>
Mon, 26 Mar 2018 14:56:48 +0000 (09:56 -0500)
committerAndrew Schoen <aschoen@redhat.com>
Mon, 26 Mar 2018 14:56:48 +0000 (09:56 -0500)
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 <aschoen@redhat.com>
scripts/build_utils.sh

index af0f94b7af0fe3bbda233919dc96980fffc475f9..66d46b3a46ee81d81434710b317208cd37fbc0eb 100644 (file)
@@ -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
+}