VOL-2042 Unify tests for BBSim and physical pod

Change-Id: Ia5aed704281c20742e3a9a78894da3d739aabf57
diff --git a/tests/data/bbsim-kind.yaml b/tests/data/bbsim-kind.yaml
new file mode 100644
index 0000000..f88bca9
--- /dev/null
+++ b/tests/data/bbsim-kind.yaml
@@ -0,0 +1,78 @@
+---
+
+# 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.
+
+# Automated deployment configuration for kind-voltha running BBSim
+
+# Change default values in tests
+has_dataplane: False
+external_libs: False
+teardown_device: True
+ports_per_onu: 4
+ONOS_REST_PORT: 8181
+ONOS_SSH_PORT: 8101
+OLT_PORT: 50060
+
+nodes:
+  -
+    ip: '127.0.0.1'
+    user: null
+    pass: null
+
+fabric_switches:
+  -
+    mac: null
+    ip: null
+    user: null
+    pass: null
+    bngPort: null
+    oltPort: null
+    device_id: null
+
+olts:
+  -
+    ip: bbsim.voltha.svc
+    user: null
+    pass: null
+    fortygig: null
+    serial: BBSIM_OLT_0
+
+onus:
+  -
+    serial: 'BBSM00000001'
+
+hosts:
+  src:
+    -
+      ip: null
+      pass: null
+      dp_iface_name: null
+      container_type: null
+      container_name: null
+      onu: null
+      c_tag: null
+      s_tag: null
+
+  dst:
+    -
+      ip: null
+      user: null
+      pass: null
+      dp_iface_name: null
+      dp_iface_ip_qinq: null
+      dp_iface_ip: null
+      dp_iface_gateway: null
+      container_type: null
+      container_name: null
\ No newline at end of file
diff --git a/tests/functional/Voltha_PODTests.robot b/tests/functional/Voltha_PODTests.robot
index 612bb18..e871079 100644
--- a/tests/functional/Voltha_PODTests.robot
+++ b/tests/functional/Voltha_PODTests.robot
@@ -19,19 +19,17 @@
 Suite Setup       Setup Suite
 Test Setup        Setup
 Test Teardown     Teardown
+Suite Teardown    Teardown Suite
 Library           Collections
 Library           String
 Library           OperatingSystem
 Library           XML
 Library           RequestsLibrary
-Library           ../../../voltha/tests/atests/common/testCaseUtils.py
-Resource          ../../../cord-tester/src/test/cord-api/Framework/Subscriber.robot
-Resource          ../../../cord-tester/src/test/cord-api/Framework/OLT.robot
-Resource          ../../../cord-tester/src/test/cord-api/Framework/DHCP.robot
-Resource          ../../../cord-tester/src/test/cord-api/Framework/Kubernetes.robot
+Library           ../../libraries/DependencyLibrary.py
 Resource          ../../libraries/onos.robot
 Resource          ../../libraries/voltctl.robot
 Resource          ../../libraries/utils.robot
+Resource          ../../libraries/k8s.robot
 Resource          ../../variables/variables.robot
 
 *** Variables ***
@@ -42,38 +40,50 @@
 ${KUBERNETES_YAML}    ${KUBERNETES_CONFIGS_DIR}/${POD_NAME}.yml
 ${HELM_CHARTS_DIR}    ~/helm-charts
 ${VOLTHA_POD_NUM}    8
-${timeout}        90s
+${timeout}        60s
 ${num_onus}       1
 ${of_id}          0
 ${logical_id}     0
+${ports_per_onu}    5
+${has_dataplane}    True
+${external_libs}    True
+${teardown_device}    False
 
 *** Test Cases ***
 Sanity E2E Test for OLT/ONU on POD
     [Documentation]    Validates E2E Ping Connectivity and object states for the given scenario:
     ...    Validate successful authentication/DHCP/E2E ping for the tech profile that is used
-    [Tags]    test1
+    [Tags]    sanity    test1
     #[Setup]    Clean Up Linux
-    ${of_id}=    Wait Until Keyword Succeeds    60s    15s    Validate OLT Device in ONOS    ${olt_serial_number}
-    #Wait Until Keyword Succeeds    60s    2s    Verify Eapol Flows Added    ${k8s_node_ip}    ${ONOS_SSH_PORT}    5
-    Validate Authentication    True    ${src0['dp_iface_name']}    wpa_supplicant.conf    ${src0['ip']}    ${src0['user']}    ${src0['pass']}
+    ${of_id}=    Wait Until Keyword Succeeds    ${timeout}    15s    Validate OLT Device in ONOS    ${olt_serial_number}
+    Set Global Variable    ${of_id}
+    ${num_flows}=    Evaluate    ${num_onus} * ${ports_per_onu}
+    ${flows_str}=    Convert To String    ${num_flows}
+    Wait Until Keyword Succeeds    ${timeout}    2s    Verify Eapol Flows Added    ${k8s_node_ip}    ${ONOS_SSH_PORT}    ${flows_str}
+    Run Keyword If    ${has_dataplane}    Validate Authentication    True    ${src0['dp_iface_name']}
+    ...    wpa_supplicant.conf    ${src0['ip']}    ${src0['user']}    ${src0['pass']}
     ...    ${src0['container_type']}    ${src0['container_name']}
-    #Validate ONU authenticated in ONOS
-    #Wait Until Keyword Succeeds    90s    2s    Verify Number of AAA-Users    ${k8s_node_ip}    ${ONOS_SSH_PORT}    ${num_onus}
-    ${onu_port}=    Wait Until Keyword Succeeds    90s    2s    Get ONU Port in ONOS    ${onu_serial_number}   ${of_id}
-    Wait Until Keyword Succeeds    60s    2s    Execute ONOS Command    ${k8s_node_ip}    ${ONOS_SSH_PORT}    volt-add-subscriber-access ${of_id} ${onu_port}
-    # Perform dhclient and ping operations
-    Validate DHCP and Ping    True    True    ${src0['dp_iface_name']}    ${src0['s_tag']}    ${src0['c_tag']}    ${dst0['dp_iface_ip_qinq']}
-    ...    ${src0['ip']}    ${src0['user']}    ${src0['pass']}    ${src0['container_type']}    ${src0['container_name']}    ${dst0['dp_iface_name']}
+    Wait Until Keyword Succeeds    ${timeout}    2s    Verify Number of AAA-Users    ${k8s_node_ip}    ${ONOS_SSH_PORT}    ${num_onus}
+    ${onu_port}=    Wait Until Keyword Succeeds    ${timeout}    2s    Get ONU Port in ONOS    ${onu_serial_number}   ${of_id}
+    Wait Until Keyword Succeeds    ${timeout}    2s    Execute ONOS CLI Command    ${k8s_node_ip}    ${ONOS_SSH_PORT}
+    ...    volt-add-subscriber-access ${of_id} ${onu_port}
+    Run Keyword If    ${has_dataplane}    Validate DHCP and Ping    True    True    ${src0['dp_iface_name']}
+    ...    ${src0['s_tag']}    ${src0['c_tag']}    ${dst0['dp_iface_ip_qinq']}    ${src0['ip']}    ${src0['user']}
+    ...    ${src0['pass']}    ${src0['container_type']}    ${src0['container_name']}    ${dst0['dp_iface_name']}
     ...    ${dst0['ip']}    ${dst0['user']}    ${dst0['pass']}    ${dst0['container_type']}    ${dst0['container_name']}
-    #Validate DHCP allocation in ONOS
-    Wait Until Keyword Succeeds    60s    2s    Validate DHCP Allocations    ${k8s_node_ip}    ${ONOS_SSH_PORT}    ${num_onus}
+    Wait Until Keyword Succeeds    ${timeout}    2s    Validate DHCP Allocations    ${k8s_node_ip}    ${ONOS_SSH_PORT}    ${num_onus}
 
 *** Keywords ***
 Setup Suite
     [Documentation]    Setup the whole test suite
+    # BBSim sanity test doesn't need these imports from other repositories
+    Run Keyword If    ${external_libs}    Import Library    ${CURDIR}/../../../voltha/tests/atests/common/testCaseUtils.py
+    Run Keyword If    ${external_libs}    Import Resource    ${CURDIR}/../../../cord-tester/src/test/cord-api/Framework/Subscriber.robot
+    Run Keyword If    ${external_libs}    Import Resource    ${CURDIR}/../../../cord-tester/src/test/cord-api/Framework/OLT.robot
+    Run Keyword If    ${external_libs}    Import Resource    ${CURDIR}/../../../cord-tester/src/test/cord-api/Framework/DHCP.robot
+    Run Keyword If    ${external_libs}    Import Resource    ${CURDIR}/../../../cord-tester/src/test/cord-api/Framework/Kubernetes.robot
     Set Global Variable    ${KUBECTL_CONFIG}    export KUBECONFIG=%{KUBECONFIG}
     Set Global Variable    ${export_kubeconfig}    export KUBECONFIG=${KUBERNETES_CONF}
-    Set Global Variable    ${of_id}
     Set Global Variable    ${VOLTCTL_CONFIG}    export VOLTCONFIG=%{VOLTCONFIG}
     ${k8s_node_ip}=    Evaluate    ${nodes}[0].get("ip")
     ${k8s_node_user}=    Evaluate    ${nodes}[0].get("user")
@@ -105,24 +115,23 @@
     Append To List    ${container_list}    voltha-rw-core-12
     Append To List    ${container_list}    voltha-ofagent
     Set Suite Variable    ${container_list}
-    Set Deployment Config Variables
-    ${datetime}=    Get Current Datetime On Kubernetes Node    ${k8s_node_ip}    ${k8s_node_user}    ${k8s_node_pass}
+    # Set Deployment Config Variables seems like a candidate for refactoring.
+    # BBSim doesn't need it right now.
+    Run Keyword If    ${external_libs}    Set Deployment Config Variables
+    ${datetime}=    Get Current Date
     Set Suite Variable    ${datetime}
 
+
 Setup
     [Documentation]    Pre-test Setup
     #create/preprovision device
     ${olt_device_id}=    Create Device    ${olt_ip}    ${OLT_PORT}
     Set Suite Variable    ${olt_device_id}
-    #enable device
     Enable Device    ${olt_device_id}
-    #validate olt states
-    Wait Until Keyword Succeeds    60s    5s    Validate Device    ${olt_serial_number}    ENABLED    ACTIVE
+    Wait Until Keyword Succeeds    ${timeout}    5s    Validate Device    ${olt_serial_number}    ENABLED    ACTIVE
     ...    REACHABLE
-    #validate onu states
-    Wait Until Keyword Succeeds    60s    5s    Validate Device    ${onu_serial_number}    ENABLED    ACTIVE
+    Wait Until Keyword Succeeds    ${timeout}    5s    Validate Device    ${onu_serial_number}    ENABLED    ACTIVE
     ...    REACHABLE    onu=True    onu_reason=tech-profile-config-download-success
-    #get onu device id
     ${onu_device_id}=    Get Device ID From SN    ${onu_serial_number}
     Set Suite Variable    ${onu_device_id}
     ${logical_id}=    Get Logical Device ID From SN    ${olt_serial_number}
@@ -132,18 +141,44 @@
     [Documentation]    kills processes and cleans up interfaces on src+dst servers
     Get Device Output from Voltha    ${olt_device_id}
     #Get Logical Device Output from Voltha    ${logical_id}
-    Get ONOS Status    ${k8s_node_ip}
-    Clean Up Linux
-    Log Kubernetes Containers Logs Since Time    ${datetime}    ${container_list}
+    Run Keyword If    ${external_libs}    Get ONOS Status    ${k8s_node_ip}
+    Run Keyword If    ${has_dataplane}    Clean Up Linux
+    Run Keyword If    ${external_libs}    Log Kubernetes Containers Logs Since Time    ${datetime}    ${container_list}
+
+Teardown Suite
+    [Documentation]    Clean up device if desired
+    Run Keyword If    ${teardown_device}    Delete Device and Verify
+    Run Keyword If    ${teardown_device}    Execute ONOS CLI Command    ${k8s_node_ip}    ${ONOS_SSH_PORT}
+    ...    device-remove ${of_id}
 
 Clean Up Linux
     [Documentation]    Kill processes and clean up interfaces on src+dst servers
-    Run Keyword And Ignore Error    Kill Linux Process    [w]pa_supplicant    ${src0['ip']}    ${src0['user']}    ${src0['pass']}    ${src0['container_type']}
-    ...    ${src0['container_name']}
-    Run Keyword And Ignore Error    Kill Linux Process    [d]hclient    ${src0['ip']}    ${src0['user']}    ${src0['pass']}    ${src0['container_type']}
-    ...    ${src0['container_name']}
-    Run Keyword If    '${dst0['ip']}' != '${None}'    Run Keyword And Ignore Error    Kill Linux Process    [d]hcpd    ${dst0['ip']}    ${dst0['user']}
+    Run Keyword And Ignore Error    Kill Linux Process    [w]pa_supplicant    ${src0['ip']}
+    ...    ${src0['user']}    ${src0['pass']}    ${src0['container_type']}    ${src0['container_name']}
+    Run Keyword And Ignore Error    Kill Linux Process    [d]hclient    ${src0['ip']}
+    ...    ${src0['user']}    ${src0['pass']}    ${src0['container_type']}    ${src0['container_name']}
+    Run Keyword If    '${dst0['ip']}' != '${None}'    Run Keyword And Ignore Error
+    ...    Kill Linux Process    [d]hcpd    ${dst0['ip']}    ${dst0['user']}
     ...    ${dst0['pass']}    ${dst0['container_type']}    ${dst0['container_name']}
-    Delete IP Addresses from Interface on Remote Host    ${src0['dp_iface_name']}    ${src0['ip']}    ${src0['user']}    ${src0['pass']}    ${src0['container_type']}    ${src0['container_name']}
-    Run Keyword If    '${dst0['ip']}' != '${None}'    Delete Interface on Remote Host    ${dst0['dp_iface_name']}.${src0['s_tag']}    ${dst0['ip']}    ${dst0['user']}    ${dst0['pass']}
+    Delete IP Addresses from Interface on Remote Host    ${src0['dp_iface_name']}    ${src0['ip']}
+    ...    ${src0['user']}    ${src0['pass']}    ${src0['container_type']}    ${src0['container_name']}
+    Run Keyword If    '${dst0['ip']}' != '${None}'    Delete Interface on Remote Host
+    ...    ${dst0['dp_iface_name']}.${src0['s_tag']}    ${dst0['ip']}    ${dst0['user']}    ${dst0['pass']}
     ...    ${dst0['container_type']}    ${dst0['container_name']}
+
+Delete Device and Verify
+    [Documentation]    Disable -> Delete devices via voltctl and verify its removed
+    ${rc}    ${output}=    Run and Return Rc and Output    ${VOLTCTL_CONFIG}; voltctl device disable ${onu_device_id}
+    Should Be Equal As Integers    ${rc}    0
+    Wait Until Keyword Succeeds    ${timeout}    5s    Validate Device    ${onu_serial_number}    DISABLED    UNKNOWN
+    ...    REACHABLE
+    ${rc}    ${output}=    Run and Return Rc and Output    ${VOLTCTL_CONFIG}; voltctl device delete ${onu_device_id}
+    Should Be Equal As Integers    ${rc}    0
+    Wait Until Keyword Succeeds    ${timeout}    5s    Validate Device Removed    ${onu_device_id}
+    ${rc}    ${output}=    Run and Return Rc and Output    ${VOLTCTL_CONFIG}; voltctl device disable ${olt_device_id}
+    Should Be Equal As Integers    ${rc}    0
+    Wait Until Keyword Succeeds    ${timeout}    5s    Validate Device    ${olt_serial_number}    DISABLED    UNKNOWN
+    ...    REACHABLE
+    ${rc}    ${output}=    Run and Return Rc and Output    ${VOLTCTL_CONFIG}; voltctl device delete ${olt_device_id}
+    Should Be Equal As Integers    ${rc}    0
+    Wait Until Keyword Succeeds    ${timeout}    5s    Validate Device Removed    ${olt_device_id}
diff --git a/tests/sanity/sanity.robot b/tests/sanity/sanity.robot
deleted file mode 100644
index 78364d6..0000000
--- a/tests/sanity/sanity.robot
+++ /dev/null
@@ -1,130 +0,0 @@
-# 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     Creates bbsim olt/onu and validates activataion
-...               Assumes voltha-go, go-based onu/olt adapters, and bbsim are installed
-...               voltctl and kubectl should be configured prior to running these tests
-Suite Setup       Setup
-Suite Teardown    Teardown
-Test Teardown     Execute ONOS CLI Command    ${server_ip}    ${ONOS_SSH_PORT}    flows -s
-Library           OperatingSystem
-Library           ${CURDIR}/../../libraries/DependencyLibrary.py
-Resource          ${CURDIR}/../../libraries/onos.robot
-Resource          ${CURDIR}/../../libraries/voltctl.robot
-Resource          ${CURDIR}/../../libraries/utils.robot
-Resource          ${CURDIR}/../../libraries/k8s.robot
-Resource          ${CURDIR}/../../variables/variables.robot
-
-*** Variables ***
-${server_ip}      localhost
-${timeout}        240s
-${num_onus}       1
-
-*** Test Cases ***
-Activate Device BBSIM OLT/ONU
-    [Documentation]    Validate deployment ->
-    ...    create and enable bbsim device ->
-    ...    re-validate deployment
-    [Tags]    sanity
-    #create/preprovision device
-    ${bbsim_ip}=    Lookup Service IP    voltha    bbsim
-    ${bbsim_port}=    Lookup Service Port    voltha    bbsim
-    ${olt_device_id}=    Create Device    ${bbsim_ip}    ${bbsim_port}
-    Set Suite Variable    ${olt_device_id}
-    #enable device
-    Enable Device    ${olt_device_id}
-    #validate olt states
-    Wait Until Keyword Succeeds    60s    5s    Validate Device    ${BBSIM_OLT_SN}    ENABLED    ACTIVE
-    ...    REACHABLE
-    #validate onu states
-    Wait Until Keyword Succeeds    60s    5s    Validate Device    ${BBSIM_ONU_SN}    ENABLED    ACTIVE
-    ...    REACHABLE    onu=True    onu_reason=tech-profile-config-download-success
-    #get onu device id
-    ${onu_device_id}=    Get Device ID From SN    ${BBSIM_ONU_SN}
-    Set Suite Variable    ${onu_device_id}
-
-Validate OLT Connected to ONOS
-    [Documentation]    Verifies the BBSIM-OLT device is activated in onos
-    [Tags]    sanity
-    [Setup]    Require test case    Activate Device BBSIM OLT/ONU
-    ${of_id}=    Wait Until Keyword Succeeds    ${timeout}    5s    Validate OLT Device in ONOS    ${BBSIM_OLT_SN}
-    Set Suite Variable    ${of_id}
-
-Check EAPOL Flows in ONOS
-    [Documentation]    Validates eapol flows for the onu are pushed from voltha
-    [Tags]    sanity
-    [Setup]    Require test case    Validate OLT Connected to ONOS
-    ${num_flows}=    Evaluate    ${num_onus} * 4
-    ${flows_str}=    Convert To String    ${num_flows}
-    Wait Until Keyword Succeeds    ${timeout}    5s    Verify Eapol Flows Added    ${server_ip}    ${ONOS_SSH_PORT}    ${flows_str}
-
-Validate ONU Authenticated in ONOS
-    [Documentation]    Validates onu is AUTHORIZED in ONOS as bbsim will attempt to authenticate
-    [Tags]    sanity
-    [Setup]    Require test case    Check EAPOL Flows in ONOS
-    Wait Until Keyword Succeeds    ${timeout}    1s    Verify Number of AAA-Users    ${server_ip}    ${ONOS_SSH_PORT}    ${num_onus}
-
-Add Subscriber-Access in ONOS
-    [Documentation]    Through the olt-app in ONOS, execute 'volt-add-subscriber-access' and validate IP Flows
-    [Tags]    sanity
-    [Setup]    Require test case    Validate ONU Authenticated in ONOS
-    ##    TODO: this works fine with 1 onu, but with multiple onus, we need to ensure this is executes
-    ##    prior to to dhclient starting. possible start a process after first test case to just attempt
-    ##    "volt-add-subscriber-access" to all onus periodically?
-    ${output}=    Execute ONOS CLI Command    ${server_ip}    ${ONOS_SSH_PORT}    volt-add-subscriber-access ${of_id} 16
-    Log    ${output}
-
-Validate DHCP Assignment in ONOS
-    [Documentation]    After IP Flows are pushed to the device, BBSIM will start a dhclient for the ONU.
-    [Tags]    sanity
-    [Setup]    Require test case    Add Subscriber-Access in ONOS
-    Wait Until Keyword Succeeds    120s    15s    Validate DHCP Allocations    ${server_ip}    ${ONOS_SSH_PORT}    ${num_onus}
-
-Delete Device and Verify
-    [Documentation]    Disable -> Delete devices via voltctl and verify its removed
-    [Tags]    sanity
-    [Setup]    Require test case    Activate Device BBSIM OLT/ONU
-    #disable/delete onu
-    ${rc}    ${output}=    Run and Return Rc and Output    ${VOLTCTL_CONFIG}; voltctl device disable ${onu_device_id}
-    Should Be Equal As Integers    ${rc}    0
-    Wait Until Keyword Succeeds    60s    5s    Validate Device    ${BBSIM_ONU_SN}    DISABLED    UNKNOWN
-    ...    REACHABLE
-    ${rc}    ${output}=    Run and Return Rc and Output    ${VOLTCTL_CONFIG}; voltctl device delete ${onu_device_id}
-    Should Be Equal As Integers    ${rc}    0
-    Wait Until Keyword Succeeds    60s    5s    Validate Device Removed    ${onu_device_id}
-    #disable/delete olt
-    ${rc}    ${output}=    Run and Return Rc and Output    ${VOLTCTL_CONFIG}; voltctl device disable ${olt_device_id}
-    Should Be Equal As Integers    ${rc}    0
-    Wait Until Keyword Succeeds    60s    5s    Validate Device    ${BBSIM_OLT_SN}    DISABLED    UNKNOWN
-    ...    REACHABLE
-    ${rc}    ${output}=    Run and Return Rc and Output    ${VOLTCTL_CONFIG}; voltctl device delete ${olt_device_id}
-    Should Be Equal As Integers    ${rc}    0
-    Wait Until Keyword Succeeds    60s    5s    Validate Device Removed    ${olt_device_id}
-
-*** Keywords ***
-Setup
-    [Documentation]    Setup environment
-    Log    Setting up
-    Set Global Variable    ${KUBECTL_CONFIG}    export KUBECONFIG=%{KUBECONFIG}
-    Set Global Variable    ${VOLTCTL_CONFIG}    export VOLTCONFIG=%{VOLTCONFIG}
-    Check CLI Tools Configured
-    ${onos_auth}=    Create List    karaf    karaf
-    ${HEADERS}    Create Dictionary    Content-Type=application/json
-    Create Session    ONOS    http://${server_ip}:${ONOS_REST_PORT}    auth=${ONOS_AUTH}
-
-Teardown
-    [Documentation]    Delete all http sessions
-    Delete All Sessions