blob: c902d385d16a77feeffe1683cfdea93108f3c567 [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
14# start_sahara
15# stop_sahara
16# cleanup_sahara
17
18# Save trace setting
19XTRACE=$(set +o | grep xtrace)
20set +o xtrace
21
22
23# Defaults
24# --------
25
26# Set up default repos
Sergey Lukjanova90898d2014-08-05 16:14:12 +040027
Sergey Lukjanov7ff84432014-03-10 20:04:51 +040028# Set up default directories
Sean Dagueee5ae7b2014-11-13 13:23:27 -050029GITDIR["python-saharaclient"]=$DEST/python-saharaclient
Sergey Lukjanov7ff84432014-03-10 20:04:51 +040030SAHARA_DIR=$DEST/sahara
Sergey Lukjanova90898d2014-08-05 16:14:12 +040031
Sergey Lukjanov7ff84432014-03-10 20:04:51 +040032SAHARA_CONF_DIR=${SAHARA_CONF_DIR:-/etc/sahara}
33SAHARA_CONF_FILE=${SAHARA_CONF_DIR}/sahara.conf
Sergey Lukjanov7ff84432014-03-10 20:04:51 +040034
35SAHARA_SERVICE_HOST=${SAHARA_SERVICE_HOST:-$SERVICE_HOST}
36SAHARA_SERVICE_PORT=${SAHARA_SERVICE_PORT:-8386}
37SAHARA_SERVICE_PROTOCOL=${SAHARA_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
38
39SAHARA_AUTH_CACHE_DIR=${SAHARA_AUTH_CACHE_DIR:-/var/cache/sahara}
40
Sergey Lukjanov10f41612014-04-25 11:42:41 +040041SAHARA_ENABLED_PLUGINS=${SAHARA_ENABLED_PLUGINS:-vanilla,hdp,fake}
42
Sergey Lukjanov7ff84432014-03-10 20:04:51 +040043# Support entry points installation of console scripts
44if [[ -d $SAHARA_DIR/bin ]]; then
45 SAHARA_BIN_DIR=$SAHARA_DIR/bin
46else
47 SAHARA_BIN_DIR=$(get_python_exec_prefix)
48fi
49
50# Tell Tempest this project is present
51TEMPEST_SERVICES+=,sahara
52
Sergey Lukjanov7ff84432014-03-10 20:04:51 +040053# Functions
54# ---------
55
56# create_sahara_accounts() - Set up common required sahara accounts
57#
58# Tenant User Roles
59# ------------------------------
60# service sahara admin
61function create_sahara_accounts {
62
Dean Troyer16ef9762014-08-19 19:31:34 -050063 local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
64 local admin_role=$(openstack role list | awk "/ admin / { print \$2 }")
Sergey Lukjanov7ff84432014-03-10 20:04:51 +040065
Dean Troyer16ef9762014-08-19 19:31:34 -050066 local sahara_user=$(get_or_create_user "sahara" \
67 "$SERVICE_PASSWORD" $service_tenant)
68 get_or_add_user_role $admin_role $sahara_user $service_tenant
Sergey Lukjanov7ff84432014-03-10 20:04:51 +040069
70 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +010071
Dean Troyer16ef9762014-08-19 19:31:34 -050072 local sahara_service=$(get_or_create_service "sahara" \
Bartosz Górski0abde392014-02-28 14:15:19 +010073 "data_processing" "Sahara Data Processing")
Dean Troyer16ef9762014-08-19 19:31:34 -050074 get_or_create_endpoint $sahara_service \
Bartosz Górski0abde392014-02-28 14:15:19 +010075 "$REGION_NAME" \
76 "$SAHARA_SERVICE_PROTOCOL://$SAHARA_SERVICE_HOST:$SAHARA_SERVICE_PORT/v1.1/\$(tenant_id)s" \
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"
Sergey Lukjanov7ff84432014-03-10 20:04:51 +040079 fi
80}
81
82# cleanup_sahara() - Remove residual data files, anything left over from
83# previous runs that would need to clean up.
84function cleanup_sahara {
85
86 # Cleanup auth cache dir
87 sudo rm -rf $SAHARA_AUTH_CACHE_DIR
88}
89
90# configure_sahara() - Set config files, create data dirs, etc
91function configure_sahara {
92
93 if [[ ! -d $SAHARA_CONF_DIR ]]; then
94 sudo mkdir -p $SAHARA_CONF_DIR
95 fi
96 sudo chown $STACK_USER $SAHARA_CONF_DIR
97
Andrew Lazarev627ca742014-10-29 17:01:15 -070098 if [[ -f $SAHARA_DIR/etc/sahara/policy.json ]]; then
99 cp -p $SAHARA_DIR/etc/sahara/policy.json $SAHARA_CONF_DIR
100 fi
101
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400102 # Copy over sahara configuration file and configure common parameters.
Sergey Lukjanov51ebda62014-03-12 22:26:12 +0400103 cp $SAHARA_DIR/etc/sahara/sahara.conf.sample $SAHARA_CONF_FILE
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400104
105 # Create auth cache dir
106 sudo mkdir -p $SAHARA_AUTH_CACHE_DIR
107 sudo chown $STACK_USER $SAHARA_AUTH_CACHE_DIR
Andrew Lazarev28d43922014-10-29 17:25:12 -0700108 sudo chmod 700 $SAHARA_AUTH_CACHE_DIR
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400109 rm -rf $SAHARA_AUTH_CACHE_DIR/*
110
Brant Knudson05952372014-09-19 17:22:22 -0500111 configure_auth_token_middleware $SAHARA_CONF_FILE sahara $SAHARA_AUTH_CACHE_DIR
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400112
Vitaly Gridneve50fcb12014-08-11 12:01:12 +0000113 # Set configuration to send notifications
114
115 if is_service_enabled ceilometer; then
116 iniset $SAHARA_CONF_FILE DEFAULT enable_notifications "true"
117 iniset $SAHARA_CONF_FILE DEFAULT notification_driver "messaging"
118 iniset_rpc_backend sahara $SAHARA_CONF_FILE DEFAULT
119 fi
120
Sergey Lukjanov3cd59e12014-03-25 00:06:31 +0400121 iniset $SAHARA_CONF_FILE DEFAULT verbose True
122 iniset $SAHARA_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400123
Sergey Lukjanov10f41612014-04-25 11:42:41 +0400124 iniset $SAHARA_CONF_FILE DEFAULT plugins $SAHARA_ENABLED_PLUGINS
125
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400126 iniset $SAHARA_CONF_FILE database connection `database_connection_url sahara`
127
128 if is_service_enabled neutron; then
129 iniset $SAHARA_CONF_FILE DEFAULT use_neutron true
130 iniset $SAHARA_CONF_FILE DEFAULT use_floating_ips true
131 fi
132
133 if is_service_enabled heat; then
134 iniset $SAHARA_CONF_FILE DEFAULT infrastructure_engine heat
135 else
136 iniset $SAHARA_CONF_FILE DEFAULT infrastructure_engine direct
137 fi
138
139 iniset $SAHARA_CONF_FILE DEFAULT use_syslog $SYSLOG
140
Luigi Toscanob4bef1f2014-04-03 19:24:57 +0200141 # Format logging
142 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
143 setup_colorized_logging $SAHARA_CONF_FILE DEFAULT
144 fi
145
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400146 recreate_database sahara utf8
147 $SAHARA_BIN_DIR/sahara-db-manage --config-file $SAHARA_CONF_FILE upgrade head
148}
149
150# install_sahara() - Collect source and prepare
151function install_sahara {
152 git_clone $SAHARA_REPO $SAHARA_DIR $SAHARA_BRANCH
153 setup_develop $SAHARA_DIR
154}
155
Sergey Lukjanova90898d2014-08-05 16:14:12 +0400156# install_python_saharaclient() - Collect source and prepare
157function install_python_saharaclient {
Sean Dagueee5ae7b2014-11-13 13:23:27 -0500158 if use_library_from_git "python-saharaclient"; then
159 git_clone_by_name "python-saharaclient"
160 setup_dev_lib "python-saharaclient"
161 fi
Sergey Lukjanova90898d2014-08-05 16:14:12 +0400162}
163
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400164# start_sahara() - Start running processes, including screen
165function start_sahara {
Chris Dent2f27a0e2014-09-09 13:46:02 +0100166 run_process sahara "$SAHARA_BIN_DIR/sahara-all --config-file $SAHARA_CONF_FILE"
Sergey Lukjanov7ff84432014-03-10 20:04:51 +0400167}
168
169# stop_sahara() - Stop running processes
170function stop_sahara {
171 # Kill the Sahara screen windows
172 screen -S $SCREEN_NAME -p sahara -X kill
173}
174
175
176# Restore xtrace
177$XTRACE
178
179# Local variables:
180# mode: shell-script
181# End: