blob: 29ae386d9f03c8fbfa841412ce893c6eb6b72a51 [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
Ian Wienandaee18c72014-02-21 15:35:08 +110076function 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
Ian Wienandaee18c72014-02-21 15:35:08 +110083function configure_marconiclient {
Flaper Fesp06b345e2013-09-04 15:35:47 +020084 setup_develop $MARCONICLIENT_DIR
85}
86
87# configure_marconi() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +110088function configure_marconi {
Flaper Fesp06b345e2013-09-04 15:35:47 +020089 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 Kamalambal2e978dd2014-02-28 14:06:59 -050098 iniset $MARCONI_CONF DEFAULT use_syslog $SYSLOG
Malini Kamalambal67df3b22014-02-20 14:48:59 -050099 iniset $MARCONI_CONF 'drivers:transport:wsgi' bind $MARCONI_SERVICE_HOST
Flaper Fesp06b345e2013-09-04 15:35:47 +0200100
Flaper Fesp06b345e2013-09-04 15:35:47 +0200101 iniset $MARCONI_CONF keystone_authtoken auth_protocol http
102 iniset $MARCONI_CONF keystone_authtoken admin_user marconi
103 iniset $MARCONI_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
104 iniset $MARCONI_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
105 iniset $MARCONI_CONF keystone_authtoken signing_dir $MARCONI_AUTH_CACHE_DIR
106
107 if [[ "$MARCONI_BACKEND" = 'mongodb' ]]; then
108 iniset $MARCONI_CONF database connection mongodb://localhost:27017/marconi
109 configure_mongodb
110 cleanup_marconi
111 fi
112}
113
Ian Wienandaee18c72014-02-21 15:35:08 +1100114function configure_mongodb {
Flaper Fesp06b345e2013-09-04 15:35:47 +0200115 # Set nssize to 2GB. This increases the number of namespaces supported
116 # # per database.
Dean Troyer41d96d72014-02-11 09:08:35 -0600117 if is_ubuntu; then
118 sudo sed -i -e "
119 s|[^ \t]*#[ \t]*\(nssize[ \t]*=.*\$\)|\1|
120 s|^\(nssize[ \t]*=[ \t]*\).*\$|\1 2047|
121 " /etc/mongodb.conf
122 restart_service mongodb
123 elif is_fedora; then
124 sudo sed -i '/--nssize/!s/OPTIONS=\"/OPTIONS=\"--nssize 2047 /' /etc/sysconfig/mongod
125 restart_service mongod
126 fi
Flaper Fesp06b345e2013-09-04 15:35:47 +0200127}
128
129# init_marconi() - Initialize etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100130function init_marconi {
Flaper Fesp06b345e2013-09-04 15:35:47 +0200131 # Create cache dir
132 sudo mkdir -p $MARCONI_AUTH_CACHE_DIR
133 sudo chown $STACK_USER $MARCONI_AUTH_CACHE_DIR
134 rm -f $MARCONI_AUTH_CACHE_DIR/*
135}
136
137# install_marconi() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100138function install_marconi {
Flaper Fesp06b345e2013-09-04 15:35:47 +0200139 git_clone $MARCONI_REPO $MARCONI_DIR $MARCONI_BRANCH
140 setup_develop $MARCONI_DIR
141}
142
143# install_marconiclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100144function install_marconiclient {
Flaper Fesp06b345e2013-09-04 15:35:47 +0200145 git_clone $MARCONICLIENT_REPO $MARCONICLIENT_DIR $MARCONICLIENT_BRANCH
146 setup_develop $MARCONICLIENT_DIR
147}
148
149# start_marconi() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100150function start_marconi {
Flaper Fesp06b345e2013-09-04 15:35:47 +0200151 screen_it marconi-server "marconi-server --config-file $MARCONI_CONF"
Malini Kamalambal67df3b22014-02-20 14:48:59 -0500152 echo "Waiting for Marconi to start..."
153 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
154 die $LINENO "Marconi did not start"
155 fi
Flaper Fesp06b345e2013-09-04 15:35:47 +0200156}
157
158# stop_marconi() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100159function stop_marconi {
Flaper Fesp06b345e2013-09-04 15:35:47 +0200160 # Kill the marconi screen windows
161 for serv in marconi-server; do
162 screen -S $SCREEN_NAME -p $serv -X kill
163 done
164}
165
Ian Wienandaee18c72014-02-21 15:35:08 +1100166function create_marconi_accounts {
Steve Martinelli19685422014-01-24 13:02:26 -0600167 SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
168 ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
Flaper Fesp06b345e2013-09-04 15:35:47 +0200169
Steve Martinelli19685422014-01-24 13:02:26 -0600170 MARCONI_USER=$(openstack user create \
171 marconi \
172 --password "$SERVICE_PASSWORD" \
173 --project $SERVICE_TENANT \
174 --email marconi@example.com \
175 | grep " id " | get_field 2)
176 openstack role add \
177 $ADMIN_ROLE \
178 --project $SERVICE_TENANT \
179 --user $MARCONI_USER
Malini Kamalambal0b3aacc2014-02-13 18:18:51 -0500180
Flaper Fesp06b345e2013-09-04 15:35:47 +0200181 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Steve Martinelli19685422014-01-24 13:02:26 -0600182 MARCONI_SERVICE=$(openstack service create \
183 marconi \
Flaper Fesp06b345e2013-09-04 15:35:47 +0200184 --type=queuing \
Malini Kamalambal0f7ad6b2013-12-13 12:42:31 -0500185 --description="Marconi Service" \
186 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -0600187 openstack endpoint create \
188 $MARCONI_SERVICE \
Flaper Fesp06b345e2013-09-04 15:35:47 +0200189 --region RegionOne \
Malini Kamalambal67df3b22014-02-20 14:48:59 -0500190 --publicurl "$MARCONI_SERVICE_PROTOCOL://$MARCONI_SERVICE_HOST:$MARCONI_SERVICE_PORT" \
191 --adminurl "$MARCONI_SERVICE_PROTOCOL://$MARCONI_SERVICE_HOST:$MARCONI_SERVICE_PORT" \
192 --internalurl "$MARCONI_SERVICE_PROTOCOL://$MARCONI_SERVICE_HOST:$MARCONI_SERVICE_PORT"
Flaper Fesp06b345e2013-09-04 15:35:47 +0200193 fi
194
195}
196
197
198# Restore xtrace
199$XTRACE
200
201# Local variables:
202# mode: shell-script
203# End: