blob: 9b2e9c406d78b786455c947bad3aa43eacb43a69 [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 Reshetnyak32ac55a2015-02-25 15:54:20 +030042SAHARA_ENABLED_PLUGINS=${SAHARA_ENABLED_PLUGINS:-vanilla,hdp,cdh,spark,fake}
Sergey Lukjanov10f41612014-04-25 11:42:41 +040043
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
Jamie Lennoxe8bc2b82015-02-10 20:38:56 +110064 create_service_user "sahara"
Sergey Lukjanov7ff84432014-03-10 20:04:51 +040065
66 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +010067
Telles Nobrega37a06f02014-11-18 07:59:10 -030068 # TODO: remove "data_processing" service when #1356053 will be fixed
69 local sahara_service_old=$(openstack service create \
70 "data_processing" \
71 --name "sahara" \
72 --description "Sahara Data Processing" \
73 -f value -c id
74 )
75 local sahara_service_new=$(openstack service create \
76 "data-processing" \
77 --name "sahara" \
78 --description "Sahara Data Processing" \
79 -f value -c id
80 )
81 get_or_create_endpoint $sahara_service_old \
82 "$REGION_NAME" \
83 "$SAHARA_SERVICE_PROTOCOL://$SAHARA_SERVICE_HOST:$SAHARA_SERVICE_PORT/v1.1/\$(tenant_id)s" \
84 "$SAHARA_SERVICE_PROTOCOL://$SAHARA_SERVICE_HOST:$SAHARA_SERVICE_PORT/v1.1/\$(tenant_id)s" \
85 "$SAHARA_SERVICE_PROTOCOL://$SAHARA_SERVICE_HOST:$SAHARA_SERVICE_PORT/v1.1/\$(tenant_id)s"
86 get_or_create_endpoint $sahara_service_new \
Bartosz Górski0abde392014-02-28 14:15:19 +010087 "$REGION_NAME" \
88 "$SAHARA_SERVICE_PROTOCOL://$SAHARA_SERVICE_HOST:$SAHARA_SERVICE_PORT/v1.1/\$(tenant_id)s" \
89 "$SAHARA_SERVICE_PROTOCOL://$SAHARA_SERVICE_HOST:$SAHARA_SERVICE_PORT/v1.1/\$(tenant_id)s" \
90 "$SAHARA_SERVICE_PROTOCOL://$SAHARA_SERVICE_HOST:$SAHARA_SERVICE_PORT/v1.1/\$(tenant_id)s"
Sergey Lukjanov7ff84432014-03-10 20:04:51 +040091 fi
92}
93
94# cleanup_sahara() - Remove residual data files, anything left over from
95# previous runs that would need to clean up.
96function cleanup_sahara {
97
98 # Cleanup auth cache dir
99 sudo rm -rf $SAHARA_AUTH_CACHE_DIR
100}
101
102# configure_sahara() - Set config files, create data dirs, etc
103function configure_sahara {
104
105 if [[ ! -d $SAHARA_CONF_DIR ]]; then
106 sudo mkdir -p $SAHARA_CONF_DIR
107 fi
108 sudo chown $STACK_USER $SAHARA_CONF_DIR
109
Andrew Lazarev627ca742014-10-29 17:01:15 -0700110 if [[ -f $SAHARA_DIR/etc/sahara/policy.json ]]; then
111 cp -p $SAHARA_DIR/etc/sahara/policy.json $SAHARA_CONF_DIR
112 fi
113
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400114 # Copy over sahara configuration file and configure common parameters.
Sergey Lukjanov51ebda62014-03-12 22:26:12 +0400115 cp $SAHARA_DIR/etc/sahara/sahara.conf.sample $SAHARA_CONF_FILE
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400116
117 # Create auth cache dir
118 sudo mkdir -p $SAHARA_AUTH_CACHE_DIR
119 sudo chown $STACK_USER $SAHARA_AUTH_CACHE_DIR
Andrew Lazarev28d43922014-10-29 17:25:12 -0700120 sudo chmod 700 $SAHARA_AUTH_CACHE_DIR
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400121 rm -rf $SAHARA_AUTH_CACHE_DIR/*
122
Brant Knudson05952372014-09-19 17:22:22 -0500123 configure_auth_token_middleware $SAHARA_CONF_FILE sahara $SAHARA_AUTH_CACHE_DIR
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400124
Vitaly Gridneve50fcb12014-08-11 12:01:12 +0000125 # Set configuration to send notifications
126
127 if is_service_enabled ceilometer; then
128 iniset $SAHARA_CONF_FILE DEFAULT enable_notifications "true"
129 iniset $SAHARA_CONF_FILE DEFAULT notification_driver "messaging"
130 iniset_rpc_backend sahara $SAHARA_CONF_FILE DEFAULT
131 fi
132
Sergey Lukjanov3cd59e12014-03-25 00:06:31 +0400133 iniset $SAHARA_CONF_FILE DEFAULT verbose True
134 iniset $SAHARA_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400135
Sergey Lukjanov10f41612014-04-25 11:42:41 +0400136 iniset $SAHARA_CONF_FILE DEFAULT plugins $SAHARA_ENABLED_PLUGINS
137
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400138 iniset $SAHARA_CONF_FILE database connection `database_connection_url sahara`
139
140 if is_service_enabled neutron; then
141 iniset $SAHARA_CONF_FILE DEFAULT use_neutron true
142 iniset $SAHARA_CONF_FILE DEFAULT use_floating_ips true
Andrew Lazarev4f7e0f22015-02-06 16:16:01 -0800143
144 if is_ssl_enabled_service "neutron" || is_service_enabled tls-proxy; then
145 iniset $SAHARA_CONF_FILE neutron ca_file $SSL_BUNDLE_FILE
146 fi
Andrew Lazarev0943e072014-12-17 16:07:32 -0800147 else
148 iniset $SAHARA_CONF_FILE DEFAULT use_neutron false
149 iniset $SAHARA_CONF_FILE DEFAULT use_floating_ips false
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400150 fi
151
152 if is_service_enabled heat; then
153 iniset $SAHARA_CONF_FILE DEFAULT infrastructure_engine heat
Andrew Lazarev4f7e0f22015-02-06 16:16:01 -0800154
155 if is_ssl_enabled_service "heat" || is_service_enabled tls-proxy; then
156 iniset $SAHARA_CONF_FILE heat ca_file $SSL_BUNDLE_FILE
157 fi
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400158 else
159 iniset $SAHARA_CONF_FILE DEFAULT infrastructure_engine direct
160 fi
161
Andrew Lazarev4f7e0f22015-02-06 16:16:01 -0800162 if is_ssl_enabled_service "cinder" || is_service_enabled tls-proxy; then
163 iniset $SAHARA_CONF_FILE cinder ca_file $SSL_BUNDLE_FILE
164 fi
165
166 if is_ssl_enabled_service "nova" || is_service_enabled tls-proxy; then
167 iniset $SAHARA_CONF_FILE nova ca_file $SSL_BUNDLE_FILE
168 fi
169
170 if is_ssl_enabled_service "swift" || is_service_enabled tls-proxy; then
171 iniset $SAHARA_CONF_FILE swift ca_file $SSL_BUNDLE_FILE
172 fi
173
174 if is_ssl_enabled_service "key" || is_service_enabled tls-proxy; then
175 iniset $SAHARA_CONF_FILE keystone ca_file $SSL_BUNDLE_FILE
176 fi
177
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400178 iniset $SAHARA_CONF_FILE DEFAULT use_syslog $SYSLOG
179
Luigi Toscanob4bef1f2014-04-03 19:24:57 +0200180 # Format logging
181 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
182 setup_colorized_logging $SAHARA_CONF_FILE DEFAULT
183 fi
184
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200185 recreate_database sahara
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400186 $SAHARA_BIN_DIR/sahara-db-manage --config-file $SAHARA_CONF_FILE upgrade head
187}
188
189# install_sahara() - Collect source and prepare
190function install_sahara {
191 git_clone $SAHARA_REPO $SAHARA_DIR $SAHARA_BRANCH
192 setup_develop $SAHARA_DIR
193}
194
Sergey Lukjanova90898d2014-08-05 16:14:12 +0400195# install_python_saharaclient() - Collect source and prepare
196function install_python_saharaclient {
Sean Dagueee5ae7b2014-11-13 13:23:27 -0500197 if use_library_from_git "python-saharaclient"; then
198 git_clone_by_name "python-saharaclient"
199 setup_dev_lib "python-saharaclient"
200 fi
Sergey Lukjanova90898d2014-08-05 16:14:12 +0400201}
202
Andrew Lazarevb3130482014-12-16 14:36:59 -0800203# sahara_register_images() - Registers images in sahara image registry
204function sahara_register_images {
205 if is_service_enabled heat && [[ ! -z "$HEAT_CFN_IMAGE_URL" ]]; then
206 # Register heat image for Fake plugin
207 local fake_plugin_properties="--property _sahara_tag_0.1=True"
208 fake_plugin_properties+=" --property _sahara_tag_fake=True"
209 fake_plugin_properties+=" --property _sahara_username=fedora"
210 openstack --os-url $GLANCE_SERVICE_PROTOCOL://$GLANCE_HOSTPORT image set $(basename "$HEAT_CFN_IMAGE_URL" ".qcow2") $fake_plugin_properties
211 fi
212}
213
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400214# start_sahara() - Start running processes, including screen
215function start_sahara {
Chris Dent2f27a0e2014-09-09 13:46:02 +0100216 run_process sahara "$SAHARA_BIN_DIR/sahara-all --config-file $SAHARA_CONF_FILE"
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400217}
218
219# stop_sahara() - Stop running processes
220function stop_sahara {
221 # Kill the Sahara screen windows
Sean Dague9a413ab2015-02-04 12:44:18 -0500222 stop_process sahara
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400223}
224
225
226# Restore xtrace
227$XTRACE
228
229# Local variables:
230# mode: shell-script
231# End: