diff options
Diffstat (limited to 'openstack/etc')
-rwxr-xr-x | openstack/etc/tempest/set_openstack_to_run_tempest.sh | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/openstack/etc/tempest/set_openstack_to_run_tempest.sh b/openstack/etc/tempest/set_openstack_to_run_tempest.sh new file mode 100755 index 00000000..2b9bd7b9 --- /dev/null +++ b/openstack/etc/tempest/set_openstack_to_run_tempest.sh @@ -0,0 +1,106 @@ +#!/bin/bash +# -*- coding: utf-8 -*- +# Copyright ©2015 Codethink Limited +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see <http://www.gnu.org/licenses/>. + +set -ex + +admin_filename="admin_env" + +create_admin_user_env(){ +# Create a file with the environment variables +# required for setting a Openstack admin user in the +# admin tenant. + cat > "$admin_filename" <<'EOF' + export OS_USERNAME=admin + export OS_PASSWORD=veryinsecure + export OS_TENANT_NAME=admin + export OS_AUTH_URL=http://franred.onenode:35357/v2.0 +EOF +} + +create_user_env(){ +# Create a file with the environment variables +# required for setting a Openstack demo user in the +# demo tenant. + local tenant_name="$1" + local user_name="$2" + local password="$3" + + cat > "${user_name}_env" <<EOF + export OS_TENANT_NAME="$tenant_name" + export OS_USERNAME="$user_name" + export OS_PASSWORD="$password" + export OS_AUTH_URL=http://franred.onenode:5000/v2.0 +EOF +} + +configure_image_ref(){ +# Set the image_ref field in tempest.conf with the UUID of the cirros64_img_ref +# image. + image_ref="$(glance image-list | grep 'cirros64_img_ref' | tr -d [:space:] | cut -d'|' -f 2)" + if [ -z "image_ref" ]; then + echo "ERROR: image_ref is empty, please check that cirros64_img_ref is created" + exit 1 + fi + # Configure the UUID (image_ref) for the created image + sed -r -i "s/[#]?image_ref =.*/image_ref = $image_ref/" tempest.conf + # Configure image_ssh_user for the created image + sed -r -i "s/[#]?image_ssh_user =.*/image_ssh_user = cirros/" tempest.conf + # Configure image_ssh_password for the created image + sed -r -i "s/[#]?image_ssh_password =.*/image_ssh_password = 'cubswin:)'/" tempest.conf +} + +create_image_for_user(){ +# Create a image in the tenant $user called cirros64_img_ref + local user_name="$1" + + # Set the credential for $user + source "${user_name}_env" + # Delete images called cirros64_img_ref previously created + if [ $(glance image-list | grep 'cirros64_img_ref' | wc -l) -gt 0 ]; then + declare -a previous_img=$(glance image-list | grep 'cirros64_img_ref' | awk -F "|" '{ print $2 }') + for index in ${previous_img[@]}; do + glance image-delete "$index" + done + fi + glance image-create --name cirros64_img_ref \ + --location http://download.cirros-cloud.net/0.3.3/cirros-0.3.3-x86_64-disk.img \ + --is-public true --disk-format qcow2 --container-format bare --progress + if [[ $? -eq 0 ]] \ + || [[ "$(glance image-list | grep 'cirros64_img_ref' | wc -l)" == "1" ]]; then + configure_image_ref + else + echo "ERROR: glance image-create failed." + exit 1 + fi +} + +create_user() { +# Create an user in a tenant in Openstack + local user_name="$1" + local tenant_name="$2" + local password="$3" + + source "$admin_filename" + keystone tenant-create --name "$tenant_name" --description "$tenant_name Tenant" + keystone user-create --name "$user_name" --tenant "$tenant_name" --pass "$password" --email "$user_name" + create_user_env "$user_name" "$tenant_name" "$password" +} + +image_ref="" +create_admin_user_env +create_image_for_user "admin" +#create_user "demo" "demo" "demo" +#create_image_for_user "demo" |