[VOL-4318] check correct indication of abort download

Further corrections:
Reset BBSIM in Teardown to make sequential running of SW Upgrade tests
possible. This makes bug [VOL-4262] as no longer needed.

Also deprecated keyword 'Restart Pod' is removed and all corresponding
test suites adapted accordingly.

Change-Id: I16b4002635ea6d23137ae93fbeb89a3846dfc484
diff --git a/tests/functional/Voltha_FailureScenarios.robot b/tests/functional/Voltha_FailureScenarios.robot
index 9d9dba6..cfae5ee 100755
--- a/tests/functional/Voltha_FailureScenarios.robot
+++ b/tests/functional/Voltha_FailureScenarios.robot
@@ -681,7 +681,7 @@
     Log    ${podStatusOutput}
     ${countBforRestart}=    Run    kubectl get pods -n ${NAMESPACE} | grep Running | wc -l
     ${podName}    Set Variable     ofagent
-    Restart Pod    ${NAMESPACE}    ${podName}
+    Restart Pod By Label   ${NAMESPACE}    app    ${podName}
     Wait Until Keyword Succeeds    ${waitforRestart}    2s    Validate Pod Status    ofagent    ${NAMESPACE}
     ...    Running
     FOR    ${I}    IN RANGE    0    ${num_all_onus}
diff --git a/tests/openonu-go-adapter/Voltha_ONUReconcileTests.robot b/tests/openonu-go-adapter/Voltha_ONUReconcileTests.robot
index 14c7964..3b34d8f 100755
--- a/tests/openonu-go-adapter/Voltha_ONUReconcileTests.robot
+++ b/tests/openonu-go-adapter/Voltha_ONUReconcileTests.robot
@@ -190,7 +190,7 @@
     Run Keyword If    ${pausebeforecleanup}    Pause Execution    Press OK to continue with clean up!
     Run Keyword If    ${pausebeforecleanup}    Log    Teardown will be continued...    console=yes
     Run Keyword If    ${teardown_device}    Delete All Devices and Verify
-    Run Keyword If    ${usekill2restart}    Restart Pod    ${namespace}    open-onu
+    Run Keyword If    ${usekill2restart}    Restart Pod By Label    ${namespace}    app    adapter-open-onu
     Run Keyword Unless    ${etcdcheckintestteardown}    Wait Until Keyword Succeeds    ${timeout}    1s
     ...    Validate Onu Data In Etcd    0    ${kvstoreprefix}    without_pm_data=False
     Wait for Ports in ONOS for all OLTs      ${ONOS_SSH_IP}    ${ONOS_SSH_PORT}  0   BBSM    ${timeout}
@@ -204,7 +204,8 @@
     ...    ${olt_ssh_ip}    ${olt_user}    ${olt_pass}
     Run Keyword If    ${has_dataplane}    Sleep    60s
     #restart open-onu pod to reset crash loop back off mechansim of kubenetes
-    Run Keyword If    "${firsttest}"=="False" and "${usekill2restart}"=="True"    Restart Pod    ${namespace}    open-onu
+    Run Keyword If    "${firsttest}"=="False" and "${usekill2restart}"=="True"
+    ...    Restart Pod By Label    ${namespace}    app    adapter-open-onu
     Run Keyword If    "${firsttest}"=="False"    Sleep    35s
     ${firsttest}    Set Variable    False
     Set Suite Variable    ${firsttest}
diff --git a/tests/software-upgrades/ONU_Upgrade.robot b/tests/software-upgrades/ONU_Upgrade.robot
index a60f5d3..0f3d467 100755
--- a/tests/software-upgrades/ONU_Upgrade.robot
+++ b/tests/software-upgrades/ONU_Upgrade.robot
@@ -85,9 +85,10 @@
     ...    Check [VOL-3903] for more details
     [Tags]    functional   ONUUpgrade
     [Setup]    Start Logging    ONUUpgrade
-    [Teardown]    Run Keywords    Collect Logs
-    ...           AND             Stop Logging    ONUUpgrade
+    [Teardown]    Run Keywords    Run Keyword If    ${logging}    Collect Logs
     ...           AND             Delete All Devices and Verify
