blob: b6ce57a295569a61dfcd793d94eb43400513d130 [file] [log] [blame]
Flaper Fesp06b345e2013-09-04 15:35:47 +02001# lib/marconi
2# Install and start **Marconi** service
3
4# To enable a minimal set of Marconi services, add the following to localrc:
5# enable_service marconi-server
6#
7# Dependencies:
8# - functions
9# - OS_AUTH_URL for auth in api
10# - DEST set to the destination directory
11# - SERVICE_PASSWORD, SERVICE_TENANT_NAME for auth in api
12# - STACK_USER service user
13
14# stack.sh
15# ---------
16# install_marconi
17# configure_marconi
18# init_marconi
19# start_marconi
20# stop_marconi
21# cleanup_marconi
22
23# Save trace setting
24XTRACE=$(set +o | grep xtrace)
25set +o xtrace
26
27
28# Defaults
29# --------
30
31# Set up default directories
32MARCONI_DIR=$DEST/marconi
33MARCONICLIENT_DIR=$DEST/python-marconiclient
34MARCONI_CONF_DIR=/etc/marconi
35MARCONI_CONF=$MARCONI_CONF_DIR/marconi.conf
36MARCONI_API_LOG_DIR=/var/log/marconi-api
37MARCONI_AUTH_CACHE_DIR=${MARCONI_AUTH_CACHE_DIR:-/var/cache/marconi}
38
39# Support potential entry-points console scripts
40MARCONI_BIN_DIR=$(get_python_exec_prefix)
41
42# Set up database backend
43MARCONI_BACKEND=${MARCONI_BACKEND:-mongodb}
44
45
46# Set Marconi repository
47MARCONI_REPO=${MARCONI_REPO:-${GIT_BASE}/openstack/marconi.git}
48MARCONI_BRANCH=${MARCONI_BRANCH:-master}
49
50# Set client library repository
51MARCONICLIENT_REPO=${MARCONICLIENT_REPO:-${GIT_BASE}/openstack/python-marconiclient.git}
52MARCONICLIENT_BRANCH=${MARCONICLIENT_BRANCH:-master}
53
Dean Troyer4237f592014-01-29 16:22:11 -060054# Tell Tempest this project is present
Malini Kamalambal1e4e3ac2014-02-14 11:29:26 -050055TEMPEST_SERVICES+=,marconi
Dean Troyer4237f592014-01-29 16:22:11 -060056
57
Flaper Fesp06b345e2013-09-04 15:35:47 +020058# Functions
59# ---------
60
Malini Kamalambal9972ec22014-02-10 11:22:39 -050061# Test if any Marconi services are enabled
62# is_marconi_enabled
63function is_marconi_enabled {
64 [[ ,${ENABLED_SERVICES} =~ ,"marconi-" ]] && return 0
65 return 1
66}
67
Flaper Fesp06b345e2013-09-04 15:35:47 +020068# cleanup_marconi() - Remove residual data files, anything left over from previous
69# runs that a clean run would need to clean up
70function cleanup_marconi() {
Malini Kamalambal2dcc7742014-02-18 13:45:18 -050071 if ! timeout $SERVICE_TIMEOUT sh -c "while ! mongo marconi --eval 'db.dropDatabase();'; do sleep 1; done"; then
72 die $LINENO "Mongo DB did not start"
73 fi
Flaper Fesp06b345e2013-09-04 15:35:47 +020074}
75
76# configure_marconiclient() - Set config files, create data dirs, etc
77function configure_marconiclient() {
78 setup_develop $MARCONICLIENT_DIR
79}
80
81# configure_marconi() - Set config files, create data dirs, etc
82function configure_marconi() {
83 setup_develop $MARCONI_DIR
84
85 [ ! -d $MARCONI_CONF_DIR ] && sudo mkdir -m 755 -p $MARCONI_CONF_DIR
86 sudo chown $USER $MARCONI_CONF_DIR
87
88 [ ! -d $MARCONI_API_LOG_DIR ] && sudo mkdir -m 755 -p $MARCONI_API_LOG_DIR
89 sudo chown $USER $MARCONI_API_LOG_DIR
90
91 iniset $MARCONI_CONF DEFAULT verbose True
92 iniset $MARCONI_CONF 'drivers:transport:wsgi' bind '0.0.0.0'
93
Flaper Fesp06b345e2013-09-04 15:35:47 +020094 iniset $MARCONI_CONF keystone_authtoken auth_protocol http
95 iniset $MARCONI_CONF keystone_authtoken admin_user marconi
96 iniset $MARCONI_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
97 iniset $MARCONI_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
98 iniset $MARCONI_CONF keystone_authtoken signing_dir $MARCONI_AUTH_CACHE_DIR
99
100 if [[ "$MARCONI_BACKEND" = 'mongodb' ]]; then
101 iniset $MARCONI_CONF database connection mongodb://localhost:27017/marconi
102 configure_mongodb
103 cleanup_marconi
104 fi
105}
106
107function configure_mongodb() {
108 # Set nssize to 2GB. This increases the number of namespaces supported
109 # # per database.
Dean Troyer41d96d72014-02-11 09:08:35 -0600110 if is_ubuntu; then
111 sudo sed -i -e "
112 s|[^ \t]*#[ \t]*\(nssize[ \t]*=.*\$\)|\1|
113 s|^\(nssize[ \t]*=[ \t]*\).*\$|\1 2047|
114 " /etc/mongodb.conf
115 restart_service mongodb
116 elif is_fedora; then
117 sudo sed -i '/--nssize/!s/OPTIONS=\"/OPTIONS=\"--nssize 2047 /' /etc/sysconfig/mongod
118 restart_service mongod
119 fi
Flaper Fesp06b345e2013-09-04 15:35:47 +0200120}
121
122# init_marconi() - Initialize etc.
123function init_marconi() {
124 # Create cache dir
125 sudo mkdir -p $MARCONI_AUTH_CACHE_DIR
126 sudo chown $STACK_USER $MARCONI_AUTH_CACHE_DIR
127 rm -f $MARCONI_AUTH_CACHE_DIR/*
128}
129
130# install_marconi() - Collect source and prepare
131function install_marconi() {
132 git_clone $MARCONI_REPO $MARCONI_DIR $MARCONI_BRANCH
133 setup_develop $MARCONI_DIR
134}
135
136# install_marconiclient() - Collect source and prepare
137function install_marconiclient() {
138 git_clone $MARCONICLIENT_REPO $MARCONICLIENT_DIR $MARCONICLIENT_BRANCH
139 setup_develop $MARCONICLIENT_DIR
140}
141
142# start_marconi() - Start running processes, including screen
143function start_marconi() {
144 screen_it marconi-server "marconi-server --config-file $MARCONI_CONF"
145}
146
147# stop_marconi() - Stop running processes
148function stop_marconi() {
149 # Kill the marconi screen windows
150 for serv in marconi-server; do
151 screen -S $SCREEN_NAME -p $serv -X kill
152 done
153}
154
155function create_marconi_accounts() {
Steve Martinelli19685422014-01-24 13:02:26 -0600156 SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
157 ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
Flaper Fesp06b345e2013-09-04 15:35:47 +0200158
Steve Martinelli19685422014-01-24 13:02:26 -0600159 MARCONI_USER=$(openstack user create \
160 marconi \
161 --password "$SERVICE_PASSWORD" \
162 --project $SERVICE_TENANT \
163 --email marconi@example.com \
164 | grep " id " | get_field 2)
165 openstack role add \
166 $ADMIN_ROLE \
167 --project $SERVICE_TENANT \
168 --user $MARCONI_USER
Malini Kamalambal0b3aacc2014-02-13 18:18:51 -0500169
Flaper Fesp06b345e2013-09-04 15:35:47 +0200170 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Steve Martinelli19685422014-01-24 13:02:26 -0600171 MARCONI_SERVICE=$(openstack service create \
172 marconi \
Flaper Fesp06b345e2013-09-04 15:35:47 +0200173 --type=queuing \
Malini Kamalambal0f7ad6b2013-12-13 12:42:31 -0500174 --description="Marconi Service" \
175 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -0600176 openstack endpoint create \
177 $MARCONI_SERVICE \
Flaper Fesp06b345e2013-09-04 15:35:47 +0200178 --region RegionOne \
Flaper Fesp06b345e2013-09-04 15:35:47 +0200179 --publicurl "http://$SERVICE_HOST:8888" \
180 --adminurl "http://$SERVICE_HOST:8888" \
181 --internalurl "http://$SERVICE_HOST:8888"
182 fi
183
184}
185
186
187# Restore xtrace
188$XTRACE
189
190# Local variables:
191# mode: shell-script
192# End: