
This commit removes the arbitrary sleep of 5 seconds and look instead for the instance status to become "Running". If after the timeout the status is not reached then a failure is injected. This will fix slow environments in which 5 seconds weren't enough for an instance to come up properly. Change-Id: I2af277548635640a2a23c7df325c0fc5800c8458
129 lines
4.4 KiB
Plaintext
129 lines
4.4 KiB
Plaintext
# Test: Instance deployment
|
|
|
|
set -e
|
|
|
|
STACKDIR=/home/stack
|
|
|
|
source $STACKDIR/overcloudrc
|
|
|
|
# Load the environment with all the info for floating network
|
|
source $STACKDIR/environment
|
|
|
|
TIMEOUT=30
|
|
INSTANCE_NAME=cirros-1
|
|
PRIVATE_NETWORK=10.1.1.0/24
|
|
|
|
# Gateway creation
|
|
# When the environment is recovering from a previous test it can happen
|
|
# that neutron is waiting to rejoin its cluster, preventing from creating
|
|
# new stuff like router. We wait at least 300 seconds before giving up.
|
|
set +e
|
|
RUN=1
|
|
while [ $RUN -lt $TIMEOUT ]
|
|
do
|
|
neutron router-create floating-router
|
|
if [ $? -eq 0 ]
|
|
then
|
|
break
|
|
else
|
|
echo "Waiting..."
|
|
let "RUN++"
|
|
sleep 10
|
|
fi
|
|
done
|
|
# If timeout was reached then we need to exit with error
|
|
if [ $RUN -ge $TIMEOUT ]
|
|
then
|
|
echo "It was not possible to create the router, giving up."
|
|
exit 1
|
|
fi
|
|
set -e
|
|
|
|
# Network and subnet creation
|
|
neutron net-create floating-network --router:external=True --provider:physical_network $FLOATING_PHYSICAL_NET --provider:network_type flat
|
|
neutron subnet-create --name floating-subnet --disable-dhcp --allocation-pool start=$FLOATING_RANGE_START,end=$FLOATING_RANGE_END --gateway $FLOATING_GW floating-network $FLOATING_SUBNET
|
|
neutron net-create private-network
|
|
neutron subnet-create private-network $PRIVATE_NETWORK --name private-subnet
|
|
# Router configuration
|
|
neutron router-interface-add floating-router private-subnet
|
|
neutron router-gateway-set floating-router floating-network
|
|
neutron security-group-create pingandssh
|
|
securitygroup_id=$(neutron security-group-list | grep pingandssh | head -1 | awk '{print $2}')
|
|
neutron security-group-rule-create --direction ingress --protocol tcp --port-range-min 22 --port-range-max 22 $securitygroup_id
|
|
neutron security-group-rule-create --protocol icmp --direction ingress $securitygroup_id
|
|
floatingip=$(neutron floatingip-create floating-network | grep floating_ip_address | awk '{print $4}')
|
|
echo floatingip=$floatingip
|
|
|
|
#[stack@mrg-06 ~]$ neutron net-list
|
|
#...
|
|
#| 6fde7d2a-e2d9-4b0f-a982-b7cbc3244807 | private-network | 31a5ccd5-07bd-4103-a4a3-ab2c6d6148d7 10.1.1.0/24 |
|
|
#...
|
|
nova flavor-create --ephemeral 0 --is-public True test.small overcloud-instance-test-small-flavor 2048 20 1
|
|
private_net_id=$(neutron net-list | grep private-network | awk '{print $2}')
|
|
wget -O /tmp/cirros-0.3.4-x86_64-disk.img http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img
|
|
projectid=$(openstack project list | awk '/admin/ {print $2}')
|
|
glance --os-project-id=$projectid image-create --name CirrOS --container-format bare --disk-format raw --file /tmp/cirros-0.3.4-x86_64-disk.img
|
|
nova boot --image CirrOS --flavor test.small --security-groups pingandssh --nic net-id=$private_net_id $INSTANCE_NAME
|
|
|
|
#[stack@mrg-06 ~]$ nova list
|
|
#...
|
|
#| eb29c1a1-c30e-4f8f-91ea-cec1fd38c088 | $INSTANCE_NAME | BUILD | spawning | NOSTATE | private-network=10.1.1.5 |
|
|
#...
|
|
echo "Waiting for instance $INSTANCE_NAME to come up"
|
|
COUNTER=1
|
|
while [ $COUNTER -lt $TIMEOUT ]
|
|
do
|
|
instance_status=$(nova list | awk "/$INSTANCE_NAME/ {print \$10}")
|
|
|
|
if [ "$instance_status" == "Running" ]
|
|
then
|
|
echo "SUCCESS"
|
|
break
|
|
else
|
|
echo -n "."
|
|
fi
|
|
let COUNTER=COUNTER+1
|
|
done
|
|
|
|
[ $COUNTER -ge $TIMEOUT ] && (echo "FAILURE! Instance status: $instance_status"; exit 1)
|
|
instance_ip=$(nova list | grep $INSTANCE_NAME | awk '{print $12}' | sed "s/private-network=//g")
|
|
echo instance_ip=$instance_ip
|
|
|
|
#[stack@mrg-06 ~]$ neutron port-list
|
|
#...
|
|
#| 61ce215d-3dc7-4873-af73-342620cdc3b6 | | fa:16:3e:8d:8b:8d | {"subnet_id": "31a5ccd5-07bd-4103-a4a3-ab2c6d6148d7", "ip_address": "10.1.1.5"} |
|
|
#...
|
|
port_id=$(neutron port-list | grep $instance_ip | awk '{print $2}')
|
|
echo port_id=$port_id
|
|
|
|
#[stack@mrg-06 ~]$ neutron floatingip-list
|
|
#...
|
|
#| 624f5256-ee89-438f-8335-904017e74a18 | | 10.16.144.77 | |
|
|
#...
|
|
floatingip_id=$(neutron floatingip-list | grep $floatingip | awk '{print $2}')
|
|
echo floatingip_id=$floatingip_id
|
|
neutron floatingip-associate $floatingip_id $port_id
|
|
|
|
echo "------------------------------------------------------------"
|
|
echo "$(date) Instance will be available at the IP $floatingip"
|
|
echo "------------------------------------------------------------"
|
|
|
|
set +e
|
|
|
|
COUNTER=1
|
|
while [ $COUNTER -lt $TIMEOUT ]
|
|
do
|
|
ping -c1 $floatingip 2>&1 > /dev/null
|
|
|
|
if [ $? -eq 0 ]
|
|
then
|
|
echo "SUCCESS"
|
|
break
|
|
else
|
|
echo -n "."
|
|
fi
|
|
let COUNTER=COUNTER+1
|
|
done
|
|
|
|
[ $COUNTER -ge $TIMEOUT ] && (echo "FAILURE!"; exit 1)
|