Browse code

Merge "Add support for tuskar-api service"

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