Update Delete / Detect SO COMPLETE in distribute

Issue-ID: TEST-92
Change-Id: I26879237743e356c9205e1c35b8f550846c168c5
Signed-off-by: Brian Freeman <bf1936@att.com>
diff --git a/robot/resources/asdc_interface.robot b/robot/resources/asdc_interface.robot
index 2eea7ee..0f9c76a 100644
--- a/robot/resources/asdc_interface.robot
+++ b/robot/resources/asdc_interface.robot
@@ -397,15 +397,18 @@
     ${AAI_DEPLOY}   Set Variable   FALSE
     ${SDNC_DEPLOY}   Set Variable  FALSE
     ${SO_DEPLOY}   Set Variable   FALSE
+    ${SO_COMPLETE}   Set Variable   FALSE
     :FOR    ${ELEMENT}    IN    @{ITEMS}
     \    Log    ${ELEMENT['omfComponentID']}
     \    Log    ${ELEMENT['status']}
     \    ${SDNC_DEPLOY}  Set Variable If   (('sdnc-docker' in '${ELEMENT['omfComponentID']}') and ('${ELEMENT['status']}' == 'DEPLOY_OK')) or ('${SDNC_DEPLOY}' == 'TRUE')    TRUE 
     \     ${SO_DEPLOY}  Set Variable If   (('mso-docker' in '${ELEMENT['omfComponentID']}') and ('${ELEMENT['status']}' == 'DEPLOY_OK')) or ('${SO_DEPLOY}' == 'TRUE')   TRUE  
     \    ${AAI_DEPLOY}   Set Variable If   (('aai-ml' in '${ELEMENT['omfComponentID']}') and ('${ELEMENT['status']}' == 'DEPLOY_OK')) or ('${AAI_DEPLOY}'=='TRUE')  TRUE 
+    \    ${SO_COMPLETE}   Set Variable If   (('mso-docker' in '${ELEMENT['omfComponentID']}') and ('${ELEMENT['status']}' == 'DISTRIBUTION_COMPLETE_OK')) or ('${SO_COMPLETE}'=='TRUE')  TRUE
     Should Be True   ( '${SDNC_DEPLOY}'=='TRUE')  SDNC Test
-    Should Be True   ( '${SO_DEPLOY}'=='TRUE')   SO Test 
+    Should Be True   ( '${SO_DEPLOY}'=='TRUE')   SO Test
     Should Be True   ( '${AAI_DEPLOY}'=='TRUE')   AAI Test
+    Should Be True   ( '${SO_COMPLETE}'=='TRUE')   SO Test
 Get Catalog Service Distribution Details
     [Documentation]    gets an asdc catalog Service distrbution details
     [Arguments]    ${catalog_service_distribution_id}
@@ -503,4 +506,3 @@
    ${fileDir}  ${fileName}=  Split Path  ${filePath}
    ${partData}=  Create List  ${fileName}  ${fileData}  ${contentType}
    Set To Dictionary  ${addTo}  ${partName}=${partData}
-
diff --git a/robot/resources/test_templates/vnf_orchestration_test_template.robot b/robot/resources/test_templates/vnf_orchestration_test_template.robot
index 838c031..6e2cd9a 100644
--- a/robot/resources/test_templates/vnf_orchestration_test_template.robot
+++ b/robot/resources/test_templates/vnf_orchestration_test_template.robot
@@ -79,8 +79,8 @@
     \   VLB Closed Loop Hack   ${service}   ${generic_vnf}   ${closedloop_vf_module}
     \   Set Test Variable    ${STACK_NAME}   ${vf_module_name}
     \   Append To List   ${STACK_NAMES}   ${STACK_NAME}
-    \   Execute Heatbridge    ${vf_module_name}    ${service_instance_id}    ${vnf}
-    \   Validate VF Module      ${vf_module_name}    ${vnf}
+    \   Run Keyword and Ignore Error   Execute Heatbridge    ${vf_module_name}    ${service_instance_id}    ${vnf}
+    \   Run Keyword and Ignore Error   Validate VF Module      ${vf_module_name}    ${vnf}
     [Return]     ${vf_module_name}    ${service}
 
 
@@ -181,9 +181,26 @@
 Delete VNF
     [Documentation]    Called at the end of a test case to tear down the VNF created by Orchestrate VNF
     ${lcp_region}=   Get Openstack Region
+    ${list}=    Create List
+    Set Test Variable    ${KEYPAIRS}   ${list}
+    # remove duplicates, sort vFW-> vPKG , revers to get vPKG > vFWSNK
+    ${sorted_stack_names}=    Create List
+    ${sorted_stack_names}=  Remove Duplicates   ${STACK_NAMES}
+    Sort List   ${sorted_stack_names}
+    Reverse List   ${sorted_stack_names}
+    :for   ${stack}   in   @{sorted_stack_names}
+    \     Get Stack Keypairs   ${stack}
     Teardown VVG Server
     Teardown VLB Closed Loop Hack
     Run Keyword and Ignore Error   Teardown VID   ${SERVICE_INSTANCE_ID}   ${lcp_region}   ${TENANT_NAME}   ${CUSTOMER_NAME}
+    #
+    :for   ${stack}   in   @{sorted_stack_names}
+    \    Run Keyword and Ignore Error    Teardown Stack    ${stack}
+    \    Log    Stack Deleted ${stack}
+    # only needed if stack deleted but not keypair
+    :for   ${key_pair}   in   @{KEYPAIRS}
+    \    Run Keyword and Ignore Error    Delete Stack Keypair  ${key_pair}
+    \    Log    Key pair Deleted ${key_pair}
     Log    VNF Deleted
 
 Teardown VNF
@@ -202,6 +219,22 @@
     Remove from Dictionary   ${vvg_params}   nova_instance
     Log    Teardown VVG Server Completed
 
+Get Stack Keypairs
+    [Documentation]  Get keypairs from openstack
+    [Arguments]   ${stack}
+    Run Openstack Auth Request    auth
+    ${stack_info}=    Get Stack Details    auth    ${stack}
+    Log    ${stack_info}
+    ${stack_id}=    Get From Dictionary    ${stack_info}    id
+    ${key_pair_status}   ${keypair_name}=   Run Keyword And Ignore Error   Get From Dictionary    ${stack_info}    key_name
+    Append To List   ${KEYPAIRS}   ${keypair_name}
+
+Delete Stack Keypair
+    [Documentation]  Delete keypairs from openstack
+    [Arguments]   ${keypair_name}
+    Run Openstack Auth Request    auth
+    Run Keyword   Delete Openstack Keypair    auth    ${keypair_name}
+
 Teardown Stack
     [Documentation]    OBSOLETE - Called at the end of a test case to tear down the Stack created by Orchestrate VNF
     [Arguments]   ${stack}
@@ -213,7 +246,7 @@
     Delete Openstack Stack      auth    ${stack}    ${stack_id}
     Log    Deleted ${stack} ${stack_id}
     Run Keyword If   '${key_pair_status}' == 'PASS'   Delete Openstack Keypair    auth    ${keypair_name}
-    Teardown VLB Closed Loop Hack
+    #Teardown VLB Closed Loop Hack
 
 Clean A&AI Inventory
     [Documentation]    Clean up Tenant in A&AI, Create Customer, Create Service and related relationships
diff --git a/robot/resources/vid/teardown_vid.robot b/robot/resources/vid/teardown_vid.robot
index 3a0697e..e1850bf 100644
--- a/robot/resources/vid/teardown_vid.robot
+++ b/robot/resources/vid/teardown_vid.robot
@@ -31,7 +31,7 @@
     [Documentation]    Teardown the next VID entity that has a Remove icon.
     [Arguments]    ${service_instance_id}    ${lcp_region}    ${tenant}   ${customer}
     # For vLB closed loop, we may have 2 vf modules and the vDNS one needs to be removed first.
-    ${remove_order}=    Create List    vDNS_Ete   Vfmodule_Ete
+    ${remove_order}=    Create List    vDNS_Ete   vPKG   Vfmodule_Ete
 
     # FAIL status is returned in ${vfmodule} because FAIL are ignored during teardown
     ${status}    ${vfmodule}=   Run Keyword and Ignore Error   Delete Next VID Entity    ${service_instance_id}    ${lcp_region}    ${tenant}   ${remove_order}   ${customer}