blob: 03b902e5b60a135d976b24cef3356bd1d980cd3d [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
Sergey Lukjanov7ff84432014-03-10 20:04:51 +04003# lib/sahara
4
5# Dependencies:
6# ``functions`` file
7# ``DEST``, ``DATA_DIR``, ``STACK_USER`` must be defined
8
9# ``stack.sh`` calls the entry points in this order:
10#
11# install_sahara
Sergey Lukjanova90898d2014-08-05 16:14:12 +040012# install_python_saharaclient
Sergey Lukjanov7ff84432014-03-10 20:04:51 +040013# configure_sahara
Andrew Lazarevb3130482014-12-16 14:36:59 -080014# sahara_register_images
Sergey Lukjanov7ff84432014-03-10 20:04:51 +040015# start_sahara
16# stop_sahara
17# cleanup_sahara
18
19# Save trace setting
20XTRACE=$(set +o | grep xtrace)
21set +o xtrace
22
23
24# Defaults
25# --------
26
27# Set up default repos
Sergey Lukjanova90898d2014-08-05 16:14:12 +040028
Sergey Lukjanov7ff84432014-03-10 20:04:51 +040029# Set up default directories
Sean Dagueee5ae7b2014-11-13 13:23:27 -050030GITDIR["python-saharaclient"]=$DEST/python-saharaclient
Sergey Lukjanov7ff84432014-03-10 20:04:51 +040031SAHARA_DIR=$DEST/sahara
Sergey Lukjanova90898d2014-08-05 16:14:12 +040032
Sergey Lukjanov7ff84432014-03-10 20:04:51 +040033SAHARA_CONF_DIR=${SAHARA_CONF_DIR:-/etc/sahara}
34SAHARA_CONF_FILE=${SAHARA_CONF_DIR}/sahara.conf
Sergey Lukjanov7ff84432014-03-10 20:04:51 +040035
36SAHARA_SERVICE_HOST=${SAHARA_SERVICE_HOST:-$SERVICE_HOST}
37SAHARA_SERVICE_PORT=${SAHARA_SERVICE_PORT:-8386}
38SAHARA_SERVICE_PROTOCOL=${SAHARA_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
39
40SAHARA_AUTH_CACHE_DIR=${SAHARA_AUTH_CACHE_DIR:-/var/cache/sahara}
41
Sergey Lukjanov10f41612014-04-25 11:42:41 +040042SAHARA_ENABLED_PLUGINS=${SAHARA_ENABLED_PLUGINS:-vanilla,hdp,fake}
43
Sergey Lukjanov7ff84432014-03-10 20:04:51 +040044# Support entry points installation of console scripts
45if [[ -d $SAHARA_DIR/bin ]]; then
46 SAHARA_BIN_DIR=$SAHARA_DIR/bin
47else
48 SAHARA_BIN_DIR=$(get_python_exec_prefix)
49fi
50
51# Tell Tempest this project is present
52TEMPEST_SERVICES+=,sahara
53
Sergey Lukjanov7ff84432014-03-10 20:04:51 +040054# Functions
55# ---------
56
57# create_sahara_accounts() - Set up common required sahara accounts
58#
59# Tenant User Roles
60# ------------------------------
61# service sahara admin
62function create_sahara_accounts {
63
Dean Troyer16ef9762014-08-19 19:31:34 -050064 local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
65 local admin_role=$(openstack role list | awk "/ admin / { print \$2 }")
Sergey Lukjanov7ff84432014-03-10 20:04:51 +040066
Dean Troyer16ef9762014-08-19 19:31:34 -050067 local sahara_user=$(get_or_create_user "sahara" \
68 "$SERVICE_PASSWORD" $service_tenant)
69 get_or_add_user_role $admin_role $sahara_user $service_tenant
Sergey Lukjanov7ff84432014-03-10 20:04:51 +040070
71 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +010072
Dean Troyer16ef9762014-08-19 19:31:34 -050073 local sahara_service=$(get_or_create_service "sahara" \
Bartosz Górski0abde392014-02-28 14:15:19 +010074 "data_processing" "Sahara Data Processing")
Dean Troyer16ef9762014-08-19 19:31:34 -050075 get_or_create_endpoint $sahara_service \
Bartosz Górski0abde392014-02-28 14:15:19 +010076 "$REGION_NAME" \
77 "$SAHARA_SERVICE_PROTOCOL://$SAHARA_SERVICE_HOST:$SAHARA_SERVICE_PORT/v1.1/\$(tenant_id)s" \
78 "$SAHARA_SERVICE_PROTOCOL://$SAHARA_SERVICE_HOST:$SAHARA_SERVICE_PORT/v1.1/\$(tenant_id)s" \
79 "$SAHARA_SERVICE_PROTOCOL://$SAHARA_SERVICE_HOST:$SAHARA_SERVICE_PORT/v1.1/\$(tenant_id)s"
Sergey Lukjanov7ff84432014-03-10 20:04:51 +040080 fi
81}
82
83# cleanup_sahara() - Remove residual data files, anything left over from
84# previous runs that would need to clean up.
85function cleanup_sahara {
86
87 # Cleanup auth cache dir
88 sudo rm -rf $SAHARA_AUTH_CACHE_DIR
89}
90
91# configure_sahara() - Set config files, create data dirs, etc
92function configure_sahara {
93
94 if [[ ! -d $SAHARA_CONF_DIR ]]; then
95 sudo mkdir -p $SAHARA_CONF_DIR
96 fi
97 sudo chown $STACK_USER $SAHARA_CONF_DIR
98
Andrew Lazarev627ca742014-10-29 17:01:15 -070099 if [[ -f $SAHARA_DIR/etc/sahara/policy.json ]]; then
100 cp -p $SAHARA_DIR/etc/sahara/policy.json $SAHARA_CONF_DIR
101 fi
102
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400103 # Copy over sahara configuration file and configure common parameters.
Sergey Lukjanov51ebda62014-03-12 22:26:12 +0400104 cp $SAHARA_DIR/etc/sahara/sahara.conf.sample $SAHARA_CONF_FILE
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400105
106 # Create auth cache dir
107 sudo mkdir -p $SAHARA_AUTH_CACHE_DIR
108 sudo chown $STACK_USER $SAHARA_AUTH_CACHE_DIR
Andrew Lazarev28d43922014-10-29 17:25:12 -0700109 sudo chmod 700 $SAHARA_AUTH_CACHE_DIR
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400110 rm -rf $SAHARA_AUTH_CACHE_DIR/*
111
Brant Knudson05952372014-09-19 17:22:22 -0500112 configure_auth_token_middleware $SAHARA_CONF_FILE sahara $SAHARA_AUTH_CACHE_DIR
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400113
Vitaly Gridneve50fcb12014-08-11 12:01:12 +0000114 # Set configuration to send notifications
115
116 if is_service_enabled ceilometer; then
117 iniset $SAHARA_CONF_FILE DEFAULT enable_notifications "true"
118 iniset $SAHARA_CONF_FILE DEFAULT notification_driver "messaging"
119 iniset_rpc_backend sahara $SAHARA_CONF_FILE DEFAULT
120 fi
121
Sergey Lukjanov3cd59e12014-03-25 00:06:31 +0400122 iniset $SAHARA_CONF_FILE DEFAULT verbose True
123 iniset $SAHARA_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400124
Sergey Lukjanov10f41612014-04-25 11:42:41 +0400125 iniset $SAHARA_CONF_FILE DEFAULT plugins $SAHARA_ENABLED_PLUGINS
126
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400127 iniset $SAHARA_CONF_FILE database connection `database_connection_url sahara`
128
129 if is_service_enabled neutron; then
130 iniset $SAHARA_CONF_FILE DEFAULT use_neutron true
131 iniset $SAHARA_CONF_FILE DEFAULT use_floating_ips true
132 fi
133
134 if is_service_enabled heat; then
135 iniset $SAHARA_CONF_FILE DEFAULT infrastructure_engine heat
136 else
137 iniset $SAHARA_CONF_FILE DEFAULT infrastructure_engine direct
138 fi
139
140 iniset $SAHARA_CONF_FILE DEFAULT use_syslog $SYSLOG
141
Luigi Toscanob4bef1f2014-04-03 19:24:57 +0200142 # Format logging
143 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
144 setup_colorized_logging $SAHARA_CONF_FILE DEFAULT
145 fi
146
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400147 recreate_database sahara utf8
148 $SAHARA_BIN_DIR/sahara-db-manage --config-file $SAHARA_CONF_FILE upgrade head
149}
150
151# install_sahara() - Collect source and prepare
152function install_sahara {
153 git_clone $SAHARA_REPO $SAHARA_DIR $SAHARA_BRANCH
154 setup_develop $SAHARA_DIR
155}
156
Sergey Lukjanova90898d2014-08-05 16:14:12 +0400157# install_python_saharaclient() - Collect source and prepare
158function install_python_saharaclient {
Sean Dagueee5ae7b2014-11-13 13:23:27 -0500159 if use_library_from_git "python-saharaclient"; then
160 git_clone_by_name "python-saharaclient"
161 setup_dev_lib "python-saharaclient"
162 fi
Sergey Lukjanova90898d2014-08-05 16:14:12 +0400163}
164
Andrew Lazarevb3130482014-12-16 14:36:59 -0800165# sahara_register_images() - Registers images in sahara image registry
166function sahara_register_images {
167 if is_service_enabled heat && [[ ! -z "$HEAT_CFN_IMAGE_URL" ]]; then
168 # Register heat image for Fake plugin
169 local fake_plugin_properties="--property _sahara_tag_0.1=True"
170 fake_plugin_properties+=" --property _sahara_tag_fake=True"
171 fake_plugin_properties+=" --property _sahara_username=fedora"
172 openstack --os-url $GLANCE_SERVICE_PROTOCOL://$GLANCE_HOSTPORT image set $(basename "$HEAT_CFN_IMAGE_URL" ".qcow2") $fake_plugin_properties
173 fi
174}
175
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400176# start_sahara() - Start running processes, including screen
177function start_sahara {
Chris Dent2f27a0e2014-09-09 13:46:02 +0100178 run_process sahara "$SAHARA_BIN_DIR/sahara-all --config-file $SAHARA_CONF_FILE"
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400179}
180
181# stop_sahara() - Stop running processes
182function stop_sahara {
183 # Kill the Sahara screen windows
184 screen -S $SCREEN_NAME -p sahara -X kill
185}
186
187
188# Restore xtrace
189$XTRACE
190
191# Local variables:
192# mode: shell-script
193# End: