blob: e1b307a52f9292c809c6ad2d9bee578c8ef04dfb [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 {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070082 if [[ "$ENABLED_SERVICES" =~ "trove" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +010083
Jamie Lennoxe8bc2b82015-02-10 20:38:56 +110084 create_service_user "trove"
Bartosz Górski0abde392014-02-28 14:15:19 +010085
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070086 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +010087
Dean Troyer16ef9762014-08-19 19:31:34 -050088 local trove_service=$(get_or_create_service "trove" \
Bartosz Górski0abde392014-02-28 14:15:19 +010089 "database" "Trove Service")
Dean Troyer16ef9762014-08-19 19:31:34 -050090 get_or_create_endpoint $trove_service \
Bartosz Górski0abde392014-02-28 14:15:19 +010091 "$REGION_NAME" \
92 "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s" \
93 "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s" \
94 "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s"
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070095 fi
96 fi
97}
98
99# stack.sh entry points
100# ---------------------
101
102# cleanup_trove() - Remove residual data files, anything left over from previous
103# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100104function cleanup_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700105 #Clean up dirs
106 rm -fr $TROVE_AUTH_CACHE_DIR/*
107 rm -fr $TROVE_CONF_DIR/*
108}
109
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700110
111# configure_trove() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100112function configure_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700113 setup_develop $TROVE_DIR
114
115 # Create the trove conf dir and cache dirs if they don't exist
116 sudo mkdir -p ${TROVE_CONF_DIR}
117 sudo mkdir -p ${TROVE_AUTH_CACHE_DIR}
118 sudo chown -R $STACK_USER: ${TROVE_CONF_DIR}
119 sudo chown -R $STACK_USER: ${TROVE_AUTH_CACHE_DIR}
120
Jamie Lennox2de47462014-12-23 11:08:15 +1000121 # Copy api-paste file over to the trove conf dir
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700122 cp $TROVE_LOCAL_CONF_DIR/api-paste.ini $TROVE_CONF_DIR/api-paste.ini
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700123
124 # (Re)create trove conf files
125 rm -f $TROVE_CONF_DIR/trove.conf
126 rm -f $TROVE_CONF_DIR/trove-taskmanager.conf
Ed Cranford1089b3a2013-09-30 11:36:55 -0500127 rm -f $TROVE_CONF_DIR/trove-conductor.conf
128
Abhishek Chandad5b74c62014-12-12 02:15:55 +0530129 iniset $TROVE_CONF_DIR/trove.conf DEFAULT rabbit_userid $RABBIT_USERID
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700130 iniset $TROVE_CONF_DIR/trove.conf DEFAULT rabbit_password $RABBIT_PASSWORD
131 iniset $TROVE_CONF_DIR/trove.conf DEFAULT sql_connection `database_connection_url trove`
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700132 iniset $TROVE_CONF_DIR/trove.conf DEFAULT default_datastore $TROVE_DATASTORE_TYPE
Robert Myers674ee842013-11-25 13:15:35 -0600133 setup_trove_logging $TROVE_CONF_DIR/trove.conf
Joe Gordonecad2f22014-09-14 20:52:38 -0700134 iniset $TROVE_CONF_DIR/trove.conf DEFAULT trove_api_workers "$API_WORKERS"
135
Jamie Lennox2de47462014-12-23 11:08:15 +1000136 configure_auth_token_middleware $TROVE_CONF_DIR/trove.conf trove $TROVE_AUTH_CACHE_DIR
Robert Myers674ee842013-11-25 13:15:35 -0600137
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700138 # (Re)create trove taskmanager conf file if needed
139 if is_service_enabled tr-tmgr; then
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000140 TROVE_AUTH_ENDPOINT=$KEYSTONE_AUTH_URI/v$IDENTITY_API_VERSION
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000141
Sushil Kumar7bb9a732014-12-13 16:32:11 +0000142 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT rabbit_userid $RABBIT_USERID
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700143 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT rabbit_password $RABBIT_PASSWORD
144 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT sql_connection `database_connection_url trove`
145 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT taskmanager_manager trove.taskmanager.manager.Manager
146 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_user radmin
147 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_tenant_name trove
148 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
149 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
Robert Myers674ee842013-11-25 13:15:35 -0600150 setup_trove_logging $TROVE_CONF_DIR/trove-taskmanager.conf
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700151 fi
Ed Cranford1089b3a2013-09-30 11:36:55 -0500152
153 # (Re)create trove conductor conf file if needed
154 if is_service_enabled tr-cond; then
Sushil Kumar7bb9a732014-12-13 16:32:11 +0000155 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT rabbit_userid $RABBIT_USERID
Ed Cranford1089b3a2013-09-30 11:36:55 -0500156 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT rabbit_password $RABBIT_PASSWORD
157 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT sql_connection `database_connection_url trove`
158 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_user radmin
159 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_tenant_name trove
160 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
161 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
162 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT control_exchange trove
Robert Myers674ee842013-11-25 13:15:35 -0600163 setup_trove_logging $TROVE_CONF_DIR/trove-conductor.conf
Ed Cranford1089b3a2013-09-30 11:36:55 -0500164 fi
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700165
166 # Set up Guest Agent conf
Sushil Kumar7bb9a732014-12-13 16:32:11 +0000167 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT rabbit_userid $RABBIT_USERID
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700168 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT rabbit_host $TROVE_HOST_GATEWAY
169 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT rabbit_password $RABBIT_PASSWORD
170 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT nova_proxy_admin_user radmin
171 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT nova_proxy_admin_tenant_name trove
172 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
173 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
174 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT control_exchange trove
Nikhil Manchanda9c4f24a2014-07-15 14:31:04 -0700175 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT ignore_users os_admin
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700176 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT log_dir /tmp/
177 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT log_file trove-guestagent.log
178 setup_trove_logging $TROVE_CONF_DIR/trove-guestagent.conf
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700179}
180
181# install_troveclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100182function install_troveclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500183 if use_library_from_git "python-troveclient"; then
184 git_clone_by_name "python-troveclient"
185 setup_dev_lib "python-troveclient"
Sean Dague5cb19062014-11-01 01:37:45 +0100186 fi
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700187}
188
189# install_trove() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100190function install_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700191 git_clone $TROVE_REPO $TROVE_DIR $TROVE_BRANCH
192}
193
194# init_trove() - Initializes Trove Database as a Service
Ian Wienandaee18c72014-02-21 15:35:08 +1100195function init_trove {
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700196 # (Re)Create trove db
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200197 recreate_database trove
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700198
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700199 # Initialize the trove database
Michael Basnight0f9a1b02013-12-28 03:42:07 +0000200 $TROVE_BIN_DIR/trove-manage db_sync
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700201
Greg Lucase6aeb592014-07-09 13:30:38 -0400202 # If no guest image is specified, skip remaining setup
Gary W. Smith58402532014-12-22 09:13:23 -0800203 [ -z "$TROVE_GUEST_IMAGE_URL" ] && return 0
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700204
Greg Lucase6aeb592014-07-09 13:30:38 -0400205 # Find the glance id for the trove guest image
206 # The image is uploaded by stack.sh -- see $IMAGE_URLS handling
207 GUEST_IMAGE_NAME=$(basename "$TROVE_GUEST_IMAGE_URL")
208 GUEST_IMAGE_NAME=${GUEST_IMAGE_NAME%.*}
Rob Crittenden213f13a2014-10-30 19:49:20 -0400209 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 -0400210 if [ -z "$TROVE_GUEST_IMAGE_ID" ]; then
211 # If no glance id is found, skip remaining setup
212 echo "Datastore ${TROVE_DATASTORE_TYPE} will not be created: guest image ${GUEST_IMAGE_NAME} not found."
213 return 1
214 fi
215
216 # Now that we have the guest image id, initialize appropriate datastores / datastore versions
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700217 $TROVE_BIN_DIR/trove-manage datastore_update "$TROVE_DATASTORE_TYPE" ""
218 $TROVE_BIN_DIR/trove-manage datastore_version_update "$TROVE_DATASTORE_TYPE" "$TROVE_DATASTORE_VERSION" "$TROVE_DATASTORE_TYPE" \
219 "$TROVE_GUEST_IMAGE_ID" "$TROVE_DATASTORE_PACKAGE" 1
220 $TROVE_BIN_DIR/trove-manage datastore_version_update "$TROVE_DATASTORE_TYPE" "inactive_version" "inactive_manager" "$TROVE_GUEST_IMAGE_ID" "" 0
221 $TROVE_BIN_DIR/trove-manage datastore_update "$TROVE_DATASTORE_TYPE" "$TROVE_DATASTORE_VERSION"
222 $TROVE_BIN_DIR/trove-manage datastore_update "Inactive_Datastore" ""
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700223}
224
225# start_trove() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100226function start_trove {
Chris Dent2f27a0e2014-09-09 13:46:02 +0100227 run_process tr-api "$TROVE_BIN_DIR/trove-api --config-file=$TROVE_CONF_DIR/trove.conf --debug"
228 run_process tr-tmgr "$TROVE_BIN_DIR/trove-taskmanager --config-file=$TROVE_CONF_DIR/trove-taskmanager.conf --debug"
229 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 -0700230}
231
232# stop_trove() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100233function stop_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700234 # Kill the trove screen windows
Dean Troyer16ef9762014-08-19 19:31:34 -0500235 local serv
Ed Cranford1089b3a2013-09-30 11:36:55 -0500236 for serv in tr-api tr-tmgr tr-cond; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100237 stop_process $serv
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700238 done
239}
240
241# Restore xtrace
242$XTRACE
243
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100244# Tell emacs to use shell-script-mode
245## Local variables:
246## mode: shell-script
247## End: