blob: 7824f2754ef0fb19fac1284ca8cfc9df11ac9aa1 [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}
Nikhil Manchandaafefaa72014-06-24 13:06:00 -070036TROVE_DATASTORE_TYPE=${TROVE_DATASTORE_TYPE:-"mysql"}
37TROVE_DATASTORE_VERSION=${TROVE_DATASTORE_VERSION:-"5.5"}
38TROVE_DATASTORE_PACKAGE=${TROVE_DATASTORE_PACKAGE:-"mysql-server-5.5"}
39TROVE_GUEST_IMAGE_URL=${TROVE_GUEST_IMAGE_URL:-"http://tarballs.openstack.org/trove/images/ubuntu_mysql.qcow2/ubuntu_mysql.qcow2"}
Michael Basnight0f9a1b02013-12-28 03:42:07 +000040
41# Support entry points installation of console scripts
42if [[ -d $TROVE_DIR/bin ]]; then
43 TROVE_BIN_DIR=$TROVE_DIR/bin
44else
45 TROVE_BIN_DIR=$(get_python_exec_prefix)
46fi
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070047
Dean Troyer4237f592014-01-29 16:22:11 -060048# Tell Tempest this project is present
49TEMPEST_SERVICES+=,trove
50
51
Dean Troyerfc744f92014-01-27 13:45:21 -060052# Functions
53# ---------
54
55# Test if any Trove services are enabled
56# is_trove_enabled
57function is_trove_enabled {
58 [[ ,${ENABLED_SERVICES} =~ ,"tr-" ]] && return 0
59 return 1
60}
61
Robert Myers674ee842013-11-25 13:15:35 -060062# setup_trove_logging() - Adds logging configuration to conf files
Ian Wienandaee18c72014-02-21 15:35:08 +110063function setup_trove_logging {
Robert Myers674ee842013-11-25 13:15:35 -060064 local CONF=$1
65 iniset $CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
66 iniset $CONF DEFAULT use_syslog $SYSLOG
67 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
68 # Add color to logging output
69 setup_colorized_logging $CONF DEFAULT tenant user
70 fi
71}
72
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070073# create_trove_accounts() - Set up common required trove accounts
74
75# Tenant User Roles
76# ------------------------------------------------------------------
77# service trove admin # if enabled
78
Ian Wienandaee18c72014-02-21 15:35:08 +110079function create_trove_accounts {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070080 # Trove
Steve Martinelli19685422014-01-24 13:02:26 -060081 SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
82 SERVICE_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070083
84 if [[ "$ENABLED_SERVICES" =~ "trove" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +010085
86 TROVE_USER=$(get_or_create_user "trove" \
87 "$SERVICE_PASSWORD" $SERVICE_TENANT "trove@example.com")
88 get_or_add_user_role $SERVICE_ROLE $TROVE_USER $SERVICE_TENANT
89
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070090 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +010091
92 TROVE_SERVICE=$(get_or_create_service "trove" \
93 "database" "Trove Service")
94 get_or_create_endpoint $TROVE_SERVICE \
95 "$REGION_NAME" \
96 "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s" \
97 "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s" \
98 "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s"
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070099 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
Ian Wienandaee18c72014-02-21 15:35:08 +1100108function cleanup_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700109 #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
Ian Wienandaee18c72014-02-21 15:35:08 +1100115function configure_troveclient {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700116 setup_develop $TROVECLIENT_DIR
117}
118
119# configure_trove() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100120function configure_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700121 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
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000132
133 iniset $TROVE_API_PASTE_INI filter:authtoken identity_uri $KEYSTONE_AUTH_URI
Nikhil Manchanda1272bc52014-01-31 15:04:05 -0800134 iniset $TROVE_API_PASTE_INI filter:authtoken cafile $KEYSTONE_SSL_CA
135 iniset $TROVE_API_PASTE_INI filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
136 iniset $TROVE_API_PASTE_INI filter:authtoken admin_user trove
137 iniset $TROVE_API_PASTE_INI filter:authtoken admin_password $SERVICE_PASSWORD
138 iniset $TROVE_API_PASTE_INI filter:authtoken signing_dir $TROVE_AUTH_CACHE_DIR
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700139
140 # (Re)create trove conf files
141 rm -f $TROVE_CONF_DIR/trove.conf
142 rm -f $TROVE_CONF_DIR/trove-taskmanager.conf
Ed Cranford1089b3a2013-09-30 11:36:55 -0500143 rm -f $TROVE_CONF_DIR/trove-conductor.conf
144
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700145 iniset $TROVE_CONF_DIR/trove.conf DEFAULT rabbit_password $RABBIT_PASSWORD
146 iniset $TROVE_CONF_DIR/trove.conf DEFAULT sql_connection `database_connection_url trove`
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700147 iniset $TROVE_CONF_DIR/trove.conf DEFAULT default_datastore $TROVE_DATASTORE_TYPE
Robert Myers674ee842013-11-25 13:15:35 -0600148 setup_trove_logging $TROVE_CONF_DIR/trove.conf
Robert Myers674ee842013-11-25 13:15:35 -0600149
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700150 # (Re)create trove taskmanager conf file if needed
151 if is_service_enabled tr-tmgr; then
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000152 TROVE_AUTH_ENDPOINT=$KEYSTONE_AUTH_URI/v$IDENTITY_API_VERSION
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000153
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700154 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT rabbit_password $RABBIT_PASSWORD
155 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT sql_connection `database_connection_url trove`
156 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT taskmanager_manager trove.taskmanager.manager.Manager
157 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_user radmin
158 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_tenant_name trove
159 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
160 iniset $TROVE_CONF_DIR/trove-taskmanager.conf DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
Robert Myers674ee842013-11-25 13:15:35 -0600161 setup_trove_logging $TROVE_CONF_DIR/trove-taskmanager.conf
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700162 fi
Ed Cranford1089b3a2013-09-30 11:36:55 -0500163
164 # (Re)create trove conductor conf file if needed
165 if is_service_enabled tr-cond; then
166 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT rabbit_password $RABBIT_PASSWORD
167 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT sql_connection `database_connection_url trove`
168 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_user radmin
169 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_tenant_name trove
170 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
171 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
172 iniset $TROVE_CONF_DIR/trove-conductor.conf DEFAULT control_exchange trove
Robert Myers674ee842013-11-25 13:15:35 -0600173 setup_trove_logging $TROVE_CONF_DIR/trove-conductor.conf
Ed Cranford1089b3a2013-09-30 11:36:55 -0500174 fi
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700175
176 # Set up Guest Agent conf
177 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT rabbit_host $TROVE_HOST_GATEWAY
178 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT rabbit_password $RABBIT_PASSWORD
179 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT nova_proxy_admin_user radmin
180 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT nova_proxy_admin_tenant_name trove
181 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
182 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
183 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT control_exchange trove
184 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT log_dir /tmp/
185 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT log_file trove-guestagent.log
186 setup_trove_logging $TROVE_CONF_DIR/trove-guestagent.conf
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700187}
188
189# install_troveclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100190function install_troveclient {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700191 git_clone $TROVECLIENT_REPO $TROVECLIENT_DIR $TROVECLIENT_BRANCH
192}
193
194# install_trove() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100195function install_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700196 git_clone $TROVE_REPO $TROVE_DIR $TROVE_BRANCH
197}
198
199# init_trove() - Initializes Trove Database as a Service
Ian Wienandaee18c72014-02-21 15:35:08 +1100200function init_trove {
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700201 # (Re)Create trove db
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700202 recreate_database trove utf8
203
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700204 # Initialize the trove database
Michael Basnight0f9a1b02013-12-28 03:42:07 +0000205 $TROVE_BIN_DIR/trove-manage db_sync
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700206
207 # Upload the trove-guest image to glance
208 TROVE_GUEST_IMAGE_ID=$(upload_image $TROVE_GUEST_IMAGE_URL $TOKEN | grep ' id ' | get_field 2)
209
210 # Initialize appropriate datastores / datastore versions
211 $TROVE_BIN_DIR/trove-manage datastore_update "$TROVE_DATASTORE_TYPE" ""
212 $TROVE_BIN_DIR/trove-manage datastore_version_update "$TROVE_DATASTORE_TYPE" "$TROVE_DATASTORE_VERSION" "$TROVE_DATASTORE_TYPE" \
213 "$TROVE_GUEST_IMAGE_ID" "$TROVE_DATASTORE_PACKAGE" 1
214 $TROVE_BIN_DIR/trove-manage datastore_version_update "$TROVE_DATASTORE_TYPE" "inactive_version" "inactive_manager" "$TROVE_GUEST_IMAGE_ID" "" 0
215 $TROVE_BIN_DIR/trove-manage datastore_update "$TROVE_DATASTORE_TYPE" "$TROVE_DATASTORE_VERSION"
216 $TROVE_BIN_DIR/trove-manage datastore_update "Inactive_Datastore" ""
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700217}
218
219# start_trove() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100220function start_trove {
Michael Basnight0f9a1b02013-12-28 03:42:07 +0000221 screen_it tr-api "cd $TROVE_DIR; $TROVE_BIN_DIR/trove-api --config-file=$TROVE_CONF_DIR/trove.conf --debug 2>&1"
222 screen_it tr-tmgr "cd $TROVE_DIR; $TROVE_BIN_DIR/trove-taskmanager --config-file=$TROVE_CONF_DIR/trove-taskmanager.conf --debug 2>&1"
223 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 -0700224}
225
226# stop_trove() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100227function stop_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700228 # Kill the trove screen windows
Ed Cranford1089b3a2013-09-30 11:36:55 -0500229 for serv in tr-api tr-tmgr tr-cond; do
Dean Troyer9fc87922013-05-22 17:19:06 -0500230 screen_stop $serv
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700231 done
232}
233
234# Restore xtrace
235$XTRACE
236
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100237# Tell emacs to use shell-script-mode
238## Local variables:
239## mode: shell-script
240## End: