stabilize memory leak test

Change-Id: Idca153e85529ab371d16e2261792a471cab3c8ff
diff --git a/tests/memory-leak/VOLTHA_Memory_Leak_Tests.robot b/tests/memory-leak/VOLTHA_Memory_Leak_Tests.robot
index 7e6f61b..c79ffca 100755
--- a/tests/memory-leak/VOLTHA_Memory_Leak_Tests.robot
+++ b/tests/memory-leak/VOLTHA_Memory_Leak_Tests.robot
@@ -91,19 +91,29 @@
     Run Keyword If    ${print2console}    Log    \r\nStart ${iterations} iterations.    console=yes
     FOR    ${I}    IN RANGE    1    ${iterations} + 1
         Run Keyword If    ${print2console}    Log    \r\nStart iteration ${I} of ${iterations}.    console=yes
-        Run Keyword If    "${workflow}"=="DT"    Run Keyword And Ignore Error    Perform Sanity Test DT
-        ...    ELSE IF    "${workflow}"=="TT"    Run Keyword And Ignore Error    Perform Sanity Tests TT
-        ...    ELSE       Run Keyword And Ignore Error    Perform Sanity Test
+        Run Keyword If    "${workflow}"=="DT"    Perform Sanity Test DT
+        ...    ELSE IF    "${workflow}"=="TT"    Perform Sanity Tests TT
+        ...    ELSE       Perform Sanity Test
+        Sleep    5s
         Run Keyword If    ${print2console}    Log    Remove Flows.    console=yes
         Remove Flows all ONUs
         Run Keyword If    ${print2console}    Log    Check Flows removed.    console=yes
         Check All Flows Removed
+        Run Keyword If    ${print2console}    Log    Get ONU Device IDs.    console=yes
+        ${onu_device_id_list}=    Get ONUs Device IDs from Voltha
         Run Keyword If    ${print2console}    Log    Delete ONUs.    console=yes
         Delete Devices In Voltha    Type=brcm_openomci_onu
         Run Keyword If    ${print2console}    Log    Wait for ONUs come back.    console=yes
+        Wait Until Keyword Succeeds    ${timeout}    1s  Check for new ONU Device IDs     ${onu_device_id_list}
         ${list_onus}    Create List
         Build ONU SN List    ${list_onus}
         Wait Until Keyword Succeeds    ${timeout}    1s  Check all ONU OperStatus     ${list_onus}  ACTIVE
+        Build ONU SN List    ${list_onus}
+        ${onu_reason}=  Set Variable If    "${workflow}"=="DT"    initial-mib-downloaded
+        ...                                "${workflow}"=="TT"    initial-mib-downloaded
+        ...                                "${workflow}"=="ATT"   omci-flows-pushed
+        Wait Until Keyword Succeeds    ${timeout}    1s  Validate ONU Devices  ENABLED  ACTIVE  REACHABLE
+        ...    ${list_onus}    onu_reason=${onu_reason}
         Run Keyword If    ${print2console}    Log    End iteration ${I} of ${iterations}.    console=yes
     END
     [Teardown]    Run Keywords    Printout ONU Serial Number and Device Id    print2console=${print2console}
@@ -173,3 +183,12 @@
     Run Keyword If    ${etcdcheckintestteardown}    Wait Until Keyword Succeeds    ${timeout}    1s
     ...    Validate Onu Data In Etcd    ${INFRA_NAMESPACE}    0    ${kvstoreprefix}    without_pm_data=False
     Sleep    5s
+
+Check for new ONU Device IDs
+    [Documentation]    Checks that no old onu device ids stay
+    [Arguments]    ${old_device_ids}
+    ${new_device_ids}=    Get ONUs Device IDs from Voltha
+    Should Not Be Empty    ${new_device_ids}    No new ONU device IDs
+    FOR    ${item}    IN    @{old_device_ids}
+        List Should Not Contain Value    ${new_device_ids}    ${item}    Old device id ${item} still present.
+    END