blob: 401ab789d4ba4ff716ae019c7a0dc1494608a73d [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
Steve Martinelli19685422014-01-24 13:02:26 -060085 TROVE_USER=$(openstack user create \
86 trove \
87 --password "$SERVICE_PASSWORD" \
88 --project $SERVICE_TENANT \
89 --email trove@example.com \
Sean Dague101b4242013-10-22 08:47:11 -040090 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -060091 openstack role add \
92 $SERVICE_ROLE \
93 --project $SERVICE_TENANT \
94 --user $TROVE_USER
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070095 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Daniel Salinasb7223562014-02-16 18:57:20 -060096 TROVE_SERVICE=$(openstack service create \
Steve Martinelli19685422014-01-24 13:02:26 -060097 trove \
Nikhil Manchanda0cccad42012-12-03 18:15:09 -070098 --type=database \
99 --description="Trove Service" \
100 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -0600101 openstack endpoint create \
102 $TROVE_SERVICE \
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700103 --region RegionOne \
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700104 --publicurl "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s" \
105 --adminurl "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s" \
106 --internalurl "http://$SERVICE_HOST:8779/v1.0/\$(tenant_id)s"
107 fi
108 fi
109}
110
111# stack.sh entry points
112# ---------------------
113
114# cleanup_trove() - Remove residual data files, anything left over from previous
115# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100116function cleanup_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700117 #Clean up dirs
118 rm -fr $TROVE_AUTH_CACHE_DIR/*
119 rm -fr $TROVE_CONF_DIR/*
120}
121
122# configure_troveclient() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100123function configure_troveclient {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700124 setup_develop $TROVECLIENT_DIR
125}
126
127# configure_trove() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100128function configure_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700129 setup_develop $TROVE_DIR
130
131 # Create the trove conf dir and cache dirs if they don't exist
132 sudo mkdir -p ${TROVE_CONF_DIR}
133 sudo mkdir -p ${TROVE_AUTH_CACHE_DIR}
134 sudo chown -R $STACK_USER: ${TROVE_CONF_DIR}
135 sudo chown -R $STACK_USER: ${TROVE_AUTH_CACHE_DIR}
136
137 # Copy api-paste file over to the trove conf dir and configure it
138 cp $TROVE_LOCAL_CONF_DIR/api-paste.ini $TROVE_CONF_DIR/api-paste.ini
139 TROVE_API_PASTE_INI=$TROVE_CONF_DIR/api-paste.ini
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000140
141 iniset $TROVE_API_PASTE_INI filter:authtoken identity_uri $KEYSTONE_AUTH_URI
Nikhil Manchanda1272bc52014-01-31 15:04:05 -0800142 iniset $TROVE_API_PASTE_INI filter:authtoken cafile $KEYSTONE_SSL_CA
143 iniset $TROVE_API_PASTE_INI filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
144 iniset $TROVE_API_PASTE_INI filter:authtoken admin_user trove
145 iniset $TROVE_API_PASTE_INI filter:authtoken admin_password $SERVICE_PASSWORD
146 iniset $TROVE_API_PASTE_INI filter:authtoken signing_dir $TROVE_AUTH_CACHE_DIR
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700147
148 # (Re)create trove conf files
149 rm -f $TROVE_CONF_DIR/trove.conf
150 rm -f $TROVE_CONF_DIR/trove-taskmanager.conf
Ed Cranford1089b3a2013-09-30 11:36:55 -0500151 rm -f $TROVE_CONF_DIR/trove-conductor.conf
152
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700153 iniset $TROVE_CONF_DIR/trove.conf DEFAULT rabbit_password $RABBIT_PASSWORD
154 iniset $TROVE_CONF_DIR/trove.conf DEFAULT sql_connection `database_connection_url trove`
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700155 iniset $TROVE_CONF_DIR/trove.conf DEFAULT default_datastore $TROVE_DATASTORE_TYPE
Robert Myers674ee842013-11-25 13:15:35 -0600156 setup_trove_logging $TROVE_CONF_DIR/trove.conf
Robert Myers674ee842013-11-25 13:15:35 -0600157
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 Manchandaafefaa72014-06-24 13:06:00 -0700183
184 # Set up Guest Agent conf
185 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT rabbit_host $TROVE_HOST_GATEWAY
186 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT rabbit_password $RABBIT_PASSWORD
187 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT nova_proxy_admin_user radmin
188 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT nova_proxy_admin_tenant_name trove
189 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT nova_proxy_admin_pass $RADMIN_USER_PASS
190 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT trove_auth_url $TROVE_AUTH_ENDPOINT
191 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT control_exchange trove
192 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT log_dir /tmp/
193 iniset $TROVE_CONF_DIR/trove-guestagent.conf DEFAULT log_file trove-guestagent.log
194 setup_trove_logging $TROVE_CONF_DIR/trove-guestagent.conf
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700195}
196
197# install_troveclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100198function install_troveclient {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700199 git_clone $TROVECLIENT_REPO $TROVECLIENT_DIR $TROVECLIENT_BRANCH
200}
201
202# install_trove() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100203function install_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700204 git_clone $TROVE_REPO $TROVE_DIR $TROVE_BRANCH
205}
206
207# init_trove() - Initializes Trove Database as a Service
Ian Wienandaee18c72014-02-21 15:35:08 +1100208function init_trove {
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700209 # (Re)Create trove db
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700210 recreate_database trove utf8
211
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700212 # Initialize the trove database
Michael Basnight0f9a1b02013-12-28 03:42:07 +0000213 $TROVE_BIN_DIR/trove-manage db_sync
Nikhil Manchandaafefaa72014-06-24 13:06:00 -0700214
215 # Upload the trove-guest image to glance
216 TROVE_GUEST_IMAGE_ID=$(upload_image $TROVE_GUEST_IMAGE_URL $TOKEN | grep ' id ' | get_field 2)
217
218 # Initialize appropriate datastores / datastore versions
219 $TROVE_BIN_DIR/trove-manage datastore_update "$TROVE_DATASTORE_TYPE" ""
220 $TROVE_BIN_DIR/trove-manage datastore_version_update "$TROVE_DATASTORE_TYPE" "$TROVE_DATASTORE_VERSION" "$TROVE_DATASTORE_TYPE" \
221 "$TROVE_GUEST_IMAGE_ID" "$TROVE_DATASTORE_PACKAGE" 1
222 $TROVE_BIN_DIR/trove-manage datastore_version_update "$TROVE_DATASTORE_TYPE" "inactive_version" "inactive_manager" "$TROVE_GUEST_IMAGE_ID" "" 0
223 $TROVE_BIN_DIR/trove-manage datastore_update "$TROVE_DATASTORE_TYPE" "$TROVE_DATASTORE_VERSION"
224 $TROVE_BIN_DIR/trove-manage datastore_update "Inactive_Datastore" ""
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700225}
226
227# start_trove() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100228function start_trove {
Michael Basnight0f9a1b02013-12-28 03:42:07 +0000229 screen_it tr-api "cd $TROVE_DIR; $TROVE_BIN_DIR/trove-api --config-file=$TROVE_CONF_DIR/trove.conf --debug 2>&1"
230 screen_it tr-tmgr "cd $TROVE_DIR; $TROVE_BIN_DIR/trove-taskmanager --config-file=$TROVE_CONF_DIR/trove-taskmanager.conf --debug 2>&1"
231 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 -0700232}
233
234# stop_trove() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100235function stop_trove {
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700236 # Kill the trove screen windows
Ed Cranford1089b3a2013-09-30 11:36:55 -0500237 for serv in tr-api tr-tmgr tr-cond; do
Dean Troyer9fc87922013-05-22 17:19:06 -0500238 screen_stop $serv
Nikhil Manchanda0cccad42012-12-03 18:15:09 -0700239 done
240}
241
242# Restore xtrace
243$XTRACE
244
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100245# Tell emacs to use shell-script-mode
246## Local variables:
247## mode: shell-script
248## End: