blob: 5dd4f2361193bc21310bb55270719218ccace482 [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
Peter Stachowski668749a2015-03-24 18:00:29 +000036TROVE_CONF_DIR=${TROVE_CONF_DIR:-/etc/trove}
37TROVE_CONF=${TROVE_CONF:-$TROVE_CONF_DIR/trove.conf}
38TROVE_TASKMANAGER_CONF=${TROVE_TASKMANAGER_CONF:-$TROVE_CONF_DIR/trove-taskmanager.conf}
39TROVE_CONDUCTOR_CONF=${TROVE_CONDUCTOR_CONF:-$TROVE_CONF_DIR/trove-conductor.conf}
40TROVE_GUESTAGENT_CONF=${TROVE_GUESTAGENT_CONF:-$TROVE_CONF_DIR/trove-guestagent.conf}
41TROVE_API_PASTE_INI=${TROVE_API_PASTE_INI:-$TROVE_CONF_DIR/api-paste.ini}
Brian Hunter236fd072015-02-12 16:14:02 -050042
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"}
Morgan Jones45e7db02015-03-16 12:20:32 -040047TROVE_DATASTORE_VERSION=${TROVE_DATASTORE_VERSION:-"5.6"}
48TROVE_DATASTORE_PACKAGE=${TROVE_DATASTORE_PACKAGE:-"mysql-server-5.6"}
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
Dean Troyer8421c2b2015-03-16 13:52:19 -0500124 sudo install -d -o $STACK_USER ${TROVE_CONF_DIR} ${TROVE_AUTH_CACHE_DIR}
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700125
Jamie Lennox2de47462014-12-23 11:08:15 +1000126 # Copy api-paste file over to the trove conf dir
Brian Hunter236fd072015-02-12 16:14:02 -0500127 cp $TROVE_LOCAL_API_PASTE_INI $TROVE_API_PASTE_INI
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700128
129 # (Re)create trove conf files
Brian Hunter236fd072015-02-12 16:14:02 -0500130 rm -f $TROVE_CONF
131 rm -f $TROVE_TASKMANAGER_CONF
132 rm -f $TROVE_CONDUCTOR_CONF
Ed Cranford1089b3a2013-09-30 11:36:55 -0500133
Brian Hunter236fd072015-02-12 16:14:02 -0500134 iniset $TROVE_CONF DEFAULT rabbit_userid $RABBIT_USERID
135 iniset $TROVE_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
Joe Gordon23d6d502015-03-06 15:24:22 -0800136 iniset $TROVE_CONF database connection `database_connection_url trove`
Brian Hunter236fd072015-02-12 16:14:02 -0500137 iniset $TROVE_CONF DEFAULT default_datastore $TROVE_DATASTORE_TYPE
138 setup_trove_logging $TROVE_CONF
139 iniset $TROVE_CONF DEFAULT trove_api_workers "$API_WORKERS"
Joe Gordonecad2f22014-09-14 20:52:38 -0700140
Brian Hunter236fd072015-02-12 16:14:02 -0500141 configure_auth_token_middleware $TROVE_CONF trove $TROVE_AUTH_CACHE_DIR
Robert Myers674ee842013-11-25 13:15:35 -0600142
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700143 # (Re)create trove taskmanager conf file if needed
144 if is_service_enabled tr-tmgr; then
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000145 TROVE_AUTH_ENDPOINT=$KEYSTONE_AUTH_URI/v$IDENTITY_API_VERSION
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000146
Brian Hunter236fd072015-02-12 16:14:02 -0500147 iniset $TROVE_TASKMANAGER_CONF DEFAULT rabbit_userid $RABBIT_USERID
148 iniset $TROVE_TASKMANAGER_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
Joe Gordon23d6d502015-03-06 15:24:22 -0800149 iniset $TROVE_TASKMANAGER_CONF database connection `database_connection_url trove`
Brian Hunter236fd072015-02-12 16:14:02 -0500150 iniset $TROVE_TASKMANAGER_CONF DEFAULT taskmanager_manager trove.taskmanager.manager.Manager
151 iniset $TROVE_TASKMANAGER_CONF DEFAULT nova_proxy_admin_user radmin
152 iniset $TROVE_TASKMANAGER_CONF DEFAULT nova_proxy_admin_tenant_name trove
153 iniset $TROVE_TASKMANAGER_CONF DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
154 iniset $TROVE_TASKMANAGER_CONF DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
155 setup_trove_logging $TROVE_TASKMANAGER_CONF
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700156 fi
Ed Cranford1089b3a2013-09-30 11:36:55 -0500157
158 # (Re)create trove conductor conf file if needed
159 if is_service_enabled tr-cond; then
Brian Hunter236fd072015-02-12 16:14:02 -0500160 iniset $TROVE_CONDUCTOR_CONF DEFAULT rabbit_userid $RABBIT_USERID
161 iniset $TROVE_CONDUCTOR_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
Joe Gordon23d6d502015-03-06 15:24:22 -0800162 iniset $TROVE_CONDUCTOR_CONF database connection `database_connection_url trove`
Brian Hunter236fd072015-02-12 16:14:02 -0500163 iniset $TROVE_CONDUCTOR_CONF DEFAULT nova_proxy_admin_user radmin
164 iniset $TROVE_CONDUCTOR_CONF DEFAULT nova_proxy_admin_tenant_name trove
165 iniset $TROVE_CONDUCTOR_CONF DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
166 iniset $TROVE_CONDUCTOR_CONF DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
167 iniset $TROVE_CONDUCTOR_CONF DEFAULT control_exchange trove
168 setup_trove_logging $TROVE_CONDUCTOR_CONF
Ed Cranford1089b3a2013-09-30 11:36:55 -0500169 fi
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700170
171 # Set up Guest Agent conf
Peter Stachowskidd4bafd2015-03-02 23:32:04 -0500172 iniset $TROVE_GUESTAGENT_CONF DEFAULT rabbit_userid $RABBIT_USERID
173 iniset $TROVE_GUESTAGENT_CONF DEFAULT rabbit_host $TROVE_HOST_GATEWAY
174 iniset $TROVE_GUESTAGENT_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
175 iniset $TROVE_GUESTAGENT_CONF DEFAULT nova_proxy_admin_user radmin
176 iniset $TROVE_GUESTAGENT_CONF DEFAULT nova_proxy_admin_tenant_name trove
177 iniset $TROVE_GUESTAGENT_CONF DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
178 iniset $TROVE_GUESTAGENT_CONF DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
179 iniset $TROVE_GUESTAGENT_CONF DEFAULT control_exchange trove
180 iniset $TROVE_GUESTAGENT_CONF DEFAULT ignore_users os_admin
181 iniset $TROVE_GUESTAGENT_CONF DEFAULT log_dir /var/log/trove/
182 iniset $TROVE_GUESTAGENT_CONF DEFAULT log_file trove-guestagent.log
183 setup_trove_logging $TROVE_GUESTAGENT_CONF
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700184}
185
186# install_troveclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100187function install_troveclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500188 if use_library_from_git "python-troveclient"; then
189 git_clone_by_name "python-troveclient"
190 setup_dev_lib "python-troveclient"
Sean Dague5cb19062014-11-01 01:37:45 +0100191 fi
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700192}
193
194# install_trove() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100195function install_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700196 git_clone $TROVE_REPO $TROVE_DIR $TROVE_BRANCH
197}
198
199# init_trove() - Initializes Trove Database as a Service
Ian Wienandaee18c72014-02-21 15:35:08 +1100200function init_trove {
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700201 # (Re)Create trove db
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200202 recreate_database trove
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700203
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700204 # Initialize the trove database
Brian Hunter236fd072015-02-12 16:14:02 -0500205 $TROVE_MANAGE db_sync
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700206
Greg Lucase6aeb592014-07-09 13:30:38 -0400207 # If no guest image is specified, skip remaining setup
Gary W. Smith58402532014-12-22 09:13:23 -0800208 [ -z "$TROVE_GUEST_IMAGE_URL" ] && return 0
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700209
Greg Lucase6aeb592014-07-09 13:30:38 -0400210 # Find the glance id for the trove guest image
211 # The image is uploaded by stack.sh -- see $IMAGE_URLS handling
212 GUEST_IMAGE_NAME=$(basename "$TROVE_GUEST_IMAGE_URL")
213 GUEST_IMAGE_NAME=${GUEST_IMAGE_NAME%.*}
Rob Crittenden213f13a2014-10-30 19:49:20 -0400214 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 -0400215 if [ -z "$TROVE_GUEST_IMAGE_ID" ]; then
216 # If no glance id is found, skip remaining setup
217 echo "Datastore ${TROVE_DATASTORE_TYPE} will not be created: guest image ${GUEST_IMAGE_NAME} not found."
218 return 1
219 fi
220
221 # Now that we have the guest image id, initialize appropriate datastores / datastore versions
Brian Hunter236fd072015-02-12 16:14:02 -0500222 $TROVE_MANAGE datastore_update "$TROVE_DATASTORE_TYPE" ""
223 $TROVE_MANAGE datastore_version_update "$TROVE_DATASTORE_TYPE" "$TROVE_DATASTORE_VERSION" "$TROVE_DATASTORE_TYPE" \
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700224 "$TROVE_GUEST_IMAGE_ID" "$TROVE_DATASTORE_PACKAGE" 1
Brian Hunter236fd072015-02-12 16:14:02 -0500225 $TROVE_MANAGE datastore_version_update "$TROVE_DATASTORE_TYPE" "inactive_version" "inactive_manager" "$TROVE_GUEST_IMAGE_ID" "" 0
226 $TROVE_MANAGE datastore_update "$TROVE_DATASTORE_TYPE" "$TROVE_DATASTORE_VERSION"
227 $TROVE_MANAGE datastore_update "Inactive_Datastore" ""
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700228}
229
230# start_trove() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100231function start_trove {
Brian Hunter236fd072015-02-12 16:14:02 -0500232 run_process tr-api "$TROVE_BIN_DIR/trove-api --config-file=$TROVE_CONF --debug"
233 run_process tr-tmgr "$TROVE_BIN_DIR/trove-taskmanager --config-file=$TROVE_TASKMANAGER_CONF --debug"
234 run_process tr-cond "$TROVE_BIN_DIR/trove-conductor --config-file=$TROVE_CONDUCTOR_CONF --debug"
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700235}
236
237# stop_trove() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100238function stop_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700239 # Kill the trove screen windows
Dean Troyer16ef9762014-08-19 19:31:34 -0500240 local serv
Ed Cranford1089b3a2013-09-30 11:36:55 -0500241 for serv in tr-api tr-tmgr tr-cond; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100242 stop_process $serv
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700243 done
244}
245
246# Restore xtrace
247$XTRACE
248
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100249# Tell emacs to use shell-script-mode
250## Local variables:
251## mode: shell-script
252## End: