blob: e467c9061bb8ff565240d7f1cfd18dcb0c330767 [file] [log] [blame]
Nikhil Manchanda0cccad42012-12-03 18:15:09 -07001# lib/trove
2# Functions to control the configuration and operation of the **Trove** service
3
4# Dependencies:
5# ``functions`` file
6# ``DEST``, ``STACK_USER`` must be defined
7# ``SERVICE_{HOST|PROTOCOL|TOKEN}`` must be defined
8
9# ``stack.sh`` calls the entry points in this order:
10#
11# install_trove
12# configure_trove
13# init_trove
14# start_trove
15# stop_trove
16# cleanup_trove
17
18# Save trace setting
19XTRACE=$(set +o | grep xtrace)
20set +o xtrace
21
22# Defaults
23# --------
Nikhil Manchandabc22e912014-05-07 23:46:01 -070024if is_service_enabled neutron; then
25 TROVE_HOST_GATEWAY=${PUBLIC_NETWORK_GATEWAY:-172.24.4.1}
26else
27 TROVE_HOST_GATEWAY=${NETWORK_GATEWAY:-10.0.0.1}
28fi
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070029
30# Set up default configuration
31TROVE_DIR=$DEST/trove
32TROVECLIENT_DIR=$DEST/python-troveclient
33TROVE_CONF_DIR=/etc/trove
34TROVE_LOCAL_CONF_DIR=$TROVE_DIR/etc/trove
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070035TROVE_AUTH_CACHE_DIR=${TROVE_AUTH_CACHE_DIR:-/var/cache/trove}
Michael Basnight0f9a1b02013-12-28 03:42:07 +000036
37# Support entry points installation of console scripts
38if [[ -d $TROVE_DIR/bin ]]; then
39 TROVE_BIN_DIR=$TROVE_DIR/bin
40else
41 TROVE_BIN_DIR=$(get_python_exec_prefix)
42fi
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070043
Dean Troyer4237f592014-01-29 16:22:11 -060044# Tell Tempest this project is present
45TEMPEST_SERVICES+=,trove
46
47
Dean Troyerfc744f92014-01-27 13:45:21 -060048# Functions
49# ---------
50
51# Test if any Trove services are enabled
52# is_trove_enabled
53function is_trove_enabled {
54 [[ ,${ENABLED_SERVICES} =~ ,"tr-" ]] && return 0
55 return 1
56}
57
Robert Myers674ee842013-11-25 13:15:35 -060058# setup_trove_logging() - Adds logging configuration to conf files
Ian Wienandaee18c72014-02-21 15:35:08 +110059function setup_trove_logging {
Robert Myers674ee842013-11-25 13:15:35 -060060 local CONF=$1
61 iniset $CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
62 iniset $CONF DEFAULT use_syslog $SYSLOG
63 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
64 # Add color to logging output
65 setup_colorized_logging $CONF DEFAULT tenant user
66 fi
67}
68
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070069# create_trove_accounts() - Set up common required trove accounts
70
71# Tenant User Roles
72# ------------------------------------------------------------------
73# service trove admin # if enabled
74
Ian Wienandaee18c72014-02-21 15:35:08 +110075function create_trove_accounts {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070076 # Trove
Steve Martinelli19685422014-01-24 13:02:26 -060077 SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
78 SERVICE_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070079
80 if [[ "$ENABLED_SERVICES" =~ "trove" ]]; then
Steve Martinelli19685422014-01-24 13:02:26 -060081 TROVE_USER=$(openstack user create \
82 trove \
83 --password "$SERVICE_PASSWORD" \
84 --project $SERVICE_TENANT \
85 --email trove@example.com \
Sean Dague101b4242013-10-22 08:47:11 -040086 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -060087 openstack role add \
88 $SERVICE_ROLE \
89 --project $SERVICE_TENANT \
90 --user $TROVE_USER
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070091 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Daniel Salinasb7223562014-02-16 18:57:20 -060092 TROVE_SERVICE=$(openstack service create \
Steve Martinelli19685422014-01-24 13:02:26 -060093 trove \
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070094 --type=database \
95 --description="Trove Service" \
96 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -060097 openstack endpoint create \
98 $TROVE_SERVICE \
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070099 --region RegionOne \
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700100 --publicurl "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s" \
101 --adminurl "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s" \
102 --internalurl "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s"
103 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
118# configure_troveclient() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100119function configure_troveclient {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700120 setup_develop $TROVECLIENT_DIR
121}
122
123# configure_trove() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100124function configure_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700125 setup_develop $TROVE_DIR
126
127 # Create the trove conf dir and cache dirs if they don't exist
128 sudo mkdir -p ${TROVE_CONF_DIR}
129 sudo mkdir -p ${TROVE_AUTH_CACHE_DIR}
130 sudo chown -R $STACK_USER: ${TROVE_CONF_DIR}
131 sudo chown -R $STACK_USER: ${TROVE_AUTH_CACHE_DIR}
132
133 # Copy api-paste file over to the trove conf dir and configure it
134 cp $TROVE_LOCAL_CONF_DIR/api-paste.ini $TROVE_CONF_DIR/api-paste.ini
135 TROVE_API_PASTE_INI=$TROVE_CONF_DIR/api-paste.ini
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000136
137 iniset $TROVE_API_PASTE_INI filter:authtoken identity_uri $KEYSTONE_AUTH_URI
Nikhil Manchanda1272bc52014-01-31 15:04:05 -0800138 iniset $TROVE_API_PASTE_INI filter:authtoken cafile $KEYSTONE_SSL_CA
139 iniset $TROVE_API_PASTE_INI filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
140 iniset $TROVE_API_PASTE_INI filter:authtoken admin_user trove
141 iniset $TROVE_API_PASTE_INI filter:authtoken admin_password $SERVICE_PASSWORD
142 iniset $TROVE_API_PASTE_INI filter:authtoken signing_dir $TROVE_AUTH_CACHE_DIR
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700143
144 # (Re)create trove conf files
145 rm -f $TROVE_CONF_DIR/trove.conf
146 rm -f $TROVE_CONF_DIR/trove-taskmanager.conf
Ed Cranford1089b3a2013-09-30 11:36:55 -0500147 rm -f $TROVE_CONF_DIR/trove-conductor.conf
148
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700149 iniset $TROVE_CONF_DIR/trove.conf DEFAULT rabbit_password $RABBIT_PASSWORD
150 iniset $TROVE_CONF_DIR/trove.conf DEFAULT sql_connection `database_connection_url trove`
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700151
152 iniset $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample DEFAULT rabbit_password $RABBIT_PASSWORD
Nikhil Manchandabc22e912014-05-07 23:46:01 -0700153 sed -i "s/localhost/$TROVE_HOST_GATEWAY/g" $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700154
Robert Myers674ee842013-11-25 13:15:35 -0600155 setup_trove_logging $TROVE_CONF_DIR/trove.conf
156 setup_trove_logging $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample
157
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700158 # (Re)create trove taskmanager conf file if needed
159 if is_service_enabled tr-tmgr; then
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000160 TROVE_AUTH_ENDPOINT=$KEYSTONE_AUTH_URI/v$IDENTITY_API_VERSION
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000161
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700162 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT rabbit_password $RABBIT_PASSWORD
163 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT sql_connection `database_connection_url trove`
164 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT taskmanager_manager trove.taskmanager.manager.Manager
165 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_user radmin
166 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_tenant_name trove
167 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
168 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
Robert Myers674ee842013-11-25 13:15:35 -0600169 setup_trove_logging $TROVE_CONF_DIR/trove-taskmanager.conf
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700170 fi
Ed Cranford1089b3a2013-09-30 11:36:55 -0500171
172 # (Re)create trove conductor conf file if needed
173 if is_service_enabled tr-cond; then
174 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT rabbit_password $RABBIT_PASSWORD
175 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT sql_connection `database_connection_url trove`
176 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_user radmin
177 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_tenant_name trove
178 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
179 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
180 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT control_exchange trove
Robert Myers674ee842013-11-25 13:15:35 -0600181 setup_trove_logging $TROVE_CONF_DIR/trove-conductor.conf
Ed Cranford1089b3a2013-09-30 11:36:55 -0500182 fi
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700183}
184
185# install_troveclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100186function install_troveclient {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700187 git_clone $TROVECLIENT_REPO $TROVECLIENT_DIR $TROVECLIENT_BRANCH
188}
189
190# install_trove() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100191function install_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700192 git_clone $TROVE_REPO $TROVE_DIR $TROVE_BRANCH
193}
194
195# init_trove() - Initializes Trove Database as a Service
Ian Wienandaee18c72014-02-21 15:35:08 +1100196function init_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700197 #(Re)Create trove db
198 recreate_database trove utf8
199
200 #Initialize the trove database
Michael Basnight0f9a1b02013-12-28 03:42:07 +0000201 $TROVE_BIN_DIR/trove-manage db_sync
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700202}
203
204# start_trove() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100205function start_trove {
Michael Basnight0f9a1b02013-12-28 03:42:07 +0000206 screen_it tr-api "cd $TROVE_DIR; $TROVE_BIN_DIR/trove-api --config-file=$TROVE_CONF_DIR/trove.conf --debug 2>&1"
207 screen_it tr-tmgr "cd $TROVE_DIR; $TROVE_BIN_DIR/trove-taskmanager --config-file=$TROVE_CONF_DIR/trove-taskmanager.conf --debug 2>&1"
208 screen_it tr-cond "cd $TROVE_DIR; $TROVE_BIN_DIR/trove-conductor --config-file=$TROVE_CONF_DIR/trove-conductor.conf --debug 2>&1"
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700209}
210
211# stop_trove() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100212function stop_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700213 # Kill the trove screen windows
Ed Cranford1089b3a2013-09-30 11:36:55 -0500214 for serv in tr-api tr-tmgr tr-cond; do
Dean Troyer9fc87922013-05-22 17:19:06 -0500215 screen_stop $serv
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700216 done
217}
218
219# Restore xtrace
220$XTRACE
221
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100222# Tell emacs to use shell-script-mode
223## Local variables:
224## mode: shell-script
225## End: