Use openstack cli instead of nova console-log cli
[integration/test.git] / csit / libraries / OpenStackOperations.robot
index 5ad5c84a12319c2b2f9b1d985395b94d15b4d291..b937e6b0e81a42aa07030f518c03a653c40a6632 100644 (file)
@@ -252,24 +252,28 @@ Get Router Id
     [Return]    ${router_id}
 
 Create Vm Instances
-    [Arguments]    ${net_name}    ${vm_instance_names}    ${image}=cirros-0.3.4-x86_64-uec    ${flavor}=m1.nano    ${sg}=default
+    [Arguments]    ${net_name}    ${vm_instance_names}    ${image}=${EMPTY}    ${flavor}=m1.nano    ${sg}=default    ${min}=1
+    ...    ${max}=1
     [Documentation]    Create X Vm Instance with the net id of the Netowrk.
+    ${image}    Set Variable If    "${image}"=="${EMPTY}"    ${CIRROS_${OPENSTACK_BRANCH}}    ${image}
     ${net_id}=    Get Net Id    ${net_name}    ${devstack_conn_id}
     : FOR    ${VmElement}    IN    @{vm_instance_names}
-    \    ${rc}    ${output}=    Run And Return Rc And Output    openstack server create --image ${image} --flavor ${flavor} --nic net-id=${net_id} ${VmElement} --security-group ${sg}
+    \    ${rc}    ${output}=    Run And Return Rc And Output    openstack server create --image ${image} --flavor ${flavor} --nic net-id=${net_id} ${VmElement} --security-group ${sg} --min ${min} --max ${max}
     \    Should Not Be True    ${rc}
     \    Log    ${output}
 
 Create Vm Instance With Port
-    [Arguments]    ${port_name}    ${vm_instance_name}    ${image}=cirros-0.3.4-x86_64-uec    ${flavor}=m1.nano    ${sg}=default
+    [Arguments]    ${port_name}    ${vm_instance_name}    ${image}=${EMPTY}    ${flavor}=m1.nano    ${sg}=default
     [Documentation]    Create One VM instance using given ${port_name} and for given ${compute_node}
+    ${image}    Set Variable If    "${image}"=="${EMPTY}"    ${CIRROS_${OPENSTACK_BRANCH}}    ${image}
     ${port_id}=    Get Port Id    ${port_name}    ${devstack_conn_id}
-    ${rc}    ${output}=    Run And Return Rc And Output    openstack server create --image ${image} --flavor ${flavor} --nic port-id=${port_id} ${vm_instance_name} --security-groups ${sg}
+    ${rc}    ${output}=    Run And Return Rc And Output    openstack server create --image ${image} --flavor ${flavor} --nic port-id=${port_id} ${vm_instance_name} --security-group ${sg}
     Log    ${output}
 
 Create Vm Instance With Ports
-    [Arguments]    ${port_name}    ${port2_name}    ${vm_instance_name}    ${image}=cirros-0.3.4-x86_64-uec    ${flavor}=m1.nano    ${sg}=default
+    [Arguments]    ${port_name}    ${port2_name}    ${vm_instance_name}    ${image}=${EMPTY}    ${flavor}=m1.nano    ${sg}=default
     [Documentation]    Create One VM instance using given ${port_name} and for given ${compute_node}
+    ${image}    Set Variable If    "${image}"=="${EMPTY}"    ${CIRROS_${OPENSTACK_BRANCH}}    ${image}
     ${port_id}=    Get Port Id    ${port_name}    ${devstack_conn_id}
     ${port2_id}=    Get Port Id    ${port2_name}    ${devstack_conn_id}
     ${rc}    ${output}=    Run And Return Rc And Output    openstack server create --image ${image} --flavor ${flavor} --nic port-id=${port_id} --nic port-id=${port2_id} ${vm_instance_name} --security-group ${sg}
@@ -277,14 +281,32 @@ Create Vm Instance With Ports
     Should Not Be True    ${rc}
 
 Create Vm Instance With Port On Compute Node
-    [Arguments]    ${port_name}    ${vm_instance_name}    ${compute_node}    ${image}=cirros-0.3.4-x86_64-uec    ${flavor}=m1.nano    ${sg}=default
+    [Arguments]    ${port_name}    ${vm_instance_name}    ${compute_node}    ${image}=${EMPTY}    ${flavor}=m1.nano    ${sg}=default
     [Documentation]    Create One VM instance using given ${port_name} and for given ${compute_node}
+    ${image}    Set Variable If    "${image}"=="${EMPTY}"    ${CIRROS_${OPENSTACK_BRANCH}}    ${image}
     ${port_id}=    Get Port Id    ${port_name}    ${devstack_conn_id}
-    ${hostname_compute_node}=    Run Command On Remote System    ${compute_node}    hostname
+    ${hostname_compute_node}=    Get Hypervisor Hostname From IP    ${compute_node}
     ${rc}    ${output}=    Run And Return Rc And Output    openstack server create --image ${image} --flavor ${flavor} --nic port-id=${port_id} --security-group ${sg} --availability-zone nova:${hostname_compute_node} ${vm_instance_name}
     Log    ${output}
     Should Not Be True    ${rc}
 
+Get Hypervisor Hostname From IP
+    [Arguments]    ${hypervisor_ip}
+    [Documentation]    Returns the hostname found for the given IP address if it's listed in hypervisor list. For debuggability
+    ...    the full listing is logged first, then followed by a grep | cut to focus on the actual hostname to return
+    ${rc}    ${output}    Run And Return Rc And Output    openstack hypervisor list
+    Log    ${output}
+    ${rc}    ${hostname}=    Run And Return Rc And Output    openstack hypervisor list -f value | grep ${hypervisor_ip} | cut -d" " -f 2
+    Log    ${hostname}
+    Should Not Be True    ${rc}
+    [Return]    ${hostname}
+
+Create Nano Flavor
+    [Documentation]    Create a nano flavor
+    ${rc}    ${output}=    Run And Return Rc And Output    openstack flavor create m1.nano --id auto --ram 64 --disk 0 --vcpus 1
+    Log    ${output}
+    Should Not Be True    ${rc}
+
 Verify VM Is ACTIVE
     [Arguments]    ${vm_name}
     [Documentation]    Run these commands to check whether the created vm instance is active or not.
@@ -293,9 +315,14 @@ Verify VM Is ACTIVE
     Should Not Be True    ${rc}
     Should Contain    ${output}    active
 
+Poll VM Is ACTIVE
+    [Arguments]    ${vm_name}    ${retry}=600s    ${retry_interval}=5s
+    [Documentation]    Run these commands to check whether the created vm instance is active or not.
+    Wait Until Keyword Succeeds    ${retry}    ${retry_interval}    Verify VM Is ACTIVE    ${vm_name}
+
 Collect VM IP Addresses
     [Arguments]    ${fail_on_none}    @{vm_list}
-    [Documentation]    Using nova console-log on the provided ${vm_list} to search for the string "obtained" which
+    [Documentation]    Using the console-log on the provided ${vm_list} to search for the string "obtained" which
     ...    correlates to the instance receiving it's IP address via DHCP. Also retrieved is the ip of the nameserver
     ...    if available in the console-log output. The keyword will also return a list of the learned ips as it
     ...    finds them in the console log output, and will have "None" for Vms that no ip was found.
@@ -315,6 +342,8 @@ Collect VM IP Addresses
     \    ${dhcp_ip_length}    Get Length    ${dhcp_ip}
     \    Run Keyword If    ${dhcp_ip_length}<=0    Append To List    ${dhcp_ip}    None
     \    Log    ${dhcp_ip}
+    \    ${vm_console_output}=    Run    openstack console log show ${vm}
+    \    Log    ${vm_console_output}
     ${dhcp_length}    Get Length    ${dhcp_ip}
     Run Keyword If    '${fail_on_none}' == 'true'    Should Not Contain    ${ip_list}    None
     Run Keyword If    '${fail_on_none}' == 'true'    Should Not Contain    ${dhcp_ip}    None
@@ -324,12 +353,12 @@ Collect VM IP Addresses
 
 Collect VM IPv6 SLAAC Addresses
     [Arguments]    ${fail_on_none}    ${prefix}    @{vm_list}
-    [Documentation]    Using nova console-log on the provided ${vm_list} to search for the string "inet6" which
+    [Documentation]    Using the console-log on the provided ${vm_list} to search for the string "inet6" which
     ...    correlates to the instance generated IPv6 address, based on the ${prefix} received from ODL (SLAAC mode).
     ${ip_list}    Create List    @{EMPTY}
     : FOR    ${vm}    IN    @{vm_list}
     \    Log    ${vm}
-    \    ${rc}    ${vm_ip_line}=    Run And Return Rc And Output    nova console-log ${vm} | grep -i "inet6"
+    \    ${rc}    ${vm_ip_line}=    Run And Return Rc And Output    openstack console log show ${vm} | grep -i "inet6"
     \    Log    ${vm_ip_line}
     \    Log    ${rc}
     \    @{vm_ip_list}    Get Regexp Matches    ${vm_ip_line}    ${prefix}
@@ -345,7 +374,7 @@ View Vm Console
     [Arguments]    ${vm_instance_names}
     [Documentation]    View Console log of the created vm instances using nova show.
     : FOR    ${VmElement}    IN    @{vm_instance_names}
-    \    ${rc}    ${output}=    Run And Return Rc And Output    nova show ${VmElement}
+    \    ${rc}    ${output}=    Run And Return Rc And Output    openstack server show ${VmElement}
     \    Log    ${output}
     \    Should Not Be True    ${rc}
     \    ${rc}    ${output}=    Run And Return Rc And Output    openstack console log show ${VmElement}
@@ -631,10 +660,6 @@ Get Test Teardown Debugs
     Run Keyword And Ignore Error    Get Model Dump    ${HA_PROXY_IP}    ${netvirt_data_models}
     Get Karaf Log Events From Test Start    ${test_name}
 
-Get Suite Teardown Debugs
-    Get OvsDebugInfo
-    Get Model Dump    ${HA_PROXY_IP}    ${netvirt_data_models}
-
 Show Debugs
     [Arguments]    @{vm_indices}
     [Documentation]    Run these commands for debugging, it can list state of VM instances and ip information in control node
@@ -791,6 +816,17 @@ Delete All Security Group Rules
     \    Log    ${output}
     \    Should Not Be True    ${rc}
 
+Create Allow All SecurityGroup
+    [Arguments]    ${sg_name}    ${ether_type}=IPv4
+    [Documentation]    Allow all TCP/UDP/ICMP packets for this suite
+    Neutron Security Group Create    ${sg_name}
+    Neutron Security Group Rule Create    ${sg_name}    direction=ingress    ethertype=${ether_type}    port_range_max=65535    port_range_min=1    protocol=tcp
+    Neutron Security Group Rule Create    ${sg_name}    direction=egress    ethertype=${ether_type}    port_range_max=65535    port_range_min=1    protocol=tcp
+    Neutron Security Group Rule Create    ${sg_name}    direction=ingress    ethertype=${ether_type}    protocol=icmp
+    Neutron Security Group Rule Create    ${sg_name}    direction=egress    ethertype=${ether_type}    protocol=icmp
+    Neutron Security Group Rule Create    ${sg_name}    direction=ingress    ethertype=${ether_type}    port_range_max=65535    port_range_min=1    protocol=udp
+    Neutron Security Group Rule Create    ${sg_name}    direction=egress    ethertype=${ether_type}    port_range_max=65535    port_range_min=1    protocol=udp
+
 Create Neutron Port With Additional Params
     [Arguments]    ${network_name}    ${port_name}    ${additional_args}=${EMPTY}
     [Documentation]    Create Port With given additional parameters
@@ -815,7 +851,7 @@ Get Ports MacAddr
 Get Port Ip
     [Arguments]    ${port_name}
     [Documentation]    Keyword would return the IP of the ${port_name} received.
-    ${rc}    ${output}=    Run And Return Rc And Output    neutron port-list | grep "${port_name}" | awk '{print $11}' | awk -F "\\"" '{print $2}'
+    ${rc}    ${output}=    Run And Return Rc And Output    openstack port list | grep "${port_name}" | awk -F\\' '{print $2}'
     Log    ${output}
     ${splitted_output}=    Split String    ${output}    ${EMPTY}
     ${port_ip}=    Get from List    ${splitted_output}    0
@@ -935,15 +971,24 @@ Add Security Group To VM
     Log    ${output}
     Should Not Be True    ${rc}
 
+Remove Security Group From VM
+    [Arguments]    ${vm}    ${sg}
+    [Documentation]    Remove the security group provided to the given VM.
+    ${devstack_conn_id}=    Get ControlNode Connection
+    Switch Connection    ${devstack_conn_id}
+    ${output}=    Write Commands Until Prompt    openstack server remove security group ${vm} ${sg}
+    Log    ${output}
+    Close Connection
+
 Create SFC Flow Classifier
     [Arguments]    ${name}    ${src_ip}    ${dest_ip}    ${protocol}    ${dest_port}    ${neutron_src_port}
     [Documentation]    Create a flow classifier for SFC
-    ${cmd}=    Set Variable    neutron flow-classifier-create --ethertype IPv4 --source-ip-prefix ${src_ip}/32 --destination-ip-prefix ${dest_ip}/32 --protocol ${protocol} --destination-port ${dest_port}:${dest_port} --logical-source-port ${neutron_src_port} ${name}
+    ${cmd}=    Set Variable    openstack sfc flow classifier create --ethertype IPv4 --source-ip-prefix ${src_ip}/32 --destination-ip-prefix ${dest_ip}/32 --protocol ${protocol} --destination-port ${dest_port}:${dest_port} --logical-source-port ${neutron_src_port} ${name}
     Log    ${cmd}
     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
     Log    ${output}
     Should Not Be True    ${rc}
-    Should Contain    ${output}    Created a new flow_classifier
+    Should Contain    ${output}    ${name}
     [Return]    ${output}
 
 Delete SFC Flow Classifier
@@ -951,12 +996,11 @@ Delete SFC Flow Classifier
     [Documentation]    Delete a SFC flow classifier
     ${devstack_conn_id}=    Get ControlNode Connection
     Switch Connection    ${devstack_conn_id}
-    ${cmd}=    Set Variable    neutron flow-classifier-delete ${name}
+    ${cmd}=    Set Variable    openstack sfc flow classifier delete ${name}
     Log    ${cmd}
     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
     Log    ${output}
     Should Not Be True    ${rc}
-    Should Contain    ${output}    Deleted flow_classifier
     [Return]    ${output}
 
 Create SFC Port Pair
@@ -964,79 +1008,76 @@ Create SFC Port Pair
     [Documentation]    Creates a neutron port pair for SFC
     ${devstack_conn_id}=    Get ControlNode Connection
     Switch Connection    ${devstack_conn_id}
-    ${cmd}=    Set Variable    neutron port-pair-create --ingress=${port_in} --egress=${port_out} ${name}
+    ${cmd}=    Set Variable    openstack sfc port pair create --ingress=${port_in} --egress=${port_out} ${name}
     Log    ${cmd}
     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
     Log    ${output}
     Should Not Be True    ${rc}
-    Should Contain    ${output}    Created a new port_pair
+    Should Contain    ${output}    ${name}
     [Return]    ${output}
 
 Delete SFC Port Pair
     [Arguments]    ${name}
     [Documentation]    Delete a SFC port pair
-    ${cmd}=    Set Variable    neutron port-pair-delete ${name}
+    ${cmd}=    Set Variable    openstack sfc port pair delete ${name}
     Log    ${cmd}
     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
     Log    ${output}
     Should Not Be True    ${rc}
-    Should Contain    ${output}    Deleted port_pair
     [Return]    ${output}
 
 Create SFC Port Pair Group
     [Arguments]    ${name}    ${port_pair}
     [Documentation]    Creates a port pair group with a single port pair for SFC
-    ${cmd}=    Set Variable    neutron port-pair-group-create --port-pair ${port_pair} ${name}
+    ${cmd}=    Set Variable    openstack sfc port pair group create --port-pair ${port_pair} ${name}
     Log    ${cmd}
     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
     Log    ${output}
     Should Not Be True    ${rc}
-    Should Contain    ${output}    Created a new port_pair_group
+    Should Contain    ${output}    ${name}
     [Return]    ${output}
 
 Create SFC Port Pair Group With Two Pairs
     [Arguments]    ${name}    ${port_pair1}    ${port_pair2}
     [Documentation]    Creates a port pair group with two port pairs for SFC
-    ${cmd}=    Set Variable    neutron port-pair-group-create --port-pair ${port_pair1} --port-pair ${port_pair2} ${name}
+    ${cmd}=    Set Variable    openstack sfc port pair group create --port-pair ${port_pair1} --port-pair ${port_pair2} ${name}
     Log    ${cmd}
     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
     Log    ${output}
     Should Not Be True    ${rc}
-    Should Contain    ${output}    Created a new port_pair_group
+    Should Contain    ${output}    ${name}
     [Return]    ${output}
 
 Delete SFC Port Pair Group
     [Arguments]    ${name}
     [Documentation]    Delete a SFC port pair group
     ${devstack_conn_id}=    Get ControlNode Connection
-    ${cmd}=    Set Variable    neutron port-pair-group-delete ${name}
+    ${cmd}=    Set Variable    openstack sfc port pair group delete ${name}
     Log    ${cmd}
     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
     Log    ${output}
     Should Not Be True    ${rc}
-    Should Contain    ${output}    Deleted port_pair_group
     [Return]    ${output}
 
 Create SFC Port Chain
     [Arguments]    ${name}    ${pg1}    ${pg2}    ${fc}
     [Documentation]    Creates a port pair chain with two port groups and a singel classifier.
-    ${cmd}=    Set Variable    neutron port-chain-create --port-pair-group ${pg1} --port-pair-group ${pg2} --flow-classifier ${fc} ${name}
+    ${cmd}=    Set Variable    openstack sfc port chain create --port-pair-group ${pg1} --port-pair-group ${pg2} --flow-classifier ${fc} ${name}
     Log    ${cmd}
     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
     Log    ${output}
     Should Not Be True    ${rc}
-    Should Contain    ${output}    Created a new port_chain
+    Should Contain    ${output}    ${name}
     [Return]    ${output}
 
 Delete SFC Port Chain
     [Arguments]    ${name}
     [Documentation]    Delete a SFC port chain
-    ${cmd}=    Set Variable    neutron port-chain-delete ${name}
+    ${cmd}=    Set Variable    openstack sfc port chain delete ${name}
     Log    ${cmd}
     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
     Log    ${output}
     Should Not Be True    ${rc}
-    Should Contain    ${output}    Deleted port_chain
     [Return]    ${output}
 
 Reboot Nova VM