[VOL-3235] Performance improvements for Integration Test for OpenOnu go adapter

Change-Id: I432475a6312e7f863fb8ed5e4bb983635731bf38
diff --git a/libraries/voltctl.robot b/libraries/voltctl.robot
index 4a63bf5..6130584 100755
--- a/libraries/voltctl.robot
+++ b/libraries/voltctl.robot
@@ -346,6 +346,48 @@
     END
     Should Be Empty    ${List_ONU_Serial}    List ${List_ONU_Serial} not empty
 
+Validate ONU Devices MIB State With Duration
+    [Documentation]
+    ...    Parses the output of "voltctl device list" and inspects all devices ${List_ONU_Serial},
+    ...    Iteratively match on each Serial number contained in ${List_ONU_Serial} and inspect MIB state.
+    [Arguments]    ${onu_reason}
+    ...    ${List_ONU_Serial}   ${startTime}    ${print2console}=False    ${output_file}=${EMPTY}
+    ${type} =    Set Variable    brcm_openomci_onu
+    ${rc}    ${output}=    Run and Return Rc and Output
+    ...    ${VOLTCTL_CONFIG}; voltctl device list -f Type=${type} -f Reason=${onu_reason} --format '{{.SerialNumber}}'
+    Should Be Equal As Integers    ${rc}    0
+    ${timeCurrent} =    Get Current Date
+    ${timeTotalMs} =    Subtract Date From Date    ${timeCurrent}    ${startTime}    result_format=number
+    @{outputdata} =    Split String    ${output}
+    ${outputlength} =    Get Length    ${outputdata}
+    ${onulength} =    Get Length    ${List_ONU_Serial}
+    ${Matches} =    Run Keyword If    ${outputlength}<=${onulength}
+    ...    Compare Lists    ${outputdata}    ${List_ONU_Serial}
+    ...    ELSE    Compare Lists    ${List_ONU_Serial}    ${outputdata}
+    ${length} =    Get Length    ${Matches}
+    FOR    ${INDEX}    IN RANGE    0    ${length}
+        ${sn}=    Get From List    ${Matches}    ${INDEX}
+        Run Keyword If    ${print2console}    Log
+        ...    \r\nONU ${sn} reached the state ${onu_reason} after ${timeTotalMs} sec.    console=yes
+        Run Keyword If    ('${output_file}'!='${EMPTY}')    Append To File    ${output_file}
+        ...    \r\nONU ${sn} reached the state ${onu_reason} after ${timeTotalMs} sec.
+        Remove Values From List    ${List_ONU_Serial}    ${sn}
+    END
+    Should Be Empty    ${List_ONU_Serial}    List ${List_ONU_Serial} not empty
+
+Compare Lists
+    [Documentation]
+    ...    Compares both lists and put all matches in the returned list
+    [Arguments]    ${ListIterate}    ${ListCompare}
+    @{list} =    Create List
+    ${length} =    Get Length    ${ListIterate}
+    FOR    ${INDEX}    IN RANGE    0    ${length}
+        ${sn}=    Get From List    ${ListIterate}    ${INDEX}
+        ${onu_id}=    Get Index From List    ${ListCompare}   ${sn}
+        Run Keyword If    -1 != ${onu_id}    Append To List    ${list}    ${sn}
+    END
+    [Return]    ${list}
+
 Validate Logical Device
     [Documentation]    Validate Logical Device is listed
     ${rc}    ${output}=    Run and Return Rc and Output    ${VOLTCTL_CONFIG}; voltctl logicaldevice list -o json
diff --git a/tests/openonu-go-adapter/Voltha_ONUStateTests.robot b/tests/openonu-go-adapter/Voltha_ONUStateTests.robot
index a42c675..000616a 100755
--- a/tests/openonu-go-adapter/Voltha_ONUStateTests.robot
+++ b/tests/openonu-go-adapter/Voltha_ONUStateTests.robot
@@ -176,32 +176,32 @@
     Build ONU SN List    ${list_onus}
     Run Keyword If    ${state2test}==1
     ...    Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    50ms
-    ...    Validate ONU Devices With Duration   ENABLED    ACTIVATING    REACHABLE
+    ...    Validate ONU Devices MIB State With Duration
     ...    activating-onu    ${list_onus}    ${timeStart}    print2console=True
     ...    output_file=ONU_Startup_Time.txt
     ...    ELSE IF    ${state2test}==2
     ...    Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    50ms
-    ...    Validate ONU Devices With Duration    ENABLED    ACTIVATING    REACHABLE
+    ...    Validate ONU Devices MIB State With Duration
     ...    starting-openomci    ${list_onus}    ${timeStart}    print2console=True
     ...    output_file=ONU_Startup_Time.txt
     ...    ELSE IF    ${state2test}==3
     ...    Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    50ms
-    ...    Validate ONU Devices With Duration    ENABLED    ACTIVATING    REACHABLE
+    ...    Validate ONU Devices MIB State With Duration
     ...    discovery-mibsync-complete    ${list_onus}    ${timeStart}    print2console=True
     ...    output_file=ONU_Startup_Time.txt
     ...    ELSE IF    ${state2test}==4
     ...    Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    50ms
-    ...    Validate ONU Devices With Duration    ENABLED    ACTIVE    REACHABLE
+    ...    Validate ONU Devices MIB State With Duration
     ...    initial-mib-downloaded    ${list_onus}    ${timeStart}    print2console=True
     ...    output_file=ONU_Startup_Time.txt
     ...    ELSE IF    ${state2test}==5
     ...    Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    50ms
-    ...    Validate ONU Devices With Duration    ENABLED    ACTIVE    REACHABLE
+    ...    Validate ONU Devices MIB State With Duration
     ...    tech-profile-config-download-success    ${list_onus}    ${timeStart}    print2console=True
     ...    output_file=ONU_Startup_Time.txt
     ...    ELSE IF    ${state2test}==6
     ...    Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    50ms
-    ...    Validate ONU Devices With Duration    ENABLED    ACTIVE    REACHABLE
+    ...    Validate ONU Devices MIB State With Duration
     ...    omci-flows-pushed    ${list_onus}    ${timeStart}    print2console=True
     ...    output_file=ONU_Startup_Time.txt
     ...    ELSE    Fail    The state to test (${state2test}) is not valid!
@@ -221,3 +221,4 @@
         Run Keyword And Continue On Failure    Wait Until Keyword Succeeds   120s   2s
         ...    Verify ONU Port Is Enabled   ${ONOS_SSH_IP}    ${ONOS_SSH_PORT}    ${onu_port}
     END
+