Files
training-labs/labs/osbash/scripts/config_private_network.sh
Roger Luethi 8ff32fa5a5 Mitaka updates
This changeset contains updates for Mitaka.

To build the basedisk (if necessary) and the cluster and launch a test VM
once:
./tools/repeat-test.sh -b -r 1

To test Orchestration:

./tools/test-once.sh scripts/test/heat_stack.sh

Change-Id: Idd96525c14abd5903a6631095ccd6797ba91365c
2016-04-09 09:23:49 +02:00

198 lines
5.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -o errexit -o nounset
TOP_DIR=$(cd "$(dirname "$0")/.." && pwd)
source "$TOP_DIR/config/paths"
source "$CONFIG_DIR/credentials"
source "$LIB_DIR/functions.guest.sh"
exec_logfile
indicate_current_auto
#------------------------------------------------------------------------------
# Create private network
# http://docs.openstack.org/mitaka/install-guide-ubuntu/launch-instance-networks-private.html
#------------------------------------------------------------------------------
echo -n "Waiting for first DHCP namespace."
until [ "$(ip netns | grep -o "^qdhcp-[a-z0-9-]*" | wc -l)" -gt 0 ]; do
sleep 1
echo -n .
done
echo
echo -n "Waiting for first bridge to show up."
# Bridge names are something like brq219ddb93-c9
until [ "$(brctl show | grep -o "^brq[a-z0-9-]*" | wc -l)" -gt 0 ]; do
sleep 1
echo -n .
done
echo
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Create the self-service network
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(
echo "Sourcing the demo credentials."
source "$CONFIG_DIR/demo-openstackrc.sh"
# Wait for neutron to start
wait_for_neutron
echo "Creating the private network."
neutron net-create selfservice
echo "Creating a subnet on the tenant network."
neutron subnet-create --name selfservice \
--dns-nameserver "$DNS_RESOLVER" --gateway "$PRIVATE_NETWORK_GATEWAY" \
selfservice "$PRIVATE_NETWORK_CIDR"
)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
echo -n "Waiting for second DHCP namespace."
until [ "$(ip netns | grep -o "^qdhcp-[a-z0-9-]*" | wc -l)" -gt 1 ]; do
sleep 1
echo -n .
done
echo
echo -n "Waiting for second bridge."
until [ "$(brctl show | grep -o "^brq[a-z0-9-]*" | wc -l)" -gt 1 ]; do
sleep 1
echo -n .
done
echo
echo "Bridges are:"
brctl show
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Create a router
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(
echo "Sourcing the admin credentials."
source "$CONFIG_DIR/admin-openstackrc.sh"
echo "Adding 'router:external' option to the public provider network."
neutron net-update provider --router:external
)
(
echo "Sourcing the demo credentials."
source "$CONFIG_DIR/demo-openstackrc.sh"
echo "Creating a router."
neutron router-create router
)
function wait_for_agent {
local agent=$1
echo -n "Waiting for neutron agent $agent."
(
source "$CONFIG_DIR/admin-openstackrc.sh"
while neutron agent-list|grep "$agent" | grep "xxx" >/dev/null; do
sleep 1
echo -n .
done
echo
)
}
wait_for_agent neutron-l3-agent
echo "linuxbridge-agent and dhcp-agent must be up before we can add interfaces."
wait_for_agent neutron-linuxbridge-agent
wait_for_agent neutron-dhcp-agent
(
source "$CONFIG_DIR/demo-openstackrc.sh"
echo "Adding the private network subnet as an interface on the router."
neutron router-interface-add router selfservice
)
# The following tests for router namespace, qr-* interface and bridges are just
# for show. They are not needed to prevent races.
echo -n "Getting router namespace."
until ip netns | grep qrouter; do
echo -n "."
sleep 1
done
nsrouter=$(ip netns | grep qrouter)
echo -n "Waiting for interface qr-* in router namespace."
until sudo ip netns exec "$nsrouter" ip addr|grep -Po "(?<=: )qr-.*(?=:)"; do
echo -n "."
sleep 1
done
(
source "$CONFIG_DIR/demo-openstackrc.sh"
echo "Setting a gateway on the public network on the router."
neutron router-gateway-set router provider
)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# The following test for qg-* is just for show.
echo -n "Waiting for interface qg-* in router namespace."
until sudo ip netns exec "$nsrouter" ip addr|grep -Po "(?<=: )qg-.*(?=:)"; do
echo -n "."
sleep 1
done
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Verify operation
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
echo "Listing network namespaces."
ip netns
echo "Sourcing the admin credentials."
source "$CONFIG_DIR/admin-openstackrc.sh"
echo "Getting the router's IP address in the public network."
echo "neutron router-port-list router"
neutron router-port-list router
# Get router IP address in given network
function get_router_ip_address {
local net_name=$1
local public_network=$(netname_to_network "$net_name")
local network_part=$(remove_last_octet "$public_network")
local line
while : ; do
line=$(neutron router-port-list -F fixed_ips router|grep "$network_part")
if [ -z "$line" ]; then
# Wait for the network_part to appear in the list
sleep 1
echo -n >&2 .
continue
fi
router_ip=$(echo $line|grep -Po "$network_part\.\d+")
echo $router_ip
return 0
done
}
PUBLIC_ROUTER_IP=$(get_router_ip_address "provider")
echo -n "Waiting for ping reply from public router IP ($PUBLIC_ROUTER_IP)."
cnt=0
until ping -c1 "$PUBLIC_ROUTER_IP" > /dev/null; do
cnt=$((cnt + 1))
if [ $cnt -eq 20 ]; then
echo "ERROR no reply from public router IP in 20 s, exiting."
exit 1
fi
sleep 1
echo -n .
done
echo