Do not fail on exceptions in suite teardown
[integration/test.git] / csit / libraries / OpenStackOperations.robot
index 66c187e8be267dccceb86c724f68512a6a18f746..5c6fd65ab83b6a62f782d405e5605b9cd3b34925 100644 (file)
@@ -9,6 +9,7 @@ Resource          DataModels.robot
 Resource          DevstackUtils.robot
 Resource          KarafKeywords.robot
 Resource          L2GatewayOperations.robot
+Resource          ODLTools.robot
 Resource          OVSDB.robot
 Resource          SetupUtils.robot
 Resource          SSHKeywords.robot
@@ -488,8 +489,8 @@ Show Router Interface
     [Return]    ${output}
 
 Add Router Gateway
-    [Arguments]    ${router_name}    ${external_network_name}
-    ${output} =    OpenStack CLI    openstack router set ${router_name} --external-gateway ${external_network_name}
+    [Arguments]    ${router_name}    ${external_network_name}    ${additional_args}=${EMPTY}
+    ${output} =    OpenStack CLI    openstack router set ${router_name} --external-gateway ${external_network_name} ${additional_args}
 
 Remove Interface
     [Arguments]    ${router_name}    ${interface_name}
@@ -510,6 +511,7 @@ Show Router
     [Arguments]    ${router_name}    ${options}
     [Documentation]    Show information of a given router. Router name and optional fields should be sent as arguments.
     ${output} =    OpenStack CLI    openstack router show ${router_name}
+    [Return]    ${output}
 
 Delete Router
     [Arguments]    ${router_name}
@@ -543,15 +545,18 @@ Get ControlNode Connection
 
 Get OvsDebugInfo
     [Documentation]    Get the OvsConfig and Flow entries from all Openstack nodes
-    BuiltIn.Run Keyword If    0 < ${NUM_OS_SYSTEM}    OpenStackOperations.Get DumpFlows And Ovsconfig    ${OS_CNTL_CONN_ID}
-    BuiltIn.Run Keyword If    1 < ${NUM_OS_SYSTEM}    OpenStackOperations.Get DumpFlows And Ovsconfig    ${OS_CMP1_CONN_ID}
-    BuiltIn.Run Keyword If    2 < ${NUM_OS_SYSTEM}    OpenStackOperations.Get DumpFlows And Ovsconfig    ${OS_CMP2_CONN_ID}
+    : FOR    ${conn_id}    IN    @{OS_ALL_CONN_IDS}
+    \    OpenStackOperations.Get DumpFlows And Ovsconfig    ${conn_id}
 
 Get Test Teardown Debugs
-    [Arguments]    ${test_name}=${SUITE_NAME}.${TEST_NAME}
+    [Arguments]    ${test_name}=${SUITE_NAME}.${TEST_NAME}    ${fail}=${FAIL_ON_EXCEPTIONS}
     OpenStackOperations.Get OvsDebugInfo
     BuiltIn.Run Keyword And Ignore Error    DataModels.Get Model Dump    ${HA_PROXY_IP}    ${netvirt_data_models}
-    Run Keyword If    "${FAIL_ON_EXCEPTIONS}"=="True"    KarafKeywords.Fail If Exceptions Found During Test    ${test_name}
+    BuiltIn.run Keyword And Ignore Error    ODLTools.Get EOS    ${HA_PROXY_IP}
+    KarafKeywords.Fail If Exceptions Found During Test    ${test_name}    fail=${fail}
+
+Get Suite Debugs
+    Get Test Teardown Debugs    test_name=${SUITE_NAME}    fail=False
 
 Get Test Teardown Debugs For SFC
     [Arguments]    ${test_name}=${TEST_NAME}
@@ -930,8 +935,7 @@ Neutron Cleanup
 OpenStack List All
     [Documentation]    Get a list of different OpenStack resources that might be in use.
     @{modules} =    BuiltIn.Create List    server    port    network    subnet    security group
-    ...    security group rule
-    BuiltIn.Run Keyword If    "${ODL_ENABLE_L3_FWD}"=="yes"    Collections.Append To List    ${modules}    floating ip    router
+    ...    security group rule    floating ip    router
     : FOR    ${module}    IN    @{modules}
     \    ${output} =    OpenStack CLI    openstack ${module} list
 
@@ -962,15 +966,13 @@ OpenStack CLI With No Log
 OpenStack Cleanup All
     [Documentation]    Cleanup all Openstack resources with best effort. The keyword will query for all resources
     ...    in use and then attempt to delete them. Errors are ignored to allow the cleanup to continue.
-    @{fips} =    BuiltIn.Run Keyword If    "${ODL_ENABLE_L3_FWD}"=="yes"    OpenStack CLI Get List    openstack floating ip list -f json
-    ...    ELSE    BuiltIn.Create List    @{EMPTY}
+    @{fips} =    OpenStack CLI Get List    openstack floating ip list -f json
     : FOR    ${fip}    IN    @{fips}
     \    BuiltIn.Run Keyword And Ignore Error    Delete Floating IP    ${fip['ID']}
     @{vms} =    OpenStack CLI Get List    openstack server list -f json
     : FOR    ${vm}    IN    @{vms}
     \    BuiltIn.Run Keyword And Ignore Error    Delete Vm Instance    ${vm['ID']}
-    @{routers} =    BuiltIn.Run Keyword If    "${ODL_ENABLE_L3_FWD}"=="yes"    OpenStack CLI Get List    openstack router list -f json
-    ...    ELSE    BuiltIn.Create List    @{EMPTY}
+    @{routers} =    OpenStack CLI Get List    openstack router list -f json
     : FOR    ${router}    IN    @{routers}
     \    BuiltIn.Run Keyword And Ignore Error    Cleanup Router    ${router['ID']}
     @{ports} =    OpenStack CLI Get List    openstack port list -f json
@@ -1005,12 +1007,18 @@ OpenStack Suite Setup
     BuiltIn.Set Suite Variable    @{tcpdump_port_6653_conn_ids}
     BuiltIn.Run Keyword If    "${PRE_CLEAN_OPENSTACK_ALL}"=="True"    OpenStack Cleanup All
     OpenStackOperations.Add OVS Logging On All OpenStack Nodes
+    Run_Keyword_If_At_Least_Oxygen    Wait Until Keyword Succeeds    60    2    ClusterManagement.Check Status Of Services Is OPERATIONAL    @{NETVIRT_DIAG_SERVICES}
+    ClusterManagement.Dump_Local_Shards_For_Each_Member
+    Verify Expected Default Tables On Nodes
 
 OpenStack Suite Teardown
     [Documentation]    Wrapper teardown keyword that can be used in any suite running in an openstack environement
     ...    to clean up all openstack resources. For example, all instances, networks, ports, etc will be listed and
     ...    and deleted. As other global cleanup tasks are needed, they can be added here and the suites will all
     ...    benefit automatically.
+    # TODO: followup patch will add the list of vms to pass to Show Debugs
+    # OpenStackOperations.Show Debugs    @{NET_1_VMS}    @{NET_2_VMS}
+    OpenStackOperations.Get Suite Debugs
     OpenStack Cleanup All
     OpenStackOperations.Stop Packet Capture On Nodes    ${tcpdump_port_6653_conn_ids}
     SSHLibrary.Close All Connections
@@ -1035,15 +1043,13 @@ Is Feature Installed
 
 Add OVS Logging On All OpenStack Nodes
     [Documentation]    Add higher levels of OVS logging to all the OpenStack nodes
