adding dhcp + onos checks in bbsim tests

Change-Id: I5b332b7def2aae7888b1e1741041b47458664b91
diff --git a/src/test/cord-api/Tests/BBSim/BBSIMScale.robot b/src/test/cord-api/Tests/BBSim/BBSIMScale.robot
index fbc51d5..eae5ac9 100644
--- a/src/test/cord-api/Tests/BBSim/BBSIMScale.robot
+++ b/src/test/cord-api/Tests/BBSim/BBSIMScale.robot
@@ -16,6 +16,7 @@
 Documentation     Test various E2E conditions for seba-in-a-box
 Suite Setup       Setup
 Suite Teardown    Teardown
+Test Teardown     Debug Tests
 Library           Collections
 Library           String
 Library           OperatingSystem
@@ -33,6 +34,7 @@
 
 *** Variables ***
 ${number_of_onus}    16
+${timeout}           300s
 
 *** Test Cases ***
 Create Subscriber and Whitelist for ONUs
@@ -50,28 +52,51 @@
     \    CORD Post    ${ATT_WHITELIST}    ${whitelist}
 
 Validate ONUs in VOLTHA
+    [Documentation]    Verify number of onus that appear in voltha and its states
     [Tags]    voltha
-    Wait Until Keyword Succeeds    120s    5s    Validate Voltha    ${number_of_onus}
+    Wait Until Keyword Succeeds    ${timeout}    5s    Validate Voltha    ${number_of_onus}
+
+Validate OLT and AAA-Users in ONOS
+    [Documentation]    Verify olt devices in ONOS and all onus are authenticated via AAA app
+    [Tags]    onos
+    Wait Until Keyword Succeeds    ${timeout}    5s    OLT Device in ONOS
+    Wait Until Keyword Succeeds    ${timeout}    5s    Verify Number of AAA-Users    ${number_of_onus}
 
 Validate ONUs in XOS
-    [Documentation]    Validates All ONU Devices are discovered and retrieve SNs
+    [Documentation]    Validates All ONU Devices are discovered in XOS
     [Tags]    onudiscovery
-    Wait Until Keyword Succeeds    120s    5s    Validate Number of ONU Devices    ${number_of_onus}
+    Wait Until Keyword Succeeds    ${timeout}    5s    Validate Number of ONU Devices    ${number_of_onus}
 
 Validate ONU States in XOS
     [Documentation]    Validates All ONU Device states are "enabled" and "active"
     [Tags]    onustates
     : FOR    ${onu}    IN    @{serial_numbers}
-    \    Wait Until Keyword Succeeds    120s    5s    Validate ONU States    ACTIVE    ENABLED    ${onu}
+    \    Wait Until Keyword Succeeds    ${timeout}    5s    Validate ONU States    ACTIVE    ENABLED    ${onu}
+
+Validate Hosts and DHCP Allocations in ONOS
+    [Documentation]    Verify number of hosts in ONOS match number of onus and verify number of DHCP allocations
+    [Tags]    onosdhcp
+    Wait Until Keyword Succeeds    ${timeout}    5s    Validate Hosts in ONOS    ${number_of_onus}
+    Wait Until Keyword Succeeds    ${timeout}    5s    Validate DHCP Allocations    ${number_of_onus}
+
+Validate ATT WF Driver SIs
+    [Documentation]    Validates all service instances per onu devices become "approved" and "dhcpdiscovered"
+    [Tags]    serviceinstances
+    : FOR    ${onu}    IN    @{serial_numbers}
+    \    Wait Until Keyword Succeeds    ${timeout}    2s    Validate ATT Workflow Driver SI    ENABLED    APPROVED    ${onu}
+    \    Wait Until Keyword Succeeds    ${timeout}    5s    Validate ATT Workflow Driver SI DHCP State    DHCPACK    ${onu}
 
 *** Keywords ***
 Setup
     ${server_ip}=    Get Environment Variable    SERVER_IP    localhost
     ${port}=    Get Environment Variable    SERVER_PORT    30001
     ${auth} =    Create List    ${XOS_USER}    ${XOS_PASSWD}
+    ${voltha_auth}=    Create List    voltha    admin
+    ${onos_auth}=    Create List    karaf    karaf
     ${HEADERS}    Create Dictionary    Content-Type=application/json
     Create Session    XOS    http://${server_ip}:${port}    auth=${AUTH}    headers=${HEADERS}
-    Create Session    VOLTHA    http://${server_ip}:30125    headers=${HEADERS}
+    Create Session    VOLTHA    http://${server_ip}:30125    auth=${VOLTHA_AUTH}    headers=${HEADERS}
+    Create Session    ONOS    http://${server_ip}:30120    auth=${ONOS_AUTH}
     @{container_list}=    Create List
     Append To List    ${container_list}    att-workflow-att-workflow-driver
     Append To List    ${container_list}    seba-services-volt
@@ -83,19 +108,7 @@
     Set Suite Variable    ${container_list}
 
 Teardown
-    Wait Until Keyword Succeeds    60s    2s    Clean Up Objects    ${VOLT_SUBSCRIBER}
-    Wait Until Keyword Succeeds    60s    2s    Clean Up Objects    ${ATT_WHITELIST}
-    Wait Until Keyword Succeeds    60s    2s    Clean Up Objects    ${VOLT_DEVICE}
-    Wait Until Keyword Succeeds    60s    2s    Clean Up Objects    ${ATT_SERVICEINSTANCES}
     Delete All Sessions
