| Sean Dague | af9bf86 | 2015-04-16 08:58:32 -0400 | [diff] [blame] | 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 |  | 
| Stanislaw Szydlo | aa81e2e | 2015-07-27 10:54:44 +0200 | [diff] [blame] | 54 | REMAINING_ARGS="${@:2}" | 
| Sean Dague | af9bf86 | 2015-04-16 08:58:32 -0400 | [diff] [blame] | 55 |  | 
|  | 56 | # BUG: with duplicate network names, this fails pretty hard. | 
| Jordan Pittier | d038b60 | 2016-11-04 13:32:39 +0100 | [diff] [blame] | 57 | NET_ID=$(openstack network show -f value -c id "$NET_NAME") | 
| Sean Dague | af9bf86 | 2015-04-16 08:58:32 -0400 | [diff] [blame] | 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 |  | 
| Stanislaw Szydlo | aa81e2e | 2015-07-27 10:54:44 +0200 | [diff] [blame] | 63 | PING_CMD="sudo $NET_NS_CMD ping $REMAINING_ARGS" | 
| Sean Dague | af9bf86 | 2015-04-16 08:58:32 -0400 | [diff] [blame] | 64 | echo "Running $PING_CMD" | 
|  | 65 | $PING_CMD |