[VOL-3976]  Restart openolt adapter restart before subscriber provisioning for TT

Change-Id: I8ac7356ba5c9209145e9cc965cf01453d396576e
diff --git a/libraries/onos.robot b/libraries/onos.robot
index a424301..fa9560e 100755
--- a/libraries/onos.robot
+++ b/libraries/onos.robot
@@ -258,6 +258,31 @@
     ...    flows -s ADDED ${olt_of_id} | grep -v deviceId | grep -v ETH_TYPE:lldp | grep -v ETH_TYPE:arp | wc -l
     Should Be Equal As Integers    ${access_flows_added}    ${expected_flows}
 
+Verify Default Downstream Flows are added in ONOS for OLT TT
+    [Arguments]    ${ip}    ${port}    ${olt_of_id}    ${nni_port}
+    [Documentation]    Verifies if the Default Downstream Flows are added in ONOS for the OLT
+    # Verify lldp flow
+    ${downstream_flow_lldp_cmd}=    Catenate    SEPARATOR=
+    ...    flows -s ADDED ${olt_of_id} | grep lldp |
+    ...     grep OUTPUT:CONTROLLER
+    ${downstream_flow_lldp_added}=    Execute ONOS CLI Command    ${ip}    ${port}
+    ...    ${downstream_flow_lldp_cmd}
+    Should Not Be Empty    ${downstream_flow_lldp_added}
+    # Verify downstream dhcp flow
+    ${downstream_flow_dhcp_cmd}=    Catenate    SEPARATOR=
+    ...    flows -s ADDED ${olt_of_id} | grep IP_PROTO:17 | grep UDP_SRC:67 | grep UDP_DST:68 |
+    ...     grep OUTPUT:CONTROLLER
+    ${downstream_flow_dhcp_added}=    Execute ONOS CLI Command    ${ip}    ${port}
+    ...    ${downstream_flow_dhcp_cmd}
+    Should Not Be Empty    ${downstream_flow_dhcp_added}
+    # Verify downstream igmp flow
+    ${downstream_flow_igmp_cmd}=    Catenate    SEPARATOR=
+    ...    flows -s ADDED ${olt_of_id} | grep IP_PROTO:2 |
+    ...     grep OUTPUT:CONTROLLER
+    ${downstream_flow_igmp_added}=    Execute ONOS CLI Command    ${ip}    ${port}
+    ...    ${downstream_flow_igmp_cmd}
+    Should Not Be Empty    ${downstream_flow_igmp_added}
+
 Get Programmed Subscribers
     [Arguments]    ${ip}    ${port}    ${olt_of_id}    ${onu_port}
     [Documentation]    Retrieves the subscriber details at a given location
diff --git a/tests/tt-workflow/Voltha_TT_FailureScenarios.robot b/tests/tt-workflow/Voltha_TT_FailureScenarios.robot
index a1617f0..5218bb8 100755
--- a/tests/tt-workflow/Voltha_TT_FailureScenarios.robot
+++ b/tests/tt-workflow/Voltha_TT_FailureScenarios.robot
@@ -293,6 +293,41 @@
     Should Be Equal As Strings    ${countAfterRestart}    ${countBeforeRestart}
     Log to console    Pod ${podName} restarted and sanity checks passed successfully
 
+Verify restart openolt-adapter container before subscriber provisioning for TT
+    [Documentation]    Restart openolt-adapter container after VOLTHA is operational.
+    [Tags]    functionalTT    Restart-OpenOlt-Before-Subscription-TT
+    [Setup]    Start Logging    Restart-OpenOlt-Before-Subscription-TT
+    [Teardown]    Run Keywords    Collect Logs
+    ...           AND             Stop Logging    Restart-OpenOlt-Before-Subscription-TT
+    ...           AND             Delete All Devices and Verify
+    # Add OLT device
+    Setup
+    Run Keyword If    ${has_dataplane}    Clean Up Linux
+    FOR   ${I}    IN RANGE    0    ${olt_count}
+        ${olt_serial_number}=    Get From Dictionary    ${olt_ids}[${I}]    sn
+        ${olt_device_id}=    Get OLTDeviceID From OLT List    ${olt_serial_number}
+        ${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}
+        Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    5s
+        ...    Verify Default Downstream Flows are added in ONOS for OLT TT    ${ONOS_SSH_IP}    ${ONOS_SSH_PORT}    ${of_id}
+        ...    ${nni_port}
+    END
+    ${podStatusOutput}=    Run    kubectl get pods -n ${NAMESPACE}
+    Log    ${podStatusOutput}
+    ${countBeforeRestart}=    Run    kubectl get pods -n ${NAMESPACE} | grep Running | wc -l
+    ${podName}    Set Variable     ${OLT_ADAPTER_APP_LABEL}
+    Wait Until Keyword Succeeds    ${timeout}    15s    Delete K8s Pods By Label    ${NAMESPACE}    app    ${podName}
+    Sleep    5s
+    Wait Until Keyword Succeeds    ${timeout}    2s    Validate Pods Status By Label    ${NAMESPACE}
+    ...    app    ${podName}    Running
+    Wait Until Keyword Succeeds    ${timeout}    3s    Pods Are Ready By Label    ${NAMESPACE}    app    ${podName}
+    ${countAfterRestart}=    Run    kubectl get pods -n ${NAMESPACE} | grep Running | wc -l
+    Should Be Equal As Strings    ${countAfterRestart}    ${countBeforeRestart}
+    Wait Until Keyword Succeeds    ${timeout}    2s    Perform Sanity Tests TT
+    Log to console    Pod ${podName} restarted and sanity checks passed successfully
+
 Verify restart openolt-adapter container after subscriber provisioning for TT
     [Documentation]    Restart openolt-adapter container after VOLTHA is operational.
     [Tags]    functionalTT    Restart-OpenOlt-TT