Add Mac Based L2L3 seggragation suite.
[integration/test.git] / csit / libraries / OpenStackOperations.robot
index b362475c7eeea4c0ce1674c09e2fb5dd235d9eb5..9a78e7b89e0829ce44be03499f4d627a904fcf7a 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
@@ -32,7 +33,7 @@ Get Tenant ID From Network
 
 Create Network
     [Arguments]    ${network_name}    ${additional_args}=${EMPTY}    ${verbose}=TRUE
-    [Documentation]    Create Network with neutron request.
+    [Documentation]    Create Network with openstack request.
     ${output} =    OpenStack CLI    openstack network create ${network_name} ${additional_args}
     [Return]    ${output}
 
@@ -70,10 +71,16 @@ Create SubNet
 
 Update SubNet
     [Arguments]    ${subnet_name}    ${additional_args}=${EMPTY}
-    [Documentation]    Update subnet with neutron request.
+    [Documentation]    Update subnet with openstack subnet set request.
     ${output} =    OpenStack CLI    openstack subnet set ${subnet_name} ${additional_args}
     [Return]    ${output}
 
+Unset SubNet
+    [Arguments]    ${subnet_name}    ${additional_args}=${EMPTY}
+    [Documentation]    Update subnet with openstack subnet unset request
+    ${output} =    OpenStack CLI    openstack subnet unset ${subnet_name} ${additional_args}
+    [Return]    ${output}
+
 Show SubNet
     [Arguments]    ${subnet_name}
     [Documentation]    Show subnet with neutron request.
@@ -130,6 +137,11 @@ Create And Associate Floating IPs
     \    ${output} =    OpenStack CLI    openstack server add floating ip ${vm} @{ip}[0]
     [Return]    ${ip_list}
 
+Remove Floating Ip From Vm
+    [Arguments]    ${vm_name}    ${fip}
+    [Documentation]    Remove the Floating IP From VM Instance
+    ${output} =    OpenStack CLI    openstack server remove floating ip ${vm_name} ${fip}
+
 Delete Floating IP
     [Arguments]    ${fip}
     [Documentation]    Delete floating ip with neutron request.
@@ -169,6 +181,14 @@ Get Port Id
     ${port_id} =    Collections.Get from List    ${splitted_output}    0
     [Return]    ${port_id}
 
+Get Sub Port Id
+    [Arguments]    ${portname}
+    [Documentation]    Retrieve the first 10 chars of the UUID for the given port name
+    ${port_id} =    OpenStackOperations.Get Port Id    ${portname}
+    ${output} =    String.Get Regexp Matches    ${port_id}    \\w{8}-\\w{2}
+    ${subport_id} =    Collections.Get from List    ${output}    0
+    [Return]    ${subport_id}
+
 Get Router Id
     [Arguments]    ${router1}
     [Documentation]    Retrieve the router id for the given router name
@@ -287,6 +307,15 @@ Get VM IPs
     OpenStackOperations.Copy DHCP Files From Control Node
     [Return]    @{vm_ips}    ${ips_and_console_log[1]}
 
+Get Subnet Gateway Ip
+    [Arguments]    ${subnet_name}
+    [Documentation]    Show information of a subnet and grep for subnet gateway ip address
+    ${output} =    OpenStackOperations.OpenStack CLI    openstack subnet show ${subnet_name} | grep gateway_ip | awk '{print $4}'
+    ${splitted_output} =    String.Split String    ${output}    ${EMPTY}
+    ${matches} =    Collections.Get Matches    ${splitted_output}    regexp=(\\d\.)+
+    ${subnet_gateway_ip} =    String.Strip String    ${matches[0]}    characters=','
+    [Return]    ${subnet_gateway_ip}
+
 Collect VM IPv6 SLAAC Addresses
     [Arguments]    ${fail_on_none}    ${vm_list}    ${network}    ${subnet}
     [Documentation]    For each VM parse output of "openstack server show" to get its IPv6 address from Neutron DB.
@@ -508,27 +537,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}
@@ -540,10 +548,10 @@ 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}
+    Run Keyword If    "${FAIL_ON_EXCEPTIONS}"=="True"    KarafKeywords.Fail If Exceptions Found During Test    ${test_name}
 
 Get Test Teardown Debugs For SFC
     [Arguments]    ${test_name}=${TEST_NAME}
@@ -728,6 +736,14 @@ Get Port Mac
     ${port_mac} =    Collections.Get from List    ${splitted_output}    0
     [Return]    ${port_mac}
 
+Get Port Mac Address From Ip
+    [Arguments]    ${ip}
+    [Documentation]    Retrieve the mac address for a port that matches any given ip.
+    ${output} =    OpenStack CLI    openstack port list | grep -w ${ip} | awk '{print $5}'
+    ${splitted_output} =    String.Split String    ${output}    ${EMPTY}
+    ${mac_addr} =    Collections.Get from List    ${splitted_output}    0
+    [Return]    ${mac_addr}
+
 Create L2Gateway
     [Arguments]    ${bridge_name}    ${intf_name}    ${gw_name}
     [Documentation]    Keyword to create an L2 Gateway ${gw_name} for bridge ${bridge_name} connected to interface ${intf_name} (Using Neutron CLI).
@@ -922,7 +938,7 @@ Wait For Routes To Propogate
     \    ${is_ipv6} =    String.Get Regexp Matches    @{subnets}[${INDEX}]    ${IP6_REGEX}
     \    ${length} =    BuiltIn.Get Length    ${is_ipv6}
     \    ${cmd} =    BuiltIn.Set Variable If    ${length} == 0    ip route    ip -6 route
-    \    ${output} =    Utils.Write Commands Until Expected Prompt    sudo ip netns exec qdhcp-${net_id} ${cmd}    ]>
+    \    ${output} =    Utils.Write Commands Until Expected Prompt    sudo ip netns exec qdhcp-${net_id} ${cmd}    ${DEFAULT_LINUX_PROMPT_STRICT}
     \    BuiltIn.Should Contain    ${output}    @{subnets}[${INDEX}]
 
 Neutron Cleanup
@@ -1009,6 +1025,8 @@ 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
+    @{loggers} =    BuiltIn.Create List    org.apache.karaf.shell.support.ShellUtil    org.apache.sshd.server.session.ServerSessionImpl
+    Setuputils.Setup_Logging_For_Debug_Purposes_On_List_Or_All    OFF    ${loggers}
     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}
@@ -1023,6 +1041,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