Flaper Fesp | 06b345e | 2013-09-04 15:35:47 +0200 | [diff] [blame] | 1 | # 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 |
| 24 | XTRACE=$(set +o | grep xtrace) |
| 25 | set +o xtrace |
| 26 | |
| 27 | |
| 28 | # Defaults |
| 29 | # -------- |
| 30 | |
| 31 | # Set up default directories |
| 32 | MARCONI_DIR=$DEST/marconi |
| 33 | MARCONICLIENT_DIR=$DEST/python-marconiclient |
| 34 | MARCONI_CONF_DIR=/etc/marconi |
| 35 | MARCONI_CONF=$MARCONI_CONF_DIR/marconi.conf |
| 36 | MARCONI_API_LOG_DIR=/var/log/marconi-api |
| 37 | MARCONI_AUTH_CACHE_DIR=${MARCONI_AUTH_CACHE_DIR:-/var/cache/marconi} |
| 38 | |
| 39 | # Support potential entry-points console scripts |
| 40 | MARCONI_BIN_DIR=$(get_python_exec_prefix) |
| 41 | |
| 42 | # Set up database backend |
| 43 | MARCONI_BACKEND=${MARCONI_BACKEND:-mongodb} |
| 44 | |
| 45 | |
| 46 | # Set Marconi repository |
| 47 | MARCONI_REPO=${MARCONI_REPO:-${GIT_BASE}/openstack/marconi.git} |
| 48 | MARCONI_BRANCH=${MARCONI_BRANCH:-master} |
| 49 | |
| 50 | # Set client library repository |
| 51 | MARCONICLIENT_REPO=${MARCONICLIENT_REPO:-${GIT_BASE}/openstack/python-marconiclient.git} |
| 52 | MARCONICLIENT_BRANCH=${MARCONICLIENT_BRANCH:-master} |
| 53 | |
Malini Kamalambal | 67df3b2 | 2014-02-20 14:48:59 -0500 | [diff] [blame^] | 54 | # Set Marconi Connection Info |
| 55 | MARCONI_SERVICE_HOST=${MARCONI_SERVICE_HOST:-$SERVICE_HOST} |
| 56 | MARCONI_SERVICE_PORT=${MARCONI_SERVICE_PORT:-8888} |
| 57 | MARCONI_SERVICE_PROTOCOL=${MARCONI_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL} |
| 58 | |
Dean Troyer | 4237f59 | 2014-01-29 16:22:11 -0600 | [diff] [blame] | 59 | # Tell Tempest this project is present |
Malini Kamalambal | 1e4e3ac | 2014-02-14 11:29:26 -0500 | [diff] [blame] | 60 | TEMPEST_SERVICES+=,marconi |
Dean Troyer | 4237f59 | 2014-01-29 16:22:11 -0600 | [diff] [blame] | 61 | |
| 62 | |
Flaper Fesp | 06b345e | 2013-09-04 15:35:47 +0200 | [diff] [blame] | 63 | # Functions |
| 64 | # --------- |
| 65 | |
Malini Kamalambal | 9972ec2 | 2014-02-10 11:22:39 -0500 | [diff] [blame] | 66 | # Test if any Marconi services are enabled |
| 67 | # is_marconi_enabled |
| 68 | function is_marconi_enabled { |
| 69 | [[ ,${ENABLED_SERVICES} =~ ,"marconi-" ]] && return 0 |
| 70 | return 1 |
| 71 | } |
| 72 | |
Flaper Fesp | 06b345e | 2013-09-04 15:35:47 +0200 | [diff] [blame] | 73 | # cleanup_marconi() - Remove residual data files, anything left over from previous |
| 74 | # runs that a clean run would need to clean up |
| 75 | function cleanup_marconi() { |
Malini Kamalambal | 2dcc774 | 2014-02-18 13:45:18 -0500 | [diff] [blame] | 76 | if ! timeout $SERVICE_TIMEOUT sh -c "while ! mongo marconi --eval 'db.dropDatabase();'; do sleep 1; done"; then |
| 77 | die $LINENO "Mongo DB did not start" |
| 78 | fi |
Flaper Fesp | 06b345e | 2013-09-04 15:35:47 +0200 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | # configure_marconiclient() - Set config files, create data dirs, etc |
| 82 | function configure_marconiclient() { |
| 83 | setup_develop $MARCONICLIENT_DIR |
| 84 | } |
| 85 | |
| 86 | # configure_marconi() - Set config files, create data dirs, etc |
| 87 | function configure_marconi() { |
| 88 | setup_develop $MARCONI_DIR |
| 89 | |
| 90 | [ ! -d $MARCONI_CONF_DIR ] && sudo mkdir -m 755 -p $MARCONI_CONF_DIR |
| 91 | sudo chown $USER $MARCONI_CONF_DIR |
| 92 | |
| 93 | [ ! -d $MARCONI_API_LOG_DIR ] && sudo mkdir -m 755 -p $MARCONI_API_LOG_DIR |
| 94 | sudo chown $USER $MARCONI_API_LOG_DIR |
| 95 | |
| 96 | iniset $MARCONI_CONF DEFAULT verbose True |
Malini Kamalambal | 67df3b2 | 2014-02-20 14:48:59 -0500 | [diff] [blame^] | 97 | iniset $MARCONI_CONF 'drivers:transport:wsgi' bind $MARCONI_SERVICE_HOST |
Flaper Fesp | 06b345e | 2013-09-04 15:35:47 +0200 | [diff] [blame] | 98 | |
Flaper Fesp | 06b345e | 2013-09-04 15:35:47 +0200 | [diff] [blame] | 99 | iniset $MARCONI_CONF keystone_authtoken auth_protocol http |
| 100 | iniset $MARCONI_CONF keystone_authtoken admin_user marconi |
| 101 | iniset $MARCONI_CONF keystone_authtoken admin_password $SERVICE_PASSWORD |
| 102 | iniset $MARCONI_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME |
| 103 | iniset $MARCONI_CONF keystone_authtoken signing_dir $MARCONI_AUTH_CACHE_DIR |
| 104 | |
| 105 | if [[ "$MARCONI_BACKEND" = 'mongodb' ]]; then |
| 106 | iniset $MARCONI_CONF database connection mongodb://localhost:27017/marconi |
| 107 | configure_mongodb |
| 108 | cleanup_marconi |
| 109 | fi |
| 110 | } |
| 111 | |
| 112 | function configure_mongodb() { |
| 113 | # Set nssize to 2GB. This increases the number of namespaces supported |
| 114 | # # per database. |
Dean Troyer | 41d96d7 | 2014-02-11 09:08:35 -0600 | [diff] [blame] | 115 | if is_ubuntu; then |
| 116 | sudo sed -i -e " |
| 117 | s|[^ \t]*#[ \t]*\(nssize[ \t]*=.*\$\)|\1| |
| 118 | s|^\(nssize[ \t]*=[ \t]*\).*\$|\1 2047| |
| 119 | " /etc/mongodb.conf |
| 120 | restart_service mongodb |
| 121 | elif is_fedora; then |
| 122 | sudo sed -i '/--nssize/!s/OPTIONS=\"/OPTIONS=\"--nssize 2047 /' /etc/sysconfig/mongod |
| 123 | restart_service mongod |
| 124 | fi |
Flaper Fesp | 06b345e | 2013-09-04 15:35:47 +0200 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | # init_marconi() - Initialize etc. |
| 128 | function init_marconi() { |
| 129 | # Create cache dir |
| 130 | sudo mkdir -p $MARCONI_AUTH_CACHE_DIR |
| 131 | sudo chown $STACK_USER $MARCONI_AUTH_CACHE_DIR |
| 132 | rm -f $MARCONI_AUTH_CACHE_DIR/* |
| 133 | } |
| 134 | |
| 135 | # install_marconi() - Collect source and prepare |
| 136 | function install_marconi() { |
| 137 | git_clone $MARCONI_REPO $MARCONI_DIR $MARCONI_BRANCH |
| 138 | setup_develop $MARCONI_DIR |
| 139 | } |
| 140 | |
| 141 | # install_marconiclient() - Collect source and prepare |
| 142 | function install_marconiclient() { |
| 143 | git_clone $MARCONICLIENT_REPO $MARCONICLIENT_DIR $MARCONICLIENT_BRANCH |
| 144 | setup_develop $MARCONICLIENT_DIR |
| 145 | } |
| 146 | |
| 147 | # start_marconi() - Start running processes, including screen |
| 148 | function start_marconi() { |
| 149 | screen_it marconi-server "marconi-server --config-file $MARCONI_CONF" |
Malini Kamalambal | 67df3b2 | 2014-02-20 14:48:59 -0500 | [diff] [blame^] | 150 | echo "Waiting for Marconi to start..." |
| 151 | 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 |
| 152 | die $LINENO "Marconi did not start" |
| 153 | fi |
Flaper Fesp | 06b345e | 2013-09-04 15:35:47 +0200 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | # stop_marconi() - Stop running processes |
| 157 | function stop_marconi() { |
| 158 | # Kill the marconi screen windows |
| 159 | for serv in marconi-server; do |
| 160 | screen -S $SCREEN_NAME -p $serv -X kill |
| 161 | done |
| 162 | } |
| 163 | |
| 164 | function create_marconi_accounts() { |
Steve Martinelli | 1968542 | 2014-01-24 13:02:26 -0600 | [diff] [blame] | 165 | SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") |
| 166 | ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }") |
Flaper Fesp | 06b345e | 2013-09-04 15:35:47 +0200 | [diff] [blame] | 167 | |
Steve Martinelli | 1968542 | 2014-01-24 13:02:26 -0600 | [diff] [blame] | 168 | MARCONI_USER=$(openstack user create \ |
| 169 | marconi \ |
| 170 | --password "$SERVICE_PASSWORD" \ |
| 171 | --project $SERVICE_TENANT \ |
| 172 | --email marconi@example.com \ |
| 173 | | grep " id " | get_field 2) |
| 174 | openstack role add \ |
| 175 | $ADMIN_ROLE \ |
| 176 | --project $SERVICE_TENANT \ |
| 177 | --user $MARCONI_USER |
Malini Kamalambal | 0b3aacc | 2014-02-13 18:18:51 -0500 | [diff] [blame] | 178 | |
Flaper Fesp | 06b345e | 2013-09-04 15:35:47 +0200 | [diff] [blame] | 179 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then |
Steve Martinelli | 1968542 | 2014-01-24 13:02:26 -0600 | [diff] [blame] | 180 | MARCONI_SERVICE=$(openstack service create \ |
| 181 | marconi \ |
Flaper Fesp | 06b345e | 2013-09-04 15:35:47 +0200 | [diff] [blame] | 182 | --type=queuing \ |
Malini Kamalambal | 0f7ad6b | 2013-12-13 12:42:31 -0500 | [diff] [blame] | 183 | --description="Marconi Service" \ |
| 184 | | grep " id " | get_field 2) |
Steve Martinelli | 1968542 | 2014-01-24 13:02:26 -0600 | [diff] [blame] | 185 | openstack endpoint create \ |
| 186 | $MARCONI_SERVICE \ |
Flaper Fesp | 06b345e | 2013-09-04 15:35:47 +0200 | [diff] [blame] | 187 | --region RegionOne \ |
Malini Kamalambal | 67df3b2 | 2014-02-20 14:48:59 -0500 | [diff] [blame^] | 188 | --publicurl "$MARCONI_SERVICE_PROTOCOL://$MARCONI_SERVICE_HOST:$MARCONI_SERVICE_PORT" \ |
| 189 | --adminurl "$MARCONI_SERVICE_PROTOCOL://$MARCONI_SERVICE_HOST:$MARCONI_SERVICE_PORT" \ |
| 190 | --internalurl "$MARCONI_SERVICE_PROTOCOL://$MARCONI_SERVICE_HOST:$MARCONI_SERVICE_PORT" |
Flaper Fesp | 06b345e | 2013-09-04 15:35:47 +0200 | [diff] [blame] | 191 | fi |
| 192 | |
| 193 | } |
| 194 | |
| 195 | |
| 196 | # Restore xtrace |
| 197 | $XTRACE |
| 198 | |
| 199 | # Local variables: |
| 200 | # mode: shell-script |
| 201 | # End: |