blob: 0672bc00876ae7f3906854ee3a154ec0f582b35f [file] [log] [blame]
Dean Troyer2aa2a892013-08-04 19:53:19 -05001#!/usr/bin/env bash
2
3# **docker**
4
5# Test Docker hypervisor
6
7echo "*********************************************************************"
8echo "Begin DevStack Exercise: $0"
9echo "*********************************************************************"
10
11# This script exits on an error so that errors don't compound and you see
12# only the first error that occurred.
13set -o errexit
14
15# Print the commands being run so that we can see the command that triggers
16# an error. It is also useful for following allowing as the install occurs.
17set -o xtrace
18
19
20# Settings
21# ========
22
23# Keep track of the current directory
24EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
25TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
26
27# Import common functions
28source $TOP_DIR/functions
29
30# Import configuration
31source $TOP_DIR/openrc
32
33# Import exercise configuration
34source $TOP_DIR/exerciserc
35
36# Skip if the hypervisor is not Docker
37[[ "$VIRT_DRIVER" == "docker" ]] || exit 55
38
39# Import docker functions and declarations
40source $TOP_DIR/lib/nova_plugins/hypervisor-docker
41
42# Image and flavor are ignored but the CLI requires them...
43
44# Instance type to create
45DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
46
47# Boot this image, use first AMI image if unset
48DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
49
50# Instance name
51VM_NAME=ex-docker
52
53
54# Launching a server
55# ==================
56
57# Grab the id of the image to launch
58IMAGE=$(glance image-list | egrep " $DOCKER_IMAGE_NAME:latest " | get_field 1)
59die_if_not_set $LINENO IMAGE "Failure getting image $DOCKER_IMAGE_NAME"
60
61# Select a flavor
62INSTANCE_TYPE=$(nova flavor-list | grep $DEFAULT_INSTANCE_TYPE | get_field 1)
63if [[ -z "$INSTANCE_TYPE" ]]; then
64 # grab the first flavor in the list to launch if default doesn't exist
65 INSTANCE_TYPE=$(nova flavor-list | head -n 4 | tail -n 1 | get_field 1)
66fi
67
68# Clean-up from previous runs
69nova delete $VM_NAME || true
70if ! timeout $ACTIVE_TIMEOUT sh -c "while nova show $VM_NAME; do sleep 1; done"; then
71 die $LINENO "server didn't terminate!"
72fi
73
74# Boot instance
75# -------------
76
77VM_UUID=$(nova boot --flavor $INSTANCE_TYPE --image $IMAGE $VM_NAME | grep ' id ' | get_field 2)
78die_if_not_set $LINENO VM_UUID "Failure launching $VM_NAME"
79
80# Check that the status is active within ACTIVE_TIMEOUT seconds
81if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then
82 die $LINENO "server didn't become active!"
83fi
84
85# Get the instance IP
86IP=$(nova show $VM_UUID | grep "$PRIVATE_NETWORK_NAME" | get_field 2)
87die_if_not_set $LINENO IP "Failure retrieving IP address"
88
89# Private IPs can be pinged in single node deployments
90ping_check "$PRIVATE_NETWORK_NAME" $IP $BOOT_TIMEOUT
91
92# Clean up
93# --------
94
95# Delete instance
96nova delete $VM_UUID || die $LINENO "Failure deleting instance $VM_NAME"
97if ! timeout $TERMINATE_TIMEOUT sh -c "while nova list | grep -q $VM_UUID; do sleep 1; done"; then
98 die $LINENO "Server $VM_NAME not deleted"
99fi
100
101set +o xtrace
102echo "*********************************************************************"
103echo "SUCCESS: End DevStack Exercise: $0"
104echo "*********************************************************************"
105