blob: 42d22198f30112cc4247ff81c95335345c5f1b35 [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# --------
24
25NETWORK_GATEWAY=${NETWORK_GATEWAY:-10.0.0.1}
26
27# Set up default configuration
28TROVE_DIR=$DEST/trove
29TROVECLIENT_DIR=$DEST/python-troveclient
30TROVE_CONF_DIR=/etc/trove
31TROVE_LOCAL_CONF_DIR=$TROVE_DIR/etc/trove
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070032TROVE_AUTH_CACHE_DIR=${TROVE_AUTH_CACHE_DIR:-/var/cache/trove}
Michael Basnight0f9a1b02013-12-28 03:42:07 +000033
34# Support entry points installation of console scripts
35if [[ -d $TROVE_DIR/bin ]]; then
36 TROVE_BIN_DIR=$TROVE_DIR/bin
37else
38 TROVE_BIN_DIR=$(get_python_exec_prefix)
39fi
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070040
Dean Troyer4237f592014-01-29 16:22:11 -060041# Tell Tempest this project is present
42TEMPEST_SERVICES+=,trove
43
44
Dean Troyerfc744f92014-01-27 13:45:21 -060045# Functions
46# ---------
47
48# Test if any Trove services are enabled
49# is_trove_enabled
50function is_trove_enabled {
51 [[ ,${ENABLED_SERVICES} =~ ,"tr-" ]] && return 0
52 return 1
53}
54
Robert Myers674ee842013-11-25 13:15:35 -060055# setup_trove_logging() - Adds logging configuration to conf files
Ian Wienandaee18c72014-02-21 15:35:08 +110056function setup_trove_logging {
Robert Myers674ee842013-11-25 13:15:35 -060057 local CONF=$1
58 iniset $CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
59 iniset $CONF DEFAULT use_syslog $SYSLOG
60 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
61 # Add color to logging output
62 setup_colorized_logging $CONF DEFAULT tenant user
63 fi
64}
65
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070066# create_trove_accounts() - Set up common required trove accounts
67
68# Tenant User Roles
69# ------------------------------------------------------------------
70# service trove admin # if enabled
71
Ian Wienandaee18c72014-02-21 15:35:08 +110072function create_trove_accounts {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070073 # Trove
Steve Martinelli19685422014-01-24 13:02:26 -060074 SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
75 SERVICE_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070076
77 if [[ "$ENABLED_SERVICES" =~ "trove" ]]; then
Steve Martinelli19685422014-01-24 13:02:26 -060078 TROVE_USER=$(openstack user create \
79 trove \
80 --password "$SERVICE_PASSWORD" \
81 --project $SERVICE_TENANT \
82 --email trove@example.com \
Sean Dague101b4242013-10-22 08:47:11 -040083 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -060084 openstack role add \
85 $SERVICE_ROLE \
86 --project $SERVICE_TENANT \
87 --user $TROVE_USER
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070088 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Daniel Salinasb7223562014-02-16 18:57:20 -060089 TROVE_SERVICE=$(openstack service create \
Steve Martinelli19685422014-01-24 13:02:26 -060090 trove \
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070091 --type=database \
92 --description="Trove Service" \
93 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -060094 openstack endpoint create \
95 $TROVE_SERVICE \
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070096 --region RegionOne \
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070097 --publicurl "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s" \
98 --adminurl "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s" \
99 --internalurl "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s"
100 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
115# configure_troveclient() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100116function configure_troveclient {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700117 setup_develop $TROVECLIENT_DIR
118}
119
120# configure_trove() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100121function configure_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700122 setup_develop $TROVE_DIR
123
124 # Create the trove conf dir and cache dirs if they don't exist
125 sudo mkdir -p ${TROVE_CONF_DIR}
126 sudo mkdir -p ${TROVE_AUTH_CACHE_DIR}
127 sudo chown -R $STACK_USER: ${TROVE_CONF_DIR}
128 sudo chown -R $STACK_USER: ${TROVE_AUTH_CACHE_DIR}
129
130 # Copy api-paste file over to the trove conf dir and configure it
131 cp $TROVE_LOCAL_CONF_DIR/api-paste.ini $TROVE_CONF_DIR/api-paste.ini
132 TROVE_API_PASTE_INI=$TROVE_CONF_DIR/api-paste.ini
Nikhil Manchanda1272bc52014-01-31 15:04:05 -0800133 iniset $TROVE_API_PASTE_INI filter:authtoken auth_host $KEYSTONE_AUTH_HOST
134 iniset $TROVE_API_PASTE_INI filter:authtoken auth_port $KEYSTONE_AUTH_PORT
135 iniset $TROVE_API_PASTE_INI filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
136 iniset $TROVE_API_PASTE_INI filter:authtoken cafile $KEYSTONE_SSL_CA
137 iniset $TROVE_API_PASTE_INI filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
138 iniset $TROVE_API_PASTE_INI filter:authtoken admin_user trove
139 iniset $TROVE_API_PASTE_INI filter:authtoken admin_password $SERVICE_PASSWORD
140 iniset $TROVE_API_PASTE_INI filter:authtoken signing_dir $TROVE_AUTH_CACHE_DIR
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700141
142 # (Re)create trove conf files
143 rm -f $TROVE_CONF_DIR/trove.conf
144 rm -f $TROVE_CONF_DIR/trove-taskmanager.conf
Ed Cranford1089b3a2013-09-30 11:36:55 -0500145 rm -f $TROVE_CONF_DIR/trove-conductor.conf
146
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700147 iniset $TROVE_CONF_DIR/trove.conf DEFAULT rabbit_password $RABBIT_PASSWORD
148 iniset $TROVE_CONF_DIR/trove.conf DEFAULT sql_connection `database_connection_url trove`
149 iniset $TROVE_CONF_DIR/trove.conf DEFAULT add_addresses True
Bob Balle5003462014-04-01 22:31:00 +0100150 iniset $TROVE_CONF_DIR/trove.conf DEFAULT nova_compute_url $NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2
151 iniset $TROVE_CONF_DIR/trove.conf DEFAULT cinder_url $CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1
152 iniset $TROVE_CONF_DIR/trove.conf DEFAULT swift_url http://$SERVICE_HOST:8080/v1/AUTH_
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700153
154 iniset $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample DEFAULT rabbit_password $RABBIT_PASSWORD
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700155 sed -i "s/localhost/$NETWORK_GATEWAY/g" $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample
156
Robert Myers674ee842013-11-25 13:15:35 -0600157 setup_trove_logging $TROVE_CONF_DIR/trove.conf
158 setup_trove_logging $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample
159
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700160 # (Re)create trove taskmanager conf file if needed
161 if is_service_enabled tr-tmgr; then
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000162 TROVE_AUTH_ENDPOINT=$KEYSTONE_AUTH_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT//v$IDENTITY_API_VERSION
163
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700164 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT rabbit_password $RABBIT_PASSWORD
165 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT sql_connection `database_connection_url trove`
166 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT taskmanager_manager trove.taskmanager.manager.Manager
167 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_user radmin
168 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_tenant_name trove
169 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
Bob Balle5003462014-04-01 22:31:00 +0100170 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_compute_url $NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2
171 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT cinder_url $CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1
172 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT swift_url http://$SERVICE_HOST:8080/v1/AUTH_
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700173 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
Robert Myers674ee842013-11-25 13:15:35 -0600174 setup_trove_logging $TROVE_CONF_DIR/trove-taskmanager.conf
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700175 fi
Ed Cranford1089b3a2013-09-30 11:36:55 -0500176
177 # (Re)create trove conductor conf file if needed
178 if is_service_enabled tr-cond; then
179 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT rabbit_password $RABBIT_PASSWORD
180 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT sql_connection `database_connection_url trove`
181 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_user radmin
182 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_tenant_name trove
183 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
184 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
185 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT control_exchange trove
Robert Myers674ee842013-11-25 13:15:35 -0600186 setup_trove_logging $TROVE_CONF_DIR/trove-conductor.conf
Ed Cranford1089b3a2013-09-30 11:36:55 -0500187 fi
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700188}
189
190# install_troveclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100191function install_troveclient {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700192 git_clone $TROVECLIENT_REPO $TROVECLIENT_DIR $TROVECLIENT_BRANCH
193}
194
195# install_trove() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100196function install_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700197 git_clone $TROVE_REPO $TROVE_DIR $TROVE_BRANCH
198}
199
200# init_trove() - Initializes Trove Database as a Service
Ian Wienandaee18c72014-02-21 15:35:08 +1100201function init_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700202 #(Re)Create trove db
203 recreate_database trove utf8
204
205 #Initialize the trove database
Michael Basnight0f9a1b02013-12-28 03:42:07 +0000206 $TROVE_BIN_DIR/trove-manage db_sync
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700207}
208
209# start_trove() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100210function start_trove {
Michael Basnight0f9a1b02013-12-28 03:42:07 +0000211 screen_it tr-api "cd $TROVE_DIR; $TROVE_BIN_DIR/trove-api --config-file=$TROVE_CONF_DIR/trove.conf --debug 2>&1"
212 screen_it tr-tmgr "cd $TROVE_DIR; $TROVE_BIN_DIR/trove-taskmanager --config-file=$TROVE_CONF_DIR/trove-taskmanager.conf --debug 2>&1"
213 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 -0700214}
215
216# stop_trove() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100217function stop_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700218 # Kill the trove screen windows
Ed Cranford1089b3a2013-09-30 11:36:55 -0500219 for serv in tr-api tr-tmgr tr-cond; do
Dean Troyer9fc87922013-05-22 17:19:06 -0500220 screen_stop $serv
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700221 done
222}
223
224# Restore xtrace
225$XTRACE
226
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100227# Tell emacs to use shell-script-mode
228## Local variables:
229## mode: shell-script
230## End: