[VOL-3613] OpenOnu-Go-Adapter: Introduction of new onu reasons

Change-Id: I652b181f9afe8f4dd83451385868d0af9a06b27b
diff --git a/libraries/voltctl.robot b/libraries/voltctl.robot
index ddafe65..868b4af 100755
--- a/libraries/voltctl.robot
+++ b/libraries/voltctl.robot
@@ -316,6 +316,7 @@
     ...    states including MIB state.
     [Arguments]    ${admin_state}    ${oper_status}    ${connect_status}    ${onu_reason}
     ...    ${List_ONU_Serial}   ${startTime}    ${print2console}=False    ${output_file}=${EMPTY}
+    ...    ${alternate_reason}=${EMPTY}
     ${rc}    ${output}=    Run and Return Rc and Output    ${VOLTCTL_CONFIG}; voltctl device list -m 8MB -o json
     Should Be Equal As Integers    ${rc}    0
     ${timeCurrent} =    Get Current Date
@@ -349,7 +350,8 @@
         ${matched}=    Set Variable If    '${astate}' == '${admin_state}'    ${matched}    False
         ${matched}=    Set Variable If    '${opstatus}' == '${oper_status}'    ${matched}    False
         ${matched}=    Set Variable If    '${cstatus}' == '${connect_status}'    ${matched}    False
-        ${matched}=    Set Variable If    '${mib_state}' == '${onu_reason}'    ${matched}    False
+        ${matched}=    Set Variable If    '${mib_state}' == '${onu_reason}' or '${mib_state}' == '${alternate_reason}'
+        ...   ${matched}    False
         Run Keyword If    ${matched} and ${print2console}    Log
         ...    \r\nONU ${sn} reached the state ${onu_reason} after ${timeTotalMs} sec.    console=yes
         Run Keyword If    ${matched} and ('${output_file}'!='${EMPTY}')    Append To File    ${output_file}
@@ -388,6 +390,50 @@
     END
     Should Be Empty    ${List_ONU_Serial}    List ${List_ONU_Serial} not empty
 
+Validate ONU Device By Device Id
+    [Documentation]
+    ...    Parses the output of "voltctl device list" filtered by device id and inspects states including reason.
+    [Arguments]    ${admin_state}    ${oper_status}    ${connect_status}    ${onu_reason}    ${onu_id}
+    ${cmd}    Catenate    ${VOLTCTL_CONFIG}; voltctl device list --filter=Id=${onu_id} -m 8MB -o json
+    ${rc}    ${output}=    Run and Return Rc and Output    ${cmd}
+    Should Be Equal As Integers    ${rc}    0
+    ${jsondata}=    To Json    ${output}
+    ${length}=    Get Length    ${jsondata}
+    Should Be Equal As Integers    ${length}    1    No match found for ${onu_id} to validate device
+    ${value}=    Get From List    ${jsondata}    0
+    Log    ${value}
+    ${jsonCamelCaseFieldnames}=    Run Keyword And Return Status
+    ...    Dictionary Should Contain Key       ${value}      adminState
+    ${astate}=    Run Keyword If     ${jsonCamelCaseFieldNames}
+    ...    Get From Dictionary    ${value}    adminState
+    ...    ELSE
+    ...    Get From Dictionary    ${value}    adminstate
+    ${opstatus}=    Run Keyword If     ${jsonCamelCaseFieldNames}
+    ...    Get From Dictionary    ${value}    operStatus
+    ...    ELSE
+    ...    Get From Dictionary    ${value}    operstatus
+    ${cstatus}=    Run Keyword If     ${jsonCamelCaseFieldNames}
+    ...    Get From Dictionary    ${value}    connectStatus
+    ...    ELSE
+    ...    Get From Dictionary    ${value}    connectstatus
+    ${sn}=    Run Keyword If     ${jsonCamelCaseFieldNames}
+    ...    Get From Dictionary    ${value}    serialNumber
+    ...    ELSE
+    ...    Get From Dictionary    ${value}    serialnumber
+    ${devId}=    Get From Dictionary    ${value}    id
+    ${mib_state}=    Get From Dictionary    ${value}    reason
+    Should Be Equal    '${devId}'    '${onu_id}'    No match found for ${onu_id} to validate device
+    ...    values=False
+    Should Be Equal    '${astate}'    '${admin_state}'    Device ${sn} admin_state != ${admin_state}
+    ...    values=False
+    Should Be Equal    '${opstatus}'    '${oper_status}'    Device ${sn} oper_status != ${oper_status}
+    ...    values=False
+    Should Be Equal    '${cstatus}'    '${connect_status}'    Device ${sn} conn_status != ${connect_status}
+    ...    values=False
+    Should Be Equal    '${mib_state}'    '${onu_reason}'
+    ...    Device ${sn} mib_state incorrect (${mib_state}) values=False
+
+
 Compare Lists
     [Documentation]
     ...    Compares both lists and put all matches in the returned list