-    BuiltIn.Run Keyword If    0 < ${NUM_OS_SYSTEM}    OVSDB.Add OVS Logging    ${OS_CNTL_CONN_ID}
-    BuiltIn.Run Keyword If    1 < ${NUM_OS_SYSTEM}    OVSDB.Add OVS Logging    ${OS_CMP1_CONN_ID}
-    BuiltIn.Run Keyword If    2 < ${NUM_OS_SYSTEM}    OVSDB.Add OVS Logging    ${OS_CMP2_CONN_ID}
+    : FOR    ${conn_id}    IN    @{OS_ALL_CONN_IDS}
+    \    OVSDB.Add OVS Logging    ${conn_id}
 
 Reset OVS Logging On All OpenStack Nodes
     [Documentation]    Reset the OVS logging to all the OpenStack nodes
-    BuiltIn.Run Keyword If    0 < ${NUM_OS_SYSTEM}    OVSDB.Reset OVS Logging    ${OS_CNTL_CONN_ID}
-    BuiltIn.Run Keyword If    1 < ${NUM_OS_SYSTEM}    OVSDB.Reset OVS Logging    ${OS_CMP1_CONN_ID}
-    BuiltIn.Run Keyword If    2 < ${NUM_OS_SYSTEM}    OVSDB.Reset OVS Logging    ${OS_CMP2_CONN_ID}
+    : FOR    ${conn_id}    IN    @{OS_ALL_CONN_IDS}
+    \    OVSDB.Reset OVS Logging    ${conn_id}
 
 Start Packet Capture On Nodes
     [Arguments]    ${tag}    ${filter}    @{ips}
@@ -1100,3 +1106,38 @@ Get Network Segmentation Id
     ${output} =    OpenStack CLI    openstack network show ${network_name} | grep segmentation_id | awk '{print $4}'
     @{list} =    String.Split String    ${output}
     [Return]    @{list}[0]
+
+Verify Expected Default Tables On Nodes
+    [Arguments]    ${node_ips}=@{OS_ALL_IPS}
+    [Documentation]    Verify if Default Table Entries are programmed on all Nodes
+    ${resp} =    RequestsLibrary.Get Request    session    ${CONFIG_NODES_API}
+    Utils.Log Content    ${resp.content}
+    ${failed_node_list} =    BuiltIn.Create List
+    : FOR    ${node_ip}    IN    @{node_ips}
+    \    ${failed_table_list} =    Verify Expected Default Tables    ${node_ip}
+    \    ${failed_table_list_size} =    BuiltIn.Get Length    ${failed_table_list}
+    \    BuiltIn.Run Keyword If    ${failed_table_list_size} > 0    Collections.Append To List    ${failed_node_list}    ${node_ip}
+    Builtin.Should Be Empty    ${failed_node_list}
+
+Verify Expected Default Tables
+    [Arguments]    ${ovs_ip}
+    [Documentation]    Verify if Default Table Entries are programmed on specific Node
+    ${flow_dump} =    Utils.Run Command On Remote System    ${ovs_ip}    sudo ovs-ofctl dump-flows ${INTEGRATION_BRIDGE} -OOpenFlow13
+    BuiltIn.Log    ${flow_dump}
+    ${failed_table_list} =    BuiltIn.Create List
+    : FOR    ${table}    IN    @{DEFAULT_FLOW_TABLES}
+    \    ${rc} =    Builtin.Run Keyword And Return Status    Builtin.Should Not Match Regexp    ${flow_dump}    .*table=${table}.*priority=0
+    \    BuiltIn.Run Keyword If    ${rc}    Collections.Append To List    ${failed_table_list}    ${table}
+    [Return]    ${failed_table_list}
+
+Get Project Id
+    [Arguments]    ${project_name}
+    [Documentation]    Returns project ID for the given project name.
+    ${project_id} =    OpenStack CLI    openstack project show ${project_name} -f value -c id
+    [Return]    ${project_id}
+
+Set Instance Quota For Project
+    [Arguments]    ${num_instances}    ${project_id}
+    [Documentation]    Set quota for the created instances using the specific project id.
+    ${output} =    OpenStack CLI    openstack quota set --instances ${num_instances} ${project_id}
+    [Return]    ${output}