blob: 4cb04ecd3abe13c50df6c932b43d773ddfc97e59 [file] [log] [blame]
Sergey Lukjanov7ff84432014-03-10 20:04:51 +04001# lib/sahara
2
3# Dependencies:
4# ``functions`` file
5# ``DEST``, ``DATA_DIR``, ``STACK_USER`` must be defined
6
7# ``stack.sh`` calls the entry points in this order:
8#
9# install_sahara
10# configure_sahara
11# start_sahara
12# stop_sahara
13# cleanup_sahara
14
15# Save trace setting
16XTRACE=$(set +o | grep xtrace)
17set +o xtrace
18
19
20# Defaults
21# --------
22
23# Set up default repos
24SAHARA_REPO=${SAHARA_REPO:-${GIT_BASE}/openstack/sahara.git}
25SAHARA_BRANCH=${SAHARA_BRANCH:-master}
26
27# Set up default directories
28SAHARA_DIR=$DEST/sahara
29SAHARA_CONF_DIR=${SAHARA_CONF_DIR:-/etc/sahara}
30SAHARA_CONF_FILE=${SAHARA_CONF_DIR}/sahara.conf
31SAHARA_DEBUG=${SAHARA_DEBUG:-True}
32
33SAHARA_SERVICE_HOST=${SAHARA_SERVICE_HOST:-$SERVICE_HOST}
34SAHARA_SERVICE_PORT=${SAHARA_SERVICE_PORT:-8386}
35SAHARA_SERVICE_PROTOCOL=${SAHARA_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
36
37SAHARA_AUTH_CACHE_DIR=${SAHARA_AUTH_CACHE_DIR:-/var/cache/sahara}
38
39# Support entry points installation of console scripts
40if [[ -d $SAHARA_DIR/bin ]]; then
41 SAHARA_BIN_DIR=$SAHARA_DIR/bin
42else
43 SAHARA_BIN_DIR=$(get_python_exec_prefix)
44fi
45
46# Tell Tempest this project is present
47TEMPEST_SERVICES+=,sahara
48
49# For backward compatibility with current tests in Tempest
50TEMPEST_SERVICES+=,savanna
51
52
53# 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
63 SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
64 ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
65
66 SAHARA_USER=$(openstack user create \
67 sahara \
68 --password "$SERVICE_PASSWORD" \
69 --project $SERVICE_TENANT \
70 --email sahara@example.com \
71 | grep " id " | get_field 2)
72 openstack role add \
73 $ADMIN_ROLE \
74 --project $SERVICE_TENANT \
75 --user $SAHARA_USER
76
77 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
78 SAHARA_SERVICE=$(openstack service create \
79 sahara \
80 --type=data_processing \
81 --description="Sahara Data Processing" \
82 | grep " id " | get_field 2)
83 openstack endpoint create \
84 $SAHARA_SERVICE \
85 --region RegionOne \
86 --publicurl "$SAHARA_SERVICE_PROTOCOL://$SAHARA_SERVICE_HOST:$SAHARA_SERVICE_PORT/v1.1/\$(tenant_id)s" \
87 --adminurl "$SAHARA_SERVICE_PROTOCOL://$SAHARA_SERVICE_HOST:$SAHARA_SERVICE_PORT/v1.1/\$(tenant_id)s" \
88 --internalurl "$SAHARA_SERVICE_PROTOCOL://$SAHARA_SERVICE_HOST:$SAHARA_SERVICE_PORT/v1.1/\$(tenant_id)s"
89 fi
90}
91
92# cleanup_sahara() - Remove residual data files, anything left over from
93# previous runs that would need to clean up.
94function cleanup_sahara {
95
96 # Cleanup auth cache dir
97 sudo rm -rf $SAHARA_AUTH_CACHE_DIR
98}
99
100# configure_sahara() - Set config files, create data dirs, etc
101function configure_sahara {
102
103 if [[ ! -d $SAHARA_CONF_DIR ]]; then
104 sudo mkdir -p $SAHARA_CONF_DIR
105 fi
106 sudo chown $STACK_USER $SAHARA_CONF_DIR
107
108 # Copy over sahara configuration file and configure common parameters.
109 # TODO(slukjanov): rename when sahara internals will be updated
110 cp $SAHARA_DIR/etc/savanna/savanna.conf.sample $SAHARA_CONF_FILE
111
112 # Create auth cache dir
113 sudo mkdir -p $SAHARA_AUTH_CACHE_DIR
114 sudo chown $STACK_USER $SAHARA_AUTH_CACHE_DIR
115 rm -rf $SAHARA_AUTH_CACHE_DIR/*
116
117 # Set obsolete keystone auth configs for backward compatibility
118 iniset $SAHARA_CONF_FILE DEFAULT os_auth_host $KEYSTONE_SERVICE_HOST
119 iniset $SAHARA_CONF_FILE DEFAULT os_auth_port $KEYSTONE_SERVICE_PORT
120 iniset $SAHARA_CONF_FILE DEFAULT os_auth_protocol $KEYSTONE_SERVICE_PROTOCOL
121 iniset $SAHARA_CONF_FILE DEFAULT os_admin_password $SERVICE_PASSWORD
122 iniset $SAHARA_CONF_FILE DEFAULT os_admin_username sahara
123 iniset $SAHARA_CONF_FILE DEFAULT os_admin_tenant_name $SERVICE_TENANT_NAME
124
125 # Set actual keystone auth configs
126 iniset $SAHARA_CONF_FILE keystone_authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
127 iniset $SAHARA_CONF_FILE keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
128 iniset $SAHARA_CONF_FILE keystone_authtoken admin_user sahara
129 iniset $SAHARA_CONF_FILE keystone_authtoken admin_password $SERVICE_PASSWORD
130 iniset $SAHARA_CONF_FILE keystone_authtoken signing_dir $SAHARA_AUTH_CACHE_DIR
131 iniset $SAHARA_CONF_FILE keystone_authtoken cafile $KEYSTONE_SSL_CA
132
133 iniset $SAHARA_CONF_FILE DEFAULT debug $SAHARA_DEBUG
134
135 iniset $SAHARA_CONF_FILE database connection `database_connection_url sahara`
136
137 if is_service_enabled neutron; then
138 iniset $SAHARA_CONF_FILE DEFAULT use_neutron true
139 iniset $SAHARA_CONF_FILE DEFAULT use_floating_ips true
140 fi
141
142 if is_service_enabled heat; then
143 iniset $SAHARA_CONF_FILE DEFAULT infrastructure_engine heat
144 else
145 iniset $SAHARA_CONF_FILE DEFAULT infrastructure_engine direct
146 fi
147
148 iniset $SAHARA_CONF_FILE DEFAULT use_syslog $SYSLOG
149
150 recreate_database sahara utf8
151 $SAHARA_BIN_DIR/sahara-db-manage --config-file $SAHARA_CONF_FILE upgrade head
152}
153
154# install_sahara() - Collect source and prepare
155function install_sahara {
156 git_clone $SAHARA_REPO $SAHARA_DIR $SAHARA_BRANCH
157 setup_develop $SAHARA_DIR
158}
159
160# start_sahara() - Start running processes, including screen
161function start_sahara {
162 screen_it sahara "cd $SAHARA_DIR && $SAHARA_BIN_DIR/sahara-api --config-file $SAHARA_CONF_FILE"
163}
164
165# stop_sahara() - Stop running processes
166function stop_sahara {
167 # Kill the Sahara screen windows
168 screen -S $SCREEN_NAME -p sahara -X kill
169}
170
171
172# Restore xtrace
173$XTRACE
174
175# Local variables:
176# mode: shell-script
177# End: