[SEBA-279] More ATT workflow test scenarios

Change-Id: I077259f02f271217437977cc7806a342c90e6fc3
diff --git a/Jenkinsfile-attworkflow-test b/Jenkinsfile-attworkflow-test
index a634e38..6e04f98 100644
--- a/Jenkinsfile-attworkflow-test
+++ b/Jenkinsfile-attworkflow-test
@@ -47,7 +47,7 @@
                     sh """
                     export KUBECONFIG=$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf
                     cd $WORKSPACE/cord-tester/src/test/cord-api/Tests/
-                    pybot -d Log -T -l log-ATT_Test001 -v src_ip:${deployment_config.hosts.src.ip} -v src_gateway:${deployment_config.hosts.src.dp_iface_gateway} -v src_user:${deployment_config.hosts.src.user} -v src_pass:${deployment_config.hosts.src.pass} -v src_iface:${deployment_config.hosts.src.dp_iface_name} -v dst_ip:${deployment_config.hosts.dst.ip} -v dst_user:${deployment_config.hosts.dst.user} -v dst_pass:${deployment_config.hosts.dst.pass} -v dst_gateway:${deployment_config.hosts.dst.dp_iface_gateway} -v dst_dp_iface:${deployment_config.hosts.dst.dp_iface_name} -v dst_dp_ip:${deployment_config.hosts.dst.dp_iface_ip_qinq} WorkflowValidations/ATT_Test001.txt || true
+                    pybot -d Log -T -l log-ATT_Test001 -v src_ip:${deployment_config.hosts.src.ip} -v src_gateway:${deployment_config.hosts.src.dp_iface_gateway} -v src_user:${deployment_config.hosts.src.user} -v src_pass:${deployment_config.hosts.src.pass} -v src_iface:${deployment_config.hosts.src.dp_iface_name} -v dst_ip:${deployment_config.hosts.dst.ip} -v dst_user:${deployment_config.hosts.dst.user} -v dst_pass:${deployment_config.hosts.dst.pass} -v dst_gateway:${deployment_config.hosts.dst.dp_iface_gateway} -v dst_dp_iface:${deployment_config.hosts.dst.dp_iface_name} -v dst_dp_ip:${deployment_config.hosts.dst.dp_iface_ip_qinq} -v olt_ip:${deployment_config.olts[0].ip} -v olt_user:${deployment_config.olts[0].user} -v olt_pass:${deployment_config.olts[0].pass} -v kubernetes_conf:$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf -v kubernetes_yml:$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.yml WorkflowValidations/ATT_Test001.txt || true
                     """
                 }
             }
diff --git a/src/test/cord-api/Framework/DHCP.robot b/src/test/cord-api/Framework/DHCP.robot
index 67525e6..979048e 100644
--- a/src/test/cord-api/Framework/DHCP.robot
+++ b/src/test/cord-api/Framework/DHCP.robot
@@ -43,8 +43,9 @@
     SSHLibrary.Close Connection
     [Return]    ${result}
 
-IPv4 Address Assigned to DHCP Client
-    [Arguments]    ${ip}    ${user}    ${pass}    ${iface}
+Check IPv4 Address on DHCP Client
+    [Arguments]    ${ip_should_exist}    ${ip}    ${user}    ${pass}    ${iface}
     [Documentation]    Check if the sepcified interface has an IPv4 address assigned
     ${output}=    Run Command On Remote System    ${ip}    ifconfig ${iface}    ${user}    ${pass}
-    Should Match Regexp    ${output}    \\b([0-9]{1,3}\\.){3}[0-9]{1,3}\\b
+    Run Keyword If    '${ip_should_exist}' == 'True'    Should Match Regexp    ${output}    \\b([0-9]{1,3}\\.){3}[0-9]{1,3}\\b
+    Run Keyword If    '${ip_should_exist}' == 'False'    Should Not Match Regexp    ${output}    \\b([0-9]{1,3}\\.){3}[0-9]{1,3}\\b
diff --git a/src/test/cord-api/Framework/Kubernetes.robot b/src/test/cord-api/Framework/Kubernetes.robot
new file mode 100644
index 0000000..41af2c5
--- /dev/null
+++ b/src/test/cord-api/Framework/Kubernetes.robot
@@ -0,0 +1,45 @@
+# Copyright 2017-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.
+
+*** Settings ***
+Documentation     Library of functions related to kubectl and helm
+Library           SSHLibrary
+Library           Collections
+Library           String
+Library           OperatingSystem
+Library           RequestsLibrary
+Library           utils/utils.py
+Library           restApi.py
+
+*** Keywords ***
+Helm Chart is Removed
+    [Arguments]    ${kubernetes_conf}    ${helm_chart}
+    [Documentation]    Verify the specified helm chart has been removed
+    Run    export KUBECONFIG=${kubernetes_conf}
+    ${rc}=    Run And Return Rc    helm ls -q | grep ${helm_chart}
+    Should Be Equal As Integers    ${rc}    1
+
+Kubernetes PODs in Namespace are Removed
+    [Arguments]    ${kubernetes_conf}    ${namespace}
+    [Documentation]    Verify all Kubernetes pods in specified namespace have been removed
+    Run    export KUBECONFIG=${kubernetes_conf}
+    ${rc}    ${output}=    Run And Return Rc And Output    kubectl get pods --no-headers -n ${namespace}
+    Should Contain    ${output}    No resources found
+
+Kubernetes PODs in Namespace are Running
+    [Arguments]    ${kubernetes_conf}    ${namespace}    ${pod_num}
+    [Documentation]    Verify the number of Kubernetes pods that are running in specified namespace is as expected
+    Run    export KUBECONFIG=${kubernetes_conf}
+    ${rc}    ${output}=    Run And Return Rc And Output    kubectl get pods -n ${namespace} | grep -i running | grep 1/1 | wc -l
+    Should Be Equal As Integers    ${output}    ${pod_num}
diff --git a/src/test/cord-api/Framework/OLT.robot b/src/test/cord-api/Framework/OLT.robot
new file mode 100644
index 0000000..394b4a2
--- /dev/null
+++ b/src/test/cord-api/Framework/OLT.robot
@@ -0,0 +1,32 @@
+# Copyright 2017-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.
+
+*** Settings ***
+Documentation     Library of functions related to OLT
+Library           SSHLibrary
+Library           Collections
+Library           String
+Library           OperatingSystem
+Library           RequestsLibrary
+Library           utils/utils.py
+Library           restApi.py
+
+*** Keywords ***
+Openolt is Up
+    [Arguments]    ${ip}    ${user}    ${pass}    ${prompt}=\#    ${prompt_timeout}=60s
+    [Documentation]    Verify that openolt process is started and ready to connect to voltha
+    ${conn_id}=    SSHLibrary.Open Connection    ${ip}    prompt=${prompt}    timeout=${prompt_timeout}
+    SSHLibrary.Login    ${user}    ${pass}
+    Check Remote File Contents    True    ${conn_id}    /var/log/    openolt.log    oper_state: up
+    SSHLibrary.Close Connection
diff --git a/src/test/cord-api/Framework/ONU.robot b/src/test/cord-api/Framework/ONU.robot
index 1b9c278..e00c9ea 100644
--- a/src/test/cord-api/Framework/ONU.robot
+++ b/src/test/cord-api/Framework/ONU.robot
@@ -1,3 +1,17 @@
+# Copyright 2017-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.
+
 *** Settings ***
 Documentation     Library to check the status in ONU List
 Library           Collections
diff --git a/src/test/cord-api/Framework/Subscriber.robot b/src/test/cord-api/Framework/Subscriber.robot
index c925675..b884075 100644
--- a/src/test/cord-api/Framework/Subscriber.robot
+++ b/src/test/cord-api/Framework/Subscriber.robot
@@ -21,15 +21,16 @@
 
 *** Keywords ***
 Send EAPOL Message
-    [Arguments]    ${ip}    ${user}    ${pass}    ${iface}    ${conf_file}    ${prompt}=$    ${prompt_timeout}=60s
+    [Arguments]    ${auth_pass}    ${ip}    ${user}    ${pass}    ${iface}    ${conf_file}    ${prompt}=$    ${prompt_timeout}=60s
     [Documentation]    SSH's into the RG (src) and executes a particular auth request via wpa_supplicant client. Requested packet should exist on src.
     ${conn_id}=    SSHLibrary.Open Connection    ${ip}    prompt=${prompt}    timeout=${prompt_timeout}
     SSHLibrary.Login    ${user}    ${pass}
-    SSHLibrary.Write    rm -f wpa.log
-    SSHLibrary.Write    sudo wpa_supplicant -B -i ${iface} -Dwired -c /etc/wpa_supplicant/${conf_file} -f wpa.log
+    SSHLibrary.Write    sudo rm -f /tmp/wpa.log; sudo wpa_supplicant -B -i ${iface} -Dwired -c /etc/wpa_supplicant/${conf_file} -f /tmp/wpa.log
     Read Until    [sudo] password for ${user}:
     SSHLibrary.Write    ${pass}
-    Wait Until Keyword Succeeds    30s    2s    Remote File Should Contain    ${conn_id}    wpa.log    authentication completed successfully
+    Run Keyword If    '${auth_pass}' == 'True'    Wait Until Keyword Succeeds    30s    2s    Check Remote File Contents    True    ${conn_id}    /tmp/    wpa.log    authentication completed successfully
+    Run Keyword If    '${auth_pass}' == 'False'    Sleep    10s
+    Run Keyword If    '${auth_pass}' == 'False'    Check Remote File Contents    False    ${conn_id}    /tmp/    wpa.log    authentication completed successfully
     SSHLibrary.Close Connection
 
 Delete IP Addresses from Interface on Remote Host
diff --git a/src/test/cord-api/Framework/utils/utils.robot b/src/test/cord-api/Framework/utils/utils.robot
index c9e3c79..cf8a771 100644
--- a/src/test/cord-api/Framework/utils/utils.robot
+++ b/src/test/cord-api/Framework/utils/utils.robot
@@ -204,9 +204,21 @@
     ${rc}=    Run Sudo Command On Remote System    ${ip}    sudo kill $(ps aux | grep '${process}' | awk '{print $2}'); echo $?    ${user}    ${pass}
     Should Contain    ${rc}    0
 
-Remote File Should Contain
-    [Arguments]    ${conn_id}    ${file_name}    ${pattern}
+Check Remote File Contents
+    [Arguments]    ${file_should_exist}    ${conn_id}    ${file_path}    ${file_name}    ${pattern}
     SSHLibrary.Switch Connection    ${conn_id}
-    SSHLibrary.Get File    ${file_name}    /tmp/
-    ${content}=    OperatingSystem.Get File    /tmp/${file_name}
-    Should Contain    ${content}    ${pattern}
+    SSHLibrary.Get File    ${file_path}${file_name}    /tmp/
+    ${content}=    OperatingSystem.Get File    /tmp/${file_name}    encoding_errors=ignore
+    Run Keyword If    '${file_should_exist}' == 'True'    Should Contain    ${content}    ${pattern}
+    Run Keyword If    '${file_should_exist}' == 'False'    Should Not Contain    ${content}    ${pattern}
+
+Check Remote System Reachability
+    [Arguments]    ${reachable}    ${ip}    ${prompt}=$    ${prompt_timeout}=60s
+    [Documentation]    Check if the specified IP address is reachable or not
+    ${result}=    Run    ping -c 3 -t 3 ${ip}
+    Log    ${result}
+    Run Keyword If    '${reachable}' == 'True'    Should Contain    ${result}    64 bytes
+    Run Keyword If    '${reachable}' == 'True'    Should Contain Any   ${result}    0% packet loss    0.0% packet loss
+    Run Keyword If    '${reachable}' == 'True'    Should Not Contain Any    ${result}    100% packet loss    100.0% packet loss
+    Run Keyword If    '${reachable}' == 'False'    Should Not Contain    ${result}    64 bytes
+    Run Keyword If    '${reachable}' == 'False'    Should Contain Any    ${result}    100% packet loss    100.0% packet loss
diff --git a/src/test/cord-api/Tests/WorkflowValidations/ATT_Test001.txt b/src/test/cord-api/Tests/WorkflowValidations/ATT_Test001.txt
index 154b03c..26de0d3 100644
--- a/src/test/cord-api/Tests/WorkflowValidations/ATT_Test001.txt
+++ b/src/test/cord-api/Tests/WorkflowValidations/ATT_Test001.txt
@@ -28,7 +28,9 @@
 Library           ../../Framework/restApi.py
 Resource          ../../Framework/Subscriber.robot
 Resource          ../../Framework/ATTWorkFlowDriver.robot
+Resource          ../../Framework/Kubernetes.robot
 Resource          ../../Framework/ONU.robot
+Resource          ../../Framework/OLT.robot
 Resource          ../../Framework/DHCP.robot
 Variables         ../../Properties/RestApiProperties.py
 
@@ -47,6 +49,13 @@
 ${dst_user}        user
 ${dst_pass}        pass
 ${dst_gateway}     X.X.X.X
+${olt_ip}          X.X.X.X
+${olt_user}          user
+${olt_pass}          pass
+${kubernetes_conf}    x.conf
+${kubernetes_yml}    x.yml
+${helm_dir}    ~/helm-charts
+${voltha_pod_num}    8
 
 *** Test Cases ***
 ONU in Correct Location + Successful Auth Request
@@ -57,18 +66,46 @@
     ...    Configuration of source server interface and execute dhclient on interface
     ...    Validate successful pings from src to dst
     [Setup]    None
-    Wait Until Keyword Succeeds    60s    2s    Validate ONU States    ACTIVE    ENABLED
+    Wait Until Keyword Succeeds    120s    2s    Validate ONU States    ACTIVE    ENABLED
     Wait Until Keyword Succeeds    60s    2s    Validate ATT Workflow Driver SI    ENABLED    AWAITING
     Wait Until Keyword Succeeds    60s    2s    Validate Subscriber Status    awaiting-auth
-    Send EAPOL Message    ${src_ip}    ${src_user}    ${src_pass}    ${src_iface}    wpa_supplicant.conf
+    Send EAPOL Message    True    ${src_ip}    ${src_user}    ${src_pass}    ${src_iface}    wpa_supplicant.conf
     Wait Until Keyword Succeeds    60s    2s    Validate ATT Workflow Driver SI    ENABLED    APPROVED
     Wait Until Keyword Succeeds    60s    2s    Validate Subscriber Status    enabled
-    Add Double Vlan Interface on Host    ${dst_ip}    ${dst_user}    ${dst_pass}    ${dst_dp_iface}    ${s_tag}    ${c_tag}
-    Add IP Address on Interface on Host    ${dst_ip}    ${dst_user}    ${dst_pass}    ${dst_dp_ip}/24    ${dst_dp_iface}.${stag}.${c_tag}
-    Start DHCP Server on Remote Host    ${dst_ip}    ${dst_user}    ${dst_pass}    ${dst_dp_iface}.${stag}.${ctag}
-    Send Dhclient Request    ${src_ip}    ${src_user}    ${src_pass}    ${src_iface}
-    Wait Until Keyword Succeeds    60s    5s    IPv4 Address Assigned to DHCP Client    ${src_ip}    ${src_user}    ${src_pass}    ${src_iface}
-    Wait Until Keyword Succeeds    60s    5s    Test Ping    PASS    ${src_ip}    ${src_user}    ${src_pass}    ${dst_dp_ip}    ${src_iface}
+    Validate DHCP and Ping    True    True
+
+ONU in Correct Location + Skip Auth
+    [Documentation]    Validates E2E Ping Connectivity and object states for the given scenario:
+    ...    Discovery of ONU Device after whitelist has been configured
+    ...    Configuration of the destination servers interface and start dhcpd
+    ...    Configuration of source server interface and execute dhclient on interface
+    ...    Validate failed DHCP and pings from src to dst
+    Wait Until Keyword Succeeds    120s    2s    Validate ONU States    ACTIVE    ENABLED
+    Wait Until Keyword Succeeds    60s    2s    Validate ATT Workflow Driver SI    ENABLED    AWAITING
+    Wait Until Keyword Succeeds    60s    2s    Validate Subscriber Status    awaiting-auth
+    Validate DHCP and Ping    False    False
+
+ONU not in Whitelist + Failed Auth Request
+    [Documentation]    Validates E2E Ping Connectivity and object states for the given scenario:
+    ...    Discovery of ONU Device that is not in the whitelist
+    ...    Sending a 802.1x auth request
+    ...    Configuration of the destination servers interface and start dhcpd
+    ...    Configuration of source server interface and execute dhclient on interface
+    ...    Validate failed DHCP and pings from src to dst
+    [Setup]    None
+    ${SubscriberList} =    Get Variable Value    ${slist}
+    ${SubscriberDict}=    utils.listToDict    ${SubscriberList}    0
+    Wait Until Keyword Succeeds    120s    15s    CORD Post    ${VOLT_SUBSCRIBER}    ${SubscriberDict}
+    ${VoltDeviceList} =    Get Variable Value    ${vlist}
+    ${VoltDeviceDict}=    utils.listToDict    ${VoltDeviceList}    0
+    CORD Post    ${VOLT_DEVICE}    ${VoltDeviceDict}
+    Wait Until Keyword Succeeds    120s    2s    Validate ONU States    UNKNOWN    DISABLED
+    Wait Until Keyword Succeeds    60s    2s    Validate ATT Workflow Driver SI    DISABLED    AWAITING
+    Wait Until Keyword Succeeds    60s    2s    Validate Subscriber Status    awaiting-auth
+    Send EAPOL Message    False    ${src_ip}    ${src_user}    ${src_pass}    ${src_iface}    wpa_supplicant.conf
+    Wait Until Keyword Succeeds    60s    2s    Validate ATT Workflow Driver SI    DISABLED    AWAITING
+    Wait Until Keyword Succeeds    60s    2s    Validate Subscriber Status    awaiting-auth
+    Validate DHCP and Ping    False    False
 
 *** Keywords ***
 Setup
@@ -123,10 +160,14 @@
     Run Keyword And Ignore Error    Kill Linux Process    ${src_ip}    ${src_user}    ${src_pass}    [d]hclient
     Run Keyword And Ignore Error    Kill Linux Process    ${dst_ip}    ${dst_user}    ${dst_pass}    [d]hcpd
     Delete IP Addresses from Interface on Remote Host    ${src_ip}    ${src_user}    ${src_pass}    ${src_iface}
-    Delete Interface on Remote Host    ${dst_ip}    ${dst_user}    ${dst_pass}    ${dst_dp_iface}.${stag}
+    Delete Interface on Remote Host    ${dst_ip}    ${dst_user}    ${dst_pass}    ${dst_dp_iface}.${s_tag}
     Wait Until Keyword Succeeds    60s    2s    Clean Up Objects   ${VOLT_SUBSCRIBER}
     Wait Until Keyword Succeeds    60s    2s    Clean Up Objects   ${VOLT_DEVICE}
     Wait Until Keyword Succeeds    60s    2s    Clean Up Objects   ${ATT_WHITELIST}
+    Wait Until Keyword Succeeds    120s    10s    Check Remote System Reachability    False    ${olt_ip}
+    Wait Until Keyword Succeeds    120s    10s    Check Remote System Reachability    True    ${olt_ip}
+    Wait Until Keyword Succeeds    120s    10s    Openolt is Up    ${olt_ip}    ${olt_user}    ${olt_pass}
+    Wait Until Keyword Succeeds    300s    10s    Reinstall Voltha
 
 Validate ONU States
     [Arguments]    ${expected_op_status}    ${expected_admin_status}
@@ -144,3 +185,25 @@
     [Arguments]    ${exepected_status}
     ${status}    Subscriber Status Check    ${onu_device}
     Should Be Equal    ${status}    ${exepected_status}
+
+Validate DHCP and Ping
+    [Arguments]    ${dhcp_pass}    ${ping_pass}
+    Add Double Vlan Interface on Host    ${dst_ip}    ${dst_user}    ${dst_pass}    ${dst_dp_iface}    ${s_tag}    ${c_tag}
+    Add IP Address on Interface on Host    ${dst_ip}    ${dst_user}    ${dst_pass}    ${dst_dp_ip}/24    ${dst_dp_iface}.${s_tag}.${c_tag}
+    Start DHCP Server on Remote Host    ${dst_ip}    ${dst_user}    ${dst_pass}    ${dst_dp_iface}.${s_tag}.${c_tag}
+    Send Dhclient Request    ${src_ip}    ${src_user}    ${src_pass}    ${src_iface}
+    Run Keyword If    '${dhcp_pass}' == 'True'    Wait Until Keyword Succeeds    60s    5s    Check IPv4 Address on DHCP Client    True    ${src_ip}    ${src_user}    ${src_pass}    ${src_iface}
+    Run Keyword If    '${dhcp_pass}' == 'False'    Sleep    10s
+    Run Keyword If    '${dhcp_pass}' == 'False'    Check IPv4 Address on DHCP Client    False    ${src_ip}    ${src_user}    ${src_pass}    ${src_iface}
+    Run Keyword If    '${ping_pass}' == 'True'    Wait Until Keyword Succeeds    60s    5s    Test Ping    PASS    ${src_ip}    ${src_user}    ${src_pass}    ${dst_dp_ip}    ${src_iface}
+    Run Keyword If    '${ping_pass}' == 'False'    Wait Until Keyword Succeeds    60s    5s    Test Ping    FAIL    ${src_ip}    ${src_user}    ${src_pass}    ${dst_dp_ip}    ${src_iface}
+
+Reinstall Voltha
+    Run    export KUBECONFIG=${kubernetes_conf}
+    Run    helm delete --purge voltha
+    Wait Until Keyword Succeeds    60s    10s    Helm Chart is Removed    ${kubernetes_conf}    voltha
+    Wait Until Keyword Succeeds    120s    10s    Kubernetes PODs in Namespace are Removed    ${kubernetes_conf}    voltha
+    ${rc}    ${output}=    Run And Return Rc And Output    helm install -n voltha -f ${kubernetes_yml} --set etcd-operator.customResources.createEtcdClusterCRD=false ${helm_dir}/voltha
+    ${rc}    ${output}=    Run And Return Rc And Output    helm upgrade -f ${kubernetes_yml} --set etcd-operator.customResources.createEtcdClusterCRD=true voltha ${helm_dir}/voltha
+    Wait Until Keyword Succeeds    30s    5s    Kubernetes PODs in Namespace are Running    ${kubernetes_conf}    voltha    ${voltha_pod_num}
+    Sleep    10s