Skip to content

Commit 9aad1b9

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "refactor ping_check"
2 parents c8305cd + af9bf86 commit 9aad1b9

File tree

8 files changed

+104
-57
lines changed

8 files changed

+104
-57
lines changed

exercises/boot_from_volume.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ IP=$(get_instance_ip $VM_UUID $PRIVATE_NETWORK_NAME)
182182
die_if_not_set $LINENO IP "Failure retrieving IP address"
183183

184184
# Private IPs can be pinged in single node deployments
185-
ping_check "$PRIVATE_NETWORK_NAME" $IP $BOOT_TIMEOUT
185+
ping_check $IP $BOOT_TIMEOUT "$PRIVATE_NETWORK_NAME"
186186

187187
# Clean up
188188
# --------

exercises/euca.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ else
142142
die $LINENO "Failure authorizing rule in $SECGROUP"
143143

144144
# Test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
145-
ping_check "$PUBLIC_NETWORK_NAME" $FLOATING_IP $ASSOCIATE_TIMEOUT
145+
ping_check $FLOATING_IP $ASSOCIATE_TIMEOUT "$PUBLIC_NETWORK_NAME"
146146

147147
# Revoke pinging
148148
euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \

exercises/floating_ips.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ IP=$(get_instance_ip $VM_UUID $PRIVATE_NETWORK_NAME)
139139
die_if_not_set $LINENO IP "Failure retrieving IP address"
140140

141141
# Private IPs can be pinged in single node deployments
142-
ping_check "$PRIVATE_NETWORK_NAME" $IP $BOOT_TIMEOUT
142+
ping_check $IP $BOOT_TIMEOUT "$PRIVATE_NETWORK_NAME"
143143

144144
# Floating IPs
145145
# ------------
@@ -158,7 +158,7 @@ nova add-floating-ip $VM_UUID $FLOATING_IP || \
158158
die $LINENO "Failure adding floating IP $FLOATING_IP to $VM_NAME"
159159

160160
# Test we can ping our floating IP within ASSOCIATE_TIMEOUT seconds
161-
ping_check "$PUBLIC_NETWORK_NAME" $FLOATING_IP $ASSOCIATE_TIMEOUT
161+
ping_check $FLOATING_IP $ASSOCIATE_TIMEOUT "$PUBLIC_NETWORK_NAME"
162162

163163
if ! is_service_enabled neutron; then
164164
# Allocate an IP from second floating pool
@@ -182,7 +182,7 @@ fi
182182
# FIXME (anthony): make xs support security groups
183183
if [ "$VIRT_DRIVER" != "ironic" -a "$VIRT_DRIVER" != "xenserver" -a "$VIRT_DRIVER" != "openvz" ]; then
184184
# Test we can aren't able to ping our floating ip within ASSOCIATE_TIMEOUT seconds
185-
ping_check "$PUBLIC_NETWORK_NAME" $FLOATING_IP $ASSOCIATE_TIMEOUT Fail
185+
ping_check $FLOATING_IP $ASSOCIATE_TIMEOUT "$PUBLIC_NETWORK_NAME" Fail
186186
fi
187187

188188
# Clean up

exercises/neutron-adv-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ function ping_ip {
281281
local VM_NAME=$1
282282
local NET_NAME=$2
283283
IP=$(get_instance_ip $VM_NAME $NET_NAME)
284-
ping_check $NET_NAME $IP $BOOT_TIMEOUT
284+
ping_check $IP $BOOT_TIMEOUT $NET_NAME
285285
}
286286

287287
function check_vm {

exercises/volumes.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ IP=$(get_instance_ip $VM_UUID $PRIVATE_NETWORK_NAME)
143143
die_if_not_set $LINENO IP "Failure retrieving IP address"
144144

145145
# Private IPs can be pinged in single node deployments
146-
ping_check "$PRIVATE_NETWORK_NAME" $IP $BOOT_TIMEOUT
146+
ping_check $IP $BOOT_TIMEOUT "$PRIVATE_NETWORK_NAME"
147147

148148
# Volumes
149149
# -------

functions

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -344,39 +344,42 @@ function wait_for_service {
344344

345345

346346
# ping check
347-
# Uses globals ``ENABLED_SERVICES``
348-
# ping_check from-net ip boot-timeout expected
347+
# Uses globals ``ENABLED_SERVICES``, ``TOP_DIR``, ``MULTI_HOST``, ``PRIVATE_NETWORK``
348+
# ping_check <ip> [boot-timeout] [from_net] [expected]
349349
function ping_check {
350-
if is_service_enabled neutron; then
351-
_ping_check_neutron "$1" $2 $3 $4
352-
return
350+
local ip=$1
351+
local timeout=${2:-30}
352+
local from_net=${3:-""}
353+
local expected=${4:-True}
354+
local op="!"
355+
local failmsg="[Fail] Couldn't ping server"
356+
local ping_cmd="ping"
357+
358+
# if we don't specify a from_net we're expecting things to work
359+
# fine from our local box.
360+
if [[ -n "$from_net" ]]; then
361+
if is_service_enabled neutron; then
362+
ping_cmd="$TOP_DIR/tools/ping_neutron.sh $from_net"
363+
elif [[ "$MULTI_HOST" = "True" && "$from_net" = "$PRIVATE_NETWORK_NAME" ]]; then
364+
# there is no way to address the multihost / private case, bail here for compatibility.
365+
# TODO: remove this cruft and redo code to handle this at the caller level.
366+
return
367+
fi
353368
fi
354-
_ping_check_novanet "$1" $2 $3 $4
355-
}
356369

357-
# ping check for nova
358-
# Uses globals ``MULTI_HOST``, ``PRIVATE_NETWORK``
359-
function _ping_check_novanet {
360-
local from_net=$1
361-
local ip=$2
362-
local boot_timeout=$3
363-
local expected=${4:-"True"}
364-
local check_command=""
365-
MULTI_HOST=$(trueorfalse False MULTI_HOST)
366-
if [[ "$MULTI_HOST" = "True" && "$from_net" = "$PRIVATE_NETWORK_NAME" ]]; then
367-
return
370+
# inverse the logic if we're testing no connectivity
371+
if [[ "$expected" != "True" ]]; then
372+
op=""
373+
failmsg="[Fail] Could ping server"
368374
fi
369-
if [[ "$expected" = "True" ]]; then
370-
check_command="while ! ping -c1 -w1 $ip; do sleep 1; done"
371-
else
372-
check_command="while ping -c1 -w1 $ip; do sleep 1; done"
373-
fi
374-
if ! timeout $boot_timeout sh -c "$check_command"; then
375-
if [[ "$expected" = "True" ]]; then
376-
die $LINENO "[Fail] Couldn't ping server"
377-
else
378-
die $LINENO "[Fail] Could ping server"
379-
fi
375+
376+
# Because we've transformed this command so many times, print it
377+
# out at the end.
378+
local check_command="while $op $ping_cmd -c1 -w1 $ip; do sleep 1; done"
379+
echo "Checking connectivity with $check_command"
380+
381+
if ! timeout $timeout sh -c "$check_command"; then
382+
die $LINENO $failmsg
380383
fi
381384
}
382385

lib/neutron-legacy

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,27 +1370,6 @@ function _get_probe_cmd_prefix {
13701370
echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
13711371
}
13721372

1373-
function _ping_check_neutron {
1374-
local from_net=$1
1375-
local ip=$2
1376-
local timeout_sec=$3
1377-
local expected=${4:-"True"}
1378-
local check_command=""
1379-
probe_cmd=`_get_probe_cmd_prefix $from_net`
1380-
if [[ "$expected" = "True" ]]; then
1381-
check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
1382-
else
1383-
check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
1384-
fi
1385-
if ! timeout $timeout_sec sh -c "$check_command"; then
1386-
if [[ "$expected" = "True" ]]; then
1387-
die $LINENO "[Fail] Couldn't ping server"
1388-
else
1389-
die $LINENO "[Fail] Could ping server"
1390-
fi
1391-
fi
1392-
}
1393-
13941373
# ssh check
13951374
function _ssh_check_neutron {
13961375
local from_net=$1

tools/ping_neutron.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2015 Hewlett-Packard Development Company, L.P.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
17+
# Ping a neutron guest using a network namespace probe
18+
19+
set -o errexit
20+
set -o pipefail
21+
22+
TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
23+
24+
# This *must* be run as the admin tenant
25+
source $TOP_DIR/openrc admin admin
26+
27+
function usage {
28+
cat - <<EOF
29+
ping_neutron.sh <net_name> [ping args]
30+
31+
This provides a wrapper to ping neutron guests that are on isolated
32+
tenant networks that the caller can't normally reach. It does so by
33+
creating a network namespace probe.
34+
35+
It takes arguments like ping, except the first arg must be the network
36+
name.
37+
38+
Note: in environments with duplicate network names, the results are
39+
non deterministic.
40+
41+
This should *really* be in the neutron cli.
42+
43+
EOF
44+
exit 1
45+
}
46+
47+
NET_NAME=$1
48+
49+
if [[ -z "$NET_NAME" ]]; then
50+
echo "Error: net_name is required"
51+
usage
52+
fi
53+
54+
REMANING_ARGS="${@:2}"
55+
56+
# BUG: with duplicate network names, this fails pretty hard.
57+
NET_ID=$(neutron net-list $NET_NAME | grep "$NET_NAME" | awk '{print $2}')
58+
PROBE_ID=$(neutron-debug probe-list -c id -c network_id | grep "$NET_ID" | awk '{print $2}' | head -n 1)
59+
60+
# This runs a command inside the specific netns
61+
NET_NS_CMD="ip netns exec qprobe-$PROBE_ID"
62+
63+
PING_CMD="sudo $NET_NS_CMD ping $REMAING_ARGS"
64+
echo "Running $PING_CMD"
65+
$PING_CMD

0 commit comments

Comments
 (0)