VOL-4334: Fix robot tests that stop logging prematurely when Delete Device
          is involved in TearDown step

Change-Id: I2e9a88ff591dfd4d178b6ed968bcc7b08446d740
diff --git a/tests/dt-workflow/Voltha_DT_FailureScenarios.robot b/tests/dt-workflow/Voltha_DT_FailureScenarios.robot
index ccd7106..d9cba37 100755
--- a/tests/dt-workflow/Voltha_DT_FailureScenarios.robot
+++ b/tests/dt-workflow/Voltha_DT_FailureScenarios.robot
@@ -72,8 +72,9 @@
     [Tags]    functionalDt    PowerSwitchOnuRebootDt    VOL-2819    PowerSwitch
     [Setup]    Start Logging    RebootOnu_PowerSwitch_Dt
     [Teardown]    Run Keywords    Run Keyword If    ${logging}    Collect Logs
-    ...           AND             Stop Logging    RebootOnu_PowerSwitch_Dt
     ...           AND             Delete All Devices and Verify
+    ...           AND             Run Keyword If    ${logging}    Collect Logs
+    ...           AND             Stop Logging    RebootOnu_PowerSwitch_Dt
     # Add OLT device
     Setup
     # Performing Sanity Test to make sure subscribers are all DHCP and pingable
@@ -137,8 +138,9 @@
     [Tags]    functionalDt   PhysicalOltRebootDt   VOL-2817
     [Setup]    Start Logging    RebootOlt_Physical_Dt
     [Teardown]    Run Keywords    Run Keyword If    ${logging}    Collect Logs
-    ...           AND             Stop Logging    RebootOlt_Physical_Dt
     ...           AND             Delete All Devices and Verify
+    ...           AND             Run Keyword If    ${logging}    Collect Logs
+    ...           AND             Stop Logging    RebootOlt_Physical_Dt
     # Add OLT device
     Setup
     # Performing Sanity Test to make sure subscribers are all DHCP and pingable
diff --git a/tests/dt-workflow/Voltha_DT_MultiOLT_Tests.robot b/tests/dt-workflow/Voltha_DT_MultiOLT_Tests.robot
index 91af1c9..8a92269 100644
--- a/tests/dt-workflow/Voltha_DT_MultiOLT_Tests.robot
+++ b/tests/dt-workflow/Voltha_DT_MultiOLT_Tests.robot
@@ -119,8 +119,9 @@
     [Tags]    MultiOLTSoftRebootDt    functionalDt
     [Setup]    Start Logging    MultiOLTSoftRebootDt
     [Teardown]    Run Keywords    Collect Logs
-    ...           AND             Stop Logging    MultiOLTSoftRebootDt
     ...           AND             Delete All Devices and Verify
+    ...           AND             Run Keyword If    ${logging}    Collect Logs
+    ...           AND             Stop Logging    MultiOLTSoftRebootDt
     Pass Execution If    ${olt_count} == 1    Skipping test: just one OLT
     Clear All Devices Then Perform Setup And Sanity
     # Reboot the first OLT
diff --git a/tests/functional/Voltha_FailureScenarios.robot b/tests/functional/Voltha_FailureScenarios.robot
index 3d2f47e..9d9dba6 100755
--- a/tests/functional/Voltha_FailureScenarios.robot
+++ b/tests/functional/Voltha_FailureScenarios.robot
@@ -74,8 +74,9 @@
     [Tags]    functional   PowerSwitch
     [Setup]    Start Logging    ONUreboot_PowerSwitch
     [Teardown]    Run Keywords    Collect Logs
-    ...           AND             Stop Logging    ONUreboot_PowerSwitch
     ...           AND             Delete All Devices and Verify
+    ...           AND             Run Keyword If    ${logging}    Collect Logs
+    ...           AND             Stop Logging    ONUreboot_PowerSwitch
     # Add OLT device
     setup
     # Performing Sanity Test to make sure subscribers are all AUTH+DHCP and pingable
@@ -147,8 +148,9 @@
     [Tags]    functional   PhysicalOLTReboot
     [Setup]    Start Logging    PhysicalOLTReboot
     [Teardown]    Run Keywords    Collect Logs
-    ...           AND             Stop Logging    PhysicalOLTReboot
     ...           AND             Delete All Devices and Verify
+    ...           AND             Run Keyword If    ${logging}    Collect Logs
+    ...           AND             Stop Logging    PhysicalOLTReboot
     # Add OLT device
     setup
     # Performing Sanity Test to make sure subscribers are all AUTH+DHCP and pingable
diff --git a/tests/functional/Voltha_MultiOLT_Tests.robot b/tests/functional/Voltha_MultiOLT_Tests.robot
index 7a032c4..be29c0e 100755
--- a/tests/functional/Voltha_MultiOLT_Tests.robot
+++ b/tests/functional/Voltha_MultiOLT_Tests.robot
@@ -130,8 +130,9 @@
     [Tags]    MultiOLTSoftReboot    functional
     [Setup]    Start Logging    MultiOlt-OLTSoftReboot
     [Teardown]    Run Keywords    Collect Logs
-    ...           AND             Stop Logging    MultiOlt-OLTSoftReboot
     ...           AND             Delete All Devices and Verify
+    ...           AND             Run Keyword If    ${logging}    Collect Logs
+    ...           AND             Stop Logging    MultiOlt-OLTSoftReboot
     # Execute the test when the number of OLTs are greater than one
     Pass Execution If    ${olt_count} == 1    Skipping test: just one OLT
     Clear All Devices Then Perform Setup And Sanity
diff --git a/tests/functional/Voltha_PODTests.robot b/tests/functional/Voltha_PODTests.robot
index 6871e4f..f58f9b3 100755
--- a/tests/functional/Voltha_PODTests.robot
+++ b/tests/functional/Voltha_PODTests.robot
@@ -466,8 +466,9 @@
     # Creates Devices in the Setup
     [Setup]    Start Logging    DisableONU_AuthCheck
     [Teardown]    Run Keywords    Collect Logs
-    ...           AND             Stop Logging    DisableONU_AuthCheck
     ...           AND             Delete All Devices and Verify
+    ...           AND             Run Keyword If    ${logging}    Collect Logs
+    ...           AND             Stop Logging    DisableONU_AuthCheck
     Clean WPA Process
     FOR    ${I}    IN RANGE    0    ${num_all_onus}
         ${src}=    Set Variable    ${hosts.src[${I}]}
@@ -677,8 +678,9 @@
     [Setup]    Run Keywords    Start Logging    DisableEnableOltPonPort
     ...        AND    Setup
     [Teardown]    Run Keywords    Collect Logs
-    ...           AND             Stop Logging    DisableEnableOltPonPort
     ...           AND             Delete All Devices and Verify
+    ...           AND             Run Keyword If    ${logging}    Collect Logs
+    ...           AND             Stop Logging    DisableEnableOltPonPort
     Run Keyword If    ${has_dataplane}    Clean Up Linux
     Wait Until Keyword Succeeds    ${timeout}    2s    Perform Sanity Test
     # Multi-OLTs
diff --git a/tests/tt-workflow/Voltha_TT_FailureScenarios.robot b/tests/tt-workflow/Voltha_TT_FailureScenarios.robot
index 0ec2909..46ba95d 100755
--- a/tests/tt-workflow/Voltha_TT_FailureScenarios.robot
+++ b/tests/tt-workflow/Voltha_TT_FailureScenarios.robot
@@ -71,8 +71,9 @@
     [Tags]    functionalTT    PowerSwitchOnuRebootTT    PowerSwitch
     [Setup]    Start Logging    RebootOnu_PowerSwitch_TT
     [Teardown]    Run Keywords    Collect Logs
-    ...           AND             Stop Logging    RebootOnu_PowerSwitch_TT
     ...           AND             Delete All Devices and Verify
+    ...           AND             Run Keyword If    ${logging}    Collect Logs
+    ...           AND             Stop Logging    RebootOnu_PowerSwitch_TT
     # Add OLT device
     Setup
     # Performing Sanity Test to make sure subscribers are all DHCP and pingable
@@ -129,8 +130,9 @@
     [Tags]    functionalTT    PhysicalOltRebootTT
     [Setup]    Start Logging    RebootOlt_Physical_TT
     [Teardown]    Run Keywords    Collect Logs
-    ...           AND             Stop Logging    RebootOlt_Physical_TT
     ...           AND             Delete All Devices and Verify
+    ...           AND             Run Keyword If    ${logging}    Collect Logs
+    ...           AND             Stop Logging    RebootOlt_Physical_TT
     # Add OLT device
     Setup
     # Performing Sanity Test to make sure subscribers are all DHCP and pingable
@@ -177,8 +179,9 @@
     [Tags]    functionalTT    OnuSoftRebootTT
     [Setup]    Start Logging    SoftRebootOnu_TT
     [Teardown]    Run Keywords    Collect Logs
-    ...           AND             Stop Logging    SoftRebootOnu_TT
     ...           AND             Delete All Devices and Verify
+    ...           AND             Collect Logs
+    ...           AND             Stop Logging    SoftRebootOnu_TT
     # Add OLT device
     Setup
     # Performing Sanity Test to make sure subscribers are all DHCP and pingable
@@ -229,8 +232,9 @@
     [Tags]    functionalTT    OltSoftRebootTT
     [Setup]    Start Logging    SoftRebootOlt_TT
     [Teardown]    Run Keywords    Collect Logs
-    ...           AND             Stop Logging    SoftRebootOlt_TT
     ...           AND             Delete All Devices and Verify
+    ...           AND             Collect Logs
+    ...           AND             Stop Logging    SoftRebootOlt_TT
     # Add OLT device
     Setup
     # Performing Sanity Test to make sure subscribers are all DHCP and pingable
@@ -278,8 +282,9 @@
     [Tags]    functionalTT    Restart-OpenOnu-TT
     [Setup]    Start Logging    Restart-OpenOnu-TT
     [Teardown]    Run Keywords    Collect Logs
-    ...           AND             Stop Logging    Restart-OpenOnu-TT
     ...           AND             Delete All Devices and Verify
+    ...           AND             Collect Logs
+    ...           AND             Stop Logging    Restart-OpenOnu-TT
     # Add OLT device
     Setup
     # Performing Sanity Test to make sure subscribers are all DHCP and pingable
@@ -306,8 +311,9 @@
     [Tags]    functionalTT    Restart-OpenOlt-Before-Subscription-TT
     [Setup]    Start Logging    Restart-OpenOlt-Before-Subscription-TT
     [Teardown]    Run Keywords    Collect Logs
-    ...           AND             Stop Logging    Restart-OpenOlt-Before-Subscription-TT
     ...           AND             Delete All Devices and Verify
+    ...           AND             Collect Logs
+    ...           AND             Stop Logging    Restart-OpenOlt-Before-Subscription-TT
     # Add OLT device
     Setup
     Run Keyword If    ${has_dataplane}    Clean Up Linux
diff --git a/tests/tt-workflow/Voltha_TT_MultiTcontTests.robot b/tests/tt-workflow/Voltha_TT_MultiTcontTests.robot
index 0bcd263..3f4bafc 100755
--- a/tests/tt-workflow/Voltha_TT_MultiTcontTests.robot
+++ b/tests/tt-workflow/Voltha_TT_MultiTcontTests.robot
@@ -74,8 +74,9 @@
     [Setup]    Run Keywords    Start Logging    TcontType1Onu1
     ...        AND             Setup
     [Teardown]    Run Keywords    Collect Logs
-    ...           AND             Stop Logging    TcontType1Onu1
     ...           AND             Delete All Devices and Verify
+    ...           AND             Run Keyword If    ${logging}    Collect Logs
+    ...           AND             Stop Logging    TcontType1Onu1
     Run Keyword If    ${has_dataplane}    Clean Up Linux
     Wait Until Keyword Succeeds    ${timeout}    2s    Perform Sanity Tests TT
     # Find the ONU as required for this test
@@ -115,8 +116,9 @@
     [Setup]    Run Keywords    Start Logging    TcontType2Type4Onu1
     ...        AND             Setup
     [Teardown]    Run Keywords    Collect Logs
-    ...           AND             Stop Logging    TcontType2Type4Onu1
     ...           AND             Delete All Devices and Verify
+    ...           AND             Run Keyword If    ${logging}    Collect Logs
+    ...           AND             Stop Logging    TcontType2Type4Onu1
     Run Keyword If    ${has_dataplane}    Clean Up Linux
     Wait Until Keyword Succeeds    ${timeout}    2s    Perform Sanity Test TT
 
@@ -192,8 +194,9 @@
     [Setup]    Run Keywords    Start Logging    TcontType1Type4Onu1Onu2Onu3
     ...        AND             Setup
     [Teardown]    Run Keywords    Collect Logs
-    ...           AND             Stop Logging    TcontType1Type4Onu1Onu2Onu3
     ...           AND             Delete All Devices and Verify
+    ...           AND             Run Keyword If    ${logging}    Collect Logs
+    ...           AND             Stop Logging    TcontType1Type4Onu1Onu2Onu3
     # Push multi-tcont sadis to ONOS
     Send File To Onos    ${CURDIR}/../../tests/data/flex-ocp-cord-sadis-TT-multi-tcont.json
     Run Keyword If    ${has_dataplane}    Clean Up Linux
@@ -308,8 +311,9 @@
     [Setup]    Run Keywords    Start Logging    TcontType2Onu1Type3Onu2
     ...        AND             Setup
     [Teardown]    Run Keywords    Collect Logs
-    ...           AND             Stop Logging    TcontType2Onu1Type3Onu2
     ...           AND             Delete All Devices and Verify
+    ...           AND             Run Keyword If    ${logging}    Collect Logs
+    ...           AND             Stop Logging    TcontType2Onu1Type3Onu2
     # Push multi-tcont sadis to ONOS
     Send File To Onos    ${CURDIR}/../../tests/data/flex-ocp-cord-sadis-TT-multi-tcont.json
     Run Keyword If    ${has_dataplane}    Clean Up Linux
@@ -407,8 +411,9 @@
     [Setup]    Run Keywords    Start Logging    TcontType4Onu1Type5Onu2
     ...        AND             Setup
     [Teardown]    Run Keywords    Collect Logs
-    ...           AND             Stop Logging    TcontType4Onu1Type5Onu2
     ...           AND             Delete All Devices and Verify
+    ...           AND             Run Keyword If    ${logging}    Collect Logs
+    ...           AND             Stop Logging    TcontType4Onu1Type5Onu2
     Run Keyword If    ${has_dataplane}    Clean Up Linux
     Send File To Onos    ${CURDIR}/../../tests/data/flex-ocp-cord-sadis-TT-multi-tcont-1.json
     Wait Until Keyword Succeeds    ${timeout}    2s    Perform Sanity Test TT