Skip to content

Commit d591a25

Browse files
author
Steven Hardy
committed
Add support for tuskar-api service
Adds initial support for configuring and starting the tuskar-api service. To enable, add the following to your localrc: enable_service tuskar enable_service tuskar-api The aim of this addition is to provide a more accessible (non devtest) way for developers to run up tuskar in a familiar devstack environment. See the official repos for more information: https://github.com/openstack/tuskar/ https://github.com/openstack/python-tuskarclient Change-Id: Id0c3c0d3a38100c66dbe6e3adf1f715162f99742
1 parent dd69403 commit d591a25

File tree

2 files changed

+206
-0
lines changed

2 files changed

+206
-0
lines changed

doc/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ Scripts
165165
* `extras.d/60-ceph.sh <extras.d/60-ceph.sh.html>`__
166166
* `extras.d/70-sahara.sh <extras.d/70-sahara.sh.html>`__
167167
* `extras.d/70-trove.sh <extras.d/70-trove.sh.html>`__
168+
* `extras.d/70-tuskar.sh <extras.d/70-tuskar.sh.html>`__
168169
* `extras.d/70-zaqar.sh <extras.d/70-zaqar.sh.html>`__
169170
* `extras.d/80-opendaylight.sh <extras.d/80-opendaylight.sh.html>`__
170171
* `extras.d/80-tempest.sh <extras.d/80-tempest.sh.html>`__

extras.d/70-tuskar.sh

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
# Install and start the **Tuskar** service
2+
#
3+
# To enable, add the following to your localrc
4+
#
5+
# enable_service tuskar
6+
# enable_service tuskar-api
7+
8+
9+
if is_service_enabled tuskar; then
10+
if [[ "$1" == "source" ]]; then
11+
# Initial source, do nothing as functions sourced
12+
# are below rather than in lib/tuskar
13+
echo_summary "source extras tuskar"
14+
elif [[ "$1" == "stack" && "$2" == "install" ]]; then
15+
echo_summary "Installing Tuskar"
16+
install_tuskarclient
17+
install_tuskar
18+
elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then
19+
echo_summary "Configuring Tuskar"
20+
configure_tuskar
21+
configure_tuskarclient
22+
23+
if is_service_enabled key; then
24+
create_tuskar_accounts
25+
fi
26+
27+
elif [[ "$1" == "stack" && "$2" == "extra" ]]; then
28+
echo_summary "Initializing Tuskar"
29+
init_tuskar
30+
start_tuskar
31+
fi
32+
33+
if [[ "$1" == "unstack" ]]; then
34+
stop_tuskar
35+
fi
36+
fi
37+
38+
# library code (equivalent to lib/tuskar)
39+
# ---------
40+
# - install_tuskarclient
41+
# - install_tuskar
42+
# - configure_tuskarclient
43+
# - configure_tuskar
44+
# - init_tuskar
45+
# - start_tuskar
46+
# - stop_tuskar
47+
# - cleanup_tuskar
48+
49+
# Save trace setting
50+
XTRACE=$(set +o | grep xtrace)
51+
set +o xtrace
52+
53+
54+
# Defaults
55+
# --------
56+
57+
# tuskar repos
58+
TUSKAR_REPO=${TUSKAR_REPO:-${GIT_BASE}/openstack/tuskar.git}
59+
TUSKAR_BRANCH=${TUSKAR_BRANCH:-master}
60+
61+
TUSKARCLIENT_REPO=${TUSKARCLIENT_REPO:-${GIT_BASE}/openstack/python-tuskarclient.git}
62+
TUSKARCLIENT_BRANCH=${TUSKARCLIENT_BRANCH:-master}
63+
64+
# set up default directories
65+
TUSKAR_DIR=$DEST/tuskar
66+
TUSKARCLIENT_DIR=$DEST/python-tuskarclient
67+
TUSKAR_AUTH_CACHE_DIR=${TUSKAR_AUTH_CACHE_DIR:-/var/cache/tuskar}
68+
TUSKAR_STANDALONE=`trueorfalse False $TUSKAR_STANDALONE`
69+
TUSKAR_CONF_DIR=/etc/tuskar
70+
TUSKAR_CONF=$TUSKAR_CONF_DIR/tuskar.conf
71+
TUSKAR_API_HOST=${TUSKAR_API_HOST:-$HOST_IP}
72+
TUSKAR_API_PORT=${TUSKAR_API_PORT:-8585}
73+
74+
# Tell Tempest this project is present
75+
TEMPEST_SERVICES+=,tuskar
76+
77+
# Functions
78+
# ---------
79+
80+
# Test if any Tuskar services are enabled
81+
# is_tuskar_enabled
82+
function is_tuskar_enabled {
83+
[[ ,${ENABLED_SERVICES} =~ ,"tuskar-" ]] && return 0
84+
return 1
85+
}
86+
87+
# cleanup_tuskar() - Remove residual data files, anything left over from previous
88+
# runs that a clean run would need to clean up
89+
function cleanup_tuskar {
90+
sudo rm -rf $TUSKAR_AUTH_CACHE_DIR
91+
}
92+
93+
# configure_tuskar() - Set config files, create data dirs, etc
94+
function configure_tuskar {
95+
setup_develop $TUSKAR_DIR
96+
97+
if [[ ! -d $TUSKAR_CONF_DIR ]]; then
98+
sudo mkdir -p $TUSKAR_CONF_DIR
99+
fi
100+
sudo chown $STACK_USER $TUSKAR_CONF_DIR
101+
# remove old config files
102+
rm -f $TUSKAR_CONF_DIR/tuskar-*.conf
103+
104+
TUSKAR_POLICY_FILE=$TUSKAR_CONF_DIR/policy.json
105+
106+
cp $TUSKAR_DIR/etc/tuskar/policy.json $TUSKAR_POLICY_FILE
107+
cp $TUSKAR_DIR/etc/tuskar/tuskar.conf.sample $TUSKAR_CONF
108+
109+
# common options
110+
iniset $TUSKAR_CONF database connection `database_connection_url tuskar`
111+
112+
# logging
113+
iniset $TUSKAR_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
114+
iniset $TUSKAR_CONF DEFAULT use_syslog $SYSLOG
115+
if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
116+
# Add color to logging output
117+
setup_colorized_logging $TUSKAR_CONF DEFAULT tenant user
118+
fi
119+
120+
configure_auth_token_middleware $TUSKAR_CONF tuskar $TUSKAR_AUTH_CACHE_DIR
121+
122+
if is_ssl_enabled_service "key"; then
123+
iniset $TUSKAR_CONF clients_keystone ca_file $SSL_BUNDLE_FILE
124+
fi
125+
126+
iniset $TUSKAR_CONF tuskar_api bind_port $TUSKAR_API_PORT
127+
128+
}
129+
130+
# init_tuskar() - Initialize database
131+
function init_tuskar {
132+
133+
# (re)create tuskar database
134+
recreate_database tuskar utf8
135+
136+
tuskar-dbsync --config-file $TUSKAR_CONF
137+
create_tuskar_cache_dir
138+
}
139+
140+
# create_tuskar_cache_dir() - Part of the init_tuskar() process
141+
function create_tuskar_cache_dir {
142+
# Create cache dirs
143+
sudo mkdir -p $TUSKAR_AUTH_CACHE_DIR
144+
sudo chown $STACK_USER $TUSKAR_AUTH_CACHE_DIR
145+
}
146+
147+
# install_tuskarclient() - Collect source and prepare
148+
function install_tuskarclient {
149+
git_clone $TUSKARCLIENT_REPO $TUSKARCLIENT_DIR $TUSKARCLIENT_BRANCH
150+
setup_develop $TUSKARCLIENT_DIR
151+
}
152+
153+
# configure_tuskarclient() - Set config files, create data dirs, etc
154+
function configure_tuskarclient {
155+
setup_develop $TUSKARCLIENT_DIR
156+
}
157+
158+
# install_tuskar() - Collect source and prepare
159+
function install_tuskar {
160+
git_clone $TUSKAR_REPO $TUSKAR_DIR $TUSKAR_BRANCH
161+
}
162+
163+
# start_tuskar() - Start running processes, including screen
164+
function start_tuskar {
165+
run_process tuskar-api "tuskar-api --config-file=$TUSKAR_CONF"
166+
}
167+
168+
# stop_tuskar() - Stop running processes
169+
function stop_tuskar {
170+
# Kill the screen windows
171+
local serv
172+
for serv in tuskar-api; do
173+
stop_process $serv
174+
done
175+
}
176+
177+
# create_tuskar_accounts() - Set up common required tuskar accounts
178+
function create_tuskar_accounts {
179+
# migrated from files/keystone_data.sh
180+
local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
181+
local admin_role=$(openstack role list | awk "/ admin / { print \$2 }")
182+
183+
local tuskar_user=$(get_or_create_user "tuskar" \
184+
"$SERVICE_PASSWORD" $service_tenant)
185+
get_or_add_user_role $admin_role $tuskar_user $service_tenant
186+
187+
if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
188+
189+
local tuskar_service=$(get_or_create_service "tuskar" \
190+
"management" "Tuskar Management Service")
191+
get_or_create_endpoint $tuskar_service \
192+
"$REGION_NAME" \
193+
"$SERVICE_PROTOCOL://$TUSKAR_API_HOST:$TUSKAR_API_PORT" \
194+
"$SERVICE_PROTOCOL://$TUSKAR_API_HOST:$TUSKAR_API_PORT" \
195+
"$SERVICE_PROTOCOL://$TUSKAR_API_HOST:$TUSKAR_API_PORT"
196+
fi
197+
}
198+
199+
# Restore xtrace
200+
$XTRACE
201+
202+
# Tell emacs to use shell-script-mode
203+
## Local variables:
204+
## mode: shell-script
205+
## End:

0 commit comments

Comments
 (0)