blob: 2000446b13ca66ee7d6ab75b4e8012690d561160 [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
56function setup_trove_logging() {
57 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
72create_trove_accounts() {
73 # Trove
74 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
75 SERVICE_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
76
77 if [[ "$ENABLED_SERVICES" =~ "trove" ]]; then
Sean Dague101b4242013-10-22 08:47:11 -040078 TROVE_USER=$(keystone user-create \
79 --name=trove \
80 --pass="$SERVICE_PASSWORD" \
Dirk Mueller25049cd2014-01-09 13:53:52 +010081 --tenant-id $SERVICE_TENANT \
Sean Dague101b4242013-10-22 08:47:11 -040082 --email=trove@example.com \
83 | grep " id " | get_field 2)
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070084 keystone user-role-add --tenant-id $SERVICE_TENANT \
Sean Dague101b4242013-10-22 08:47:11 -040085 --user-id $TROVE_USER \
86 --role-id $SERVICE_ROLE
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070087 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
88 TROVE_SERVICE=$(keystone service-create \
89 --name=trove \
90 --type=database \
91 --description="Trove Service" \
92 | grep " id " | get_field 2)
93 keystone endpoint-create \
94 --region RegionOne \
95 --service_id $TROVE_SERVICE \
96 --publicurl "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s" \
97 --adminurl "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s" \
98 --internalurl "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s"
99 fi
100 fi
101}
102
103# stack.sh entry points
104# ---------------------
105
106# cleanup_trove() - Remove residual data files, anything left over from previous
107# runs that a clean run would need to clean up
108function cleanup_trove() {
109 #Clean up dirs
110 rm -fr $TROVE_AUTH_CACHE_DIR/*
111 rm -fr $TROVE_CONF_DIR/*
112}
113
114# configure_troveclient() - Set config files, create data dirs, etc
115function configure_troveclient() {
116 setup_develop $TROVECLIENT_DIR
117}
118
119# configure_trove() - Set config files, create data dirs, etc
120function configure_trove() {
121 setup_develop $TROVE_DIR
122
123 # Create the trove conf dir and cache dirs if they don't exist
124 sudo mkdir -p ${TROVE_CONF_DIR}
125 sudo mkdir -p ${TROVE_AUTH_CACHE_DIR}
126 sudo chown -R $STACK_USER: ${TROVE_CONF_DIR}
127 sudo chown -R $STACK_USER: ${TROVE_AUTH_CACHE_DIR}
128
129 # Copy api-paste file over to the trove conf dir and configure it
130 cp $TROVE_LOCAL_CONF_DIR/api-paste.ini $TROVE_CONF_DIR/api-paste.ini
131 TROVE_API_PASTE_INI=$TROVE_CONF_DIR/api-paste.ini
Nikhil Manchanda1272bc52014-01-31 15:04:05 -0800132 iniset $TROVE_API_PASTE_INI filter:authtoken auth_host $KEYSTONE_AUTH_HOST
133 iniset $TROVE_API_PASTE_INI filter:authtoken auth_port $KEYSTONE_AUTH_PORT
134 iniset $TROVE_API_PASTE_INI filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
135 iniset $TROVE_API_PASTE_INI filter:authtoken cafile $KEYSTONE_SSL_CA
136 iniset $TROVE_API_PASTE_INI filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
137 iniset $TROVE_API_PASTE_INI filter:authtoken admin_user trove
138 iniset $TROVE_API_PASTE_INI filter:authtoken admin_password $SERVICE_PASSWORD
139 iniset $TROVE_API_PASTE_INI filter:authtoken signing_dir $TROVE_AUTH_CACHE_DIR
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700140
141 # (Re)create trove conf files
142 rm -f $TROVE_CONF_DIR/trove.conf
143 rm -f $TROVE_CONF_DIR/trove-taskmanager.conf
Ed Cranford1089b3a2013-09-30 11:36:55 -0500144 rm -f $TROVE_CONF_DIR/trove-conductor.conf
145
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700146 iniset $TROVE_CONF_DIR/trove.conf DEFAULT rabbit_password $RABBIT_PASSWORD
147 iniset $TROVE_CONF_DIR/trove.conf DEFAULT sql_connection `database_connection_url trove`
148 iniset $TROVE_CONF_DIR/trove.conf DEFAULT add_addresses True
149
150 iniset $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample DEFAULT rabbit_password $RABBIT_PASSWORD
151 iniset $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample DEFAULT sql_connection `database_connection_url trove`
Ed Cranford1089b3a2013-09-30 11:36:55 -0500152 iniset $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample DEFAULT control_exchange trove
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700153 sed -i "s/localhost/$NETWORK_GATEWAY/g" $TROVE_LOCAL_CONF_DIR/trove-guestagent.conf.sample
154
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 Lennoxbd24a8d2013-09-20 16:26:42 +1000160 TROVE_AUTH_ENDPOINT=$KEYSTONE_AUTH_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT//v$IDENTITY_API_VERSION
161
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
186function install_troveclient() {
187 git_clone $TROVECLIENT_REPO $TROVECLIENT_DIR $TROVECLIENT_BRANCH
188}
189
190# install_trove() - Collect source and prepare
191function install_trove() {
192 git_clone $TROVE_REPO $TROVE_DIR $TROVE_BRANCH
193}
194
195# init_trove() - Initializes Trove Database as a Service
196function init_trove() {
197 #(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
205function 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
212function stop_trove() {
213 # 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: