Remove BC option in netconf testtool
[integration/test.git] / csit / libraries / OpenStackOperations.robot
index 2a66bc1762adaea3ef4c96317c8bda7ddfe9d798..6e24ffc459bc06609f760bae7b025372edfe32aa 100644 (file)
@@ -43,6 +43,16 @@ Create Network
     ${output} =    OpenStack CLI    openstack network create ${network_name} ${additional_args}
     [Return]    ${output}
 
+Create Multiple Networks
+    [Arguments]    @{name_of_networks}
+    [Documentation]    Create required number of networks and return a list of the resulting network ids
+    ${net_list_ids} =    BuiltIn.Create List    @{EMPTY}
+    : FOR    ${net}    IN    @{name_of_networks}
+    \    ${output} =    OpenStackOperations.Create Network    ${net}
+    \    ${net_id} =    Get Regexp Matches    ${output}    ${REGEX_UUID}
+    \    Collections.Append To List    ${net_list_ids}    ${net_id}
+    [Return]    @{net_list_ids}
+
 Update Network
     [Arguments]    ${network_name}    ${additional_args}=${EMPTY}
     [Documentation]    Update Network with neutron request.
@@ -75,6 +85,20 @@ Create SubNet
     [Documentation]    Create SubNet for the Network with neutron request.
     ${output} =    OpenStack CLI    openstack subnet create --network ${network_name} --subnet-range ${range_ip} ${subnet_name} ${additional_args}
 
+Create Multiple Subnets
+    [Arguments]    ${network_names}    ${subnet_names}    ${subnet_cidr}
+    [Documentation]    Create required number of subnets for previously created networks and return subnet id
+    ${number_of_networks} =    BuiltIn.Get Length    ${network_names}
+    @{subnet_id_list} =    BuiltIn.Create List    @{EMPTY}
+    : FOR    ${index}    IN RANGE    ${number_of_networks}
+    \    OpenStackOperations.Create SubNet    ${network_names[${index}]}    ${subnet_names[${index}]}    ${subnet_cidr[${index}]}
+    ${sub_list} =    OpenStackOperations.List Subnets
+    : FOR    ${index}    IN RANGE    ${number_of_networks}
+    \    BuiltIn.Should Contain    ${sub_list}    ${subnet_names[${index}]}
+    \    ${subnet_id} =    OpenStackOperations.Get Subnet Id    ${subnet_names[${index}]}
+    \    Collections.Append To List    ${subnet_id_list}    ${subnet_id}
+    [Return]    @{subnet_id_list}
+
 Update SubNet
     [Arguments]    ${subnet_name}    ${additional_args}=${EMPTY}
     [Documentation]    Update subnet with openstack subnet set request.
@@ -203,6 +227,13 @@ Get Router Id
     ${router_id} =    Collections.Get from List    ${splitted_output}    0
     [Return]    ${router_id}
 
+Get VMs OVS Port Number
+    [Arguments]    ${ip_address}    ${portname}
+    [Documentation]    Get the port number for given portname
+    ${subportid} =    OpenStackOperations.Get Sub Port Id    ${portname}
+    ${vm_port_number} =    OVSDB.Get Port Number    ${subportid}    ${ip_address}
+    [Return]    ${vm_port_number}
+
 Add New Image From Url
     [Arguments]    ${image_url}    ${image_name}
     [Documentation]    To add new qcow2 images for testing.
@@ -345,9 +376,10 @@ Check If Instance Is Ready For Ssh Login Using PublicKey
     BuiltIn.Should Contain    ${output}    ${vm_ip}
 
 Check If Instance Is Ready For Ssh Login Using Password
-    [Arguments]    ${net_name}    ${vm_ip}    ${user}=cirros    ${console}=cirros
+    [Arguments]    ${net_name}    ${vm_ip}    ${user}=cirros    ${password}=cubswin:)    ${console}=cirros
     [Documentation]    Ensure the VM is reachable from ssh as tests would require. This keyword will use password authentication
-    ${output} =    Execute Command on VM Instance    ${net_name}    ${vm_ip}    ifconfig    console=${console}
+    ${output} =    Execute Command on VM Instance    ${net_name}    ${vm_ip}    ifconfig    ${user}    ${password}
+    ...    console=${console}
     BuiltIn.Should Contain    ${output}    ${vm_ip}
 
 Get VM IPs
@@ -375,6 +407,17 @@ Get VM IPs
     OpenStackOperations.Copy DHCP Files From Control Node
     [Return]    @{vm_ips}    ${ips_and_console_log[1]}
 
+Get All VM IP Addresses
+    [Arguments]    ${conn_id}    ${vm_name}
+    [Documentation]    Show information of a given two port VM and grep for two ip address. VM name should be sent as arguments.
+    SSHLibrary.Switch Connection    ${conn_id}
+    ${cmd} =    BuiltIn.Set Variable    openstack server show ${vm_name}
+    ${output} =    OpenStackOperations.OpenStack CLI    ${cmd}
+    BuiltIn.Log    ${output}
+    ${address_output} =    OpenStackOperations.OpenStack CLI    ${cmd} | grep "addresses" | awk '{print $4$5}'
+    @{vm_ips} =    String.Get Regexp Matches    ${address_output}    ${REGEX_IPV4}
+    [Return]    @{vm_ips}
+
 Get Subnet Gateway Ip
     [Arguments]    ${subnet_name}
     [Documentation]    Show information of a subnet and grep for subnet gateway ip address
@@ -459,11 +502,13 @@ Exit From Vm Console
     BuiltIn.Run Keyword If    ${rcode}    DevstackUtils.Write Commands Until Prompt    exit
 
 Check Ping
-    [Arguments]    ${ip_address}    ${ttl}=64
+    [Arguments]    ${ip_address}    ${ttl}=64    ${ping_tries}=3
     [Documentation]    Run Ping command on the IP available as argument
     ${ethertype} =    String.Get Regexp Matches    ${ip_address}    ${IP_REGEX}
-    ${output} =    BuiltIn.Run Keyword If    ${ethertype}    Utils.Write Commands Until Expected Prompt    ping -t ${ttl} -c 3 ${ip_address}    ${OS_SYSTEM_PROMPT}
-    ...    ELSE    Utils.Write Commands Until Expected Prompt    ping6 -t ${ttl} -c 3 ${ip_address}    ${OS_SYSTEM_PROMPT}
+    ${ping} =    BuiltIn.Set Variable If    ${ethertype}    ping    ping6
+    ${cmd} =    BuiltIn.Set Variable    rc=0; for count in `seq 1 ${ping_tries}`; do ${ping} -W1 -t${ttl} -c1 ${ip_address}; rc=$?; if [ $rc -eq 0 ]; then break; fi; done; echo ping_rc=$rc
+    ${output} =    Utils.Write Commands Until Expected Regexp    ${cmd}    ping_rc=\\d+    120
+    BuiltIn.Log    output: ${output}
     BuiltIn.Should Contain    ${output}    64 bytes
 
 Check No Ping
@@ -511,7 +556,7 @@ Copy File To VM Instance With PublicKey Auth
 
 Test Operations From Vm Instance
     [Arguments]    ${net_name}    ${src_ip}    ${dest_ips}    ${user}=cirros    ${password}=cubswin:)    ${ttl}=64
-    ...    ${ping_should_succeed}=True    ${check_metadata}=True    ${console}=cirros
+    ...    ${ping_should_succeed}=True    ${check_metadata}=True    ${console}=cirros    ${ping_tries}=3
     [Documentation]    Login to the vm instance using ssh in the network.
     OpenStackOperations.Get ControlNode Connection
     ${net_id} =    OpenStackOperations.Get Net Id    ${net_name}
@@ -526,7 +571,7 @@ Test Operations From Vm Instance
     : FOR    ${dest_ip}    IN    @{dest_ips}
     \    ${string_empty} =    BuiltIn.Run Keyword And Return Status    Should Be Empty    ${dest_ip}
     \    BuiltIn.Run Keyword If    ${string_empty}    Continue For Loop
-    \    BuiltIn.Run Keyword If    ${rcode} and "${ping_should_succeed}" == "True"    OpenStackOperations.Check Ping    ${dest_ip}    ttl=${ttl}
+    \    BuiltIn.Run Keyword If    ${rcode} and "${ping_should_succeed}" == "True"    OpenStackOperations.Check Ping    ${dest_ip}    ttl=${ttl}    ping_tries=${ping_tries}
     \    ...    ELSE    OpenStackOperations.Check No Ping    ${dest_ip}    ttl=${ttl}
     ${ethertype} =    String.Get Regexp Matches    ${src_ip}    ${IP_REGEX}
     BuiltIn.Run Keyword If    ${rcode} and "${check_metadata}" and ${ethertype} == "True"    OpenStackOperations.Check Metadata Access
@@ -716,6 +761,7 @@ Neutron Security Group Rule Create
     ${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}
+    ${remote_ip}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    remote_ip    default=${None}
     ${cmd} =    BuiltIn.Set Variable    openstack security group rule create ${Security_group_name}
     ${cmd} =    BuiltIn.Run Keyword If    '${description}'!='None'    BuiltIn.Catenate    ${cmd}    --description ${description}
     ...    ELSE    BuiltIn.Catenate    ${cmd}
@@ -733,6 +779,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}
+    ${cmd} =    BuiltIn.Run Keyword If    '${remote_ip}'!='None'    BuiltIn.Catenate    ${cmd}    --remote-ip ${remote_ip}
+    ...    ELSE    BuiltIn.Catenate    ${cmd}
     ${output} =    OpenStack CLI    ${cmd}
     ${rule_id} =    BuiltIn.Should Match Regexp    ${output}    ${REGEX_UUID}
     [Return]    ${output}    ${rule_id}
@@ -1141,7 +1189,7 @@ Validate Deployment
     Write To Validate File    ----------------------------------------\n${SUITE_NAME}\n
     : FOR    ${keyword}    IN    @{VALIDATION_KEYWORDS}
     \    ${status} =    Builtin.Run Keyword And Return Status    ${keyword}
-    \    BuiltIn.Run Keyword If    "${status}" == "FAIL"    BuiltIn.Run Keywords    Write To Validate File    Failed: ${keyword}
+    \    BuiltIn.Run Keyword If    "${status}" == "FAIL" or "${status}" == "False"    BuiltIn.Run Keywords    Write To Validate File    Failed: ${keyword}
     \    ...    AND    BuiltIn.Fail
     \    ...    ELSE    Write To Validate File    Passed: ${keyword}
 
@@ -1239,7 +1287,14 @@ Verify Services
     Wait Until Keyword Succeeds    60    2    ClusterManagement.Check Status Of Services Is OPERATIONAL    @{NETVIRT_DIAG_SERVICES}
 
 Verify Expected Default Tunnels
-    [Documentation]    Verify if the default tunnels are created
+    [Documentation]    Verify if the default tunnels are created.
+    ...    SFC jobs currently fail this validation because it uses of-tunnels.
+    ...    This validation will be blocked for NEtvirt SFC jobs until support for of-tunnels
+    ...    added to odltools.
+    ${check_feature_list} =    BuiltIn.Create List    odl-netvirt-sfc
+    ${is_sfc_enabled} =    OpenStackOperations.Is Feature Installed    features=${check_feature_list}
+    BuiltIn.Return From Keyword If    ${is_sfc_enabled} == ${True}    ${True}
+    BuiltIn.Return From Keyword If    ${OS_NODE_CNT} == ${1}    ${True}
     ${output} =    ODLTools.Analyze Tunnels    test_name=${SUITE_NAME}.Suite Setup
     BuiltIn.Should Contain    ${output}    All tunnels are up
 
@@ -1277,3 +1332,16 @@ Set Instance Quota For Project
     [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}
+
+Create Bgpvpn
+    [Arguments]    ${vpnname}    ${additional_args}=${EMPTY}
+    [Documentation]    Create Bgpvpn with neutron request.
+    ${output} =    OpenStack CLI    openstack bgpvpn create --name ${vpnname} ${additional_args}
+
+Get BgpVpn Id
+    [Arguments]    ${vpnName}
+    [Documentation]    Retrieve the bgpvpn id for the given bgpvpn name
+    ${output} =    OpenStack CLI    OperatingSystem.Run And Return Rc And Output    openstack bgpvpn show ${vpnName} | grep " ID" | awk '{print $4}'
+    ${splitted_output}=    String.Split String    ${output}    ${EMPTY}
+    ${vpn_id}=    Collections.Get from List    ${splitted_output}    0
+    [Return]    ${vpn_id}