blob: d889b056e8de1516243a3090d4af4d2a419d066d [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
37TROVE_LOCAL_CONF_DIR=$TROVE_DIR/etc/trove
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070038TROVE_AUTH_CACHE_DIR=${TROVE_AUTH_CACHE_DIR:-/var/cache/trove}
Nikhil Manchandaafefaa72014-06-24 13:06:00 -070039TROVE_DATASTORE_TYPE=${TROVE_DATASTORE_TYPE:-"mysql"}
40TROVE_DATASTORE_VERSION=${TROVE_DATASTORE_VERSION:-"5.5"}
41TROVE_DATASTORE_PACKAGE=${TROVE_DATASTORE_PACKAGE:-"mysql-server-5.5"}
Michael Basnight0f9a1b02013-12-28 03:42:07 +000042
43# Support entry points installation of console scripts
44if [[ -d $TROVE_DIR/bin ]]; then
45 TROVE_BIN_DIR=$TROVE_DIR/bin
46else
47 TROVE_BIN_DIR=$(get_python_exec_prefix)
48fi
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070049
Dean Troyer4237f592014-01-29 16:22:11 -060050# Tell Tempest this project is present
51TEMPEST_SERVICES+=,trove
52
53
Dean Troyerfc744f92014-01-27 13:45:21 -060054# Functions
55# ---------
56
57# Test if any Trove services are enabled
58# is_trove_enabled
59function is_trove_enabled {
60 [[ ,${ENABLED_SERVICES} =~ ,"tr-" ]] && return 0
61 return 1
62}
63
Robert Myers674ee842013-11-25 13:15:35 -060064# setup_trove_logging() - Adds logging configuration to conf files
Ian Wienandaee18c72014-02-21 15:35:08 +110065function setup_trove_logging {
Robert Myers674ee842013-11-25 13:15:35 -060066 local CONF=$1
67 iniset $CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
68 iniset $CONF DEFAULT use_syslog $SYSLOG
69 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
70 # Add color to logging output
71 setup_colorized_logging $CONF DEFAULT tenant user
72 fi
73}
74
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070075# create_trove_accounts() - Set up common required trove accounts
76
77# Tenant User Roles
78# ------------------------------------------------------------------
79# service trove admin # if enabled
80
Ian Wienandaee18c72014-02-21 15:35:08 +110081function create_trove_accounts {
Dean Troyer16ef9762014-08-19 19:31:34 -050082 local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
83 local service_role=$(openstack role list | awk "/ admin / { print \$2 }")
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070084
85 if [[ "$ENABLED_SERVICES" =~ "trove" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +010086
Dean Troyer16ef9762014-08-19 19:31:34 -050087 local trove_user=$(get_or_create_user "trove" \
88 "$SERVICE_PASSWORD" $service_tenant)
89 get_or_add_user_role $service_role $trove_user $service_tenant
Bartosz Górski0abde392014-02-28 14:15:19 +010090
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070091 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +010092
Dean Troyer16ef9762014-08-19 19:31:34 -050093 local trove_service=$(get_or_create_service "trove" \
Bartosz Górski0abde392014-02-28 14:15:19 +010094 "database" "Trove Service")
Dean Troyer16ef9762014-08-19 19:31:34 -050095 get_or_create_endpoint $trove_service \
Bartosz Górski0abde392014-02-28 14:15:19 +010096 "$REGION_NAME" \
97 "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s" \
98 "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s" \
99 "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s"
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700100 fi
101 fi
102}
103
104# stack.sh entry points
105# ---------------------
106
107# cleanup_trove() - Remove residual data files, anything left over from previous
108# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100109function cleanup_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700110 #Clean up dirs
111 rm -fr $TROVE_AUTH_CACHE_DIR/*
112 rm -fr $TROVE_CONF_DIR/*
113}
114
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700115
116# configure_trove() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100117function configure_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700118 setup_develop $TROVE_DIR
119
120 # Create the trove conf dir and cache dirs if they don't exist
121 sudo mkdir -p ${TROVE_CONF_DIR}
122 sudo mkdir -p ${TROVE_AUTH_CACHE_DIR}
123 sudo chown -R $STACK_USER: ${TROVE_CONF_DIR}
124 sudo chown -R $STACK_USER: ${TROVE_AUTH_CACHE_DIR}
125
126 # Copy api-paste file over to the trove conf dir and configure it
127 cp $TROVE_LOCAL_CONF_DIR/api-paste.ini $TROVE_CONF_DIR/api-paste.ini
128 TROVE_API_PASTE_INI=$TROVE_CONF_DIR/api-paste.ini
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000129
Brant Knudson05952372014-09-19 17:22:22 -0500130 configure_auth_token_middleware $TROVE_API_PASTE_INI trove $TROVE_AUTH_CACHE_DIR filter:authtoken
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700131
132 # (Re)create trove conf files
133 rm -f $TROVE_CONF_DIR/trove.conf
134 rm -f $TROVE_CONF_DIR/trove-taskmanager.conf
Ed Cranford1089b3a2013-09-30 11:36:55 -0500135 rm -f $TROVE_CONF_DIR/trove-conductor.conf
136
Abhishek Chandad5b74c62014-12-12 02:15:55 +0530137 iniset $TROVE_CONF_DIR/trove.conf DEFAULT rabbit_userid $RABBIT_USERID
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700138 iniset $TROVE_CONF_DIR/trove.conf DEFAULT rabbit_password $RABBIT_PASSWORD
139 iniset $TROVE_CONF_DIR/trove.conf DEFAULT sql_connection `database_connection_url trove`
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700140 iniset $TROVE_CONF_DIR/trove.conf DEFAULT default_datastore $TROVE_DATASTORE_TYPE
Robert Myers674ee842013-11-25 13:15:35 -0600141 setup_trove_logging $TROVE_CONF_DIR/trove.conf
Joe Gordonecad2f22014-09-14 20:52:38 -0700142 iniset $TROVE_CONF_DIR/trove.conf DEFAULT trove_api_workers "$API_WORKERS"
143
Robert Myers674ee842013-11-25 13:15:35 -0600144
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700145 # (Re)create trove taskmanager conf file if needed
146 if is_service_enabled tr-tmgr; then
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000147 TROVE_AUTH_ENDPOINT=$KEYSTONE_AUTH_URI/v$IDENTITY_API_VERSION
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000148
Sushil Kumar7bb9a732014-12-13 16:32:11 +0000149 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT rabbit_userid $RABBIT_USERID
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700150 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT rabbit_password $RABBIT_PASSWORD
151 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT sql_connection `database_connection_url trove`
152 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT taskmanager_manager trove.taskmanager.manager.Manager
153 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_user radmin
154 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_tenant_name trove
155 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
156 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
Robert Myers674ee842013-11-25 13:15:35 -0600157 setup_trove_logging $TROVE_CONF_DIR/trove-taskmanager.conf
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700158 fi
Ed Cranford1089b3a2013-09-30 11:36:55 -0500159
160 # (Re)create trove conductor conf file if needed
161 if is_service_enabled tr-cond; then
Sushil Kumar7bb9a732014-12-13 16:32:11 +0000162 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT rabbit_userid $RABBIT_USERID
Ed Cranford1089b3a2013-09-30 11:36:55 -0500163 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT rabbit_password $RABBIT_PASSWORD
164 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT sql_connection `database_connection_url trove`
165 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_user radmin
166 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_tenant_name trove
167 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
168 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
169 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT control_exchange trove
Robert Myers674ee842013-11-25 13:15:35 -0600170 setup_trove_logging $TROVE_CONF_DIR/trove-conductor.conf
Ed Cranford1089b3a2013-09-30 11:36:55 -0500171 fi
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700172
173 # Set up Guest Agent conf
Sushil Kumar7bb9a732014-12-13 16:32:11 +0000174 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT rabbit_userid $RABBIT_USERID
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700175 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT rabbit_host $TROVE_HOST_GATEWAY
176 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT rabbit_password $RABBIT_PASSWORD
177 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT nova_proxy_admin_user radmin
178 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT nova_proxy_admin_tenant_name trove
179 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
180 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
181 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT control_exchange trove
Nikhil Manchanda9c4f24a2014-07-15 14:31:04 -0700182 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT ignore_users os_admin
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700183 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT log_dir /tmp/
184 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT log_file trove-guestagent.log
185 setup_trove_logging $TROVE_CONF_DIR/trove-guestagent.conf
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700186}
187
188# install_troveclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100189function install_troveclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500190 if use_library_from_git "python-troveclient"; then
191 git_clone_by_name "python-troveclient"
192 setup_dev_lib "python-troveclient"
Sean Dague5cb19062014-11-01 01:37:45 +0100193 fi
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700194}
195
196# install_trove() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100197function install_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700198 git_clone $TROVE_REPO $TROVE_DIR $TROVE_BRANCH
199}
200
201# init_trove() - Initializes Trove Database as a Service
Ian Wienandaee18c72014-02-21 15:35:08 +1100202function init_trove {
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700203 # (Re)Create trove db
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700204 recreate_database trove utf8
205
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700206 # Initialize the trove database
Michael Basnight0f9a1b02013-12-28 03:42:07 +0000207 $TROVE_BIN_DIR/trove-manage db_sync
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700208
Greg Lucase6aeb592014-07-09 13:30:38 -0400209 # If no guest image is specified, skip remaining setup
Gary W. Smith58402532014-12-22 09:13:23 -0800210 [ -z "$TROVE_GUEST_IMAGE_URL" ] && return 0
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700211
Greg Lucase6aeb592014-07-09 13:30:38 -0400212 # Find the glance id for the trove guest image
213 # The image is uploaded by stack.sh -- see $IMAGE_URLS handling
214 GUEST_IMAGE_NAME=$(basename "$TROVE_GUEST_IMAGE_URL")
215 GUEST_IMAGE_NAME=${GUEST_IMAGE_NAME%.*}
Rob Crittenden213f13a2014-10-30 19:49:20 -0400216 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 -0400217 if [ -z "$TROVE_GUEST_IMAGE_ID" ]; then
218 # If no glance id is found, skip remaining setup
219 echo "Datastore ${TROVE_DATASTORE_TYPE} will not be created: guest image ${GUEST_IMAGE_NAME} not found."
220 return 1
221 fi
222
223 # Now that we have the guest image id, initialize appropriate datastores / datastore versions
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700224 $TROVE_BIN_DIR/trove-manage datastore_update "$TROVE_DATASTORE_TYPE" ""
225 $TROVE_BIN_DIR/trove-manage datastore_version_update "$TROVE_DATASTORE_TYPE" "$TROVE_DATASTORE_VERSION" "$TROVE_DATASTORE_TYPE" \
226 "$TROVE_GUEST_IMAGE_ID" "$TROVE_DATASTORE_PACKAGE" 1
227 $TROVE_BIN_DIR/trove-manage datastore_version_update "$TROVE_DATASTORE_TYPE" "inactive_version" "inactive_manager" "$TROVE_GUEST_IMAGE_ID" "" 0
228 $TROVE_BIN_DIR/trove-manage datastore_update "$TROVE_DATASTORE_TYPE" "$TROVE_DATASTORE_VERSION"
229 $TROVE_BIN_DIR/trove-manage datastore_update "Inactive_Datastore" ""
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700230}
231
232# start_trove() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100233function start_trove {
Chris Dent2f27a0e2014-09-09 13:46:02 +0100234 run_process tr-api "$TROVE_BIN_DIR/trove-api --config-file=$TROVE_CONF_DIR/trove.conf --debug"
235 run_process tr-tmgr "$TROVE_BIN_DIR/trove-taskmanager --config-file=$TROVE_CONF_DIR/trove-taskmanager.conf --debug"
236 run_process tr-cond "$TROVE_BIN_DIR/trove-conductor --config-file=$TROVE_CONF_DIR/trove-conductor.conf --debug"
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700237}
238
239# stop_trove() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100240function stop_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700241 # Kill the trove screen windows
Dean Troyer16ef9762014-08-19 19:31:34 -0500242 local serv
Ed Cranford1089b3a2013-09-30 11:36:55 -0500243 for serv in tr-api tr-tmgr tr-cond; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100244 stop_process $serv
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700245 done
246}
247
248# Restore xtrace
249$XTRACE
250
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100251# Tell emacs to use shell-script-mode
252## Local variables:
253## mode: shell-script
254## End: