Merge "Remove devstack exercises"

This commit is contained in:
Zuul 2018-08-27 14:35:53 +00:00 committed by Gerrit Code Review
commit 4c82af68a0
15 changed files with 1 additions and 2014 deletions

View File

@ -49,10 +49,6 @@ level.
``doc`` - Contains the Sphinx source for the documentation.
A complete doc build can be run with ``tox -edocs``.
``exercises`` - Contains the test scripts used to sanity-check and
demonstrate some OpenStack functions. These scripts know how to exit
early or skip services that are not enabled.
``extras.d`` - Contains the dispatch scripts called by the hooks in
``stack.sh``, ``unstack.sh`` and ``clean.sh``. See :doc:`the plugins
docs <plugins>` for more information.
@ -182,88 +178,6 @@ The complete docs build is also handled with <code>tox -edocs</code> per the
OpenStack project standard.
Exercises
---------
The scripts in the exercises directory are meant to 1) perform basic operational
checks on certain aspects of OpenStack; and b) document the use of the
OpenStack command-line clients.
In addition to the guidelines above, exercise scripts MUST follow the structure
outlined here. ``swift.sh`` is perhaps the clearest example of these guidelines.
These scripts are executed serially by ``exercise.sh`` in testing situations.
* Begin and end with a banner that stands out in a sea of script logs to aid
in debugging failures, particularly in automated testing situations. If the
end banner is not displayed, the script ended prematurely and can be assumed
to have failed.
::
echo "**************************************************"
echo "Begin DevStack Exercise: $0"
echo "**************************************************"
...
set +o xtrace
echo "**************************************************"
echo "End DevStack Exercise: $0"
echo "**************************************************"
* The scripts will generally have the shell ``xtrace`` attribute set to display
the actual commands being executed, and the ``errexit`` attribute set to exit
the script on non-zero exit codes::
# This script exits on an error so that errors don't compound and you see
# only the first error that occurred.
set -o errexit
# Print the commands being run so that we can see the command that triggers
# an error. It is also useful for following as the install occurs.
set -o xtrace
* Settings and configuration are stored in ``exerciserc``, which must be
sourced after ``openrc`` or ``stackrc``::
# Import exercise configuration
source $TOP_DIR/exerciserc
* There are a couple of helper functions in the common ``functions`` sub-script
that will check for non-zero exit codes and unset environment variables and
print a message and exit the script. These should be called after most client
commands that are not otherwise checked to short-circuit long timeouts
(instance boot failure, for example)::
swift post $CONTAINER
die_if_error "Failure creating container $CONTAINER"
FLOATING_IP=`euca-allocate-address | cut -f2`
die_if_not_set FLOATING_IP "Failure allocating floating IP"
* If you want an exercise to be skipped when for example a service wasn't
enabled for the exercise to be run, you can exit your exercise with the
special exitcode 55 and it will be detected as skipped.
* The exercise scripts should only use the various OpenStack client binaries to
interact with OpenStack. This specifically excludes any ``*-manage`` tools
as those assume direct access to configuration and databases, as well as direct
database access from the exercise itself.
* If specific configuration needs to be present for the exercise to complete,
it should be staged in ``stack.sh``, or called from ``stack.sh``.
* The ``OS_*`` environment variables should be the only ones used for all
authentication to OpenStack clients as documented in the CLIAuth_ wiki page.
.. _CLIAuth: https://wiki.openstack.org/CLIAuth
* The exercise MUST clean up after itself if successful. If it is not successful,
it is assumed that state will be left behind; this allows a chance for developers
to look around and attempt to debug the problem. The exercise SHOULD clean up
or graciously handle possible artifacts left over from previous runs if executed
again. It is acceptable to require a reboot or even a re-install of DevStack
to restore a clean test environment.
Bash Style Guidelines
~~~~~~~~~~~~~~~~~~~~~
DevStack defines a bash set of best practices for maintaining large

View File

@ -665,8 +665,7 @@ following to your ``localrc`` section:
enable_service n-cell
Be aware that there are some features currently missing in cells, one
notable one being security groups. The exercises have been patched to
disable functionality not supported by cells.
notable one being security groups.
Cinder
~~~~~~
@ -729,44 +728,6 @@ use the v3 API. It is possible to setup keystone without v2 API, by doing:
ENABLE_IDENTITY_V2=False
Exercises
~~~~~~~~~
``exerciserc`` is used to configure settings for the exercise scripts.
The values shown below are the default values. These can all be
overridden by setting them in the ``localrc`` section.
* Max time to wait while vm goes from build to active state
::
ACTIVE_TIMEOUT==30
* Max time to wait for proper IP association and dis-association.
::
ASSOCIATE_TIMEOUT=15
* Max time till the vm is bootable
::
BOOT_TIMEOUT=30
* Max time from run instance command until it is running
::
RUNNING_TIMEOUT=$(($BOOT_TIMEOUT + $ACTIVE_TIMEOUT))
* Max time to wait for a vm to terminate
::
TERMINATE_TIMEOUT=30
.. _arch-configuration:
Architectures

View File

@ -127,7 +127,3 @@ computers on the local network. In this example that would be
http://192.168.1.201/ for the dashboard (aka Horizon). Launch VMs and if
you give them floating IPs and security group access those VMs will be
accessible from other machines on your network.
Some examples of using the OpenStack command-line clients ``nova`` and
``glance`` are in the shakedown scripts in ``devstack/exercises``.
``exercise.sh`` will run all of those scripts and report on the results.

View File

@ -75,11 +75,3 @@ Node Configurations
- single node
- multi-node configurations as are tested by the gate
Exercises
---------
The DevStack exercise scripts are no longer used as integration and gate
testing as that job has transitioned to Tempest. They are still
maintained as a demonstrations of using OpenStack from the command line
and for quick operational testing.

View File

@ -1,74 +0,0 @@
#!/usr/bin/env bash
# **exercise.sh**
# Keep track of the current DevStack directory.
TOP_DIR=$(cd $(dirname "$0") && pwd)
# Import common functions
source $TOP_DIR/functions
# Load local configuration
source $TOP_DIR/stackrc
# Run everything in the exercises/ directory that isn't explicitly disabled
# comma separated list of script basenames to skip
# to refrain from exercising foo.sh use ``SKIP_EXERCISES=foo``
SKIP_EXERCISES=${SKIP_EXERCISES:-""}
# comma separated list of script basenames to run
# to run only foo.sh use ``RUN_EXERCISES=foo``
basenames=${RUN_EXERCISES:-""}
EXERCISE_DIR=$TOP_DIR/exercises
if [[ -z "${basenames}" ]]; then
# Locate the scripts we should run
basenames=$(for b in `ls $EXERCISE_DIR/*.sh`; do basename $b .sh; done)
else
# If ``RUN_EXERCISES`` was specified, ignore ``SKIP_EXERCISES``.
SKIP_EXERCISES=
fi
# Track the state of each script
passes=""
failures=""
skips=""
# Loop over each possible script (by basename)
for script in $basenames; do
if [[ ,$SKIP_EXERCISES, =~ ,$script, ]]; then
skips="$skips $script"
else
echo "====================================================================="
echo Running $script
echo "====================================================================="
$EXERCISE_DIR/$script.sh
exitcode=$?
if [[ $exitcode == 55 ]]; then
skips="$skips $script"
elif [[ $exitcode -ne 0 ]]; then
failures="$failures $script"
else
passes="$passes $script"
fi
fi
done
# Output status of exercise run
echo "====================================================================="
for script in $skips; do
echo SKIP $script
done
for script in $passes; do
echo PASS $script
done
for script in $failures; do
echo FAILED $script
done
echo "====================================================================="
if [[ -n "$failures" ]]; then
exit 1
fi

View File

@ -1,26 +0,0 @@
#!/usr/bin/env bash
#
# source exerciserc
#
# Configure the DevStack exercise scripts
# For best results, source this _after_ stackrc/localrc as it will set
# values only if they are not already set.
# Max time to wait while vm goes from build to active state
export ACTIVE_TIMEOUT=${ACTIVE_TIMEOUT:-30}
# Max time to wait for proper IP association and dis-association.
export ASSOCIATE_TIMEOUT=${ASSOCIATE_TIMEOUT:-15}
# Max time till the vm is bootable
export BOOT_TIMEOUT=${BOOT_TIMEOUT:-30}
# Max time from run instance command until it is running
export RUNNING_TIMEOUT=${RUNNING_TIMEOUT:-$(($BOOT_TIMEOUT + $ACTIVE_TIMEOUT))}
# Max time to wait for a vm to terminate
export TERMINATE_TIMEOUT=${TERMINATE_TIMEOUT:-30}
# The size of the volume we want to boot from; some storage back-ends
# do not allow a disk resize, so it's important that this can be tuned
export DEFAULT_VOLUME_SIZE=${DEFAULT_VOLUME_SIZE:-1}

View File

@ -1,150 +0,0 @@
#!/usr/bin/env bash
# **aggregates.sh**
# This script demonstrates how to use host aggregates:
#
# * Create an Aggregate
# * Updating Aggregate details
# * Testing Aggregate metadata
# * Testing Aggregate delete
# * Testing General Aggregates (https://blueprints.launchpad.net/nova/+spec/general-host-aggregates)
# * Testing add/remove hosts (with one host)
echo "**************************************************"
echo "Begin DevStack Exercise: $0"
echo "**************************************************"
# This script exits on an error so that errors don't compound and you see
# only the first error that occurred.
set -o errexit
# Print the commands being run so that we can see the command that triggers
# an error. It is also useful for following as the install occurs.
set -o xtrace
# Settings
# ========
# Keep track of the current directory
EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
# Test as the admin user
# note this imports stackrc/functions, etc
. $TOP_DIR/openrc admin admin
# Import exercise configuration
source $TOP_DIR/exerciserc
# If nova api is not enabled we exit with exitcode 55 so that
# the exercise is skipped
is_service_enabled n-api || exit 55
# Cells does not support aggregates.
is_service_enabled n-cell && exit 55
# Create an aggregate
# ===================
AGGREGATE_NAME=test_aggregate_$RANDOM
AGGREGATE2_NAME=test_aggregate_$RANDOM
AGGREGATE_A_ZONE=nova
function exit_if_aggregate_present {
aggregate_name=$1
if [ $(nova aggregate-list | grep -c " $aggregate_name ") == 0 ]; then
echo "SUCCESS $aggregate_name not present"
else
die $LINENO "found aggregate: $aggregate_name"
exit -1
fi
}
exit_if_aggregate_present $AGGREGATE_NAME
AGGREGATE_ID=$(nova aggregate-create $AGGREGATE_NAME $AGGREGATE_A_ZONE | grep " $AGGREGATE_NAME " | get_field 1)
die_if_not_set $LINENO AGGREGATE_ID "Failure creating AGGREGATE_ID for $AGGREGATE_NAME $AGGREGATE_A_ZONE"
AGGREGATE2_ID=$(nova aggregate-create $AGGREGATE2_NAME $AGGREGATE_A_ZONE | grep " $AGGREGATE2_NAME " | get_field 1)
die_if_not_set $LINENO AGGREGATE2_ID "Fail creating AGGREGATE2_ID for $AGGREGATE2_NAME $AGGREGATE_A_ZONE"
# check aggregate created
nova aggregate-list | grep -q " $AGGREGATE_NAME " || die $LINENO "Aggregate $AGGREGATE_NAME not created"
# Ensure creating a duplicate fails
# =================================
if nova aggregate-create $AGGREGATE_NAME $AGGREGATE_A_ZONE; then
die $LINENO "could create duplicate aggregate"
fi
# Test aggregate-update (and aggregate-details)
# =============================================
AGGREGATE_NEW_NAME=test_aggregate_$RANDOM
nova aggregate-update $AGGREGATE_ID $AGGREGATE_NEW_NAME
nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_NEW_NAME
nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_A_ZONE
nova aggregate-update $AGGREGATE_ID $AGGREGATE_NAME $AGGREGATE_A_ZONE
nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_NAME
nova aggregate-details $AGGREGATE_ID | grep $AGGREGATE_A_ZONE
# Test aggregate-set-metadata
# ===========================
META_DATA_1_KEY=asdf
META_DATA_2_KEY=foo
META_DATA_3_KEY=bar
#ensure no additional metadata is set
nova aggregate-details $AGGREGATE_ID | egrep "\|[{u ]*'availability_zone.+$AGGREGATE_A_ZONE'[ }]*\|"
nova aggregate-set-metadata $AGGREGATE_ID ${META_DATA_1_KEY}=123
nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY
nova aggregate-details $AGGREGATE_ID | grep 123
nova aggregate-set-metadata $AGGREGATE_ID ${META_DATA_2_KEY}=456
nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY
nova aggregate-details $AGGREGATE_ID | grep $META_DATA_2_KEY
nova aggregate-set-metadata $AGGREGATE_ID $META_DATA_2_KEY ${META_DATA_3_KEY}=789
nova aggregate-details $AGGREGATE_ID | grep $META_DATA_1_KEY
nova aggregate-details $AGGREGATE_ID | grep $META_DATA_3_KEY
nova aggregate-details $AGGREGATE_ID | grep $META_DATA_2_KEY && die $LINENO "ERROR metadata was not cleared"
nova aggregate-set-metadata $AGGREGATE_ID $META_DATA_3_KEY $META_DATA_1_KEY
nova aggregate-details $AGGREGATE_ID | egrep "\|[{u ]*'availability_zone.+$AGGREGATE_A_ZONE'[ }]*\|"
# Test aggregate-add/remove-host
# ==============================
if [ "$VIRT_DRIVER" == "xenserver" ]; then
echo "TODO(johngarbutt) add tests for add/remove host from pool aggregate"
fi
FIRST_HOST=$(nova host-list | grep compute | get_field 1 | head -1)
# Make sure can add two aggregates to same host
nova aggregate-add-host $AGGREGATE_ID $FIRST_HOST
nova aggregate-add-host $AGGREGATE2_ID $FIRST_HOST
if nova aggregate-add-host $AGGREGATE2_ID $FIRST_HOST; then
die $LINENO "could add duplicate host to single aggregate"
fi
nova aggregate-remove-host $AGGREGATE2_ID $FIRST_HOST
nova aggregate-remove-host $AGGREGATE_ID $FIRST_HOST
# Test aggregate-delete
# =====================
nova aggregate-delete $AGGREGATE_ID
nova aggregate-delete $AGGREGATE2_ID
exit_if_aggregate_present $AGGREGATE_NAME
set +o xtrace
echo "**************************************************"
echo "End DevStack Exercise: $0"
echo "**************************************************"

View File

@ -1,224 +0,0 @@
#!/usr/bin/env bash
# **boot_from_volume.sh**
# This script demonstrates how to boot from a volume. It does the following:
#
# * Create a bootable volume
# * Boot a volume-backed instance
echo "*********************************************************************"
echo "Begin DevStack Exercise: $0"
echo "*********************************************************************"
# This script exits on an error so that errors don't compound and you see
# only the first error that occurred.
set -o errexit
# Print the commands being run so that we can see the command that triggers
# an error. It is also useful for following as the install occurs.
set -o xtrace
# Settings
# ========
# Keep track of the current directory
EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
# Import common functions
source $TOP_DIR/functions
# Import project functions
source $TOP_DIR/lib/cinder
source $TOP_DIR/lib/neutron
source $TOP_DIR/lib/neutron-legacy
# Import configuration
source $TOP_DIR/openrc
# Import exercise configuration
source $TOP_DIR/exerciserc
# If cinder is not enabled we exit with exitcode 55 so that
# the exercise is skipped
is_service_enabled cinder || exit 55
# Ironic does not support boot from volume.
[ "$VIRT_DRIVER" == "ironic" ] && exit 55
# Instance type to create
DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
# Boot this image, use first AMI image if unset
DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
# Security group name
SECGROUP=${SECGROUP:-boot_secgroup}
# Instance and volume names
VM_NAME=${VM_NAME:-ex-bfv-inst}
VOL_NAME=${VOL_NAME:-ex-vol-bfv}
# Launching a server
# ==================
# List servers for project:
nova list
# Images
# ------
# List the images available
openstack image list
# Grab the id of the image to launch
IMAGE=$(openstack image list | egrep " $DEFAULT_IMAGE_NAME " | get_field 1)
die_if_not_set $LINENO IMAGE "Failure getting image $DEFAULT_IMAGE_NAME"
# Security Groups
# ---------------
# List security groups
nova secgroup-list
if is_service_enabled n-cell; then
# Cells does not support security groups, so force the use of "default"
SECGROUP="default"
echo "Using the default security group because of Cells."
else
# Create a secgroup
if ! nova secgroup-list | grep -q $SECGROUP; then
nova secgroup-create $SECGROUP "$SECGROUP description"
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! nova secgroup-list | grep -q $SECGROUP; do sleep 1; done"; then
echo "Security group not created"
exit 1
fi
fi
fi
# Configure Security Group Rules
if ! nova secgroup-list-rules $SECGROUP | grep -q icmp; then
nova secgroup-add-rule $SECGROUP icmp -1 -1 0.0.0.0/0
fi
if ! nova secgroup-list-rules $SECGROUP | grep -q " tcp .* 22 "; then
nova secgroup-add-rule $SECGROUP tcp 22 22 0.0.0.0/0
fi
# List secgroup rules
nova secgroup-list-rules $SECGROUP
# Set up instance
# ---------------
# List flavors
nova flavor-list
# Select a flavor
INSTANCE_TYPE=$(nova flavor-list | grep $DEFAULT_INSTANCE_TYPE | get_field 1)
if [[ -z "$INSTANCE_TYPE" ]]; then
# grab the first flavor in the list to launch if default doesn't exist
INSTANCE_TYPE=$(nova flavor-list | head -n 4 | tail -n 1 | get_field 1)
fi
# Clean-up from previous runs
nova delete $VM_NAME || true
if ! timeout $ACTIVE_TIMEOUT sh -c "while nova show $VM_NAME; do sleep 1; done"; then
echo "server didn't terminate!"
exit 1
fi
# Setup Keypair
KEY_NAME=test_key
KEY_FILE=key.pem
nova keypair-delete $KEY_NAME || true
nova keypair-add $KEY_NAME > $KEY_FILE
chmod 600 $KEY_FILE
# Set up volume
# -------------
# Delete any old volume
cinder delete $VOL_NAME || true
if ! timeout $ACTIVE_TIMEOUT sh -c "while cinder list | grep $VOL_NAME; do sleep 1; done"; then
echo "Volume $VOL_NAME not deleted"
exit 1
fi
# Create the bootable volume
start_time=$(date +%s)
cinder create --image-id $IMAGE --display-name=$VOL_NAME --display-description "test bootable volume: $VOL_NAME" $DEFAULT_VOLUME_SIZE || \
die $LINENO "Failure creating volume $VOL_NAME"
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! cinder list | grep $VOL_NAME | grep available; do sleep 1; done"; then
echo "Volume $VOL_NAME not created"
exit 1
fi
end_time=$(date +%s)
echo "Completed cinder create in $((end_time - start_time)) seconds"
# Get volume ID
VOL_ID=$(cinder list | grep $VOL_NAME | get_field 1)
die_if_not_set $LINENO VOL_ID "Failure retrieving volume ID for $VOL_NAME"
# Boot instance
# -------------
# Boot using the --block-device-mapping param. The format of mapping is:
# <dev_name>=<id>:<type>:<size(GB)>:<delete_on_terminate>
# Leaving the middle two fields blank appears to do-the-right-thing
VM_UUID=$(nova boot --flavor $INSTANCE_TYPE --image $IMAGE --block-device-mapping vda=$VOL_ID --security-groups=$SECGROUP --key-name $KEY_NAME $VM_NAME | grep ' id ' | get_field 2)
die_if_not_set $LINENO VM_UUID "Failure launching $VM_NAME"
# Check that the status is active within ACTIVE_TIMEOUT seconds
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then
echo "server didn't become active!"
exit 1
fi
# Get the instance IP
IP=$(get_instance_ip $VM_UUID $PRIVATE_NETWORK_NAME)
die_if_not_set $LINENO IP "Failure retrieving IP address"
# Private IPs can be pinged in single node deployments
ping_check $IP $BOOT_TIMEOUT "$PRIVATE_NETWORK_NAME"
# Clean up
# --------
# Delete volume backed instance
nova delete $VM_UUID || die $LINENO "Failure deleting instance $VM_NAME"
if ! timeout $TERMINATE_TIMEOUT sh -c "while nova list | grep -q $VM_UUID; do sleep 1; done"; then
echo "Server $VM_NAME not deleted"
exit 1
fi
# Wait for volume to be released
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! cinder list | grep $VOL_NAME | grep available; do sleep 1; done"; then
echo "Volume $VOL_NAME not released"
exit 1
fi
# Delete volume
start_time=$(date +%s)
cinder delete $VOL_ID || die $LINENO "Failure deleting volume $VOLUME_NAME"
if ! timeout $ACTIVE_TIMEOUT sh -c "while cinder list | grep $VOL_NAME; do sleep 1; done"; then
echo "Volume $VOL_NAME not deleted"
exit 1
fi
end_time=$(date +%s)
echo "Completed cinder delete in $((end_time - start_time)) seconds"
if [[ $SECGROUP = "default" ]] ; then
echo "Skipping deleting default security group"
else
# Delete secgroup
nova secgroup-delete $SECGROUP || die $LINENO "Failure deleting security group $SECGROUP"
fi
set +o xtrace
echo "*********************************************************************"
echo "SUCCESS: End DevStack Exercise: $0"
echo "*********************************************************************"

View File

@ -1,174 +0,0 @@
#!/usr/bin/env bash
# **client-args.sh**
# Test OpenStack client authentication arguments handling
echo "*********************************************************************"
echo "Begin DevStack Exercise: $0"
echo "*********************************************************************"
# This script exits on an error so that errors don't compound and you see
# only the first error that occurred.
set -o errexit
# Print the commands being run so that we can see the command that triggers
# an error. It is also useful for following as the install occurs.
set -o xtrace
# Settings
# ========
# Keep track of the current directory
EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
# Import common functions
source $TOP_DIR/functions
# Import configuration
source $TOP_DIR/openrc
# Import exercise configuration
source $TOP_DIR/exerciserc
# Unset all of the known NOVA_* vars
unset NOVA_API_KEY
unset NOVA_ENDPOINT_NAME
unset NOVA_PASSWORD
unset NOVA_PROJECT_ID
unset NOVA_REGION_NAME
unset NOVA_URL
unset NOVA_USERNAME
# Save the known variables for later
export x_PROJECT_NAME=$OS_PROJECT_NAME
export x_USERNAME=$OS_USERNAME
export x_PASSWORD=$OS_PASSWORD
export x_AUTH_URL=$OS_AUTH_URL
# Unset the usual variables to force argument processing
unset OS_PROJECT_NAME
unset OS_USERNAME
unset OS_PASSWORD
unset OS_AUTH_URL
# Common authentication args
PROJECT_ARG="--os-project-name=$x_PROJECT_NAME"
ARGS="--os-username=$x_USERNAME --os-password=$x_PASSWORD --os-auth-url=$x_AUTH_URL"
# Set global return
RETURN=0
# Keystone client
# ---------------
if [[ "$ENABLED_SERVICES" =~ "key" ]]; then
if [[ "$SKIP_EXERCISES" =~ "key" ]]; then
STATUS_KEYSTONE="Skipped"
else
echo -e "\nTest Keystone"
if openstack $PROJECT_ARG $ARGS catalog show identity; then
STATUS_KEYSTONE="Succeeded"
else
STATUS_KEYSTONE="Failed"
RETURN=1
fi
fi
fi
# Nova client
# -----------
if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
if [[ "$SKIP_EXERCISES" =~ "n-api" ]]; then
STATUS_NOVA="Skipped"
else
# Test OSAPI
echo -e "\nTest Nova"
if nova $PROJECT_ARG $ARGS flavor-list; then
STATUS_NOVA="Succeeded"
else
STATUS_NOVA="Failed"
RETURN=1
fi
fi
fi
# Cinder client
# -------------
if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
if [[ "$SKIP_EXERCISES" =~ "c-api" ]]; then
STATUS_CINDER="Skipped"
else
echo -e "\nTest Cinder"
if cinder $PROJECT_ARG $ARGS list; then
STATUS_CINDER="Succeeded"
else
STATUS_CINDER="Failed"
RETURN=1
fi
fi
fi
# Glance client
# -------------
if [[ "$ENABLED_SERVICES" =~ "g-api" ]]; then
if [[ "$SKIP_EXERCISES" =~ "g-api" ]]; then
STATUS_GLANCE="Skipped"
else
echo -e "\nTest Glance"
if openstack $PROJECT_ARG $ARGS image list; then
STATUS_GLANCE="Succeeded"
else
STATUS_GLANCE="Failed"
RETURN=1
fi
fi
fi
# Swift client
# ------------
if [[ "$ENABLED_SERVICES" =~ "swift" || "$ENABLED_SERVICES" =~ "s-proxy" ]]; then
if [[ "$SKIP_EXERCISES" =~ "swift" ]]; then
STATUS_SWIFT="Skipped"
else
echo -e "\nTest Swift"
if swift $PROJECT_ARG $ARGS stat; then
STATUS_SWIFT="Succeeded"
else
STATUS_SWIFT="Failed"
RETURN=1
fi
fi
fi
set +o xtrace
# Results
# =======
function report {
if [[ -n "$2" ]]; then
echo "$1: $2"
fi
}
echo -e "\n"
report "Keystone" $STATUS_KEYSTONE
report "Nova" $STATUS_NOVA
report "Cinder" $STATUS_CINDER
report "Glance" $STATUS_GLANCE
report "Swift" $STATUS_SWIFT
if (( $RETURN == 0 )); then
echo "*********************************************************************"
echo "SUCCESS: End DevStack Exercise: $0"
echo "*********************************************************************"
fi
exit $RETURN

View File

@ -1,171 +0,0 @@
#!/usr/bin/env bash
# **client-env.sh**
# Test OpenStack client environment variable handling
echo "*********************************************************************"
echo "Begin DevStack Exercise: $0"
echo "*********************************************************************"
# This script exits on an error so that errors don't compound and you see
# only the first error that occurred.
set -o errexit
# Print the commands being run so that we can see the command that triggers
# an error. It is also useful for following as the install occurs.
set -o xtrace
# Settings
# ========
# Keep track of the current directory
EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
# Import common functions
source $TOP_DIR/functions
# Import configuration
source $TOP_DIR/openrc admin
# Import exercise configuration
source $TOP_DIR/exerciserc
# Unset all of the known NOVA_* vars
unset NOVA_API_KEY
unset NOVA_ENDPOINT_NAME
unset NOVA_PASSWORD
unset NOVA_PROJECT_ID
unset NOVA_REGION_NAME
unset NOVA_URL
unset NOVA_USERNAME
for i in OS_TENANT_NAME OS_USERNAME OS_PASSWORD OS_AUTH_URL; do
is_set $i
if [[ $? -ne 0 ]]; then
echo "$i expected to be set"
ABORT=1
fi
done
if [[ -n "$ABORT" ]]; then
exit 1
fi
# Set global return
RETURN=0
# Keystone client
# ---------------
if [[ "$ENABLED_SERVICES" =~ "key" ]]; then
if [[ "$SKIP_EXERCISES" =~ "key" ]]; then
STATUS_KEYSTONE="Skipped"
else
echo -e "\nTest Keystone"
if openstack endpoint show identity; then
STATUS_KEYSTONE="Succeeded"
else
STATUS_KEYSTONE="Failed"
RETURN=1
fi
fi
fi
# Nova client
# -----------
if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
if [[ "$SKIP_EXERCISES" =~ "n-api" ]]; then
STATUS_NOVA="Skipped"
else
# Test OSAPI
echo -e "\nTest Nova"
if nova flavor-list; then
STATUS_NOVA="Succeeded"
else
STATUS_NOVA="Failed"
RETURN=1
fi
fi
fi
# Cinder client
# -------------
if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
if [[ "$SKIP_EXERCISES" =~ "c-api" ]]; then
STATUS_CINDER="Skipped"
else
echo -e "\nTest Cinder"
if cinder list; then
STATUS_CINDER="Succeeded"
else
STATUS_CINDER="Failed"
RETURN=1
fi
fi
fi
# Glance client
# -------------
if [[ "$ENABLED_SERVICES" =~ "g-api" ]]; then
if [[ "$SKIP_EXERCISES" =~ "g-api" ]]; then
STATUS_GLANCE="Skipped"
else
echo -e "\nTest Glance"
if openstack image list; then
STATUS_GLANCE="Succeeded"
else
STATUS_GLANCE="Failed"
RETURN=1
fi
fi
fi
# Swift client
# ------------
if [[ "$ENABLED_SERVICES" =~ "swift" || "$ENABLED_SERVICES" =~ "s-proxy" ]]; then
if [[ "$SKIP_EXERCISES" =~ "swift" ]]; then
STATUS_SWIFT="Skipped"
else
echo -e "\nTest Swift"
if swift stat; then
STATUS_SWIFT="Succeeded"
else
STATUS_SWIFT="Failed"
RETURN=1
fi
fi
fi
set +o xtrace
# Results
# =======
function report {
if [[ -n "$2" ]]; then
echo "$1: $2"
fi
}
echo -e "\n"
report "Keystone" $STATUS_KEYSTONE
report "Nova" $STATUS_NOVA
report "Cinder" $STATUS_CINDER
report "Glance" $STATUS_GLANCE
report "Swift" $STATUS_SWIFT
if (( $RETURN == 0 )); then
echo "*********************************************************************"
echo "SUCCESS: End DevStack Exercise: $0"
echo "*********************************************************************"
fi
exit $RETURN

View File

