Cluster id test case
[integration/test.git] / csit / libraries / OpenStackOperations.robot
index cc6003c0012730f9c1ae831540be858d65c39a39..efc9bb0534585f93d3a39e24c424c6a92b36ee81 100644 (file)
@@ -7,6 +7,7 @@ Library           SSHLibrary
 Library           String
 Resource          DataModels.robot
 Resource          DevstackUtils.robot
+Resource          KarafKeywords.robot
 Resource          L2GatewayOperations.robot
 Resource          OVSDB.robot
 Resource          SetupUtils.robot
@@ -16,6 +17,7 @@ Resource          Utils.robot
 Resource          ../variables/Variables.robot
 Resource          ../variables/netvirt/Variables.robot
 Variables         ../variables/netvirt/Modules.py
+Variables         ../variables/netvirt/Exceptions_Whitelist.py
 
 *** Keywords ***
 Get Tenant ID From Security Group
@@ -39,10 +41,7 @@ Create Network
 Update Network
     [Arguments]    ${network_name}    ${additional_args}=${EMPTY}
     [Documentation]    Update Network with neutron request.
-    ${cmd} =    BuiltIn.Set Variable If    '${OPENSTACK_BRANCH}'=='stable/newton'    neutron -v net-update ${network_name} ${additional_args}    openstack network set ${network_name} ${additional_args}
-    ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${cmd}
-    BuiltIn.Log    ${output}
-    BuiltIn.Should Be True    '${rc}' == '0'
+    ${output} =    OpenStack CLI    openstack network set ${network_name} ${additional_args}
     [Return]    ${output}
 
 Show Network
@@ -74,10 +73,7 @@ Create SubNet
 Update SubNet
     [Arguments]    ${subnet_name}    ${additional_args}=${EMPTY}
     [Documentation]    Update subnet with neutron request.
-    ${cmd} =    BuiltIn.Set Variable If    '${OPENSTACK_BRANCH}'=='stable/newton'    neutron -v subnet-update ${subnet_name} ${additional_args}    openstack subnet set ${subnet_name} ${additional_args}
-    ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${cmd}
-    BuiltIn.Log    ${output}
-    BuiltIn.Should Be True    '${rc}' == '0'
+    ${output} =    OpenStack CLI    openstack subnet set ${subnet_name} ${additional_args}
     [Return]    ${output}
 
 Show SubNet
@@ -92,13 +88,9 @@ Create Port
     # if allowed_address_pairs is not empty we need to create the arguments to pass to the port create command. They are
     # in a different format with the neutron vs openstack cli.
     ${address_pair_length} =    BuiltIn.Get Length    ${allowed_address_pairs}
-    ${allowed_pairs_argv} =    BuiltIn.Set Variable If    '${OPENSTACK_BRANCH}'=='stable/newton' and '${address_pair_length}'=='2'    --allowed-address-pairs type=dict list=true ip_address=@{allowed_address_pairs}[0] ip_address=@{allowed_address_pairs}[1]
-    ${allowed_pairs_argv} =    BuiltIn.Set Variable If    '${OPENSTACK_BRANCH}'!='stable/newton' and '${address_pair_length}'=='2'    --allowed-address ip-address=@{allowed_address_pairs}[0] --allowed-address ip-address=@{allowed_address_pairs}[1]    ${allowed_pairs_argv}
-    ${allowed_pairs_argv} =    BuiltIn.Set Variable If    '${address_pair_length}'=='0'    ${EMPTY}    ${allowed_pairs_argv}
-    ${cmd} =    BuiltIn.Set Variable If    '${OPENSTACK_BRANCH}'=='stable/newton'    neutron -v port-create ${network_name} --name ${port_name} --security-group ${sg} ${additional_args} ${allowed_pairs_argv}    openstack port create --network ${network_name} ${port_name} --security-group ${sg} ${additional_args} ${allowed_pairs_argv}
-    ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${cmd}
-    BuiltIn.Log    ${output}
-    BuiltIn.Should Be True    '${rc}' == '0'
+    ${allowed_pairs_argv} =    BuiltIn.Set Variable    ${EMPTY}
+    ${allowed_pairs_argv} =    BuiltIn.Set Variable If    '${address_pair_length}'=='2'    --allowed-address ip-address=@{allowed_address_pairs}[0] --allowed-address ip-address=@{allowed_address_pairs}[1]    ${allowed_pairs_argv}
+    ${output} =    OpenStack CLI    openstack port create --network ${network_name} ${port_name} --security-group ${sg} ${additional_args} ${allowed_pairs_argv}
 
 Update Port
     [Arguments]    ${port_name}    ${additional_args}=${EMPTY}
@@ -470,9 +462,7 @@ Show Router Interface
 
 Add Router Gateway
     [Arguments]    ${router_name}    ${external_network_name}
-    ${cmd} =    BuiltIn.Set Variable If    '${OPENSTACK_BRANCH}'=='stable/newton'    neutron -v router-gateway-set ${router_name} ${external_network_name}    openstack router set ${router_name} --external-gateway ${external_network_name}
-    ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${cmd}
-    BuiltIn.Should Be True    '${rc}' == '0'
+    ${output} =    OpenStack CLI    openstack router set ${router_name} --external-gateway ${external_network_name}
 
 Remove Interface
     [Arguments]    ${router_name}    ${interface_name}
@@ -520,27 +510,6 @@ Get DumpFlows And Ovsconfig
     Utils.Write Commands Until Expected Prompt    sudo ovs-ofctl dump-groups br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
     Utils.Write Commands Until Expected Prompt    sudo ovs-ofctl dump-group-stats br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
 
-Get Karaf Log Type From Test Start
-    [Arguments]    ${ip}    ${test_name}    ${type}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
-    ...    ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
-    ${cmd} =    BuiltIn.Set Variable    sed '1,/ROBOT MESSAGE: Starting test ${test_name}/d' ${log_file} | grep '${type}'
-    ${output} =    Utils.Run Command On Controller    ${ip}    ${cmd}    ${user}    ${password}    ${prompt}
-    [Return]    ${output}
-
-Get Karaf Log Types From Test Start
-    [Arguments]    ${ip}    ${test_name}    ${types}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
-    ...    ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
-    : FOR    ${type}    IN    @{types}
-    \    OpenStackOperations.Get Karaf Log Type From Test Start    ${ip}    ${test_name}    ${type}    ${user}    ${password}
-    \    ...    ${prompt}    ${log_file}
-
-Get Karaf Log Events From Test Start
-    [Arguments]    ${test_name}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
-    ${log_types} =    BuiltIn.Create List    ERROR    WARN    Exception
-    BuiltIn.Run Keyword If    0 < ${NUM_ODL_SYSTEM}    OpenStackOperations.Get Karaf Log Types From Test Start    ${ODL_SYSTEM_IP}    ${test_name}    ${log_types}
-    BuiltIn.Run Keyword If    1 < ${NUM_ODL_SYSTEM}    OpenStackOperations.Get Karaf Log Types From Test Start    ${ODL_SYSTEM_2_IP}    ${test_name}    ${log_types}
-    BuiltIn.Run Keyword If    2 < ${NUM_ODL_SYSTEM}    OpenStackOperations.Get Karaf Log Types From Test Start    ${ODL_SYSTEM_3_IP}    ${test_name}    ${log_types}
-
 Get ControlNode Connection
     SSHLibrary.Switch Connection    ${OS_CNTL_CONN_ID}
     [Return]    ${OS_CNTL_CONN_ID}
@@ -552,10 +521,11 @@ Get OvsDebugInfo
     BuiltIn.Run Keyword If    2 < ${NUM_OS_SYSTEM}    OpenStackOperations.Get DumpFlows And Ovsconfig    ${OS_CMP2_CONN_ID}
 
 Get Test Teardown Debugs
-    [Arguments]    ${test_name}=${TEST_NAME}
+    [Arguments]    ${test_name}=${SUITE_NAME}.${TEST_NAME}
     OpenStackOperations.Get OvsDebugInfo
     BuiltIn.Run Keyword And Ignore Error    DataModels.Get Model Dump    ${HA_PROXY_IP}    ${netvirt_data_models}
-    OpenStackOperations.Get Karaf Log Events From Test Start    ${test_name}
+    KarafKeywords.Get Karaf Log Events From Test Start    ${test_name}
+    Run Keyword If    "${FAIL_ON_EXCEPTIONS}"=="True"    Fail If Exceptions Found During Test    ${test_name}    ${NETVIRT_EXCEPTIONS_WHITELIST}
 
 Get Test Teardown Debugs For SFC
     [Arguments]    ${test_name}=${TEST_NAME}
@@ -642,10 +612,8 @@ Neutron Security Group Rule Create
     ...    ELSE    BuiltIn.Catenate    ${cmd}
     ${cmd} =    BuiltIn.Run Keyword If    '${remote_ip_prefix}'!='None'    BuiltIn.Catenate    ${cmd}    --src-ip ${remote_ip_prefix}
     ...    ELSE    BuiltIn.Catenate    ${cmd}
-    ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${cmd}
+    ${output} =    OpenStack CLI    ${cmd}
     ${rule_id} =    BuiltIn.Should Match Regexp    ${output}    ${REGEX_UUID}
-    BuiltIn.Log    ${rule_id}
-    BuiltIn.Should Be True    '${rc}' == '0'
     [Return]    ${output}    ${rule_id}
 
 Neutron Security Group Rule Create Legacy Cli
@@ -749,6 +717,13 @@ Create L2Gateway
     BuiltIn.Log    ${l2gw_output}
     [Return]    ${l2gw_output}
 
+Update L2Gateway
+    [Arguments]    ${bridge_name}    ${gw_name}    ${intf_name_1}    ${intf_name_2}
+    [Documentation]    Keyword to add {intf_name_list} to an existing L2 Gateway ${gw_name} (Using Neutron CLI).
+    ${rc}    ${l2gw_output}=    Run And Return Rc And Output    ${L2GW_UPDATE} name=${bridge_name},interface_names="${intf_name_1};${intf_name_2}" ${gw_name}
+    Log    ${l2gw_output}
+    [Return]    ${l2gw_output}
+
 Create L2Gateway Connection
     [Arguments]    ${gw_name}    ${net_name}
     [Documentation]    Keyword would create a new L2 Gateway Connection for ${gw_name} to ${net_name} (Using Neutron CLI).
@@ -1016,10 +991,10 @@ Cleanup Router
 OpenStack Suite Setup
     [Documentation]    Wrapper teardown keyword that can be used in any suite running in an openstack environement
     SetupUtils.Setup_Utils_For_Setup_And_Teardown
-    @{tcpdump_port_6653_conn_ids} =    OpenStackOperations.Start Packet Capture On Nodes    tcpdump_port_6653    port 6653    ${OS_CONTROL_NODE_IP}    ${OS_COMPUTE_1_IP}    ${OS_COMPUTE_2_IP}
+    DevstackUtils.Devstack Suite Setup
+    @{tcpdump_port_6653_conn_ids} =    OpenStackOperations.Start Packet Capture On Nodes    tcpdump_port_6653    port 6653    @{OS_ALL_IPS}
     BuiltIn.Set Suite Variable    @{tcpdump_port_6653_conn_ids}
     BuiltIn.Run Keyword If    "${PRE_CLEAN_OPENSTACK_ALL}"=="True"    OpenStack Cleanup All
-    DevstackUtils.Devstack Suite Setup
     OpenStackOperations.Add OVS Logging On All OpenStack Nodes
 
 OpenStack Suite Teardown
@@ -1030,6 +1005,8 @@ OpenStack Suite Teardown
     OpenStack Cleanup All
     OpenStackOperations.Stop Packet Capture On Nodes    ${tcpdump_port_6653_conn_ids}
     SSHLibrary.Close All Connections
+    : FOR    ${i}    IN RANGE    ${NUM_ODL_SYSTEM}
+    \    KarafKeywords.Issue Command On Karaf Console    threads --list | wc -l    ${ODL_SYSTEM_${i+1}_IP}
 
 Copy DHCP Files From Control Node
     [Documentation]    Copy the current DHCP files to the robot vm. The keyword must be called