[VOL-3325] OpenOnu-Go-Adapter: Test for OpenOnu-Go soft Reboot

Change-Id: I91eb741b5911a69f807d3da71199080734c846e5
diff --git a/libraries/voltctl.robot b/libraries/voltctl.robot
index ac249eb..f45518c 100755
--- a/libraries/voltctl.robot
+++ b/libraries/voltctl.robot
@@ -378,6 +378,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
@@ -658,12 +702,12 @@
     List Should Not Contain Value    ${ids}    ${id}
 
 Reboot ONU
-    [Arguments]    ${onu_id}    ${src}   ${dst}
+    [Arguments]    ${onu_id}
     [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 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 696041b..a493133 100755
--- a/tests/openonu-go-adapter/Voltha_ONUStateTests.robot
+++ b/tests/openonu-go-adapter/Voltha_ONUStateTests.robot
@@ -138,6 +138,17 @@
     [Teardown]    Run Keywords    Run Keyword If    ${logging}    Collect Logs
     ...    AND    Stop Logging    PowerOffPowerOnONUDevice
 
+Soft Reboot Onu Device
+    [Documentation]    Reboots softly all ONU Devices and check state
+    ...    Assuming that ONU State Test was executed where all the ONUs are reached the expected state!
+    [Tags]    functionalOnuGo    SoftRebootOnuGo
+    [Setup]    Start Logging    SoftRebootONUDevice
+    Run Keyword If    '${onu_state}'=='tech-profile-config-download-success' or '${onu_state}'=='omci-flows-pushed'
+    ...    Do Soft Reboot Onu Device
+    ...    ELSE    Pass Execution    ${skip_message}    skipped
+    [Teardown]    Run Keywords    Run Keyword If    ${logging}    Collect Logs
+    ...    AND    Stop Logging    SoftRebootONUDevice
+
 *** Keywords ***
 Setup Suite
     [Documentation]    Set up the test suite
@@ -340,8 +351,8 @@
 
 Do Disable Enable Onu Test
     [Documentation]    This keyword disables/enables all onus and checks the states.
-    [Arguments]    ${state2check}=${state2test}
-    Do Current State Test All Onus    ${state2check}
+    [Arguments]    ${state2check}=${state2test}    ${checkstatebeforedisable}=True
+    Run Keyword If    ${checkstatebeforedisable}    Do Current State Test All Onus    ${state2check}
     Do Disable Onu Device
     Do Current State Test All Onus    omci-admin-lock
     Log Ports
@@ -383,6 +394,18 @@
     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}
+        ${src}=    Set Variable    ${hosts.src[${I}]}
+        ${onu_device_id}=    Get Device ID From SN    ${src['onu']}
+        Reboot ONU    ${onu_device_id}
+    END
+    Run Keyword If    ${has_dataplane}    Sleep    30s
+    Do Disable Enable Onu Test    checkstatebeforedisable=False
+    Do Onu Port Check
+
 Do Disable Onu Device
     [Documentation]    This keyword disables all onus.
     FOR    ${I}    IN RANGE    0    ${num_onus}