-    #Get Pod Logs
-
-Get Pod Logs
-    : FOR    ${pod}    IN    @{container_list}
-    \    ${full_pod_name}=    Run    kubectl get pods --all-namespaces | grep '${pod}' | head -1 | awk '{print $2}'
-    \    ${namespace}=    Run    kubectl get pods --all-namespaces | grep ' ${pod}' | head -1 | awk '{print $1}'
-    \    ${output}=    Run    kubectl logs --timestamps -n ${namespace} ${full_pod_name}
-    \    Log    ${output}
 
 Validate Number of ONU Devices
     [Arguments]    ${expected_onus}
@@ -108,6 +121,7 @@
     Log    ${resp.content}
     Should Be Equal As Strings    ${resp.status_code}    200
     Validate ONUs in Response    ${resp}    ${expected_onus}
+    Validate ONU States in Voltha    ${resp}
 
 Validate ONUs in Response
     [Arguments]    ${resp}    ${expected_onus}
@@ -124,6 +138,19 @@
     ${length_of_bbsim_onus}=    Get Length    ${serial_numbers}
     Should Be Equal as Integers    ${length_of_bbsim_onus}    ${expected_onus}
 
+Validate ONU States in Voltha
+    [Arguments]    ${resp}
+    ${jsondata}=    To Json    ${resp.content}
+    Should Not Be Empty    ${jsondata['items']}
+    ${length}=    Get Length    ${jsondata['items']}
+    @{serial_numbers}=    Create List
+    : FOR    ${INDEX}    IN RANGE    0    ${length}
+    \    ${value}=    Get From List    ${jsondata['items']}    ${INDEX}
+    \    ${admin_state}=    Get From Dictionary    ${value}    admin_state
+    \    ${oper_status}=    Get From Dictionary    ${value}    oper_status
+    \    Should Be Equal As Strings    ${admin_state}    ENABLED
+    \    Should Be Equal As Strings    ${oper_status}    ACTIVE
+
 CORD Get
     [Documentation]    Make a GET call to XOS
     [Arguments]    ${service}
@@ -148,3 +175,45 @@
     Log    ${resp.content}
     Should Be Equal As Strings    ${resp.status_code}    200
     [Return]    ${resp}
+
+Verify Number of AAA-Users
+    [Arguments]    ${expected_onus}
+    ${aaa_users}=    Execute ONOS Command    aaa-users | wc -l
+    Should Contain    ${aaa_users}    ${expected_onus}
+
+Validate Hosts in ONOS
+    [Arguments]    ${expected_onus}
+    ${hosts}=    Execute ONOS Command    hosts | grep -v 65537 | wc -l
+    Should Contain    ${hosts}    ${expected_onus}
+
+Validate DHCP Allocations
+    [Arguments]    ${expected_onus}
+    ${allocations}=    Execute ONOS Command    dhcpl2relay-allocations | wc -l
+    Should Contain    ${allocations}    ${expected_onus}
+
+OLT Device in ONOS
+    ${resp}=    Get Request    ONOS    onos/v1/devices
+    ${jsondata}=    To Json    ${resp.content}
+    Should Not Be Empty    ${jsondata['devices']}
+    ${length}=    Get Length    ${jsondata['devices']}
+    @{serial_numbers}=    Create List
+    : FOR    ${INDEX}    IN RANGE    0    ${length}
+    \    ${value}=    Get From List    ${jsondata['devices']}    ${INDEX}
+    \    ${sn}=    Get From Dictionary    ${value}    serial
+    \    ${dpid}=    Get From Dictionary    ${value}    id
+    Should Be Equal As Strings    ${dpid}    of:0000626273696d76
+    Should Be Equal As Strings    ${sn}    bbsim.voltha.svc:50060
+
+Execute ONOS Command
+    [Arguments]    ${cmd}
+    ${conn_id}=    SSHLibrary.Open Connection    localhost    port=30115    prompt=onos>    timeout=300s
+    SSHLibrary.Login    karaf    karaf
+    ${output}=    SSHLibrary.Execute Command    ${cmd}
+    SSHLibrary.Close Connection
+    [Return]    ${output}
+
+Debug Tests
+    ${flows}=    Execute ONOS Command    flows
+    ${onos_logs}=    Execute ONOS Command    log:display
+    Log    ${flows}
+    Log    ${onos_logs}
diff --git a/src/test/cord-api/Tests/BBSim/bbsim_utils.py b/src/test/cord-api/Tests/BBSim/bbsim_utils.py
index a5e729f..2e7f4b5 100644
--- a/src/test/cord-api/Tests/BBSim/bbsim_utils.py
+++ b/src/test/cord-api/Tests/BBSim/bbsim_utils.py
@@ -23,7 +23,21 @@
         :return: List of subscribers to POST
         """
         subscribers = []
-        for index in range(1, int(num_subs) + 1):
+        for index in xrange(1, int(num_subs) + 1):
+            sub = {
+                "name" : "Sub_BBSM" + str("00000") + str(pon_id) + '{0:02x}'.format(int(index)-1),
+                "status" : "pre-provisioned",
+                "c_tag" : ctag_start + int(index)-1,
+                "s_tag" : stag,
+                "onu_device" : "BBSM" + str("00000") + str(pon_id) + '{0:02x}'.format(int(index)-1),
+                "circuit_id" : "circuit" + '{0:02x}'.format(int(index)-1),
+                "remote_id" : "remote" + '{0:02x}'.format(int(index)-1),
+                "nas_port_id" : "PON 2/1/01/1:1.1." + '{0:0x}'.format(int(index)-1)
+            }
+            subscribers.append(sub)
+            if index == 10:
+                break
+        for index in range(11, int(num_subs) + 1):
             sub = {
                 "name" : "Sub_BBSM" + str("00000") + str(pon_id) + '{0:02x}'.format(int(index)-1),
                 "status" : "pre-provisioned",