delete device testcase + test improvements

Change-Id: Ia2b6d5c2912e5c513e2ac08efa1a691a89d4c5c0
diff --git a/tests/sanity/sanity.robot b/tests/sanity/sanity.robot
index ce107af..72ddd9b 100644
--- a/tests/sanity/sanity.robot
+++ b/tests/sanity/sanity.robot
@@ -27,7 +27,6 @@
 ${server_ip}        localhost
 ${timeout}          90s
 ${num_onus}         1
-${SADIS_CONFIG}     ${CURDIR}/../data/sadis-notp-1.json
 
 *** Test Cases ***
 Activate Device BBSIM OLT/ONU
@@ -36,15 +35,20 @@
     ...    re-validate deployment
     [Tags]    activate
     #create/preprovision device
-    ${rc}    ${device_id}=    Run and Return Rc and Output    ${VOLTCTL_CONFIG} voltctl device create -t openolt -H ${BBSIM_SERVICE}:${BBSIM_PORT}
+    ${rc}    ${olt_device_id}=    Run and Return Rc and Output
+    ...    ${VOLTCTL_CONFIG}; voltctl device create -t openolt -H ${BBSIM_IP}:${BBSIM_PORT}
     Should Be Equal As Integers    ${rc}    0
+    Set Suite Variable    ${olt_device_id}
     #enable device
-    ${rc}    ${output}=    Run and Return Rc and Output    ${VOLTCTL_CONFIG} voltctl device enable ${device_id}
+    ${rc}    ${output}=    Run and Return Rc and Output    ${VOLTCTL_CONFIG}; voltctl device enable ${device_id}
     Should Be Equal As Integers    ${rc}    0
     #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
+    #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
@@ -54,20 +58,35 @@
 Check EAPOL Flows in ONOS
     [Documentation]    Validates eapol flows for the onu are pushed from voltha
     [Tags]    eapol
-    Wait Until Keyword Succeeds    ${timeout}    5s    Verify Eapol Flows Added
+    Wait Until Keyword Succeeds    ${timeout}    5s    Verify Eapol Flows Added    ${num_onus}
 
 Validate ONU Authenticated in ONOS
     [Documentation]    Validates onu is AUTHORIZED in ONOS as bbsim will attempt to authenticate
     [Tags]    aaa
-    Wait Until Keyword Succeeds    ${timeout}    5s    Verify Number of AAA-Users    ${number_of_onus}
-
-Provision ONU Subscriber in ONOS
-    [Documentation]    Through the olt-app in ONOS, execute 'volt-add-subscriber-access' and validate IP Flows
-    [Tags]    notready
+    Wait Until Keyword Succeeds    ${timeout}    5s    Verify Number of AAA-Users    ${num_onus}
 
 Validate DHCP Assignment in ONOS
     [Documentation]    After IP Flows are pushed to the device, BBSIM will start a dhclient for the ONU.
-    [Tags]    notready
+    [Tags]    dhcp
+    Wait Until Keyword Succeeds    120s    15s    Validate DHCP Allocations    ${num_onus}
+
+Delete Device and Verify
+    [Documentation]    Disable -> Delete devices via voltctl and verify its removed
+    [Tags]    deletedevice
+    #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    UNREACHABLE
+    ${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    UNREACHABLE
+    ${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
@@ -79,8 +98,6 @@
     ${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}
-    ## TODO upload sadis ${sadis_config}
-
 
 Teardown
     [Documentation]    Delete all http sessions
@@ -110,4 +127,10 @@
     [Arguments]    ${expected_onus}
     [Documentation]    Matches for number of aaa-users authorized based on number of onus
     ${aaa_users}=    Execute ONOS Command    aaa-users | grep AUTHORIZED | wc -l
-    Should Contain    ${aaa_users}    ${expected_onus}
\ No newline at end of file
+    Should Contain    ${aaa_users}    ${expected_onus}
+
+Validate DHCP Allocations
+    [Arguments]    ${expected_onus}
+    [Documentation]    Matches for number of dhcpacks based on number of onus
+    ${allocations}=    Execute ONOS Command    dhcpl2relay-allocations | grep DHCPACK | wc -l
+    Should Contain    ${allocations}    ${expected_onus}
\ No newline at end of file