[VOL-2483] DT workflow sanity test

Change-Id: I482dc6a463bb8bc733e37f8c7e093b52eea89de2
diff --git a/libraries/utils.robot b/libraries/utils.robot
index 9143fc1..5d1d2a2 100644
--- a/libraries/utils.robot
+++ b/libraries/utils.robot
@@ -186,6 +186,51 @@
         Run Keyword and Ignore Error    Collect Logs
     END
 
+Perform Sanity Test DT
+    [Documentation]    This keyword performs Sanity Test Procedure for DT Workflow
+    ...    Sanity test performs dhcp and pings (without EAPOL and DHCP flows) for all the ONUs given for the POD
+    ...    This keyword can be used to call in any other tests where sanity check is required
+    ...    and avoids duplication of code.
+    ${of_id}=    Wait Until Keyword Succeeds    ${timeout}    15s    Validate OLT Device in ONOS    ${olt_serial_number}
+    Set Global Variable    ${of_id}
+    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}=    Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    2s
+        ...    Get ONU Port in ONOS    ${src['onu']}    ${of_id}
+        # Check ONU port is Enabled in ONOS
+        Run Keyword And Continue On Failure    Wait Until Keyword Succeeds   120s   2s
+        ...    Verify ONU Port Is Enabled   ${k8s_node_ip}    ${ONOS_SSH_PORT}    ${onu_port}
+        Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    2
+        ...    Execute ONOS CLI Command    ${k8s_node_ip}    ${ONOS_SSH_PORT}
+        ...    volt-add-subscriber-access ${of_id} ${onu_port}
+        # Verify ONU state in voltha
+        Run Keyword And Continue On Failure    Wait Until Keyword Succeeds    ${timeout}    5s    Validate Device
+        ...    ENABLED    ACTIVE    REACHABLE
+        ...    ${src['onu']}    onu=True    onu_reason=omci-flows-pushed
+        # TODO: Yet to Verify on the Physical POD
+        Run Keyword If    ${has_dataplane}    Run Keyword And Continue On Failure    Validate DHCP and Ping    True
+        ...    True    ${src['dp_iface_name']}    ${src['s_tag']}    ${src['c_tag']}    ${dst['dp_iface_ip_qinq']}
+        ...    ${src['ip']}    ${src['user']}    ${src['pass']}    ${src['container_type']}    ${src['container_name']}
+        ...    ${dst['dp_iface_name']}    ${dst['ip']}    ${dst['user']}    ${dst['pass']}    ${dst['container_type']}
+        ...    ${dst['container_name']}
+        Run Keyword and Ignore Error    Get Device Output from Voltha    ${onu_device_id}
+        Run Keyword and Ignore Error    Collect Logs
+    END
+    # 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}
+
 Setup
     [Documentation]    Pre-test Setup
     #test for empty device list
diff --git a/libraries/voltctl.robot b/libraries/voltctl.robot
index 00c85c4..e0883d7 100644
--- a/libraries/voltctl.robot
+++ b/libraries/voltctl.robot
@@ -209,7 +209,7 @@
     END
 
 Validate Device Flows
-    [Arguments]    ${device_id}    ${test}=${EMPTY}
+    [Arguments]    ${device_id}    ${flow_count}=${EMPTY}
     [Documentation]    Parses the output of voltctl device flows <device_id> and expects flow count > 0
     ${rc}    ${output}=    Run and Return Rc and Output    ${VOLTCTL_CONFIG}; voltctl device flows ${device_id} -o json
     Should Be Equal As Integers    ${rc}    0
@@ -217,22 +217,24 @@
     Log    ${jsondata}
     ${length}=    Get Length    ${jsondata}
     Log    'Number of flows = ' ${length}
-    Run Keyword If    '${test}' == '${EMPTY}'    Should Be True    ${length} > 0
+    Run Keyword If    '${flow_count}' == '${EMPTY}'    Should Be True    ${length} > 0
     ...    Number of flows for ${device_id} was 0
-    ...    ELSE    Should Be True    ${length} == ${test}
-    ...    Number of flows for ${device_id} was not ${test}
+    ...    ELSE    Should Be True    ${length} == ${flow_count}
+    ...    Number of flows for ${device_id} was not ${flow_count}
 
 Validate OLT Flows
-    [Documentation]    Parses the output of voltctl device flows ${olt_device_id} and expects flow count > 0
-    Validate Device Flows    ${olt_device_id}
+    [Arguments]    ${flow_count}=${EMPTY}
+    [Documentation]    Parses the output of voltctl device flows ${olt_device_id}
+    ...    and expects flow count == ${flow_count}
+    Validate Device Flows    ${olt_device_id}    ${flow_count}
 
 Validate ONU Flows
-    [Arguments]    ${List_ONU_Serial}    ${test}
+    [Arguments]    ${List_ONU_Serial}    ${flow_count}=${EMPTY}
     [Documentation]    Parses the output of voltctl device flows for each ONU SN listed in ${List_ONU_Serial}
-    ...    and expects flow count == 0
+    ...    and expects flow count == ${flow_count}
     FOR    ${serial_number}    IN    @{List_ONU_Serial}
         ${onu_dev_id}=    Get Device ID From SN    ${serial_number}
-        Validate Device Flows    ${onu_dev_id}    ${test}
+        Validate Device Flows    ${onu_dev_id}    ${flow_count}
     END
 
 Validate Logical Device