blob: 73fe3f3bdf1e280e3b242947281ef5d88375d659 [file] [log] [blame]
Sean Dagueaf9bf862015-04-16 08:58:32 -04001#!/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
19set -o errexit
20set -o pipefail
21
22TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
23
24# This *must* be run as the admin tenant
25source $TOP_DIR/openrc admin admin
26
27function usage {
28 cat - <<EOF
29ping_neutron.sh <net_name> [ping args]
30
31This provides a wrapper to ping neutron guests that are on isolated
32tenant networks that the caller can't normally reach. It does so by
33creating a network namespace probe.
34
35It takes arguments like ping, except the first arg must be the network
36name.
37
38Note: in environments with duplicate network names, the results are
39non deterministic.
40
41This should *really* be in the neutron cli.
42
43EOF
44 exit 1
45}
46
47NET_NAME=$1
48
49if [[ -z "$NET_NAME" ]]; then
50 echo "Error: net_name is required"
51 usage
52fi
53
Stanislaw Szydloaa81e2e2015-07-27 10:54:44 +020054REMAINING_ARGS="${@:2}"
Sean Dagueaf9bf862015-04-16 08:58:32 -040055
56# BUG: with duplicate network names, this fails pretty hard.
Jordan Pittierd038b602016-11-04 13:32:39 +010057NET_ID=$(openstack network show -f value -c id "$NET_NAME")
Sean Dagueaf9bf862015-04-16 08:58:32 -040058PROBE_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
61NET_NS_CMD="ip netns exec qprobe-$PROBE_ID"
62
Stanislaw Szydloaa81e2e2015-07-27 10:54:44 +020063PING_CMD="sudo $NET_NS_CMD ping $REMAINING_ARGS"
Sean Dagueaf9bf862015-04-16 08:58:32 -040064echo "Running $PING_CMD"
65$PING_CMD