blob: 1c8be4929151cd17412ba744ed2a5a37205169cd [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:
Dean Troyerd8864fe2014-02-17 11:00:42 -06005#
6# enable_service marconi-server
Flaper Fesp06b345e2013-09-04 15:35:47 +02007#
8# Dependencies:
9# - functions
10# - OS_AUTH_URL for auth in api
11# - DEST set to the destination directory
12# - SERVICE_PASSWORD, SERVICE_TENANT_NAME for auth in api
13# - STACK_USER service user
14
15# stack.sh
16# ---------
17# install_marconi
18# configure_marconi
19# init_marconi
20# start_marconi
21# stop_marconi
22# cleanup_marconi
23
24# Save trace setting
25XTRACE=$(set +o | grep xtrace)
26set +o xtrace
27
28
29# Defaults
30# --------
31
32# Set up default directories
33MARCONI_DIR=$DEST/marconi
34MARCONICLIENT_DIR=$DEST/python-marconiclient
35MARCONI_CONF_DIR=/etc/marconi
36MARCONI_CONF=$MARCONI_CONF_DIR/marconi.conf
37MARCONI_API_LOG_DIR=/var/log/marconi-api
38MARCONI_AUTH_CACHE_DIR=${MARCONI_AUTH_CACHE_DIR:-/var/cache/marconi}
39
40# Support potential entry-points console scripts
41MARCONI_BIN_DIR=$(get_python_exec_prefix)
42
43# Set up database backend
44MARCONI_BACKEND=${MARCONI_BACKEND:-mongodb}
45
46
47# Set Marconi repository
48MARCONI_REPO=${MARCONI_REPO:-${GIT_BASE}/openstack/marconi.git}
49MARCONI_BRANCH=${MARCONI_BRANCH:-master}
50
51# Set client library repository
52MARCONICLIENT_REPO=${MARCONICLIENT_REPO:-${GIT_BASE}/openstack/python-marconiclient.git}
53MARCONICLIENT_BRANCH=${MARCONICLIENT_BRANCH:-master}
54
Malini Kamalambal67df3b22014-02-20 14:48:59 -050055# Set Marconi Connection Info
56MARCONI_SERVICE_HOST=${MARCONI_SERVICE_HOST:-$SERVICE_HOST}
57MARCONI_SERVICE_PORT=${MARCONI_SERVICE_PORT:-8888}
58MARCONI_SERVICE_PROTOCOL=${MARCONI_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
59
Dean Troyer4237f592014-01-29 16:22:11 -060060# Tell Tempest this project is present
Malini Kamalambal1e4e3ac2014-02-14 11:29:26 -050061TEMPEST_SERVICES+=,marconi
Dean Troyer4237f592014-01-29 16:22:11 -060062
63
Flaper Fesp06b345e2013-09-04 15:35:47 +020064# Functions
65# ---------
66
Malini Kamalambal9972ec22014-02-10 11:22:39 -050067# Test if any Marconi services are enabled
68# is_marconi_enabled
69function is_marconi_enabled {
70 [[ ,${ENABLED_SERVICES} =~ ,"marconi-" ]] && return 0
71 return 1
72}
73
Flaper Fesp06b345e2013-09-04 15:35:47 +020074# cleanup_marconi() - Remove residual data files, anything left over from previous
75# runs that a clean run would need to clean up
76function cleanup_marconi() {
Malini Kamalambal2dcc7742014-02-18 13:45:18 -050077 if ! timeout $SERVICE_TIMEOUT sh -c "while ! mongo marconi --eval 'db.dropDatabase();'; do sleep 1; done"; then
78 die $LINENO "Mongo DB did not start"
79 fi
Flaper Fesp06b345e2013-09-04 15:35:47 +020080}
81
82# configure_marconiclient() - Set config files, create data dirs, etc
83function configure_marconiclient() {
84 setup_develop $MARCONICLIENT_DIR
85}
86
87# configure_marconi() - Set config files, create data dirs, etc
88function configure_marconi() {
89 setup_develop $MARCONI_DIR
90
91 [ ! -d $MARCONI_CONF_DIR ] && sudo mkdir -m 755 -p $MARCONI_CONF_DIR
92 sudo chown $USER $MARCONI_CONF_DIR
93
94 [ ! -d $MARCONI_API_LOG_DIR ] && sudo mkdir -m 755 -p $MARCONI_API_LOG_DIR
95 sudo chown $USER $MARCONI_API_LOG_DIR
96
97 iniset $MARCONI_CONF DEFAULT verbose True
Malini Kamalambal67df3b22014-02-20 14:48:59 -050098 iniset $MARCONI_CONF 'drivers:transport:wsgi' bind $MARCONI_SERVICE_HOST
Flaper Fesp06b345e2013-09-04 15:35:47 +020099
Flaper Fesp06b345e2013-09-04 15:35:47 +0200100 iniset $MARCONI_CONF keystone_authtoken auth_protocol http
101 iniset $MARCONI_CONF keystone_authtoken admin_user marconi
102 iniset $MARCONI_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
103 iniset $MARCONI_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
104 iniset $MARCONI_CONF keystone_authtoken signing_dir $MARCONI_AUTH_CACHE_DIR
105
106 if [[ "$MARCONI_BACKEND" = 'mongodb' ]]; then
107 iniset $MARCONI_CONF database connection mongodb://localhost:27017/marconi
108 configure_mongodb
109 cleanup_marconi
110 fi
111}
112
113function configure_mongodb() {
114 # Set nssize to 2GB. This increases the number of namespaces supported
115 # # per database.
Dean Troyer41d96d72014-02-11 09:08:35 -0600116 if is_ubuntu; then
117 sudo sed -i -e "
118 s|[^ \t]*#[ \t]*\(nssize[ \t]*=.*\$\)|\1|
119 s|^\(nssize[ \t]*=[ \t]*\).*\$|\1 2047|
120 " /etc/mongodb.conf
121 restart_service mongodb
122 elif is_fedora; then
123 sudo sed -i '/--nssize/!s/OPTIONS=\"/OPTIONS=\"--nssize 2047 /' /etc/sysconfig/mongod
124 restart_service mongod
125 fi
Flaper Fesp06b345e2013-09-04 15:35:47 +0200126}
127
128# init_marconi() - Initialize etc.
129function init_marconi() {
130 # Create cache dir
131 sudo mkdir -p $MARCONI_AUTH_CACHE_DIR
132 sudo chown $STACK_USER $MARCONI_AUTH_CACHE_DIR
133 rm -f $MARCONI_AUTH_CACHE_DIR/*
134}
135
136# install_marconi() - Collect source and prepare
137function install_marconi() {
138 git_clone $MARCONI_REPO $MARCONI_DIR $MARCONI_BRANCH
139 setup_develop $MARCONI_DIR
140}
141
142# install_marconiclient() - Collect source and prepare
143function install_marconiclient() {
144 git_clone $MARCONICLIENT_REPO $MARCONICLIENT_DIR $MARCONICLIENT_BRANCH
145 setup_develop $MARCONICLIENT_DIR
146}
147
148# start_marconi() - Start running processes, including screen
149function start_marconi() {
150 screen_it marconi-server "marconi-server --config-file $MARCONI_CONF"
Malini Kamalambal67df3b22014-02-20 14:48:59 -0500151 echo "Waiting for Marconi to start..."
152 if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget --no-proxy -q -O- $MARCONI_SERVICE_PROTOCOL://$MARCONI_SERVICE_HOST:$MARCONI_SERVICE_PORT/v1/health; do sleep 1; done"; then
153 die $LINENO "Marconi did not start"
154 fi
Flaper Fesp06b345e2013-09-04 15:35:47 +0200155}
156
157# stop_marconi() - Stop running processes
158function stop_marconi() {
159 # Kill the marconi screen windows
160 for serv in marconi-server; do
161 screen -S $SCREEN_NAME -p $serv -X kill
162 done
163}
164
165function create_marconi_accounts() {
Steve Martinelli19685422014-01-24 13:02:26 -0600166 SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
167 ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
Flaper Fesp06b345e2013-09-04 15:35:47 +0200168
Steve Martinelli19685422014-01-24 13:02:26 -0600169 MARCONI_USER=$(openstack user create \
170 marconi \
171 --password "$SERVICE_PASSWORD" \
172 --project $SERVICE_TENANT \
173 --email marconi@example.com \
174 | grep " id " | get_field 2)
175 openstack role add \
176 $ADMIN_ROLE \
177 --project $SERVICE_TENANT \
178 --user $MARCONI_USER
Malini Kamalambal0b3aacc2014-02-13 18:18:51 -0500179
Flaper Fesp06b345e2013-09-04 15:35:47 +0200180 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Steve Martinelli19685422014-01-24 13:02:26 -0600181 MARCONI_SERVICE=$(openstack service create \
182 marconi \
Flaper Fesp06b345e2013-09-04 15:35:47 +0200183 --type=queuing \
Malini Kamalambal0f7ad6b2013-12-13 12:42:31 -0500184 --description="Marconi Service" \
185 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -0600186 openstack endpoint create \
187 $MARCONI_SERVICE \
Flaper Fesp06b345e2013-09-04 15:35:47 +0200188 --region RegionOne \
Malini Kamalambal67df3b22014-02-20 14:48:59 -0500189 --publicurl "$MARCONI_SERVICE_PROTOCOL://$MARCONI_SERVICE_HOST:$MARCONI_SERVICE_PORT" \
190 --adminurl "$MARCONI_SERVICE_PROTOCOL://$MARCONI_SERVICE_HOST:$MARCONI_SERVICE_PORT" \
191 --internalurl "$MARCONI_SERVICE_PROTOCOL://$MARCONI_SERVICE_HOST:$MARCONI_SERVICE_PORT"
Flaper Fesp06b345e2013-09-04 15:35:47 +0200192 fi
193
194}
195
196
197# Restore xtrace
198$XTRACE
199
200# Local variables:
201# mode: shell-script
202# End: