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 | |
Dean Troyer | 4237f59 | 2014-01-29 16:22:11 -0600 | [diff] [blame] | 54 | # Tell Tempest this project is present |
Malini Kamalambal | 1d50d78 | 2014-02-12 18:23:36 -0500 | [diff] [blame] | 55 | TEMPEST_SERVICES+=,marconi-server |
Dean Troyer | 4237f59 | 2014-01-29 16:22:11 -0600 | [diff] [blame] | 56 | |
| 57 | |
Flaper Fesp | 06b345e | 2013-09-04 15:35:47 +0200 | [diff] [blame] | 58 | # Functions |
| 59 | # --------- |
| 60 | |
Malini Kamalambal | 9972ec2 | 2014-02-10 11:22:39 -0500 | [diff] [blame] | 61 | # Test if any Marconi services are enabled |
| 62 | # is_marconi_enabled |
| 63 | function is_marconi_enabled { |
| 64 | [[ ,${ENABLED_SERVICES} =~ ,"marconi-" ]] && return 0 |
| 65 | return 1 |
| 66 | } |
| 67 | |
Flaper Fesp | 06b345e | 2013-09-04 15:35:47 +0200 | [diff] [blame] | 68 | # cleanup_marconi() - Remove residual data files, anything left over from previous |
| 69 | # runs that a clean run would need to clean up |
| 70 | function cleanup_marconi() { |
| 71 | mongo marconi --eval "db.dropDatabase();" |
| 72 | } |
| 73 | |
| 74 | # configure_marconiclient() - Set config files, create data dirs, etc |
| 75 | function configure_marconiclient() { |
| 76 | setup_develop $MARCONICLIENT_DIR |
| 77 | } |
| 78 | |
| 79 | # configure_marconi() - Set config files, create data dirs, etc |
| 80 | function configure_marconi() { |
| 81 | setup_develop $MARCONI_DIR |
| 82 | |
| 83 | [ ! -d $MARCONI_CONF_DIR ] && sudo mkdir -m 755 -p $MARCONI_CONF_DIR |
| 84 | sudo chown $USER $MARCONI_CONF_DIR |
| 85 | |
| 86 | [ ! -d $MARCONI_API_LOG_DIR ] && sudo mkdir -m 755 -p $MARCONI_API_LOG_DIR |
| 87 | sudo chown $USER $MARCONI_API_LOG_DIR |
| 88 | |
| 89 | iniset $MARCONI_CONF DEFAULT verbose True |
| 90 | iniset $MARCONI_CONF 'drivers:transport:wsgi' bind '0.0.0.0' |
| 91 | |
| 92 | # Install the policy file for the API server |
| 93 | cp $MARCONI_DIR/etc/marconi/policy.json $MARCONI_CONF_DIR |
| 94 | iniset $MARCONI_CONF DEFAULT policy_file $MARCONI_CONF_DIR/policy.json |
| 95 | |
| 96 | iniset $MARCONI_CONF keystone_authtoken auth_protocol http |
| 97 | iniset $MARCONI_CONF keystone_authtoken admin_user marconi |
| 98 | iniset $MARCONI_CONF keystone_authtoken admin_password $SERVICE_PASSWORD |
| 99 | iniset $MARCONI_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME |
| 100 | iniset $MARCONI_CONF keystone_authtoken signing_dir $MARCONI_AUTH_CACHE_DIR |
| 101 | |
| 102 | if [[ "$MARCONI_BACKEND" = 'mongodb' ]]; then |
| 103 | iniset $MARCONI_CONF database connection mongodb://localhost:27017/marconi |
| 104 | configure_mongodb |
| 105 | cleanup_marconi |
| 106 | fi |
| 107 | } |
| 108 | |
| 109 | function configure_mongodb() { |
| 110 | # Set nssize to 2GB. This increases the number of namespaces supported |
| 111 | # # per database. |
| 112 | sudo sed -i '/--nssize/!s/OPTIONS=\"/OPTIONS=\"--nssize 2047 /' /etc/sysconfig/mongod |
| 113 | |
| 114 | restart_service mongod |
| 115 | } |
| 116 | |
| 117 | # init_marconi() - Initialize etc. |
| 118 | function init_marconi() { |
| 119 | # Create cache dir |
| 120 | sudo mkdir -p $MARCONI_AUTH_CACHE_DIR |
| 121 | sudo chown $STACK_USER $MARCONI_AUTH_CACHE_DIR |
| 122 | rm -f $MARCONI_AUTH_CACHE_DIR/* |
| 123 | } |
| 124 | |
| 125 | # install_marconi() - Collect source and prepare |
| 126 | function install_marconi() { |
| 127 | git_clone $MARCONI_REPO $MARCONI_DIR $MARCONI_BRANCH |
| 128 | setup_develop $MARCONI_DIR |
| 129 | } |
| 130 | |
| 131 | # install_marconiclient() - Collect source and prepare |
| 132 | function install_marconiclient() { |
| 133 | git_clone $MARCONICLIENT_REPO $MARCONICLIENT_DIR $MARCONICLIENT_BRANCH |
| 134 | setup_develop $MARCONICLIENT_DIR |
| 135 | } |
| 136 | |
| 137 | # start_marconi() - Start running processes, including screen |
| 138 | function start_marconi() { |
| 139 | screen_it marconi-server "marconi-server --config-file $MARCONI_CONF" |
| 140 | } |
| 141 | |
| 142 | # stop_marconi() - Stop running processes |
| 143 | function stop_marconi() { |
| 144 | # Kill the marconi screen windows |
| 145 | for serv in marconi-server; do |
| 146 | screen -S $SCREEN_NAME -p $serv -X kill |
| 147 | done |
| 148 | } |
| 149 | |
| 150 | function create_marconi_accounts() { |
| 151 | SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") |
| 152 | ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }") |
| 153 | |
| 154 | MARCONI_USER=$(get_id keystone user-create --name=marconi \ |
| 155 | --pass="$SERVICE_PASSWORD" \ |
Dirk Mueller | 25049cd | 2014-01-09 13:53:52 +0100 | [diff] [blame] | 156 | --tenant-id $SERVICE_TENANT \ |
Malini Kamalambal | 0b3aacc | 2014-02-13 18:18:51 -0500 | [diff] [blame^] | 157 | --email=marconi@example.com \ |
| 158 | | grep " id " | get_field 2) |
Flaper Fesp | 06b345e | 2013-09-04 15:35:47 +0200 | [diff] [blame] | 159 | keystone user-role-add --tenant-id $SERVICE_TENANT \ |
| 160 | --user-id $MARCONI_USER \ |
| 161 | --role-id $ADMIN_ROLE |
Malini Kamalambal | 0b3aacc | 2014-02-13 18:18:51 -0500 | [diff] [blame^] | 162 | |
Flaper Fesp | 06b345e | 2013-09-04 15:35:47 +0200 | [diff] [blame] | 163 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then |
Malini Kamalambal | 0f7ad6b | 2013-12-13 12:42:31 -0500 | [diff] [blame] | 164 | MARCONI_SERVICE=$(keystone service-create \ |
Flaper Fesp | 06b345e | 2013-09-04 15:35:47 +0200 | [diff] [blame] | 165 | --name=marconi \ |
| 166 | --type=queuing \ |
Malini Kamalambal | 0f7ad6b | 2013-12-13 12:42:31 -0500 | [diff] [blame] | 167 | --description="Marconi Service" \ |
| 168 | | grep " id " | get_field 2) |
Flaper Fesp | 06b345e | 2013-09-04 15:35:47 +0200 | [diff] [blame] | 169 | keystone endpoint-create \ |
| 170 | --region RegionOne \ |
| 171 | --service_id $MARCONI_SERVICE \ |
| 172 | --publicurl "http://$SERVICE_HOST:8888" \ |
| 173 | --adminurl "http://$SERVICE_HOST:8888" \ |
| 174 | --internalurl "http://$SERVICE_HOST:8888" |
| 175 | fi |
| 176 | |
| 177 | } |
| 178 | |
| 179 | |
| 180 | # Restore xtrace |
| 181 | $XTRACE |
| 182 | |
| 183 | # Local variables: |
| 184 | # mode: shell-script |
| 185 | # End: |