Add ping retries and break on success 94/78394/12
authorSam Hague <shague@redhat.com>
Mon, 3 Dec 2018 19:58:11 +0000 (14:58 -0500)
committerSam Hague <shague@redhat.com>
Thu, 6 Dec 2018 02:42:45 +0000 (21:42 -0500)
Change the ping command to take a retries value. This
allows the ping to be more independent of timing issues
with flow additions.

The cirros images and the SSHLibary have some weird quirks
that the patch had to workaround:

- The cirros images use a dash like shell and not bash. This
required catering the shell command to be posix compliant.
- The typical prompt of $ is in the shell command so it can't
be used to read until. This was changed to read until regexp
to look for the final rc=n from the command.
- The SSHLibrary Write keyword actually consumes and returns
the command itself, which was causing an early match. The regex
helped here also since the regex would only match on the rc=n -
so a number had to be in the output for it to match.

JIRA: NETVIRT-1399
Change-Id: I06d43fbd2ce7a0f32ccc60cdfd2783abaadd260b
Signed-off-by: Sam Hague <shague@redhat.com>
csit/libraries/OpenStackOperations.robot
csit/libraries/Utils.robot
csit/suites/openstack/connectivity/external_network.robot

index cfcc7c014f1b81db368b63f7a13d24554f936d95..0b91311bc965d0be61581a06d76007b2dd19edf2 100644 (file)
@@ -459,11 +459,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 +513,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 +528,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
index cfcefc11aab1d8bf6319869556f3abf70ff8f667..00991c75b6773ba5495a1aa76f4ee38b195e7ee2 100644 (file)
@@ -504,12 +504,23 @@ Convert_To_Minutes
 Write Commands Until Expected Prompt
     [Arguments]    ${cmd}    ${prompt}    ${timeout}=${DEFAULT_TIMEOUT}
     [Documentation]    quick wrapper for Write and Read Until Prompt Keywords to make test cases more readable
+    BuiltIn.Log    cmd: ${cmd}
     SSHLibrary.Set Client Configuration    timeout=${timeout}
     SSHLibrary.Read
     SSHLibrary.Write    ${cmd}
     ${output}=    SSHLibrary.Read Until    ${prompt}
     [Return]    ${output}
 
+Write Commands Until Expected Regexp
+    [Arguments]    ${cmd}    ${regexp}    ${timeout}=${DEFAULT_TIMEOUT}
+    [Documentation]    quick wrapper for Write and Read Until Prompt Keywords to make test cases more readable
+    BuiltIn.Log    cmd: ${cmd}
+    SSHLibrary.Set Client Configuration    timeout=${timeout}
+    SSHLibrary.Read
+    SSHLibrary.Write    ${cmd}
+    ${output}=    SSHLibrary.Read Until Regexp    ${regexp}
+    [Return]    ${output}
+
 Install Package On Ubuntu System
     [Arguments]    ${package_name}    ${system}=${TOOLS_SYSTEM_IP}    ${user}=${TOOLS_SYSTEM_USER}    ${password}=${TOOLS_SYSTEM_PASSWORD}    ${prompt}=${DEFAULT_LINUX_PROMPT}    ${prompt_timeout}=30s
     [Documentation]    Keyword to install packages for testing to Ubuntu Mininet VM
index b9705e12e9f04caf695dafda6b815a8476ca964b..1320d11f50fdefd586412e4dbf18a2364230e947 100644 (file)
@@ -38,13 +38,13 @@ Initial Ping To External Network PNF from Vm Instance 1
     [Documentation]    Check reachability of External Network PNF from VM instance (with ttl=1 to make sure no router hops)
     ${expect_ping_to_work} =    Set Variable If    "skip_if_controller" in @{TEST_TAGS}    False    True
     ${dst_ip}=    BuiltIn.Create List    ${EXTERNAL_PNF}
-    OpenStackOperations.Test Operations From Vm Instance    @{NETWORKS}[0]    @{NET1_FIP_VM_IPS}[0]    ${dst_ip}    ttl=1    ping_should_succeed=${expect_ping_to_work}
+    OpenStackOperations.Test Operations From Vm Instance    @{NETWORKS}[0]    @{NET1_FIP_VM_IPS}[0]    ${dst_ip}    ttl=1    ping_should_succeed=${expect_ping_to_work}    ping_tries=8
 
 Initial Ping To External Network PNF from Vm Instance 2
     [Documentation]    Check reachability of External Network PNF from VM instance (with ttl=1 to make sure no router hops)
     ${expect_ping_to_work} =    Set Variable If    "skip_if_controller" in @{TEST_TAGS}    False    True
     ${dst_ip}=    BuiltIn.Create List    ${EXTERNAL_PNF}
-    OpenStackOperations.Test Operations From Vm Instance    @{NETWORKS}[0]    @{NET1_FIP_VM_IPS}[1]    ${dst_ip}    ttl=1    ping_should_succeed=${expect_ping_to_work}
+    OpenStackOperations.Test Operations From Vm Instance    @{NETWORKS}[0]    @{NET1_FIP_VM_IPS}[1]    ${dst_ip}    ttl=1    ping_should_succeed=${expect_ping_to_work}    ping_tries=8
 
 Create And Associate Floating IPs for VMs
     [Documentation]    Create and associate a floating IP for the VM
@@ -105,7 +105,7 @@ Ping Vm Instance2 Floating IP From SNAT VM Instance2
 Ping External Network PNF from Vm Instance 1 After Floating IP Assignment
     [Documentation]    Check reachability of External Network PNF from VM instance (with ttl=1 to make sure no router hops)
     ${dst_ip} =    BuiltIn.Create List    ${EXTERNAL_PNF}
-    OpenStackOperations.Test Operations From Vm Instance    @{NETWORKS}[0]    @{NET1_FIP_VM_IPS}[0]    ${dst_ip}    ttl=1
+    OpenStackOperations.Test Operations From Vm Instance    @{NETWORKS}[0]    @{NET1_FIP_VM_IPS}[0]    ${dst_ip}    ttl=1    ping_tries=8
 
 SNAT - TCP connection to External Gateway From SNAT VM Instance1
     [Documentation]    Login to the VM instance and test TCP connection to the controller via SNAT