summaryrefslogtreecommitdiff
path: root/openstack/etc/tempest/set_openstack_to_run_tempest.sh
blob: 2b9bd7b97cd9130631423791cb7a82ceba852c22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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"