@ -1,216 +0,0 @@
#!/usr/bin/env bash
# **floating_ips.sh** - using the cloud can be fun
# Test instance connectivity with the ``nova`` command from ``python-novaclient``
echo "*********************************************************************"
echo "Begin DevStack Exercise: $0"
echo "*********************************************************************"
# This script exits on an error so that errors don't compound and you see
# only the first error that occurred.
set -o errexit
# Print the commands being run so that we can see the command that triggers
# an error. It is also useful for following as the install occurs.
set -o xtrace
# Settings
# ========
# Keep track of the current directory
EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
# Import common functions
source $TOP_DIR/functions
# Import configuration
source $TOP_DIR/openrc
# Import project functions
source $TOP_DIR/lib/neutron
source $TOP_DIR/lib/neutron-legacy
# Import exercise configuration
source $TOP_DIR/exerciserc
# If nova api is not enabled we exit with exitcode 55 so that
# the exercise is skipped
is_service_enabled n-api || exit 55
# Instance type to create
DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
# Boot this image, use first AMI image if unset
DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
# Security group name
SECGROUP=${SECGROUP:-test_secgroup}
# Default floating IP pool name
DEFAULT_FLOATING_POOL=${DEFAULT_FLOATING_POOL:-public}
# Additional floating IP pool and range
TEST_FLOATING_POOL=${TEST_FLOATING_POOL:-test}
# Instance name
VM_NAME="ex-float"
# Cells does not support floating ips API calls
is_service_enabled n-cell && exit 55
# Launching a server
# ==================
# List servers for tenant:
nova list
# Images
# ------
# List the images available
openstack image list
# Grab the id of the image to launch
IMAGE=$(openstack image list | egrep " $DEFAULT_IMAGE_NAME " | get_field 1)
die_if_not_set $LINENO IMAGE "Failure getting image $DEFAULT_IMAGE_NAME"
# Security Groups
# ---------------
# List security groups
nova secgroup-list
# Create a secgroup
if ! nova secgroup-list | grep -q $SECGROUP; then
nova secgroup-create $SECGROUP "$SECGROUP description"
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! nova secgroup-list | grep -q $SECGROUP; do sleep 1; done"; then
die $LINENO "Security group not created"
fi
fi
# Configure Security Group Rules
if ! nova secgroup-list-rules $SECGROUP | grep -q icmp; then
nova secgroup-add-rule $SECGROUP icmp -1 -1 0.0.0.0/0
fi
if ! nova secgroup-list-rules $SECGROUP | grep -q " tcp .* 22 "; then
nova secgroup-add-rule $SECGROUP tcp 22 22 0.0.0.0/0
fi
# List secgroup rules
nova secgroup-list-rules $SECGROUP
# Set up instance
# ---------------
# List flavors
nova flavor-list
# Select a flavor
INSTANCE_TYPE=$(nova flavor-list | grep $DEFAULT_INSTANCE_TYPE | get_field 1)
if [[ -z "$INSTANCE_TYPE" ]]; then
# grab the first flavor in the list to launch if default doesn't exist
INSTANCE_TYPE=$(nova flavor-list | head -n 4 | tail -n 1 | get_field 1)
die_if_not_set $LINENO INSTANCE_TYPE "Failure retrieving INSTANCE_TYPE"
fi
# Clean-up from previous runs
nova delete $VM_NAME || true
if ! timeout $ACTIVE_TIMEOUT sh -c "while nova show $VM_NAME; do sleep 1; done"; then
die $LINENO "server didn't terminate!"
exit 1
fi
# Boot instance
# -------------
VM_UUID=$(nova boot --flavor $INSTANCE_TYPE --image $IMAGE --security-groups=$SECGROUP $VM_NAME | grep ' id ' | get_field 2)
die_if_not_set $LINENO VM_UUID "Failure launching $VM_NAME"
# Check that the status is active within ACTIVE_TIMEOUT seconds
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then
die $LINENO "server didn't become active!"
fi
# Get the instance IP
IP=$(get_instance_ip $VM_UUID $PRIVATE_NETWORK_NAME)
die_if_not_set $LINENO IP "Failure retrieving IP address"
# Private IPs can be pinged in single node deployments
ping_check $IP $BOOT_TIMEOUT "$PRIVATE_NETWORK_NAME"
# Floating IPs
# ------------
# Allocate a floating IP from the default pool
FLOATING_IP=$(nova floating-ip-create | grep $DEFAULT_FLOATING_POOL | get_field 1)
die_if_not_set $LINENO FLOATING_IP "Failure creating floating IP from pool $DEFAULT_FLOATING_POOL"
# List floating addresses
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! nova floating-ip-list | grep -q $FLOATING_IP; do sleep 1; done"; then
die $LINENO "Floating IP not allocated"
fi
# Add floating IP to our server
nova add-floating-ip $VM_UUID $FLOATING_IP || \
die $LINENO "Failure adding floating IP $FLOATING_IP to $VM_NAME"
# Test we can ping our floating IP within ASSOCIATE_TIMEOUT seconds
ping_check $FLOATING_IP $ASSOCIATE_TIMEOUT "$PUBLIC_NETWORK_NAME"
if ! is_service_enabled neutron; then
# Allocate an IP from second floating pool
TEST_FLOATING_IP=$(nova floating-ip-create $TEST_FLOATING_POOL | grep $TEST_FLOATING_POOL | get_field 1)
die_if_not_set $LINENO TEST_FLOATING_IP "Failure creating floating IP in $TEST_FLOATING_POOL"
# list floating addresses
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! nova floating-ip-list | grep $TEST_FLOATING_POOL | grep -q $TEST_FLOATING_IP; do sleep 1; done"; then
die $LINENO "Floating IP not allocated"
fi
fi
# Dis-allow icmp traffic (ping)
nova secgroup-delete-rule $SECGROUP icmp -1 -1 0.0.0.0/0 || \
die $LINENO "Failure deleting security group rule from $SECGROUP"
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while nova secgroup-list-rules $SECGROUP | grep -q icmp; do sleep 1; done"; then
die $LINENO "Security group rule not deleted from $SECGROUP"
fi
# FIXME (anthony): make xs support security groups
if [ "$VIRT_DRIVER" != "ironic" -a "$VIRT_DRIVER" != "xenserver" -a "$VIRT_DRIVER" != "openvz" ]; then
# Test we can aren't able to ping our floating ip within ASSOCIATE_TIMEOUT seconds
ping_check $FLOATING_IP $ASSOCIATE_TIMEOUT "$PUBLIC_NETWORK_NAME" Fail
fi
# Clean up
# --------
if ! is_service_enabled neutron; then
# Delete second floating IP
nova floating-ip-delete $TEST_FLOATING_IP || \
die $LINENO "Failure deleting floating IP $TEST_FLOATING_IP"
fi
# Delete the floating ip
nova floating-ip-delete $FLOATING_IP || \
die $LINENO "Failure deleting floating IP $FLOATING_IP"
# Delete instance
nova delete $VM_UUID || die $LINENO "Failure deleting instance $VM_NAME"
# Wait for termination
if ! timeout $TERMINATE_TIMEOUT sh -c "while nova list | grep -q $VM_UUID; do sleep 1; done"; then
die $LINENO "Server $VM_NAME not deleted"
fi
# Delete secgroup
nova secgroup-delete $SECGROUP || \
die $LINENO "Failure deleting security group $SECGROUP"
set +o xtrace
echo "*********************************************************************"
echo "SUCCESS: End DevStack Exercise: $0"
echo "*********************************************************************"

View File

@ -1,466 +0,0 @@
#!/usr/bin/env bash
#
# Copyright 2012, Cisco Systems
# Copyright 2012, VMware, Inc.
# Copyright 2012, NTT MCL, Inc.
#
# Please direct any questions to dedutta@cisco.com, dwendlandt@vmware.com, nachi@nttmcl.com
#
# **neutron-adv-test.sh**
# Perform integration testing of Nova and other components with Neutron.
echo "*********************************************************************"
echo "Begin DevStack Exercise: $0"
echo "*********************************************************************"
# This script exits on an error so that errors don't compound and you see
# only the first error that occurred.
set -o errtrace
# Print the commands being run so that we can see the command that triggers
# an error. It is also useful for following as the install occurs.
set -o xtrace
# Environment
# -----------
# Keep track of the current directory
EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
# Import common functions
source $TOP_DIR/functions
# Import configuration
source $TOP_DIR/openrc
# Import neutron functions
source $TOP_DIR/lib/neutron
source $TOP_DIR/lib/neutron-legacy
# If neutron is not enabled we exit with exitcode 55, which means exercise is skipped.
neutron_plugin_check_adv_test_requirements || exit 55
# Import exercise configuration
source $TOP_DIR/exerciserc
# Neutron Settings
# ----------------
PROJECTS="DEMO1"
# TODO (nati)_Test public network
#PROJECTS="DEMO1,DEMO2"
PUBLIC_NAME="admin"
DEMO1_NAME="demo1"
DEMO2_NAME="demo2"
PUBLIC_NUM_NET=1
DEMO1_NUM_NET=1
DEMO2_NUM_NET=2
PUBLIC_NET1_CIDR="200.0.0.0/24"
DEMO1_NET1_CIDR="10.10.0.0/24"
DEMO2_NET1_CIDR="10.20.0.0/24"
DEMO2_NET2_CIDR="10.20.1.0/24"
PUBLIC_NET1_GATEWAY="200.0.0.1"
DEMO1_NET1_GATEWAY="10.10.0.1"
DEMO2_NET1_GATEWAY="10.20.0.1"
DEMO2_NET2_GATEWAY="10.20.1.1"
PUBLIC_NUM_VM=1
DEMO1_NUM_VM=1
DEMO2_NUM_VM=2
PUBLIC_VM1_NET='admin-net1'
DEMO1_VM1_NET='demo1-net1'
# Multinic settings. But this is fail without nic setting in OS image
DEMO2_VM1_NET='demo2-net1'
DEMO2_VM2_NET='demo2-net2'
PUBLIC_NUM_ROUTER=1
DEMO1_NUM_ROUTER=1
DEMO2_NUM_ROUTER=1
PUBLIC_ROUTER1_NET="admin-net1"
DEMO1_ROUTER1_NET="demo1-net1"
DEMO2_ROUTER1_NET="demo2-net1"
# Various functions
# -----------------
function foreach_project {
COMMAND=$1
for PROJECT in ${PROJECTS//,/ };do
eval ${COMMAND//%PROJECT%/$PROJECT}
done
}
function foreach_project_resource {
COMMAND=$1
RESOURCE=$2
for PROJECT in ${PROJECTS//,/ };do
eval 'NUM=$'"${PROJECT}_NUM_$RESOURCE"
for i in `seq $NUM`;do
local COMMAND_LOCAL=${COMMAND//%PROJECT%/$PROJECT}
COMMAND_LOCAL=${COMMAND_LOCAL//%NUM%/$i}
eval $COMMAND_LOCAL
done
done
}
function foreach_project_vm {
COMMAND=$1
foreach_project_resource "$COMMAND" 'VM'
}
function foreach_project_net {
COMMAND=$1
foreach_project_resource "$COMMAND" 'NET'
}
function get_image_id {
local IMAGE_ID
IMAGE_ID=$(openstack image list | egrep " $DEFAULT_IMAGE_NAME " | get_field 1)
die_if_not_set $LINENO IMAGE_ID "Failure retrieving IMAGE_ID"
echo "$IMAGE_ID"
}
function get_project_id {
local PROJECT_NAME=$1
local PROJECT_ID
PROJECT_ID=`openstack project list | grep " $PROJECT_NAME " | head -n 1 | get_field 1`
die_if_not_set $LINENO PROJECT_ID "Failure retrieving PROJECT_ID for $PROJECT_NAME"
echo "$PROJECT_ID"
}
function get_user_id {
local USER_NAME=$1
local USER_ID
USER_ID=`openstack user list | grep $USER_NAME | awk '{print $2}'`
die_if_not_set $LINENO USER_ID "Failure retrieving USER_ID for $USER_NAME"
echo "$USER_ID"
}
function get_role_id {
local ROLE_NAME=$1
local ROLE_ID
ROLE_ID=`openstack role assignment list | grep $ROLE_NAME | awk '{print $2}'`
die_if_not_set $LINENO ROLE_ID "Failure retrieving ROLE_ID for $ROLE_NAME"
echo "$ROLE_ID"
}
function get_network_id {
local NETWORK_NAME="$1"
local NETWORK_ID
NETWORK_ID=`openstack network show -f value -c id $NETWORK_NAME`
echo $NETWORK_ID
}
function get_flavor_id {
local INSTANCE_TYPE=$1
local FLAVOR_ID
FLAVOR_ID=`nova flavor-list | grep $INSTANCE_TYPE | awk '{print $2}'`
die_if_not_set $LINENO FLAVOR_ID "Failure retrieving FLAVOR_ID for $INSTANCE_TYPE"
echo "$FLAVOR_ID"
}
function confirm_server_active {
local VM_UUID=$1
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then
echo "server '$VM_UUID' did not become active!"
false
fi
}
function neutron_debug_admin {
local os_username=$OS_USERNAME
local os_project_id=$OS_PROJECT_ID
source $TOP_DIR/openrc admin admin
neutron-debug $@
source $TOP_DIR/openrc $os_username $os_project_id
}
function add_project {
openstack project create $1
openstack user create $2 --password ${ADMIN_PASSWORD} --project $1
openstack role add Member --project $1 --user $2
}
function remove_project {
local PROJECT=$1
local PROJECT_ID
PROJECT_ID=$(get_project_id $PROJECT)
openstack project delete $PROJECT_ID
}
function remove_user {
local USER=$1
local USER_ID
USER_ID=$(get_user_id $USER)
openstack user delete $USER_ID
}
function create_projects {
source $TOP_DIR/openrc admin admin
add_project demo1 demo1 demo1
add_project demo2 demo2 demo2
source $TOP_DIR/openrc demo demo
}
function delete_projects_and_users {
source $TOP_DIR/openrc admin admin
remove_user demo1
remove_project demo1
remove_user demo2
remove_project demo2
echo "removed all projects"
source $TOP_DIR/openrc demo demo
}
function create_network {
local PROJECT=$1
local GATEWAY=$2
local CIDR=$3
local NUM=$4
local EXTRA=$5
local NET_NAME="${PROJECT}-net$NUM"
local ROUTER_NAME="${PROJECT}-router${NUM}"
source $TOP_DIR/openrc admin admin
local PROJECT_ID
PROJECT_ID=$(get_project_id $PROJECT)
source $TOP_DIR/openrc $PROJECT $PROJECT
local NET_ID
NET_ID=$(openstack network create --project $PROJECT_ID $NET_NAME $EXTRA| grep ' id ' | awk '{print $4}' )
die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PROJECT_ID $NET_NAME $EXTRA"
openstack subnet create --ip-version 4 --project $PROJECT_ID --gateway $GATEWAY --subnet-pool None --network $NET_ID --subnet-range $CIDR "${NET_NAME}_subnet"
neutron_debug_admin probe-create --device-owner compute $NET_ID
source $TOP_DIR/openrc demo demo
}
function create_networks {
foreach_project_net 'create_network ${%PROJECT%_NAME} ${%PROJECT%_NET%NUM%_GATEWAY} ${%PROJECT%_NET%NUM%_CIDR} %NUM% ${%PROJECT%_NET%NUM%_EXTRA}'
#TODO(nati) test security group function
# allow ICMP for both project's security groups
#source $TOP_DIR/openrc demo1 demo1
#$NOVA secgroup-add-rule default icmp -1 -1 0.0.0.0/0
#source $TOP_DIR/openrc demo2 demo2
#$NOVA secgroup-add-rule default icmp -1 -1 0.0.0.0/0
}
function create_vm {
local PROJECT=$1
local NUM=$2
local NET_NAMES=$3
source $TOP_DIR/openrc $PROJECT $PROJECT
local NIC=""
for NET_NAME in ${NET_NAMES//,/ };do
NIC="$NIC --nic net-id="`get_network_id $NET_NAME`
done
#TODO (nati) Add multi-nic test
#TODO (nati) Add public-net test
local VM_UUID
VM_UUID=`nova boot --flavor $(get_flavor_id m1.tiny) \
--image $(get_image_id) \
$NIC \
$PROJECT-server$NUM | grep ' id ' | cut -d"|" -f3 | sed 's/ //g'`
die_if_not_set $LINENO VM_UUID "Failure launching $PROJECT-server$NUM"
confirm_server_active $VM_UUID
}
function create_vms {
foreach_project_vm 'create_vm ${%PROJECT%_NAME} %NUM% ${%PROJECT%_VM%NUM%_NET}'
}
function ping_ip {
# Test agent connection. Assumes namespaces are disabled, and
# that DHCP is in use, but not L3
local VM_NAME=$1
local NET_NAME=$2
IP=$(get_instance_ip $VM_NAME $NET_NAME)
ping_check $IP $BOOT_TIMEOUT $NET_NAME
}
function check_vm {
local PROJECT=$1
local NUM=$2
local VM_NAME="$PROJECT-server$NUM"
local NET_NAME=$3
source $TOP_DIR/openrc $PROJECT $PROJECT
ping_ip $VM_NAME $NET_NAME
# TODO (nati) test ssh connection
# TODO (nati) test inter connection between vm
# TODO (nati) test dhcp host routes
# TODO (nati) test multi-nic
}
function check_vms {
foreach_project_vm 'check_vm ${%PROJECT%_NAME} %NUM% ${%PROJECT%_VM%NUM%_NET}'
}
function shutdown_vm {
local PROJECT=$1
local NUM=$2
source $TOP_DIR/openrc $PROJECT $PROJECT
VM_NAME=${PROJECT}-server$NUM
nova delete $VM_NAME
}
function shutdown_vms {
foreach_project_vm 'shutdown_vm ${%PROJECT%_NAME} %NUM%'
if ! timeout $TERMINATE_TIMEOUT sh -c "while nova list | grep -q ACTIVE; do sleep 1; done"; then
die $LINENO "Some VMs failed to shutdown"
fi
}
function delete_network {
local PROJECT=$1
local NUM=$2
local NET_NAME="${PROJECT}-net$NUM"
source $TOP_DIR/openrc admin admin
local PROJECT_ID
PROJECT_ID=$(get_project_id $PROJECT)
#TODO(nati) comment out until l3-agent merged
#for res in port subnet net router;do
for net_id in `openstack network list -c ID -c Name | grep $NET_NAME | awk '{print $2}'`;do
delete_probe $net_id
openstack subnet list | grep $net_id | awk '{print $2}' | xargs -I% openstack subnet delete %
openstack network delete $net_id
done
source $TOP_DIR/openrc demo demo
}
function delete_networks {
foreach_project_net 'delete_network ${%PROJECT%_NAME} %NUM%'
# TODO(nati) add secuirty group check after it is implemented
# source $TOP_DIR/openrc demo1 demo1
# nova secgroup-delete-rule default icmp -1 -1 0.0.0.0/0
# source $TOP_DIR/openrc demo2 demo2
# nova secgroup-delete-rule default icmp -1 -1 0.0.0.0/0
}
function create_all {
create_projects
create_networks
create_vms
}
function delete_all {
shutdown_vms
delete_networks
delete_projects_and_users
}
function all {
create_all
check_vms
delete_all
}
# Test functions
# --------------
function test_functions {
IMAGE=$(get_image_id)
echo $IMAGE
PROJECT_ID=$(get_project_id demo)
echo $PROJECT_ID
FLAVOR_ID=$(get_flavor_id m1.tiny)
echo $FLAVOR_ID
NETWORK_ID=$(get_network_id admin)
echo $NETWORK_ID
}
# Usage and main
# --------------
function usage {
echo "$0: [-h]"
echo " -h, --help Display help message"
echo " -t, --project Create projects"
echo " -n, --net Create networks"
echo " -v, --vm Create vms"
echo " -c, --check Check connection"
echo " -x, --delete-projects Delete projects"
echo " -y, --delete-nets Delete networks"
echo " -z, --delete-vms Delete vms"
echo " -T, --test Test functions"
}
function main {
echo Description
if [ $# -eq 0 ] ; then
# if no args are provided, run all tests
all
else
while [ "$1" != "" ]; do
case $1 in
-h | --help ) usage
exit
;;
-n | --net ) create_networks
exit
;;
-v | --vm ) create_vms
exit
;;
-t | --project ) create_projects
exit
;;
-c | --check ) check_vms
exit
;;
-T | --test ) test_functions
exit
;;
-x | --delete-projects ) delete_projects_and_users
exit
;;
-y | --delete-nets ) delete_networks
exit
;;
-z | --delete-vms ) shutdown_vms
exit
;;
-a | --all ) all
exit
;;
* ) usage
exit 1
esac
shift
done
fi
}
trap failed ERR
function failed {
local r=$?
set +o errtrace
set +o xtrace
echo "Failed to execute"
echo "Starting cleanup..."
delete_all
echo "Finished cleanup"
exit $r
}
# Kick off script
# ---------------
echo $*
main $*
set +o xtrace
echo "*********************************************************************"
echo "SUCCESS: End DevStack Exercise: $0"
echo "*********************************************************************"

View File

@ -1,81 +0,0 @@
#!/usr/bin/env bash
# **sec_groups.sh**
# Test security groups via the command line
echo "*********************************************************************"
echo "Begin DevStack Exercise: $0"
echo "*********************************************************************"
# This script exits on an error so that errors don't compound and you see
# only the first error that occurred.
set -o errexit
# Print the commands being run so that we can see the command that triggers
# an error. It is also useful for following as the install occurs.
set -o xtrace
# Settings
# ========
# Keep track of the current directory
EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
# Import common functions
source $TOP_DIR/functions
# Import configuration
source $TOP_DIR/openrc
# Import exercise configuration
source $TOP_DIR/exerciserc
# If nova api is not enabled we exit with exitcode 55 so that
# the exercise is skipped
is_service_enabled n-api || exit 55
# Testing Security Groups
# =======================
# List security groups
nova secgroup-list
# Create random name for new sec group and create secgroup of said name
SEC_GROUP_NAME="ex-secgroup-$(openssl rand -hex 4)"
nova secgroup-create $SEC_GROUP_NAME 'a test security group'
# Add some rules to the secgroup
RULES_TO_ADD=( 22 3389 5900 )
for RULE in "${RULES_TO_ADD[@]}"; do
nova secgroup-add-rule $SEC_GROUP_NAME tcp $RULE $RULE 0.0.0.0/0
done
# Check to make sure rules were added
SEC_GROUP_RULES=( $(nova secgroup-list-rules $SEC_GROUP_NAME | grep -v \- | grep -v 'Source Group' | cut -d '|' -f3 | tr -d ' ') )
die_if_not_set $LINENO SEC_GROUP_RULES "Failure retrieving SEC_GROUP_RULES for $SEC_GROUP_NAME"
for i in "${RULES_TO_ADD[@]}"; do
skip=
for j in "${SEC_GROUP_RULES[@]}"; do
[[ $i == $j ]] && { skip=1; break; }
done
[[ -n $skip ]] || exit 1
done
# Delete rules and secgroup
for RULE in "${RULES_TO_ADD[@]}"; do
nova secgroup-delete-rule $SEC_GROUP_NAME tcp $RULE $RULE 0.0.0.0/0
done
# Delete secgroup
nova secgroup-delete $SEC_GROUP_NAME || \
die $LINENO "Failure deleting security group $SEC_GROUP_NAME"
set +o xtrace
echo "*********************************************************************"
echo "SUCCESS: End DevStack Exercise: $0"
echo "*********************************************************************"

View File

@ -1,69 +0,0 @@
#!/usr/bin/env bash
# **swift.sh**
# Test swift via the ``python-openstackclient`` command line
echo "*********************************************************************"
echo "Begin DevStack Exercise: $0"
echo "*********************************************************************"
# This script exits on an error so that errors don't compound and you see
# only the first error that occurred.
set -o errexit
# Print the commands being run so that we can see the command that triggers
# an error. It is also useful for following as the install occurs.
set -o xtrace
# Settings
# ========
# Keep track of the current directory
EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
# Import common functions
source $TOP_DIR/functions
# Import configuration
source $TOP_DIR/openrc
# Import exercise configuration
source $TOP_DIR/exerciserc
# If swift is not enabled we exit with exitcode 55 which mean
# exercise is skipped.
is_service_enabled s-proxy || exit 55
# Container name
CONTAINER=ex-swift
OBJECT=/etc/issue
# Testing Swift
# =============
# Check if we have to swift via keystone
openstack object store account show || die $LINENO "Failure getting account status"
# We start by creating a test container
openstack container create $CONTAINER || die $LINENO "Failure creating container $CONTAINER"
# add a file into it.
openstack object create $CONTAINER $OBJECT || die $LINENO "Failure uploading file to container $CONTAINER"
# list the objects
openstack object list $CONTAINER || die $LINENO "Failure listing contents of container $CONTAINER"
# delete the object first
openstack object delete $CONTAINER $OBJECT || die $LINENO "Failure deleting object $OBJECT in container $CONTAINER"
# delete the container
openstack container delete $CONTAINER || die $LINENO "Failure deleting container $CONTAINER"
set +o xtrace
echo "*********************************************************************"
echo "SUCCESS: End DevStack Exercise: $0"
echo "*********************************************************************"

View File

@ -1,225 +0,0 @@
#!/usr/bin/env bash
# **volumes.sh**
# Test cinder volumes with the ``cinder`` command from ``python-cinderclient``
echo "*********************************************************************"
echo "Begin DevStack Exercise: $0"
echo "*********************************************************************"
# This script exits on an error so that errors don't compound and you see
# only the first error that occurred.
set -o errexit
# Print the commands being run so that we can see the command that triggers
# an error. It is also useful for following as the install occurs.
set -o xtrace
# Settings
# ========
# Keep track of the current directory
EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
# Import common functions
source $TOP_DIR/functions
# Import configuration
source $TOP_DIR/openrc
# Import project functions
source $TOP_DIR/lib/cinder
source $TOP_DIR/lib/neutron
source $TOP_DIR/lib/neutron-legacy
# Import exercise configuration
source $TOP_DIR/exerciserc
# If cinder is not enabled we exit with exitcode 55 which mean
# exercise is skipped.
is_service_enabled cinder || exit 55
# Ironic does not currently support volume attachment.
[ "$VIRT_DRIVER" == "ironic" ] && exit 55
# Instance type to create
DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
# Boot this image, use first AMI image if unset
DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
# Security group name
SECGROUP=${SECGROUP:-vol_secgroup}
# Instance and volume names
VM_NAME=${VM_NAME:-ex-vol-inst}
VOL_NAME="ex-vol-$(openssl rand -hex 4)"
# Launching a server
# ==================
# List servers for tenant:
nova list
# Images
# ------
# List the images available
openstack image list
# Grab the id of the image to launch
IMAGE=$(openstack image list | egrep " $DEFAULT_IMAGE_NAME " | get_field 1)
die_if_not_set $LINENO IMAGE "Failure getting image $DEFAULT_IMAGE_NAME"
# Security Groups
# ---------------
# List security groups
nova secgroup-list
if is_service_enabled n-cell; then
# Cells does not support security groups, so force the use of "default"
SECGROUP="default"
echo "Using the default security group because of Cells."
else
# Create a secgroup
if ! nova secgroup-list | grep -q $SECGROUP; then
nova secgroup-create $SECGROUP "$SECGROUP description"
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! nova secgroup-list | grep -q $SECGROUP; do sleep 1; done"; then
echo "Security group not created"
exit 1
fi
fi
fi
# Configure Security Group Rules
if ! nova secgroup-list-rules $SECGROUP | grep -q icmp; then
nova secgroup-add-rule $SECGROUP icmp -1 -1 0.0.0.0/0
fi
if ! nova secgroup-list-rules $SECGROUP | grep -q " tcp .* 22 "; then
nova secgroup-add-rule $SECGROUP tcp 22 22 0.0.0.0/0
fi
# List secgroup rules
nova secgroup-list-rules $SECGROUP
# Set up instance
# ---------------
# List flavors
nova flavor-list
# Select a flavor
INSTANCE_TYPE=$(nova flavor-list | grep $DEFAULT_INSTANCE_TYPE | get_field 1)
if [[ -z "$INSTANCE_TYPE" ]]; then
# grab the first flavor in the list to launch if default doesn't exist
INSTANCE_TYPE=$(nova flavor-list | head -n 4 | tail -n 1 | get_field 1)
die_if_not_set $LINENO INSTANCE_TYPE "Failure retrieving INSTANCE_TYPE"
fi
# Clean-up from previous runs
nova delete $VM_NAME || true
if ! timeout $ACTIVE_TIMEOUT sh -c "while nova show $VM_NAME; do sleep 1; done"; then
die $LINENO "server didn't terminate!"
fi
# Boot instance
# -------------
VM_UUID=$(nova boot --flavor $INSTANCE_TYPE --image $IMAGE --security-groups=$SECGROUP $VM_NAME | grep ' id ' | get_field 2)
die_if_not_set $LINENO VM_UUID "Failure launching $VM_NAME"
# Check that the status is active within ACTIVE_TIMEOUT seconds
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then
die $LINENO "server didn't become active!"
fi
# Get the instance IP
IP=$(get_instance_ip $VM_UUID $PRIVATE_NETWORK_NAME)
die_if_not_set $LINENO IP "Failure retrieving IP address"
# Private IPs can be pinged in single node deployments
ping_check $IP $BOOT_TIMEOUT "$PRIVATE_NETWORK_NAME"
# Volumes
# -------
# Verify it doesn't exist
if [[ -n $(cinder list | grep $VOL_NAME | head -1 | get_field 2) ]]; then
die $LINENO "Volume $VOL_NAME already exists"
fi
# Create a new volume
start_time=$(date +%s)
cinder create --display-name $VOL_NAME --display-description "test volume: $VOL_NAME" $DEFAULT_VOLUME_SIZE || \
die $LINENO "Failure creating volume $VOL_NAME"
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! cinder list | grep $VOL_NAME | grep available; do sleep 1; done"; then
die $LINENO "Volume $VOL_NAME not created"
fi
end_time=$(date +%s)
echo "Completed cinder create in $((end_time - start_time)) seconds"
# Get volume ID
VOL_ID=$(cinder list | grep $VOL_NAME | head -1 | get_field 1)
die_if_not_set $LINENO VOL_ID "Failure retrieving volume ID for $VOL_NAME"
# Attach to server
DEVICE=/dev/vdb
start_time=$(date +%s)
nova volume-attach $VM_UUID $VOL_ID $DEVICE || \
die $LINENO "Failure attaching volume $VOL_NAME to $VM_NAME"
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! cinder list | grep $VOL_NAME | grep in-use; do sleep 1; done"; then
die $LINENO "Volume $VOL_NAME not attached to $VM_NAME"
fi
end_time=$(date +%s)
echo "Completed volume-attach in $((end_time - start_time)) seconds"
VOL_ATTACH=$(cinder list | grep $VOL_NAME | head -1 | get_field -1)
die_if_not_set $LINENO VOL_ATTACH "Failure retrieving $VOL_NAME status"
if [[ "$VOL_ATTACH" != $VM_UUID ]]; then
die $LINENO "Volume not attached to correct instance"
fi
# Clean up
# --------
# Detach volume
start_time=$(date +%s)
nova volume-detach $VM_UUID $VOL_ID || die $LINENO "Failure detaching volume $VOL_NAME from $VM_NAME"
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! cinder list | grep $VOL_NAME | grep available; do sleep 1; done"; then
die $LINENO "Volume $VOL_NAME not detached from $VM_NAME"
fi
end_time=$(date +%s)
echo "Completed volume-detach in $((end_time - start_time)) seconds"
# Delete volume
start_time=$(date +%s)
cinder delete $VOL_ID || die $LINENO "Failure deleting volume $VOL_NAME"
if ! timeout $ACTIVE_TIMEOUT sh -c "while cinder list | grep $VOL_NAME; do sleep 1; done"; then
die $LINENO "Volume $VOL_NAME not deleted"
fi
end_time=$(date +%s)
echo "Completed cinder delete in $((end_time - start_time)) seconds"
# Delete instance
nova delete $VM_UUID || die $LINENO "Failure deleting instance $VM_NAME"
if ! timeout $TERMINATE_TIMEOUT sh -c "while nova list | grep -q $VM_UUID; do sleep 1; done"; then
die $LINENO "Server $VM_NAME not deleted"
fi
if [[ $SECGROUP = "default" ]] ; then
echo "Skipping deleting default security group"
else
# Delete secgroup
nova secgroup-delete $SECGROUP || die $LINENO "Failure deleting security group $SECGROUP"
fi
set +o xtrace
echo "*********************************************************************"
echo "SUCCESS: End DevStack Exercise: $0"
echo "*********************************************************************"