summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancisco Redondo Marchena <francisco.marchena@codethink.co.uk>2015-06-04 10:58:02 +0000
committerFrancisco Redondo Marchena <francisco.marchena@codethink.co.uk>2015-06-04 10:58:02 +0000
commitb934b4e3d85cfa0e84feff28c17fda78f0309c30 (patch)
treeb2e37cd961db42c0367f4134e2829c91e9d30073
parentd3f3de03a35e3e9d66be0ad8adf38f2e23401ebf (diff)
downloaddefinitions-b934b4e3d85cfa0e84feff28c17fda78f0309c30.tar.gz
WIP: Add script to set OpenStack for run tempest test suite
Change-Id: I6a9adb990607a3d92a783590a95ee447157de8f4
-rwxr-xr-xopenstack/etc/tempest/set_openstack_to_run_tempest.sh106
-rw-r--r--openstack/manifest1
2 files changed, 107 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"
diff --git a/openstack/manifest b/openstack/manifest
index da38a638..8a5b47c1 100644
--- a/openstack/manifest
+++ b/openstack/manifest
@@ -1,6 +1,7 @@
0040755 0 0 /etc/horizon
0100644 0 0 /etc/horizon/apache-horizon.conf
template 0100644 0 0 /etc/tempest/tempest.conf
+0100755 0 0 /etc/tempest/set_openstack_to_run_tempest.sh
0040755 0 0 /usr/share/openstack
0100644 0 0 /usr/share/openstack/hosts
0040755 0 0 /usr/share/openstack/ceilometer