blob: d77798308bbaecd31acc02f61dfbb55b0adaeb2b [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
Nikhil Manchanda0cccad42012-12-03 18:15:09 -07003# lib/trove
4# Functions to control the configuration and operation of the **Trove** service
5
6# Dependencies:
7# ``functions`` file
8# ``DEST``, ``STACK_USER`` must be defined
9# ``SERVICE_{HOST|PROTOCOL|TOKEN}`` must be defined
10
11# ``stack.sh`` calls the entry points in this order:
12#
13# install_trove
14# configure_trove
15# init_trove
16# start_trove
17# stop_trove
18# cleanup_trove
19
20# Save trace setting
21XTRACE=$(set +o | grep xtrace)
22set +o xtrace
23
24# Defaults
25# --------
Nikhil Manchandabc22e912014-05-07 23:46:01 -070026if is_service_enabled neutron; then
27 TROVE_HOST_GATEWAY=${PUBLIC_NETWORK_GATEWAY:-172.24.4.1}
28else
29 TROVE_HOST_GATEWAY=${NETWORK_GATEWAY:-10.0.0.1}
30fi
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070031
32# Set up default configuration
Sean Daguee08ab102014-11-13 17:09:28 -050033GITDIR["python-troveclient"]=$DEST/python-troveclient
Sean Dague5cb19062014-11-01 01:37:45 +010034
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070035TROVE_DIR=$DEST/trove
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070036TROVE_CONF_DIR=/etc/trove
Brian Hunter236fd072015-02-12 16:14:02 -050037TROVE_CONF=$TROVE_CONF_DIR/trove.conf
38TROVE_TASKMANAGER_CONF=$TROVE_CONF_DIR/trove-taskmanager.conf
39TROVE_CONDUCTOR_CONF=$TROVE_CONF_DIR/trove-conductor.conf
Peter Stachowskidd4bafd2015-03-02 23:32:04 -050040TROVE_GUESTAGENT_CONF=$TROVE_CONF_DIR/trove-guestagent.conf
Brian Hunter236fd072015-02-12 16:14:02 -050041TROVE_API_PASTE_INI=$TROVE_CONF_DIR/api-paste.ini
42
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070043TROVE_LOCAL_CONF_DIR=$TROVE_DIR/etc/trove
Brian Hunter236fd072015-02-12 16:14:02 -050044TROVE_LOCAL_API_PASTE_INI=$TROVE_LOCAL_CONF_DIR/api-paste.ini
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070045TROVE_AUTH_CACHE_DIR=${TROVE_AUTH_CACHE_DIR:-/var/cache/trove}
Nikhil Manchandaafefaa72014-06-24 13:06:00 -070046TROVE_DATASTORE_TYPE=${TROVE_DATASTORE_TYPE:-"mysql"}
47TROVE_DATASTORE_VERSION=${TROVE_DATASTORE_VERSION:-"5.5"}
48TROVE_DATASTORE_PACKAGE=${TROVE_DATASTORE_PACKAGE:-"mysql-server-5.5"}
Michael Basnight0f9a1b02013-12-28 03:42:07 +000049
50# Support entry points installation of console scripts
51if [[ -d $TROVE_DIR/bin ]]; then
52 TROVE_BIN_DIR=$TROVE_DIR/bin
53else
54 TROVE_BIN_DIR=$(get_python_exec_prefix)
55fi
Brian Hunter236fd072015-02-12 16:14:02 -050056TROVE_MANAGE=$TROVE_BIN_DIR/trove-manage
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070057
Dean Troyer4237f592014-01-29 16:22:11 -060058# Tell Tempest this project is present
59TEMPEST_SERVICES+=,trove
60
61
Dean Troyerfc744f92014-01-27 13:45:21 -060062# Functions
63# ---------
64
65# Test if any Trove services are enabled
66# is_trove_enabled
67function is_trove_enabled {
68 [[ ,${ENABLED_SERVICES} =~ ,"tr-" ]] && return 0
69 return 1
70}
71
Robert Myers674ee842013-11-25 13:15:35 -060072# setup_trove_logging() - Adds logging configuration to conf files
Ian Wienandaee18c72014-02-21 15:35:08 +110073function setup_trove_logging {
Robert Myers674ee842013-11-25 13:15:35 -060074 local CONF=$1
75 iniset $CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
76 iniset $CONF DEFAULT use_syslog $SYSLOG
77 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
78 # Add color to logging output
79 setup_colorized_logging $CONF DEFAULT tenant user
80 fi
81}
82
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070083# create_trove_accounts() - Set up common required trove accounts
84
85# Tenant User Roles
86# ------------------------------------------------------------------
87# service trove admin # if enabled
88
Ian Wienandaee18c72014-02-21 15:35:08 +110089function create_trove_accounts {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070090 if [[ "$ENABLED_SERVICES" =~ "trove" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +010091
Jamie Lennoxe8bc2b82015-02-10 20:38:56 +110092 create_service_user "trove"
Bartosz Górski0abde392014-02-28 14:15:19 +010093
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070094 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +010095
Dean Troyer16ef9762014-08-19 19:31:34 -050096 local trove_service=$(get_or_create_service "trove" \
Bartosz Górski0abde392014-02-28 14:15:19 +010097 "database" "Trove Service")
Dean Troyer16ef9762014-08-19 19:31:34 -050098 get_or_create_endpoint $trove_service \
Bartosz Górski0abde392014-02-28 14:15:19 +010099 "$REGION_NAME" \
100 "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s" \
101 "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s" \
102 "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s"
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700103 fi
104 fi
105}
106
107# stack.sh entry points
108# ---------------------
109
110# cleanup_trove() - Remove residual data files, anything left over from previous
111# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100112function cleanup_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700113 #Clean up dirs
114 rm -fr $TROVE_AUTH_CACHE_DIR/*
115 rm -fr $TROVE_CONF_DIR/*
116}
117
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700118
119# configure_trove() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100120function configure_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700121 setup_develop $TROVE_DIR
122
123 # Create the trove conf dir and cache dirs if they don't exist
124 sudo mkdir -p ${TROVE_CONF_DIR}
125 sudo mkdir -p ${TROVE_AUTH_CACHE_DIR}
126 sudo chown -R $STACK_USER: ${TROVE_CONF_DIR}
127 sudo chown -R $STACK_USER: ${TROVE_AUTH_CACHE_DIR}
128
Jamie Lennox2de47462014-12-23 11:08:15 +1000129 # Copy api-paste file over to the trove conf dir
Brian Hunter236fd072015-02-12 16:14:02 -0500130 cp $TROVE_LOCAL_API_PASTE_INI $TROVE_API_PASTE_INI
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700131
132 # (Re)create trove conf files
Brian Hunter236fd072015-02-12 16:14:02 -0500133 rm -f $TROVE_CONF
134 rm -f $TROVE_TASKMANAGER_CONF
135 rm -f $TROVE_CONDUCTOR_CONF
Ed Cranford1089b3a2013-09-30 11:36:55 -0500136
Brian Hunter236fd072015-02-12 16:14:02 -0500137 iniset $TROVE_CONF DEFAULT rabbit_userid $RABBIT_USERID
138 iniset $TROVE_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
139 iniset $TROVE_CONF DEFAULT sql_connection `database_connection_url trove`
140 iniset $TROVE_CONF DEFAULT default_datastore $TROVE_DATASTORE_TYPE
141 setup_trove_logging $TROVE_CONF
142 iniset $TROVE_CONF DEFAULT trove_api_workers "$API_WORKERS"
Joe Gordonecad2f22014-09-14 20:52:38 -0700143
Brian Hunter236fd072015-02-12 16:14:02 -0500144 configure_auth_token_middleware $TROVE_CONF trove $TROVE_AUTH_CACHE_DIR
Robert Myers674ee842013-11-25 13:15:35 -0600145
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700146 # (Re)create trove taskmanager conf file if needed
147 if is_service_enabled tr-tmgr; then
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000148 TROVE_AUTH_ENDPOINT=$KEYSTONE_AUTH_URI/v$IDENTITY_API_VERSION
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000149
Brian Hunter236fd072015-02-12 16:14:02 -0500150 iniset $TROVE_TASKMANAGER_CONF DEFAULT rabbit_userid $RABBIT_USERID
151 iniset $TROVE_TASKMANAGER_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
152 iniset $TROVE_TASKMANAGER_CONF DEFAULT sql_connection `database_connection_url trove`
153 iniset $TROVE_TASKMANAGER_CONF DEFAULT taskmanager_manager trove.taskmanager.manager.Manager
154 iniset $TROVE_TASKMANAGER_CONF DEFAULT nova_proxy_admin_user radmin
155 iniset $TROVE_TASKMANAGER_CONF DEFAULT nova_proxy_admin_tenant_name trove
156 iniset $TROVE_TASKMANAGER_CONF DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
157 iniset $TROVE_TASKMANAGER_CONF DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
158 setup_trove_logging $TROVE_TASKMANAGER_CONF
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700159 fi
Ed Cranford1089b3a2013-09-30 11:36:55 -0500160
161 # (Re)create trove conductor conf file if needed
162 if is_service_enabled tr-cond; then
Brian Hunter236fd072015-02-12 16:14:02 -0500163 iniset $TROVE_CONDUCTOR_CONF DEFAULT rabbit_userid $RABBIT_USERID
164 iniset $TROVE_CONDUCTOR_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
165 iniset $TROVE_CONDUCTOR_CONF DEFAULT sql_connection `database_connection_url trove`
166 iniset $TROVE_CONDUCTOR_CONF DEFAULT nova_proxy_admin_user radmin
167 iniset $TROVE_CONDUCTOR_CONF DEFAULT nova_proxy_admin_tenant_name trove
168 iniset $TROVE_CONDUCTOR_CONF DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
169 iniset $TROVE_CONDUCTOR_CONF DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
170 iniset $TROVE_CONDUCTOR_CONF DEFAULT control_exchange trove
171 setup_trove_logging $TROVE_CONDUCTOR_CONF
Ed Cranford1089b3a2013-09-30 11:36:55 -0500172 fi
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700173
174 # Set up Guest Agent conf
Peter Stachowskidd4bafd2015-03-02 23:32:04 -0500175 iniset $TROVE_GUESTAGENT_CONF DEFAULT rabbit_userid $RABBIT_USERID
176 iniset $TROVE_GUESTAGENT_CONF DEFAULT rabbit_host $TROVE_HOST_GATEWAY
177 iniset $TROVE_GUESTAGENT_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
178 iniset $TROVE_GUESTAGENT_CONF DEFAULT nova_proxy_admin_user radmin
179 iniset $TROVE_GUESTAGENT_CONF DEFAULT nova_proxy_admin_tenant_name trove
180 iniset $TROVE_GUESTAGENT_CONF DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
181 iniset $TROVE_GUESTAGENT_CONF DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
182 iniset $TROVE_GUESTAGENT_CONF DEFAULT control_exchange trove
183 iniset $TROVE_GUESTAGENT_CONF DEFAULT ignore_users os_admin
184 iniset $TROVE_GUESTAGENT_CONF DEFAULT log_dir /var/log/trove/
185 iniset $TROVE_GUESTAGENT_CONF DEFAULT log_file trove-guestagent.log
186 setup_trove_logging $TROVE_GUESTAGENT_CONF
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700187}
188
189# install_troveclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100190function install_troveclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500191 if use_library_from_git "python-troveclient"; then
192 git_clone_by_name "python-troveclient"
193 setup_dev_lib "python-troveclient"
Sean Dague5cb19062014-11-01 01:37:45 +0100194 fi
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700195}
196
197# install_trove() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100198function install_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700199 git_clone $TROVE_REPO $TROVE_DIR $TROVE_BRANCH
200}
201
202# init_trove() - Initializes Trove Database as a Service
Ian Wienandaee18c72014-02-21 15:35:08 +1100203function init_trove {
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700204 # (Re)Create trove db
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200205 recreate_database trove
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700206
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700207 # Initialize the trove database
Brian Hunter236fd072015-02-12 16:14:02 -0500208 $TROVE_MANAGE db_sync
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700209
Greg Lucase6aeb592014-07-09 13:30:38 -0400210 # If no guest image is specified, skip remaining setup
Gary W. Smith58402532014-12-22 09:13:23 -0800211 [ -z "$TROVE_GUEST_IMAGE_URL" ] && return 0
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700212
Greg Lucase6aeb592014-07-09 13:30:38 -0400213 # Find the glance id for the trove guest image
214 # The image is uploaded by stack.sh -- see $IMAGE_URLS handling
215 GUEST_IMAGE_NAME=$(basename "$TROVE_GUEST_IMAGE_URL")
216 GUEST_IMAGE_NAME=${GUEST_IMAGE_NAME%.*}
Rob Crittenden213f13a2014-10-30 19:49:20 -0400217 TROVE_GUEST_IMAGE_ID=$(openstack --os-token $TOKEN --os-url $GLANCE_SERVICE_PROTOCOL://$GLANCE_HOSTPORT image list | grep "${GUEST_IMAGE_NAME}" | get_field 1)
Greg Lucase6aeb592014-07-09 13:30:38 -0400218 if [ -z "$TROVE_GUEST_IMAGE_ID" ]; then
219 # If no glance id is found, skip remaining setup
220 echo "Datastore ${TROVE_DATASTORE_TYPE} will not be created: guest image ${GUEST_IMAGE_NAME} not found."
221 return 1
222 fi
223
224 # Now that we have the guest image id, initialize appropriate datastores / datastore versions
Brian Hunter236fd072015-02-12 16:14:02 -0500225 $TROVE_MANAGE datastore_update "$TROVE_DATASTORE_TYPE" ""
226 $TROVE_MANAGE datastore_version_update "$TROVE_DATASTORE_TYPE" "$TROVE_DATASTORE_VERSION" "$TROVE_DATASTORE_TYPE" \
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700227 "$TROVE_GUEST_IMAGE_ID" "$TROVE_DATASTORE_PACKAGE" 1
Brian Hunter236fd072015-02-12 16:14:02 -0500228 $TROVE_MANAGE datastore_version_update "$TROVE_DATASTORE_TYPE" "inactive_version" "inactive_manager" "$TROVE_GUEST_IMAGE_ID" "" 0
229 $TROVE_MANAGE datastore_update "$TROVE_DATASTORE_TYPE" "$TROVE_DATASTORE_VERSION"
230 $TROVE_MANAGE datastore_update "Inactive_Datastore" ""
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700231}
232
233# start_trove() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100234function start_trove {
Brian Hunter236fd072015-02-12 16:14:02 -0500235 run_process tr-api "$TROVE_BIN_DIR/trove-api --config-file=$TROVE_CONF --debug"
236 run_process tr-tmgr "$TROVE_BIN_DIR/trove-taskmanager --config-file=$TROVE_TASKMANAGER_CONF --debug"
237 run_process tr-cond "$TROVE_BIN_DIR/trove-conductor --config-file=$TROVE_CONDUCTOR_CONF --debug"
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700238}
239
240# stop_trove() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100241function stop_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700242 # Kill the trove screen windows
Dean Troyer16ef9762014-08-19 19:31:34 -0500243 local serv
Ed Cranford1089b3a2013-09-30 11:36:55 -0500244 for serv in tr-api tr-tmgr tr-cond; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100245 stop_process $serv
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700246 done
247}
248
249# Restore xtrace
250$XTRACE
251
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100252# Tell emacs to use shell-script-mode
253## Local variables:
254## mode: shell-script
255## End: