Finalize CSIT script regardless of setup success 69/103969/7
authorLasse Kaihlavirta <l.kaihlavirt@partner.samsung.com>
Thu, 19 Mar 2020 15:01:24 +0000 (17:01 +0200)
committerLasse Kaihlavirta <l.kaihlavirt@partner.samsung.com>
Mon, 23 Mar 2020 12:08:23 +0000 (12:08 +0000)
 - run teardown and env info collection steps always on exit
   regardless of any potential failures in previous steps
   (particularly setup)
 - Note that this puts an implicit requirement on project-specific
   teardown scripts to be able to do their job even if some setup steps
   have failed!
 - add trivial sdc-dcae-d change to trigger CSIT verify job
Issue-ID: TEST-231
Signed-off-by: Lasse Kaihlavirta <l.kaihlavirt@partner.samsung.com>
Change-Id: Iafd362602d3e8ae8c40eb0c73efae12d00a470c5

run-csit.sh
tests/sdc-dcae-d/dcaed/monitoring_configuration_service_test.robot

index 2c45812..634b0c7 100755 (executable)
 # functions
 #
 
+function on_exit(){
+    rc=$?
+    rsync -av "$WORKDIR/" "$WORKSPACE/archives"
+
+    # Record list of active docker containers
+    docker ps --format "{{.Image}}" > "$WORKSPACE/archives/_docker-images.log"
+
+    # show memory consumption after all docker instances initialized
+    docker_stats | tee "$WORKSPACE/archives/_sysinfo-2-after-robot.txt"
+
+    # Run teardown script plan if it exists
+    cd "${TESTPLANDIR}"
+    TEARDOWN="${TESTPLANDIR}/teardown.sh"
+    if [ -f "${TEARDOWN}" ]; then
+        echo "Running teardown script ${TEARDOWN}"
+        source_safely "${TEARDOWN}"
+    fi
+    # TODO: do something with the output
+     exit $rc
+}
+# ensure that teardown and other finalizing steps are always executed
+trap on_exit EXIT
+
 function docker_stats(){
     #General memory details
     echo "> top -bn1 | head -3"
@@ -166,22 +189,5 @@ python -m robot.run -N ${TESTPLAN} -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${TESTOP
 RESULT=$?
 load_set
 echo "RESULT: $RESULT"
-rsync -av "$WORKDIR/" "$WORKSPACE/archives"
-
-# Record list of active docker containers
-docker ps --format "{{.Image}}" > "$WORKSPACE/archives/_docker-images.log"
-
-# show memory consumption after all docker instances initialized
-docker_stats | tee "$WORKSPACE/archives/_sysinfo-2-after-robot.txt"
-
-# Run teardown script plan if it exists
-cd "${TESTPLANDIR}"
-TEARDOWN="${TESTPLANDIR}/teardown.sh"
-if [ -f "${TEARDOWN}" ]; then
-    echo "Running teardown script ${TEARDOWN}"
-    source_safely "${TEARDOWN}"
-fi
-
-# TODO: do something with the output
-
+# Note that the final steps are done in on_exit function after this exit!
 exit $RESULT
index 1941e35..49e4faa 100644 (file)
@@ -3,7 +3,7 @@ Resource          sdc_interface.robot
 Resource          sdc_dcaed_interface.robot
 
 *** Test Cases ***
-# This test case implements the steps described in
+# For now, this test case implements the steps described in
 # https://wiki.onap.org/display/DW/How+to+Create+a+Service+with+a+Monitoring+Configuration+using+SDC
 Create Service With Monitoring Configuration Test
     [Tags]  sdc-dcae-d