@@ -668,12 +714,12 @@
     List Should Not Contain Value    ${ids}    ${id}
 
 Reboot ONU
-    [Arguments]    ${onu_id}    ${src}   ${dst}
+    [Arguments]    ${onu_id}    ${validate_device}=True
     [Documentation]   Using voltctl command reboot ONU and verify that ONU comes up to running state
     ${rc}    ${devices}=    Run and Return Rc and Output    ${VOLTCTL_CONFIG}; voltctl device reboot ${onu_id}
     Should Be Equal As Integers    ${rc}    0
-    Run Keyword and Ignore Error    Wait Until Keyword Succeeds    60s   1s    Validate Device
-    ...    ENABLED    DISCOVERED    UNREACHABLE   ${onu_id}    onu=True
+    Run Keyword If    ${validate_device}    Run Keyword And Continue On Failure    Wait Until Keyword Succeeds
+    ...    60s   1s    Validate ONU Device By Device Id    ENABLED    DISCOVERED    REACHABLE    rebooting   ${onu_id}
 
 Assert ONUs in Voltha
     [Arguments]    ${count}
diff --git a/tests/openonu-go-adapter/Voltha_ONUStateTests.robot b/tests/openonu-go-adapter/Voltha_ONUStateTests.robot
index 999e34e..c772a00 100755
--- a/tests/openonu-go-adapter/Voltha_ONUStateTests.robot
+++ b/tests/openonu-go-adapter/Voltha_ONUStateTests.robot
@@ -16,6 +16,7 @@
 Resource          ../../libraries/utils.robot
 Resource          ../../libraries/k8s.robot
 Resource          ../../variables/variables.robot
+Resource          Voltha_ONUUtilities.robot
 
 *** Variables ***
 ${timeout}        180s
@@ -62,7 +63,13 @@
     [Setup]    Run Keywords    Start Logging    ONUStateTest
     ...    AND    Setup Test
     Run Keyword If    ${has_dataplane}    Clean Up Linux
-    Enable Device    ${olt_device_id}
+    FOR    ${I}    IN RANGE    0    ${num_olts}
+        #get olt serial number
+        ${olt_serial_number}=    Set Variable    ${list_olts}[${I}][sn]
+        #validate olt states
+        ${olt_device_id}=    Get OLTDeviceID From OLT List    ${olt_serial_number}
+        Enable Device    ${olt_device_id}
+    END
     ${timeStart} =    Get Current Date
     Set Global Variable    ${timeStart}
     Run Keyword If    "${testmode}"=="SingleState"    Do ONU Single State Test
@@ -163,7 +170,7 @@
     ${skipped}=  Evaluate  "\\033[33m${SPACE*14} ===> Test case above was skipped! <=== ${SPACE*15}\\033[0m"
     ${skip_message}    Catenate    ${skipped} | ${skip} |
     Set Suite Variable    ${skip_message}
-    Run Keyword If   ${num_onus}>4    Calculate Timeout
+    Run Keyword If   ${num_all_onus}>4    Calculate Timeout
     ${techprofile}=    Set Variable If    "${techprofile}"=="1T1GEM"    default    ${techprofile}
     Run Keyword If    "${techprofile}"=="default"   Log To Console    \nTechProfile:default (1T1GEM)
     ...    ELSE IF    "${techprofile}"=="1T4GEM"    Set Tech Profile    1T4GEM
@@ -202,18 +209,27 @@
     Run Keyword If    ${has_dataplane}    Wait Until Keyword Succeeds    120s    10s    Openolt is Up
     ...    ${olt_ssh_ip}    ${olt_user}    ${olt_pass}
     Run Keyword If    ${has_dataplane}    Sleep    60s
-    #create/preprovision device
-    ${olt_device_id}=    Create Device    ${olt_ip}    ${OLT_PORT}
-    Set Suite Variable    ${olt_device_id}
-    #validate olt states
-    Wait Until Keyword Succeeds    ${timeout}    5s    Validate OLT Device    PREPROVISIONED    UNKNOWN    UNKNOWN
-    ...    ${olt_device_id}
-    Sleep    5s
+    # Create a list of olt ids (logical and device_id)
+    ${olt_ids}    Create List
+    FOR    ${I}    IN RANGE    0    ${num_olts}
+        #create/preprovision device
+        ${olt_device_id}=    Create Device    ${list_olts}[${I}][ip]    ${OLT_PORT}
+        ${olt_serial_number}=    Set Variable    ${list_olts}[${I}][sn]
+        #validate olt states
+        Wait Until Keyword Succeeds    ${timeout}    5s
+        ...    Validate OLT Device    PREPROVISIONED    UNKNOWN    UNKNOWN    ${olt_device_id}
+        Sleep    5s
+        ${logical_id}=    Get Logical Device ID From SN    ${olt_serial_number}
+        ${olt}    Create Dictionary    device_id    ${olt_device_id}    logical_id    ${logical_id}
+        ...    of_id    ${of_id}    sn    ${olt_serial_number}
+        Append To List    ${olt_ids}    ${olt}
+    END
+    Set Global Variable    ${olt_ids}
 
 Calculate Timeout
     [Documentation]    Calculates the timeout regarding num-onus in case of more than 4 onus
     ${timeout}    Fetch From Left    ${timeout}    s
-    ${timeout}=    evaluate    ${timeout}+((${num_onus}-4)*30)
+    ${timeout}=    evaluate    ${timeout}+((${num_all_onus}-4)*30)
     ${timeout}=    Set Variable If    (not ${debugmode}) and (${timeout}>600)    600    ${timeout}
     ${timeout}=    Catenate    SEPARATOR=    ${timeout}    s
     Set Suite Variable    ${timeout}
@@ -221,7 +237,7 @@
 Do ONU Up To State Test
     [Documentation]    This keyword performs Up2State Test
     ...    All states up to the passed have to be checked
-    FOR    ${I}    IN RANGE    0    ${num_onus}
+    FOR    ${I}    IN RANGE    0    ${num_all_onus}
         ${src}=    Set Variable    ${hosts.src[${I}]}
         ${dst}=    Set Variable    ${hosts.dst[${I}]}
         Run Keyword If   ${onu_state_nb}>=1
@@ -253,7 +269,7 @@
 Do ONU Single State Test
     [Documentation]    This keyword performs SingleState Test
     ...    Only the passed state has to be checked
-    FOR    ${I}    IN RANGE    0    ${num_onus}
+    FOR    ${I}    IN RANGE    0    ${num_all_onus}
         ${src}=    Set Variable    ${hosts.src[${I}]}
         ${dst}=    Set Variable    ${hosts.dst[${I}]}
         Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    50ms
@@ -277,16 +293,30 @@
 
 Do Onu Port Check
     [Documentation]    Check that all the UNI ports show up in ONOS
-    Wait for Ports in ONOS    ${onos_ssh_connection}    ${num_onus}    BBSM
+    Wait for Ports in ONOS    ${onos_ssh_connection}    ${num_all_onus}    BBSM
 
 Do Onu Flow Check
-    [Documentation]    Check that all ONU flows show up in ONOS and Voltha
-    ${of_id}=    Wait Until Keyword Succeeds    ${timeout}    15s    Validate OLT Device in ONOS    ${olt_serial_number}
-    ${nni_port}=    Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    2s
-    ...    Get NNI Port in ONOS    ${of_id}
-    FOR    ${I}    IN RANGE    0    ${num_onus}
+    [Documentation]    This keyword iterate all OLTs and performs Do Onu Flow Check Per OLT
+    FOR    ${J}    IN RANGE    0    ${num_olts}
+        ${olt_serial_number}=    Set Variable    ${list_olts}[${J}][sn]
+        ${onu_count}=    Set Variable    ${list_olts}[${J}][onucount]
+        ${of_id}=    Wait Until Keyword Succeeds    ${timeout}    15s    Validate OLT Device in ONOS
+        ...    ${olt_serial_number}
+        Set Global Variable    ${of_id}
+        ${nni_port}=    Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    2s
+        ...    Get NNI Port in ONOS    ${of_id}
+        Set Global Variable    ${nni_port}
+        # Verify Default Meter in ONOS (valid only for ATT)
+        Do Onu Flow Check Per OLT    ${of_id}    ${nni_port}    ${olt_serial_number}   ${onu_count}
+    END
+
+Do Onu Flow Check Per OLT
+    [Documentation]    Check per OLT that all ONU flows show up in ONOS and Voltha
+    [Arguments]    ${of_id}    ${nni_port}    ${olt_serial_number}    ${num_onus}
+    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']}
         ${onu_port}=    Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    2s
         ...    Get ONU Port in ONOS    ${src['onu']}    ${of_id}
@@ -344,17 +374,20 @@
     @{resultList}    Split String    ${result}     separator=,
     ${num_of_count_matches}=    Get Match Count    ${resultList}    "num_gem_ports": ${num_gem_ports}
     ...    whitespace_insensitive=True
-    ${num_of_expected_matches}=    Run Keyword If    "${techprofile}"=="default"    Evaluate    ${num_onus}
-    ...    ELSE     Evaluate    ${num_onus}+1
+    ${num_of_expected_matches}=    Run Keyword If    "${techprofile}"=="default"    Evaluate    ${num_all_onus}
+    ...    ELSE     Evaluate    ${num_all_onus}+1
     Run Keyword If    ${num_of_expected_matches}!=${num_of_count_matches}    Log To Console
     ...    \nTechProfile (${TechProfile}) not loaded correctly:${num_of_count_matches} of ${num_of_expected_matches}
 
 Do Disable Enable Onu Test
     [Documentation]    This keyword disables/enables all onus and checks the states.
     [Arguments]    ${state2check}=${state2test}    ${checkstatebeforedisable}=True
+    ...    ${state2checkafterdisable}=tech-profile-config-delete-success
     Run Keyword If    ${checkstatebeforedisable}    Do Current State Test All Onus    ${state2check}
     Do Disable Onu Device
-    Do Current State Test All Onus    omci-admin-lock
+    ${alternative_onu_reason}=    Set Variable If    '${state2checkafterdisable}'=='tech-profile-config-delete-success'
+    ...    omci-flows-deleted    ${EMPTY}
+    Do Current State Test All Onus    ${state2checkafterdisable}    alternativeonustate=${alternative_onu_reason}
     Log Ports
     #check no port is enabled in ONOS
     Wait for Ports in ONOS    ${onos_ssh_connection}    0    BBSM
@@ -362,7 +395,7 @@
     Do Current State Test All Onus    ${state2check}
     Log Ports    onlyenabled=True
     #check that all the UNI ports show up in ONOS again
-    Wait for Ports in ONOS    ${onos_ssh_connection}    ${num_onus}    BBSM
+    Wait for Ports in ONOS    ${onos_ssh_connection}    ${num_all_onus}    BBSM
 
 Do Reconcile Onu Device
     [Documentation]    This keyword reconciles ONU device and check the state afterwards.
@@ -390,26 +423,30 @@
     [Documentation]    This keyword power off/on all onus and checks the states.
     Do Power Off ONU Device
     Sleep    5s
-    Do Current State Test All Onus    stopping-openomci
+    #Do Current State Test All Onus    stopping-openomci
+    Do Current State Test All Onus    tech-profile-config-delete-success
+    ...    ENABLED    DISCOVERED    UNREACHABLE    alternativeonustate=omci-flows-deleted
     Do Power On ONU Device
     Do Current State Test All Onus    ${state2test}
 
 Do Soft Reboot Onu Device
     [Documentation]    This keyword reboots softly all onus and checks the states.
     ${namespace}=    Set Variable    voltha
-    FOR    ${I}    IN RANGE    0    ${num_onus}
+    FOR    ${I}    IN RANGE    0    ${num_all_onus}
         ${src}=    Set Variable    ${hosts.src[${I}]}
         ${onu_device_id}=    Get Device ID From SN    ${src['onu']}
         Reboot ONU    ${onu_device_id}   False
     END
-    Run Keyword Unless    ${has_dataplane}    Do Current State Test All Onus    rebooting
+    Run Keyword Unless    ${has_dataplane}    Do Current State Test All Onus    tech-profile-config-delete-success
+    ...   ENABLED    DISCOVERED    REACHABLE    alternativeonustate=omci-flows-deleted
     Run Keyword Unless    ${has_dataplane}    Do Disable Enable Onu Test    checkstatebeforedisable=False
+    ...    state2checkafterdisable=omci-admin-lock
     Run Keyword If    ${has_dataplane}    Do Current State Test All Onus    omci-flows-pushed
     Do Onu Port Check
 
 Do Disable Onu Device
     [Documentation]    This keyword disables all onus.
-    FOR    ${I}    IN RANGE    0    ${num_onus}
+    FOR    ${I}    IN RANGE    0    ${num_all_onus}
         ${src}=    Set Variable    ${hosts.src[${I}]}
         ${onu_device_id}=    Get Device ID From SN    ${src['onu']}
         Disable Device    ${onu_device_id}
@@ -418,7 +455,7 @@
 
 Do Enable Onu Device
     [Documentation]    This keyword enables all onus.
-    FOR    ${I}    IN RANGE    0    ${num_onus}
+    FOR    ${I}    IN RANGE    0    ${num_all_onus}
         ${src}=    Set Variable    ${hosts.src[${I}]}
         ${onu_device_id}=    Get Device ID From SN    ${src['onu']}
         Enable Device    ${onu_device_id}
@@ -427,95 +464,8 @@
 Do Power Off ONU Device
     [Documentation]    This keyword power off all onus.
     ${namespace}=    Set Variable    voltha
-    FOR    ${I}    IN RANGE    0    ${num_onus}
+    FOR    ${I}    IN RANGE    0    ${num_all_onus}
         ${src}=    Set Variable    ${hosts.src[${I}]}
         ${result}=    Exec Pod    ${namespace}    bbsim    bbsimctl onu shutdown ${src['onu']}
         Should Contain    ${result}    successfully    msg=Can not shutdown ${src['onu']}    values=False
     END
-
-Do Power On ONU Device
-    [Documentation]    This keyword power on all onus.
-    ${namespace}=    Set Variable    voltha
-    FOR    ${I}    IN RANGE    0    ${num_onus}
-        ${src}=    Set Variable    ${hosts.src[${I}]}
-        ${result}=    Exec Pod    ${namespace}    bbsim    bbsimctl onu poweron ${src['onu']}
-        Should Contain    ${result}    successfully    msg=Can not poweron ${src['onu']}    values=False
-    END
-
-Do Current State Test
-    [Documentation]    This keyword checks the passed state of the given onu.
-    [Arguments]    ${state}    ${onu}
-    ${admin_state}    ${oper_status}    ${connect_status}    ${onu_state_nb}    ${onu_state}=    Map State    ${state}
-    Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    50ms
-    ...    Validate Device    ${admin_state}    ${oper_status}    ${connect_status}
-    ...    ${onu}    onu=True    onu_reason=${onu_state}
-
-Do Current State Test All Onus
-    [Documentation]    This keyword checks the passed state of all onus.
-    ...                Hint: ${timeStart} will be not evaluated here!
-    [Arguments]    ${state}
-    ${list_onus}    Create List
-    Build ONU SN List    ${list_onus}
-    ${admin_state}    ${oper_status}    ${connect_status}    ${onu_state_nb}    ${onu_state}=    Map State    ${state}
-    Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    50ms
-    ...    Validate ONU Devices With Duration
-    ...    ${admin_state}    ${oper_status}    ${connect_status}
-    ...    ${onu_state}    ${list_onus}    ${timeStart}
-
-Log Ports
-    [Documentation]    This keyword logs all port data available in ONOS of first port per ONU
-    [Arguments]    ${onlyenabled}=False
-    ${cmd}    Set Variable If    ${onlyenabled}    ports -e    ports
-    ${onu_ports}=    Execute ONOS CLI Command on open connection    ${onos_ssh_connection}   ${cmd}
-    ${lines} =     Get Lines Matching Regexp    ${onu_ports}    .*portName=BBSM[0-9]{8}-1
-    Log    ${lines}
-
-Kill Adaptor
-    [Documentation]    This keyword kills the passed adaptor.
-    [Arguments]    ${namespace}    ${name}
-    ${cmd}    Catenate
-    ...    kubectl exec -it -n voltha $(kubectl get pods -n ${namespace} | grep ${name} | awk 'NR==1{print $1}')
-    ...     -- /bin/sh -c "kill 1"
-    ${rc}    ${output}=    Run and Return Rc and Output    ${cmd}
-    Log    ${output}
-
-Delete MIB Template Data
-    [Documentation]    This keyword deletes MIB Template Data stored in etcd
-    ${namespace}=    Set Variable    default
-    ${podname}=    Set Variable    etcd
-    ${commanddel}    Catenate
-    ...    /bin/sh -c 'ETCDCTL_API=3 etcdctl del --prefix service/voltha/omci_mibs/go_templates/'
-    ${result}=    Exec Pod    ${namespace}    ${podname}    ${commanddel}
-    Sleep    3s
-    ${commandget}    Catenate
-    ...    /bin/sh -c 'ETCDCTL_API=3 etcdctl get --prefix service/voltha/omci_mibs/go_templates/'
-    ${result}=    Exec Pod    ${namespace}    ${podname}    ${commandget}
-    Should Be Empty    ${result}    Could not delete MIB Template Data stored in etcd!
-
-Map State
-    [Documentation]    This keyword converts the passed numeric value or name of a onu state to its state values.
-    [Arguments]    ${state}
-    # create state lists with corresponding return values
-    #                             ADMIN-STATE OPER-STATUS   CONNECT-STATUS ONU-STATE (number/name)
-    ${state1}     Create List      ENABLED     ACTIVATING    REACHABLE       1    activating-onu
-    ${state2}     Create List      ENABLED     ACTIVATING    REACHABLE       2    starting-openomci
-    ${state3}     Create List      ENABLED     ACTIVATING    REACHABLE       3    discovery-mibsync-complete
-    ${state4}     Create List      ENABLED     ACTIVE        REACHABLE       4    initial-mib-downloaded
-    ${state5}     Create List      ENABLED     ACTIVE        REACHABLE       5    tech-profile-config-download-success
-    ${state6}     Create List      ENABLED     ACTIVE        REACHABLE       6    omci-flows-pushed
-    ${state7}     Create List      DISABLED    UNKNOWN       REACHABLE       7    omci-admin-lock
-    ${state8}     Create List      ENABLED     ACTIVE        REACHABLE       8    onu-reenabled
-    ${state9}     Create List      ENABLED     DISCOVERED    UNREACHABLE     9    stopping-openomci
-    ${state10}    Create List      ENABLED     DISCOVERED    REACHABLE      10    rebooting
-    ${admin_state}    ${oper_status}    ${connect_status}    ${onu_state_nb}    ${onu_state}=    Set Variable If
-    ...    '${state}'=='1' or '${state}'=='activating-onu'                          ${state1}
-    ...    '${state}'=='2' or '${state}'=='starting-openomci'                       ${state2}
-    ...    '${state}'=='3' or '${state}'=='discovery-mibsync-complete'              ${state3}
-    ...    '${state}'=='4' or '${state}'=='initial-mib-downloaded'                  ${state4}
-    ...    '${state}'=='5' or '${state}'=='tech-profile-config-download-success'    ${state5}
-    ...    '${state}'=='6' or '${state}'=='omci-flows-pushed'                       ${state6}
-    ...    '${state}'=='7' or '${state}'=='omci-admin-lock'                         ${state7}
-    ...    '${state}'=='8' or '${state}'=='onu-reenabled'                           ${state8}
-    ...    '${state}'=='9' or '${state}'=='stopping-openomci'                       ${state9}
-    ...    '${state}'=='10' or '${state}'=='rebooting'                              ${state10}
-    [Return]    ${admin_state}    ${oper_status}    ${connect_status}    ${onu_state_nb}    ${onu_state}
diff --git a/tests/openonu-go-adapter/Voltha_ONUTemplateTests.robot b/tests/openonu-go-adapter/Voltha_ONUTemplateTests.robot
index 7e788ff..9dc0c55 100755
--- a/tests/openonu-go-adapter/Voltha_ONUTemplateTests.robot
+++ b/tests/openonu-go-adapter/Voltha_ONUTemplateTests.robot
@@ -18,6 +18,7 @@
 Resource          ../../libraries/utils.robot
 Resource          ../../libraries/k8s.robot
 Resource          ../../variables/variables.robot
+Resource          Voltha_ONUUtilities.robot
 
 *** Variables ***
 ${NAMESPACE}      voltha
@@ -133,51 +134,3 @@
     ${timeTotalMs} =    Subtract Date From Date    ${timeCurrent}    ${startTime}    result_format=number
     Log    ONU ${src['onu']}: reached the state ${onu_state} after ${timeTotalMs} sec.    console=yes
     [Return]    ${timeTotalMs}
-
-Verify MIB Template Data Available
-    [Documentation]    This keyword verifies MIB Template Data stored in etcd
-    ${namespace}=    Set Variable    default
-    ${podname}=    Set Variable    etcd
-    ${commandget}    Catenate
-    ...    /bin/sh -c 'ETCDCTL_API=3 etcdctl get --prefix service/voltha/omci_mibs/go_templates/'
-    ${result}=    Exec Pod    ${namespace}    ${podname}    ${commandget}
-    Should Not Be Empty    ${result}    No MIB Template Data stored in etcd!
-
-Delete MIB Template Data
-    [Documentation]    This keyword deletes MIB Template Data stored in etcd
-    ${namespace}=    Set Variable    default
-    ${podname}=    Set Variable    etcd
-    ${commanddel}    Catenate
-    ...    /bin/sh -c 'ETCDCTL_API=3 etcdctl del --prefix service/voltha/omci_mibs/go_templates/'
-    ${result}=    Exec Pod    ${namespace}    ${podname}    ${commanddel}
-    Sleep    3s
-    ${commandget}    Catenate
-    ...    /bin/sh -c 'ETCDCTL_API=3 etcdctl get --prefix service/voltha/omci_mibs/go_templates/'
-    ${result}=    Exec Pod    ${namespace}    ${podname}    ${commandget}
-    Should Be Empty    ${result}    Could not delete MIB Template Data stored in etcd!
-
-Map State
-    [Documentation]    This keyword converts the passed numeric value or name of a onu state to its state values.
-    [Arguments]    ${state}
-    # create state lists with corresponding return values
-    #                             ADMIN-STATE OPER-STATUS   CONNECT-STATUS ONU-STATE (number/name)
-    ${state1}    Create List      ENABLED     ACTIVATING    REACHABLE      1    activating-onu
-    ${state2}    Create List      ENABLED     ACTIVATING    REACHABLE      2    starting-openomci
-    ${state3}    Create List      ENABLED     ACTIVATING    REACHABLE      3    discovery-mibsync-complete
-    ${state4}    Create List      ENABLED     ACTIVE        REACHABLE      4    initial-mib-downloaded
-    ${state5}    Create List      ENABLED     ACTIVE        REACHABLE      5    tech-profile-config-download-success
-    ${state6}    Create List      ENABLED     ACTIVE        REACHABLE      6    omci-flows-pushed
-    ${state7}    Create List      DISABLED    UNKNOWN       REACHABLE      7    omci-admin-lock
-    ${state8}    Create List      ENABLED     ACTIVE        REACHABLE      8    onu-reenabled
-    ${state9}    Create List      ENABLED     DISCOVERED    UNREACHABLE    9    stopping-openomci
-    ${admin_state}    ${oper_status}    ${connect_status}    ${onu_state_nb}    ${onu_state}=    Set Variable If
-    ...    '${state}'=='1' or '${state}'=='activating-onu'                          ${state1}
-    ...    '${state}'=='2' or '${state}'=='starting-openomci'                       ${state2}
-    ...    '${state}'=='3' or '${state}'=='discovery-mibsync-complete'              ${state3}
-    ...    '${state}'=='4' or '${state}'=='initial-mib-downloaded'                  ${state4}
-    ...    '${state}'=='5' or '${state}'=='tech-profile-config-download-success'    ${state5}
-    ...    '${state}'=='6' or '${state}'=='omci-flows-pushed'                       ${state6}
-    ...    '${state}'=='7' or '${state}'=='omci-admin-lock'                         ${state7}
-    ...    '${state}'=='8' or '${state}'=='onu-reenabled'                           ${state8}
-    ...    '${state}'=='9' or '${state}'=='stopping-openomci'                       ${state9}
-    [Return]    ${admin_state}    ${oper_status}    ${connect_status}    ${onu_state_nb}    ${onu_state}
diff --git a/tests/openonu-go-adapter/Voltha_ONUUtilities.robot b/tests/openonu-go-adapter/Voltha_ONUUtilities.robot
new file mode 100755
index 0000000..c92fd38
--- /dev/null
+++ b/tests/openonu-go-adapter/Voltha_ONUUtilities.robot
@@ -0,0 +1,139 @@
+# Copyright 2020-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# voltctl common functions
+
+*** Settings ***
+Documentation     Library for various openonu-go-adpter utilities
+
+*** Keywords ***
+Do Power On ONU Device
+    [Documentation]    This keyword power on all onus.
+    ${namespace}=    Set Variable    voltha
+    FOR    ${I}    IN RANGE    0    ${num_all_onus}
+        ${src}=    Set Variable    ${hosts.src[${I}]}
+        ${result}=    Exec Pod    ${namespace}    bbsim    bbsimctl onu poweron ${src['onu']}
+        Should Contain    ${result}    successfully    msg=Can not poweron ${src['onu']}    values=False
+    END
+
+Do Current State Test
+    [Documentation]    This keyword checks the passed state of the given onu.
+    [Arguments]    ${state}    ${onu}    ${reqadminstate}=${EMPTY}    ${reqoperstatus}=${EMPTY}
+    ...    ${reqconnectstatus}=${EMPTY}
+    ${admin_state}    ${oper_status}    ${connect_status}    ${onu_state_nb}    ${onu_state}=    Map State    ${state}
+    ${admin_state}=       Set Variable If    '${reqadminstate}'!='${EMPTY}'       ${reqadminstate}       ${admin_state}
+    ${oper_status}=       Set Variable If    '${reqoperstatus}'!='${EMPTY}'       ${reqoperstatus}       ${oper_status}
+    ${connect_status}=    Set Variable If    '${reqconnectstatus}'!='${EMPTY}'    ${reqconnectstatus}
+    ...    ${connect_status}
+    Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    50ms
+    ...    Validate Device    ${admin_state}    ${oper_status}    ${connect_status}
+    ...    ${onu}    onu=True    onu_reason=${onu_state}
+
+Do Current State Test All Onus
+    [Documentation]    This keyword checks the passed state of all onus.
+    ...                Hint: ${timeStart} will be not evaluated here!
+    [Arguments]    ${state}    ${reqadminstate}=${EMPTY}    ${reqoperstatus}=${EMPTY}    ${reqconnectstatus}=${EMPTY}
+    ...    ${alternativeonustate}=${EMPTY}
+    ${list_onus}    Create List
+    Build ONU SN List    ${list_onus}
+    ${admin_state}    ${oper_status}    ${connect_status}    ${onu_state_nb}    ${onu_state}=    Map State    ${state}
+    ${admin_state}=       Set Variable If    '${reqadminstate}'!='${EMPTY}'       ${reqadminstate}       ${admin_state}
+    ${oper_status}=       Set Variable If    '${reqoperstatus}'!='${EMPTY}'       ${reqoperstatus}       ${oper_status}
+    ${connect_status}=    Set Variable If    '${reqconnectstatus}'!='${EMPTY}'    ${reqconnectstatus}
+    ...    ${connect_status}
+    Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    50ms
+    ...    Validate ONU Devices With Duration
+    ...    ${admin_state}    ${oper_status}    ${connect_status}
+    ...    ${onu_state}    ${list_onus}    ${timeStart}    alternate_reason=${alternativeonustate)
+
+Do Current Reason Test All Onus
+    [Documentation]    This keyword checks the passed state of all onus.
+    ...                Hint: ${timeStart} will be not evaluated here!
+    [Arguments]    ${state}
+    ${list_onus}    Create List
+    Build ONU SN List    ${list_onus}
+    ${admin_state}    ${oper_status}    ${connect_status}    ${onu_state_nb}    ${onu_state}=    Map State    ${state}
+    Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    50ms
+    ...    Validate ONU Devices MIB State With Duration
+    ...    ${onu_state}    ${list_onus}    ${timeStart}
+
+Log Ports
+    [Documentation]    This keyword logs all port data available in ONOS of first port per ONU
+    [Arguments]    ${onlyenabled}=False
+    ${cmd}    Set Variable If    ${onlyenabled}    ports -e    ports
+    ${onu_ports}=    Execute ONOS CLI Command on open connection    ${onos_ssh_connection}   ${cmd}
+    ${lines} =     Get Lines Matching Regexp    ${onu_ports}    .*portName=BBSM[0-9]{8}-1
+    Log    ${lines}
+
+Kill Adaptor
+    [Documentation]    This keyword kills the passed adaptor.
+    [Arguments]    ${namespace}    ${name}
+    ${cmd}    Catenate
+    ...    kubectl exec -it -n voltha $(kubectl get pods -n ${namespace} | grep ${name} | awk 'NR==1{print $1}')
+    ...     -- /bin/sh -c "kill 1"
+    ${rc}    ${output}=    Run and Return Rc and Output    ${cmd}
+    Log    ${output}
+
+Verify MIB Template Data Available
+    [Documentation]    This keyword verifies MIB Template Data stored in etcd
+    ${namespace}=    Set Variable    default
+    ${podname}=    Set Variable    etcd
+    ${commandget}    Catenate
+    ...    /bin/sh -c 'ETCDCTL_API=3 etcdctl get --prefix service/voltha/omci_mibs/go_templates/'
+    ${result}=    Exec Pod    ${namespace}    ${podname}    ${commandget}
+    Should Not Be Empty    ${result}    No MIB Template Data stored in etcd!
+
+Delete MIB Template Data
+    [Documentation]    This keyword deletes MIB Template Data stored in etcd
+    ${namespace}=    Set Variable    default
+    ${podname}=    Set Variable    etcd
+    ${commanddel}    Catenate
+    ...    /bin/sh -c 'ETCDCTL_API=3 etcdctl del --prefix service/voltha/omci_mibs/go_templates/'
+    ${result}=    Exec Pod    ${namespace}    ${podname}    ${commanddel}
+    Sleep    3s
+    ${commandget}    Catenate
+    ...    /bin/sh -c 'ETCDCTL_API=3 etcdctl get --prefix service/voltha/omci_mibs/go_templates/'
+    ${result}=    Exec Pod    ${namespace}    ${podname}    ${commandget}
+    Should Be Empty    ${result}    Could not delete MIB Template Data stored in etcd!
+
+Map State
+    [Documentation]    This keyword converts the passed numeric value or name of a onu state to its state values.
+    [Arguments]    ${state}
+    # create state lists with corresponding return values
+    #                             ADMIN-STATE OPER-STATUS   CONNECT-STATUS ONU-STATE (number/name)
+    ${state1}     Create List      ENABLED     ACTIVATING    REACHABLE       1    activating-onu
+    ${state2}     Create List      ENABLED     ACTIVATING    REACHABLE       2    starting-openomci
+    ${state3}     Create List      ENABLED     ACTIVATING    REACHABLE       3    discovery-mibsync-complete
+    ${state4}     Create List      ENABLED     ACTIVE        REACHABLE       4    initial-mib-downloaded
+    ${state5}     Create List      ENABLED     ACTIVE        REACHABLE       5    tech-profile-config-download-success
+    ${state6}     Create List      ENABLED     ACTIVE        REACHABLE       6    omci-flows-pushed
+    ${state7}     Create List      DISABLED    UNKNOWN       REACHABLE       7    omci-admin-lock
+    ${state8}     Create List      ENABLED     ACTIVE        REACHABLE       8    onu-reenabled
+    ${state9}     Create List      ENABLED     DISCOVERED    UNREACHABLE     9    stopping-openomci
+    ${state10}    Create List      ENABLED     DISCOVERED    REACHABLE      10    rebooting
+    ${state11}    Create List      ENABLED     DISCOVERED    REACHABLE      11    omci-flows-deleted
+    ${state12}    Create List      DISABLED    UNKNOWN       REACHABLE      12    tech-profile-config-delete-success
+    ${admin_state}    ${oper_status}    ${connect_status}    ${onu_state_nb}    ${onu_state}=    Set Variable If
+    ...    '${state}'=='1' or '${state}'=='activating-onu'                          ${state1}
+    ...    '${state}'=='2' or '${state}'=='starting-openomci'                       ${state2}
+    ...    '${state}'=='3' or '${state}'=='discovery-mibsync-complete'              ${state3}
+    ...    '${state}'=='4' or '${state}'=='initial-mib-downloaded'                  ${state4}
+    ...    '${state}'=='5' or '${state}'=='tech-profile-config-download-success'    ${state5}
+    ...    '${state}'=='6' or '${state}'=='omci-flows-pushed'                       ${state6}
+    ...    '${state}'=='7' or '${state}'=='omci-admin-lock'                         ${state7}
+    ...    '${state}'=='8' or '${state}'=='onu-reenabled'                           ${state8}
+    ...    '${state}'=='9' or '${state}'=='stopping-openomci'                       ${state9}
+    ...    '${state}'=='10' or '${state}'=='rebooting'                              ${state10}
+    ...    '${state}'=='11' or '${state}'=='omci-flows-deleted'                     ${state11}
+    ...    '${state}'=='12' or '${state}'=='tech-profile-config-delete-success'     ${state12}
+    [Return]    ${admin_state}    ${oper_status}    ${connect_status}    ${onu_state_nb}    ${onu_state}