[VOL-2550] DT: Functional TC: Disable-Delete OLT

Change-Id: I31e2711ecc8e30eee971ab2c2245592a6ea8498f
diff --git a/libraries/utils.robot b/libraries/utils.robot
index 908bfbc..59a6e55 100644
--- a/libraries/utils.robot
+++ b/libraries/utils.robot
@@ -256,6 +256,28 @@
     ${logical_id}=    Get Logical Device ID From SN    ${olt_serial_number}
     Set Suite Variable    ${logical_id}
 
+Validate ONUs After OLT Disable
+    [Documentation]    Validates the ONUs state in Voltha, ONUs port state in ONOS
+    ...    and that pings do not succeed After corresponding OLT is Disabled
+    FOR    ${I}    IN RANGE    0    ${num_onus}
+        ${src}=    Set Variable    ${hosts.src[${I}]}
+        ${dst}=    Set Variable    ${hosts.dst[${I}]}
+        ${onu_device_id}=    Get Device ID From SN    ${src['onu']}
+        ${onu_port}=    Wait Until Keyword Succeeds    ${timeout}    2s    Get ONU Port in ONOS    ${src['onu']}
+        ...    ${of_id}
+        Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    5s
+        ...    Validate Device    ENABLED    DISCOVERED
+        ...    UNREACHABLE    ${src['onu']}    onu=True    onu_reason=stopping-openomci
+        Run Keyword And Continue On Failure    Wait Until Keyword Succeeds   ${timeout}    2s
+        ...    Verify ONU Port Is Disabled   ${ONOS_SSH_IP}    ${ONOS_SSH_PORT}    ${onu_port}
+        Run Keyword If    ${has_dataplane}    Run Keyword And Continue On Failure
+        ...    Wait Until Keyword Succeeds    60s    2s
+        ...    Check Ping    False    ${dst['dp_iface_ip_qinq']}    ${src['dp_iface_name']}
+        ...    ${src['ip']}    ${src['user']}    ${src['pass']}    ${src['container_type']}    ${src['container_name']}
+        Run Keyword and Ignore Error    Get Device Output from Voltha    ${onu_device_id}
+        Run Keyword and Ignore Error    Collect Logs
+    END
+
 Delete All Devices and Verify
     [Documentation]    Remove any devices from VOLTHA and ONOS
     # Clear devices from VOLTHA
diff --git a/libraries/voltctl.robot b/libraries/voltctl.robot
index 2d5fbf7..f35d171 100644
--- a/libraries/voltctl.robot
+++ b/libraries/voltctl.robot
@@ -51,11 +51,18 @@
 
 Disable Device
     [Arguments]    ${device_id}
-    [Documentation]    Enables a device in VOLTHA
+    [Documentation]    Disables a device in VOLTHA
     ${rc}    ${output}=    Run and Return Rc and Output
     ...    ${VOLTCTL_CONFIG}; voltctl device disable ${device_id}
     Should Be Equal As Integers    ${rc}    0
 
+Delete Device
+    [Arguments]    ${device_id}
+    [Documentation]    Deletes a device in VOLTHA
+    ${rc}    ${output}=    Run and Return Rc and Output
+    ...    ${VOLTCTL_CONFIG}; voltctl device delete ${device_id}
+    Should Be Equal As Integers    ${rc}    0
+
 Disable Devices In Voltha
     [Documentation]    Disables all the known devices in voltha
     [Arguments]    ${filter}
diff --git a/tests/dt-workflow/Voltha_DT_PODTests.robot b/tests/dt-workflow/Voltha_DT_PODTests.robot
index 7bb8f04..68fa5e0 100644
--- a/tests/dt-workflow/Voltha_DT_PODTests.robot
+++ b/tests/dt-workflow/Voltha_DT_PODTests.robot
@@ -186,6 +186,44 @@
         Run Keyword and Ignore Error    Collect Logs
     END
 
+Test Disable and Delete OLT for DT
+    [Documentation]    Validates E2E Ping Connectivity and object states for the given scenario:
+    ...    Assuming that all the ONUs are DHCP/pingable (i.e. assuming sanityDt test was executed)
+    ...    Perform disable on the OLT and validate ONUs state and that the pings do not succeed
+    ...    Perform delete on the OLT, Re-do Setup (Recreate the OLT) and Perform Sanity Test DT
+    [Tags]    functionalDt    DisableDeleteOLTDt    bbsim    released
+    [Setup]    Run Keywords    Announce Message    START TEST DisableDeleteOLTDt
+    ...        AND             Start Logging    DisableDeleteOLTDt
+    [Teardown]    Run Keywords    Collect Logs
+    ...           AND             Stop Logging    DisableDeleteOLTDt
+    ...           AND             Announce Message    END TEST DisableDeleteOLTDt
+    # Disable and Validate OLT Device
+    Disable Device    ${olt_device_id}
+    Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    5s
+    ...    Validate OLT Device    DISABLED    UNKNOWN    REACHABLE
+    ...    ${olt_serial_number}
+    # Validate ONUs
+    Run Keyword    Wait Until Keyword Succeeds    ${timeout}    5s    Validate ONUs After OLT Disable
+    # Verify VOLTHA Flows (TODO: Add verification for ONOS Flows)
+    # Number of per OLT Flows equals Twice the Number of Active ONUs (each for downstream and upstream) + 1 for LLDP
+    ${olt_flows}=    Evaluate    2 * ${num_onus} + 1
+    # Number of per ONU Flows equals 2 (one each for downstream and upstream)
+    ${onu_flows}=    Set Variable    2
+    Run Keyword    Wait Until Keyword Succeeds    ${timeout}    5s    Validate OLT Flows    ${olt_flows}
+    ${List_ONU_Serial}    Create List
+    Set Suite Variable    ${List_ONU_Serial}
+    Build ONU SN List    ${List_ONU_Serial}
+    Log    ${List_ONU_Serial}
+    Run Keyword    Wait Until Keyword Succeeds    ${timeout}    5s    Validate ONU Flows
+    ...    ${List_ONU_Serial}    ${onu_flows}
+    # Delete OLT and Validate Empty Device List
+    Delete Device    ${olt_device_id}
+    Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    5s    Test Empty Device List
+    Run Keyword and Ignore Error    Collect Logs
+    # Re-do Setup (Recreate the OLT) and Perform Sanity Test DT
+    Run Keyword    Setup
+    Wait Until Keyword Succeeds    ${timeout}   2s    Perform Sanity Test DT
+
 *** Keywords ***
 Setup Suite
     [Documentation]    Set up the test suite