Use consistent naming in elan suite
[integration/test.git] / csit / libraries / OpenStackOperations.robot
index ba6951e4dc9356ccabaa3d6b1b4f3b0ca34f9766..f52d11cea962972c4e446fddc75160a473ca4e65 100644 (file)
@@ -331,45 +331,52 @@ Collect VM IP Addresses
     [Return]    ${ip_list}    ${dhcp_ip}
 
 Get Match
-    [Arguments]    ${text}    ${regexp}
+    [Arguments]    ${text}    ${regexp}    ${index}=0
     [Documentation]    Wrapper around Get Regexp Matches to return None if not found or the first match if found.
     @{matches} =    String.Get Regexp Matches    ${text}    ${regexp}
     ${matches_length} =    Get Length    ${matches}
     BuiltIn.Set Test Variable    ${match}    None
-    BuiltIn.Run Keyword If    ${matches_length} > 0    BuiltIn.Set Test Variable    ${match}    @{matches}[0]
+    BuiltIn.Run Keyword If    ${matches_length} > ${index}    BuiltIn.Set Test Variable    ${match}    @{matches}[${index}]
     [Return]    ${match}
 
 Get VM IP
     [Arguments]    ${fail_on_none}    ${vm}
     [Documentation]    Get the vm ip address and nameserver by scraping the vm's console log.
-    ${rc}    ${vm_console_output} =    Run And Return Rc And Output    openstack console log show ${vm}
-    # TODO Add hooks to only tail the console log on subsequent runs, e.g. look for "info: initramfs:".
-    # This would drop repeatedly logging the kernel messages which are long.
-    # Also add flag to log or not
-    BuiltIn.Log    ${vm_console_output}
+    ...    Get VM IP returns three values: [0] the vm IP, [1] the DHCP IP and [2] the vm console log.
+    ${rc}    ${vm_console_output}=    Run And Return Rc And Output    openstack console log show ${vm}
+    ${vm_ip} =    Set Variable    None
+    ${dhcp_ip} =    Set Variable    None
     ${match} =    Get Match    ${vm_console_output}    ${REGEX_OBTAINED}
-    ${OSO_VM_IP} =    Get Match    ${match}    ${REGEX_IPV4}
-    ${match} =    Get Match    ${vm_console_output}    ${REGEX_NAMESERVER}
-    ${OSO_DHCP_IP} =    Get Match    ${match}    ${REGEX_IPV4}
-    BuiltIn.Set Test Variable    ${OSO_VM_IP}
-    BuiltIn.Set Test Variable    ${OSO_DHCP_IP}
-    BuiltIn.Run Keyword If    '${fail_on_none}' == 'true'    Should Not Contain    ${OSO_VM_IP}    None
-    BuiltIn.Run Keyword If    '${fail_on_none}' == 'true'    Should Not Contain    ${OSO_DHCP_IP}    None
+    ${vm_ip} =    Get Match    ${match}    ${REGEX_IPV4}    0
+    ${match} =    Get Match    ${vm_console_output}    ${REGEX_IPROUTE}
+    ${dhcp_ip} =    Get Match    ${match}    ${REGEX_IPV4}    1
+    BuiltIn.Run Keyword If    '${fail_on_none}' == 'true'    Should Not Contain    ${vm_ip}    None
+    BuiltIn.Run Keyword If    '${fail_on_none}' == 'true'    Should Not Contain    ${dhcp_ip}    None
+    [Return]    ${vm_ip}    ${dhcp_ip}    ${vm_console_output}
 
 Get VM IPs
     [Arguments]    @{vms}
     [Documentation]    Get the instance IP addresses and nameserver address for the list of given vms.
     ...    First poll for the vm instance to be in the active state, then poll for the vm ip address and nameserver.
-    ...    ${OSO_VM_IP} and ${OSO_DHCP_IP} are test variables shared with Get VM IP.
-    @{OSO_VM_IPS}    BuiltIn.Create List    @{EMPTY}
+    ...    Get VM IPs returns two things: [0] a list of the ips for the vms passed to this keyword (may contain values
+    ...    of None) and [1] the dhcp ip address found in the last vm checked.
+    ...    TODO: there is a potential issue for a caller that passes in VMs belonging to different networks that
+    ...    may have different dhcp server addresses. Not sure what TODO about that, but noting it here for reference.
+    @{vm_ips}    BuiltIn.Create List    @{EMPTY}
     : FOR    ${vm}    IN    @{vms}
-    \    BuiltIn.Set Test Variable    ${OSO_VM_IP}    None
-    \    BuiltIn.Set Test Variable    ${OSO_DHCP_IP}    None
     \    Poll VM Is ACTIVE    ${vm}
-    \    ${status}    ${message}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    60s    15s
+    \    ${status}    ${ips_and_console_log}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    120s    15s
     \    ...    Get VM IP    true    ${vm}
-    \    BuiltIn.Run Keyword If    '${OSO_VM_IP}' != 'None'    Collections.Append To List    ${OSO_VM_IPS}    ${OSO_VM_IP}
-    [Return]    @{OSO_VM_IPS}    ${OSO_DHCP_IP}
+    \    # If there is trouble with Get VM IP, the status will be FAIL and the return value will be a string of what went
+    \    # wrong. We need to handle both the PASS and FAIL cases. In the FAIL case we know we wont have access to the
+    \    # console log, as it would not be returned; so we need to grab it again to log it. We also can append 'None' to
+    \    # the vm ip list if status is FAIL.
+    \    Run Keyword If    "${status}" == "PASS"    BuiltIn.Log    ${ips_and_console_log[2]}
+    \    BuiltIn.Run Keyword If    "${status}" == "PASS"    Collections.Append To List    ${vm_ips}    ${ips_and_console_log[0]}
+    \    BuiltIn.Run Keyword If    "${status}" == "FAIL"    Collections.Append To List    ${vm_ips}    None
+    \    ${rc}    ${vm_console_output}=    BuiltIn.Run Keyword If    "${status}" == "FAIL"    Run And Return Rc And Output    openstack console log show ${vm}
+    \    BuiltIn.Run Keyword If    "${status}" == "FAIL"    BuiltIn.Log    ${vm_console_output}
+    [Return]    @{vm_ips}    ${ips_and_console_log[1]}
 
 Collect VM IPv6 SLAAC Addresses
     [Arguments]    ${fail_on_none}    ${prefix}    @{vm_list}
@@ -518,7 +525,7 @@ Test Operations From Vm Instance
     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    route -n    ${OS_SYSTEM_PROMPT}
     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    route -A inet6    ${OS_SYSTEM_PROMPT}
     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    arp -an    ${OS_SYSTEM_PROMPT}
-    Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    ip -6 neigh    ${OS_SYSTEM_PROMPT}
+    Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    ip -f inet6 neigh show    ${OS_SYSTEM_PROMPT}
     : FOR    ${dest_ip}    IN    @{dest_ips}
     \    Log    ${dest_ip}
     \    ${string_empty}=    Run Keyword And Return Status    Should Be Empty    ${dest_ip}
@@ -562,8 +569,8 @@ Create Router
     ${rc}    ${output}=    Run And Return Rc And Output    openstack router create ${router_name}
     Should Not Be True    ${rc}
 
-List Router
-    [Documentation]    List Router and return output with neutron client.
+List Routers
+    [Documentation]    List Routers and return output with neutron client.
     ${rc}    ${output}=    Run And Return Rc And Output    openstack router list -f value
     Log    ${output}
     Should Not Be True    ${rc}
@@ -576,7 +583,7 @@ Add Router Interface
 
 Show Router Interface
     [Arguments]    ${router_name}
-    [Documentation]    List Router interface associated with given Router and return output with neutron client.
+    [Documentation]    List Routers interface associated with given Router and return output with neutron client.
     ${rc}    ${output}=    Run And Return Rc And Output    openstack port list --router ${router_name} -f value
     Should Not Be True    ${rc}
     [Return]    ${output}
@@ -689,9 +696,19 @@ Show Debugs
     \    ${rc}    ${output}=    Run And Return Rc And Output    nova show ${index}
     \    Log    ${output}
     List Nova VMs
+    List Routers
     List Networks
     List Subnets
     List Ports
+    List Security Groups
+
+List Security Groups
+    [Documentation]    Logging keyword to display all security groups using the openstack cli. Assumes openstack
+    ...    credentials are already sourced
+    ${rc}    ${output}=    Run And Return Rc And Output    openstack security group list
+    Log    ${output}
+    Should Not Be True    ${rc}
+    [Return]    ${output}
 
 Neutron Security Group Show
     [Arguments]    ${SecurityGroupRuleName}
@@ -1068,7 +1085,7 @@ Reboot Nova VM
     Should Not Be True    ${rc}
     Wait Until Keyword Succeeds    35s    10s    Verify VM Is ACTIVE    ${vm_name}
 
-Remove RSA Key From KnowHosts
+Remove RSA Key From KnownHosts
     [Arguments]    ${vm_ip}
     [Documentation]    Remove RSA
     ${devstack_conn_id}=    Get ControlNode Connection