Remove use of ODL_ENABLE_L3_FWD
[integration/test.git] / csit / libraries / OpenStackOperations.robot
index 0e7bd6c67528dd0e733d6aac22a77aa06257c090..1d6051e8fa9ea92d72a512d6f9267bcd5b625c2e 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
@@ -17,7 +18,6 @@ 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
@@ -182,6 +182,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
@@ -525,10 +533,10 @@ Get DumpFlows And Ovsconfig
     \    Utils.Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip route    ${DEFAULT_LINUX_PROMPT_STRICT}
     Utils.Write Commands Until Expected Prompt    sudo ovs-vsctl show    ${DEFAULT_LINUX_PROMPT_STRICT}
     Utils.Write Commands Until Expected Prompt    sudo ovs-vsctl list Open_vSwitch    ${DEFAULT_LINUX_PROMPT_STRICT}
-    Utils.Write Commands Until Expected Prompt    sudo ovs-ofctl show br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
-    Utils.Write Commands Until Expected Prompt    sudo ovs-ofctl dump-flows br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
-    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}
+    Utils.Write Commands Until Expected Prompt    sudo ovs-ofctl show ${INTEGRATION_BRIDGE} -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
+    Utils.Write Commands Until Expected Prompt    sudo ovs-ofctl dump-flows ${INTEGRATION_BRIDGE} -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
+    Utils.Write Commands Until Expected Prompt    sudo ovs-ofctl dump-groups ${INTEGRATION_BRIDGE} -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
+    Utils.Write Commands Until Expected Prompt    sudo ovs-ofctl dump-group-stats ${INTEGRATION_BRIDGE} -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
 
 Get ControlNode Connection
     SSHLibrary.Switch Connection    ${OS_CNTL_CONN_ID}
@@ -544,6 +552,7 @@ Get Test Teardown Debugs
     [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}
+    BuiltIn.run Keyword And Ignore Error    ODLTools.Get EOS    ${HA_PROXY_IP}
     Run Keyword If    "${FAIL_ON_EXCEPTIONS}"=="True"    KarafKeywords.Fail If Exceptions Found During Test    ${test_name}
 
 Get Test Teardown Debugs For SFC
@@ -635,41 +644,6 @@ Neutron Security Group Rule Create
     ${rule_id} =    BuiltIn.Should Match Regexp    ${output}    ${REGEX_UUID}
     [Return]    ${output}    ${rule_id}
 
-Neutron Security Group Rule Create Legacy Cli
-    [Arguments]    ${Security_group_name}    &{Kwargs}
-    [Documentation]    Creates neutron security rule with neutron request with or without optional params, here security group name is mandatory args, rule with optional params can be created by passing the optional args values ex: direction=${INGRESS_EGRESS}, Then these optional params are BuiltIn.Catenated with mandatory args, example of usage: "OpenStack Neutron Security Group Rule Create ${SGP_SSH} direction=${RULE_PARAMS[0]} ethertype=${RULE_PARAMS[1]} ..."
-    BuiltIn.Run Keyword If    ${Kwargs}    BuiltIn.Log    ${Kwargs}
-    ${description}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    description    default=${None}
-    ${direction}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    direction    default=${None}
-    ${ethertype}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    ethertype    default=${None}
-    ${port_range_max}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    port_range_max    default=${None}
-    ${port_range_min}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    port_range_min    default=${None}
-    ${protocol}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    protocol    default=${None}
-    ${remote_group_id}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    remote_group_id    default=${None}
-    ${remote_ip_prefix}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    remote_ip_prefix    default=${None}
-    ${cmd} =    BuiltIn.Set Variable    neutron security-group-rule-create ${Security_group_name}
-    ${cmd} =    BuiltIn.Run Keyword If    '${description}'!='None'    BuiltIn.Catenate    ${cmd}    --description ${description}
-    ...    ELSE    BuiltIn.Catenate    ${cmd}
-    ${cmd} =    BuiltIn.Run Keyword If    '${direction}'!='None'    BuiltIn.Catenate    ${cmd}    --direction ${direction}
-    ...    ELSE    BuiltIn.Catenate    ${cmd}
-    ${cmd} =    BuiltIn.Run Keyword If    '${ethertype}'!='None'    BuiltIn.Catenate    ${cmd}    --ethertype ${ethertype}
-    ...    ELSE    BuiltIn.Catenate    ${cmd}
-    ${cmd} =    BuiltIn.Run Keyword If    '${port_range_max}'!='None'    BuiltIn.Catenate    ${cmd}    --port_range_max ${port_range_max}
-    ...    ELSE    BuiltIn.Catenate    ${cmd}
-    ${cmd} =    BuiltIn.Run Keyword If    '${port_range_min}'!='None'    BuiltIn.Catenate    ${cmd}    --port_range_min ${port_range_min}
-    ...    ELSE    BuiltIn.Catenate    ${cmd}
-    ${cmd} =    BuiltIn.Run Keyword If    '${protocol}'!='None'    BuiltIn.Catenate    ${cmd}    --protocol ${protocol}
-    ...    ELSE    BuiltIn.Catenate    ${cmd}
-    ${cmd} =    BuiltIn.Run Keyword If    '${remote_group_id}'!='None'    BuiltIn.Catenate    ${cmd}    --remote_group_id ${remote_group_id}
-    ...    ELSE    BuiltIn.Catenate    ${cmd}
-    ${cmd} =    BuiltIn.Run Keyword If    '${remote_ip_prefix}'!='None'    BuiltIn.Catenate    ${cmd}    --remote_ip_prefix ${remote_ip_prefix}
-    ...    ELSE    BuiltIn.Catenate    ${cmd}
-    ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${cmd}
-    ${rule_id} =    BuiltIn.Should Match Regexp    ${output}    ${REGEX_UUID}
-    BuiltIn.Log    ${rule_id}
-    BuiltIn.Should Be True    '${rc}' == '0'
-    [Return]    ${output}    ${rule_id}
-
 Security Group Create Without Default Security Rules
     [Arguments]    ${sg_name}    ${additional_args}=${EMPTY}
     [Documentation]    Create Neutron Security Group with no default rules, using specified name and optional arguments.
@@ -729,6 +703,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).
@@ -816,6 +798,14 @@ Update Port Rest
     BuiltIn.Should Be Equal As Strings    ${resp.status_code}    200
     [Return]    ${resp.content}
 
+Get Neutron Network Rest
+    [Arguments]    ${net_id}
+    [Documentation]    Keyword to get the specific network details in Neutron (Using REST).
+    ${resp} =    RequestsLibrary.Get Request    session    ${NETWORK_URL}/network/${net_id}
+    BuiltIn.Log    ${resp.content}
+    BuiltIn.Should Be Equal As Strings    ${resp.status_code}    200
+    [Return]    ${resp.content}
+
 Create And Configure Security Group
     [Arguments]    ${sg-name}
     [Documentation]    Create Security Group with given name, and default allow rules for TCP/UDP/ICMP protocols.
@@ -942,8 +932,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
 
@@ -974,15 +963,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
@@ -1010,13 +997,15 @@ 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
+    @{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}
     BuiltIn.Run Keyword If    "${PRE_CLEAN_OPENSTACK_ALL}"=="True"    OpenStack Cleanup All
     OpenStackOperations.Add OVS Logging On All OpenStack Nodes
+    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
@@ -1070,3 +1059,71 @@ Start Packet Capture On Nodes
 Stop Packet Capture On Nodes
     [Arguments]    ${conn_ids}=@{EMPTY}
     Tcpdump.Stop Packet Capture on Nodes    ${conn_ids}
+
+Server Live Migrate
+    [Arguments]    ${vm_instance_name}
+    [Documentation]    Keyword for live migration of VM instance
+    ...    additional_agrs is to select particular migration(live/shared-migration/block-migration)
+    ...    if the additional_agrs is not given default migration(shared-migration) will happen
+    ${output} =    OpenStackOperations.OpenStack CLI    nova live-migration ${vm_instance_name}
+
+Get Hypervisor Host Of Vm
+    [Arguments]    ${vm_name}
+    [Documentation]    Show server with neutron request.
+    ${output} =    OpenStackOperations.OpenStack CLI    openstack server show -f value -c OS-EXT-SRV-ATTR:host ${vm_name}
+    [Return]    ${output}
+
+Check If Migration Is Complete
+    [Arguments]    ${vm_name}
+    [Documentation]    Show server and verify if task_state is not migrating
+    ${output} =    OpenStackOperations.OpenStack CLI    openstack server show ${vm_name} | grep "OS-EXT-STS:task_state"
+    BuiltIn.Should Not Contain    ${output}    migrating
+
+Modify OpenStack Configuration File
+    [Arguments]    ${conn_id}    ${file_name}    ${section}    ${key}    ${value}
+    [Documentation]    Use crudini to modify any parameter in any Openstack configuration File
+    SSHLibrary.Switch Connection    ${conn_id}
+    ${output}    ${rc} =    SSHLibrary.Execute Command    sudo crudini --verbose --set --inplace ${file_name} ${section} ${key} ${value}    return_rc=True    return_stdout=True
+    BuiltIn.Log    ${output}
+    BuiltIn.Should Be True    '${rc}' == '0'
+
+Restart DevStack Service
+    [Arguments]    ${conn_id}    ${service_name}
+    [Documentation]    Restart the Openstack Service
+    SSHLibrary.Switch Connection    ${conn_id}
+    ${output}    ${rc} =    SSHLibrary.Execute Command    sudo systemctl restart devstack@${service_name}.service    return_rc=True    return_stdout=True
+    BuiltIn.Log    ${output}
+    BuiltIn.Should Be True    '${rc}' == '0'
+
+Get Network Segmentation Id
+    [Arguments]    ${network_name}
+    [Documentation]    Returns network segmentation id for the given network name.
+    ${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
+    : FOR    ${node_ip}    IN    @{node_ips}
+    \    Verify Expected Default Tables    ${node_ip}
+
+Verify Expected Default Tables
+    [Arguments]    ${ovs_ip}
+    [Documentation]    Verify if Default Table Entries are programmed on specific Node
+    ${flow_dump} =    Utils.Write Commands Until Expected Prompt    sudo ovs-ofctl dump-flows ${INTEGRATION_BRIDGE} -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
+    BuiltIn.Log    ${flow_dump}
+    : FOR    ${table}    IN    @{DEFAULT_FLOW_TABLES}
+    \    Builtin.Should Match Regexp    ${flow_dump}    .*table=${table}.*priority=0
+
+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}