+    ...           AND             Restart And Check BBSIM    ${NAMESPACE}
+    ...           AND             Stop Logging    ONUUpgrade
     Test ONU Upgrade All OLTs
 
 Test ONU Upgrade All Activate and Commit Combinations
@@ -98,11 +99,12 @@
     ...    onu_image_name, onu_image_url, onu_image_version, onu_image_crc, onu_image_local_dir
     ...    Note: The TC expects the image url and other parameters to be common for all ONUs on all BBSim
     ...    Check [VOL-4250] for more details
-    [Tags]    functional   ONUUpgradeAllCombies    notready
+    [Tags]    functional   ONUUpgradeAllCombies
     [Setup]    Start Logging    ONUUpgradeAllCombies
-    [Teardown]    Run Keywords    Collect Logs
-    ...           AND             Stop Logging    ONUUpgradeAllCombies
+    [Teardown]    Run Keywords    Run Keyword If    ${logging}    Collect Logs
     ...           AND             Delete All Devices and Verify
+    ...           AND             Restart And Check BBSIM    ${NAMESPACE}
+    ...           AND             Stop Logging    ONUUpgradeAllCombies
     ${false_false}=    Create Dictionary    activate    false    commit    false
     ${true_false}=     Create Dictionary    activate    true     commit    false
     ${false_true}=     Create Dictionary    activate    false    commit    true
@@ -111,6 +113,7 @@
     FOR    ${item}     IN      @{flag_list}
         Test ONU Upgrade All OLTs    ${item['activate']}    ${item['commit']}
         Delete All Devices and Verify
+        Restart And Check BBSIM    ${NAMESPACE}
     END
 
 Test ONU Upgrade Correct Indication of Download Wrong Url
@@ -120,9 +123,10 @@
     ...    Check [VOL-4257] for more details
     [Tags]    functional   ONUUpgradeDownloadWrongUrl
     [Setup]    Start Logging    ONUUpgradeDownloadWrongUrl
-    [Teardown]    Run Keywords    Collect Logs
-    ...           AND             Stop Logging    ONUUpgradeDownloadWrongUrl
+    [Teardown]    Run Keywords    Run Keyword If    ${logging}    Collect Logs
     ...           AND             Delete All Devices and Verify
+    ...           AND             Restart And Check BBSIM    ${NAMESPACE}
+    ...           AND             Stop Logging    ONUUpgradeDownloadWrongUrl
     # Add OLT device
     Setup
     # Performing Sanity Test to make sure subscribers are all DHCP and pingable
@@ -151,9 +155,10 @@
     ...    Check [VOL-3935] for more details
     [Tags]    functional   ONUUpgradeDownloadFailure
     [Setup]    Start Logging    ONUUpgradeDownloadFailure
-    [Teardown]    Run Keywords    Collect Logs
-    ...           AND             Stop Logging    ONUUpgradeDownloadFailure
+    [Teardown]    Run Keywords    Run Keyword If    ${logging}    Collect Logs
     ...           AND             Delete All Devices and Verify
+    ...           AND             Restart And Check BBSIM    ${NAMESPACE}
+    ...           AND             Stop Logging    ONUUpgradeDownloadFailure
     # Add OLT device
     Setup
     # Performing Sanity Test to make sure subscribers are all DHCP and pingable
@@ -173,6 +178,34 @@
     Run Keyword If    ${has_dataplane}    Clean Up Linux
     Wait Until Keyword Succeeds    ${timeout}    2s    Perform Sanity Test
 
+Test ONU Upgrade Correct Indication of Download Abort
+    [Documentation]    Validates the ONU Upgrade download abort will be indicated correctly and
+    ...    doesn't affect the system functionality
+    ...    Performs the sanity and verifies all the ONUs are authenticated/DHCP/pingable
+    ...    Check [VOL-4318] for more details
+    [Tags]    functional   ONUUpgradeDownloadAbort
+    [Setup]    Start Logging    ONUUpgradeDownloadAbort
+    [Teardown]    Run Keywords    Run Keyword If    ${logging}    Collect Logs
+    ...           AND             Delete All Devices and Verify
+    ...           AND             Stop Logging    ONUUpgradeDownloadAbort
+    # Add OLT device
+    Setup
+    # Performing Sanity Test to make sure subscribers are all DHCP and pingable
+    Run Keyword If    ${has_dataplane}    Clean Up Linux
+    Wait Until Keyword Succeeds    ${timeout}    2s    Perform Sanity Test
+    FOR    ${J}    IN RANGE    0    ${num_olts}
+        ${olt_serial_number}=    Set Variable    ${list_olts}[${J}][sn]
+        ${bbsim_rel}=    Catenate    SEPARATOR=    bbsim    ${J}
+        ${bbsim_pod}=    Get Pod Name By Label    ${NAMESPACE}    release     ${bbsim_rel}
+        Test ONU Upgrade Download Abort Per OLT    ${bbsim_pod}    ${olt_serial_number}
+        List ONUs    ${NAMESPACE}    ${bbsim_pod}
+    END
+    # Additional Verification
+    Wait Until Keyword Succeeds    ${timeout}    2s    Delete All Devices and Verify
+    Setup
+    Run Keyword If    ${has_dataplane}    Clean Up Linux
+    Wait Until Keyword Succeeds    ${timeout}    2s    Perform Sanity Test
+
 
 *** Keywords ***
 Test ONU Upgrade All OLTs
@@ -261,6 +294,40 @@
         Wait Until Keyword Succeeds    ${timeout}    5s    Perform Sanity Test     ${suppressaddsubscriber}
     END
 
+Test ONU Upgrade Download Abort Per OLT
+    [Documentation]    This keyword performs the ONU Upgrade Dowload Abort test on single OLT
+    [Arguments]    ${bbsim_pod}    ${olt_serial_number}    ${url}=${image_url}
+    FOR    ${I}    IN RANGE    0    ${num_all_onus}
+        ${src}=    Set Variable    ${hosts.src[${I}]}
+        ${dst}=    Set Variable    ${hosts.dst[${I}]}
+        Continue For Loop If    "${olt_serial_number}"!="${src['olt']}"
+        ${onu_device_id}=    Get Device ID From SN    ${src['onu']}
+        # Download Image
+        Download ONU Device Image    ${image_version}    ${url}    ${image_vendor}
+        ...    ${image_activate_on_success}    ${image_commit_on_success}    ${image_crc}    ${onu_device_id}
+        Abort ONU Device Image    ${image_version}    ${onu_device_id}
+        ...    DOWNLOAD_CANCELLED    CANCELLED_ON_REQUEST    IMAGE_DOWNLOADING
+        Wait Until Keyword Succeeds    ${timeout}    2s    Verify ONU Device Image Status    ${image_version}
+        ...    ${onu_device_id}    DOWNLOAD_CANCELLED    CANCELLED_ON_REQUEST    IMAGE_DOWNLOADING
+        #   !!!    Expected is image is not visible in list   !!!
+        Wait Until Keyword Succeeds    ${timeout}    2s    Verify ONU Device Image List    ${onu_device_id}
+        ...    ${image_version}    False    False    True
+        Wait Until Keyword Succeeds    ${timeout}    5s    Perform Sanity Test     ${suppressaddsubscriber}
+    END
+
+Restart And Check BBSIM
+    [Documentation]    This keyword restarts bbsim and waits for it to come up again
+    ...    Following steps will be executed:
+    ...    - restart bbsim adaptor
+    ...    - check bbsim adaptor is ready again
+    [Arguments]    ${namespace}
+    ${bbsim_apps}   Create List    bbsim
+    ${label_key}    Set Variable   app
+    ${bbsim_label_value}    Set Variable   bbsim
+    Restart Pod By Label    ${namespace}    ${label_key}    ${bbsim_label_value}
+    Sleep    5s
+    Wait For Pods Ready    ${namespace}    ${bbsim_apps}
+
 Setup Suite
     [Documentation]    Set up the test suite
     Common Test Suite Setup