add docker cleanup step 71/13971/2
authorJamo Luhrsen <jluhrsen@redhat.com>
Wed, 11 May 2016 23:26:43 +0000 (16:26 -0700)
committerFatih Degirmenci <fatih.degirmenci@ericsson.com>
Thu, 12 May 2016 07:31:13 +0000 (07:31 +0000)
basically just a copy/paste from what looks good in the functest job.

Change-Id: I56aca8835b2102bf3559f6653ea2d52947d5040b
Signed-off-by: Jamo Luhrsen <jluhrsen@redhat.com>
jjb/cperf/cperf-ci-jobs.yml

index b824f78..8843524 100644 (file)
 ########################
 - builder:
     name: cperf-daily-builder
 ########################
 - builder:
     name: cperf-daily-builder
+    builders:
+        - 'cperf-cleanup'
+        - 'cperf-robot-cbench'
+
+- builder:
+    name: cperf-robot-cbench
     builders:
         - shell: |
             #!/bin/bash
     builders:
         - shell: |
             #!/bin/bash
                               -v TOOLS_SYSTEM_IP:localhost -v duration_in_seconds:60"
             robot_suite="/home/opnfv/repos/test/csit/suites/openflowplugin/Performance/010_Cbench.robot"
             sudo docker run opnfv/cperf:$DOCKER_TAG ${robot_cmd} ${robot_suite}
                               -v TOOLS_SYSTEM_IP:localhost -v duration_in_seconds:60"
             robot_suite="/home/opnfv/repos/test/csit/suites/openflowplugin/Performance/010_Cbench.robot"
             sudo docker run opnfv/cperf:$DOCKER_TAG ${robot_cmd} ${robot_suite}
+
+- builder:
+    name: cperf-cleanup
+    builders:
+        - shell: |
+            #!/bin/bash
+            [[ $CI_DEBUG == true ]] && redirect="/dev/stdout" || redirect="/dev/null"
+
+            echo "Cleaning up docker containers/images..."
+            # Remove previous running containers if exist
+            if [[ ! -z $(docker ps -a | grep opnfv/cperf) ]]; then
+                echo "Removing existing opnfv/cperf containers..."
+                docker ps -a | grep opnfv/cperf | awk '{print $1}' | xargs docker rm -f >${redirect}
+            fi
+
+            # Remove existing images if exist
+            if [[ ! -z $(docker images | grep opnfv/cperf) ]]; then
+                echo "Docker images to remove:"
+                docker images | head -1 && docker images | grep opnfv/cperf >${redirect}
+                image_tags=($(docker images | grep opnfv/cperf | awk '{print $2}'))
+                for tag in "${image_tags[@]}"; do
+                    echo "Removing docker image opnfv/cperf:$tag..."
+                    docker rmi opnfv/cperf:$tag >/dev/null
+                done
+            fi