Sergey Lukjanov | 7ff8443 | 2014-03-10 20:04:51 +0400 | [diff] [blame] | 1 | # lib/sahara |
| 2 | |
| 3 | # Dependencies: |
| 4 | # ``functions`` file |
| 5 | # ``DEST``, ``DATA_DIR``, ``STACK_USER`` must be defined |
| 6 | |
| 7 | # ``stack.sh`` calls the entry points in this order: |
| 8 | # |
| 9 | # install_sahara |
| 10 | # configure_sahara |
| 11 | # start_sahara |
| 12 | # stop_sahara |
| 13 | # cleanup_sahara |
| 14 | |
| 15 | # Save trace setting |
| 16 | XTRACE=$(set +o | grep xtrace) |
| 17 | set +o xtrace |
| 18 | |
| 19 | |
| 20 | # Defaults |
| 21 | # -------- |
| 22 | |
| 23 | # Set up default repos |
| 24 | SAHARA_REPO=${SAHARA_REPO:-${GIT_BASE}/openstack/sahara.git} |
| 25 | SAHARA_BRANCH=${SAHARA_BRANCH:-master} |
| 26 | |
| 27 | # Set up default directories |
| 28 | SAHARA_DIR=$DEST/sahara |
| 29 | SAHARA_CONF_DIR=${SAHARA_CONF_DIR:-/etc/sahara} |
| 30 | SAHARA_CONF_FILE=${SAHARA_CONF_DIR}/sahara.conf |
| 31 | SAHARA_DEBUG=${SAHARA_DEBUG:-True} |
| 32 | |
| 33 | SAHARA_SERVICE_HOST=${SAHARA_SERVICE_HOST:-$SERVICE_HOST} |
| 34 | SAHARA_SERVICE_PORT=${SAHARA_SERVICE_PORT:-8386} |
| 35 | SAHARA_SERVICE_PROTOCOL=${SAHARA_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL} |
| 36 | |
| 37 | SAHARA_AUTH_CACHE_DIR=${SAHARA_AUTH_CACHE_DIR:-/var/cache/sahara} |
| 38 | |
| 39 | # Support entry points installation of console scripts |
| 40 | if [[ -d $SAHARA_DIR/bin ]]; then |
| 41 | SAHARA_BIN_DIR=$SAHARA_DIR/bin |
| 42 | else |
| 43 | SAHARA_BIN_DIR=$(get_python_exec_prefix) |
| 44 | fi |
| 45 | |
| 46 | # Tell Tempest this project is present |
| 47 | TEMPEST_SERVICES+=,sahara |
| 48 | |
| 49 | # For backward compatibility with current tests in Tempest |
| 50 | TEMPEST_SERVICES+=,savanna |
| 51 | |
| 52 | |
| 53 | # Functions |
| 54 | # --------- |
| 55 | |
| 56 | # create_sahara_accounts() - Set up common required sahara accounts |
| 57 | # |
| 58 | # Tenant User Roles |
| 59 | # ------------------------------ |
| 60 | # service sahara admin |
| 61 | function create_sahara_accounts { |
| 62 | |
| 63 | SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") |
| 64 | ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }") |
| 65 | |
| 66 | SAHARA_USER=$(openstack user create \ |
| 67 | sahara \ |
| 68 | --password "$SERVICE_PASSWORD" \ |
| 69 | --project $SERVICE_TENANT \ |
| 70 | --email sahara@example.com \ |
| 71 | | grep " id " | get_field 2) |
| 72 | openstack role add \ |
| 73 | $ADMIN_ROLE \ |
| 74 | --project $SERVICE_TENANT \ |
| 75 | --user $SAHARA_USER |
| 76 | |
| 77 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then |
| 78 | SAHARA_SERVICE=$(openstack service create \ |
| 79 | sahara \ |
| 80 | --type=data_processing \ |
| 81 | --description="Sahara Data Processing" \ |
| 82 | | grep " id " | get_field 2) |
| 83 | openstack endpoint create \ |
| 84 | $SAHARA_SERVICE \ |
| 85 | --region RegionOne \ |
| 86 | --publicurl "$SAHARA_SERVICE_PROTOCOL://$SAHARA_SERVICE_HOST:$SAHARA_SERVICE_PORT/v1.1/\$(tenant_id)s" \ |
| 87 | --adminurl "$SAHARA_SERVICE_PROTOCOL://$SAHARA_SERVICE_HOST:$SAHARA_SERVICE_PORT/v1.1/\$(tenant_id)s" \ |
| 88 | --internalurl "$SAHARA_SERVICE_PROTOCOL://$SAHARA_SERVICE_HOST:$SAHARA_SERVICE_PORT/v1.1/\$(tenant_id)s" |
| 89 | fi |
| 90 | } |
| 91 | |
| 92 | # cleanup_sahara() - Remove residual data files, anything left over from |
| 93 | # previous runs that would need to clean up. |
| 94 | function cleanup_sahara { |
| 95 | |
| 96 | # Cleanup auth cache dir |
| 97 | sudo rm -rf $SAHARA_AUTH_CACHE_DIR |
| 98 | } |
| 99 | |
| 100 | # configure_sahara() - Set config files, create data dirs, etc |
| 101 | function configure_sahara { |
| 102 | |
| 103 | if [[ ! -d $SAHARA_CONF_DIR ]]; then |
| 104 | sudo mkdir -p $SAHARA_CONF_DIR |
| 105 | fi |
| 106 | sudo chown $STACK_USER $SAHARA_CONF_DIR |
| 107 | |
| 108 | # Copy over sahara configuration file and configure common parameters. |
Sergey Lukjanov | 51ebda6 | 2014-03-12 22:26:12 +0400 | [diff] [blame^] | 109 | cp $SAHARA_DIR/etc/sahara/sahara.conf.sample $SAHARA_CONF_FILE |
Sergey Lukjanov | 7ff8443 | 2014-03-10 20:04:51 +0400 | [diff] [blame] | 110 | |
| 111 | # Create auth cache dir |
| 112 | sudo mkdir -p $SAHARA_AUTH_CACHE_DIR |
| 113 | sudo chown $STACK_USER $SAHARA_AUTH_CACHE_DIR |
| 114 | rm -rf $SAHARA_AUTH_CACHE_DIR/* |
| 115 | |
| 116 | # Set obsolete keystone auth configs for backward compatibility |
| 117 | iniset $SAHARA_CONF_FILE DEFAULT os_auth_host $KEYSTONE_SERVICE_HOST |
| 118 | iniset $SAHARA_CONF_FILE DEFAULT os_auth_port $KEYSTONE_SERVICE_PORT |
| 119 | iniset $SAHARA_CONF_FILE DEFAULT os_auth_protocol $KEYSTONE_SERVICE_PROTOCOL |
| 120 | iniset $SAHARA_CONF_FILE DEFAULT os_admin_password $SERVICE_PASSWORD |
| 121 | iniset $SAHARA_CONF_FILE DEFAULT os_admin_username sahara |
| 122 | iniset $SAHARA_CONF_FILE DEFAULT os_admin_tenant_name $SERVICE_TENANT_NAME |
| 123 | |
| 124 | # Set actual keystone auth configs |
| 125 | iniset $SAHARA_CONF_FILE keystone_authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/ |
| 126 | iniset $SAHARA_CONF_FILE keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME |
| 127 | iniset $SAHARA_CONF_FILE keystone_authtoken admin_user sahara |
| 128 | iniset $SAHARA_CONF_FILE keystone_authtoken admin_password $SERVICE_PASSWORD |
| 129 | iniset $SAHARA_CONF_FILE keystone_authtoken signing_dir $SAHARA_AUTH_CACHE_DIR |
| 130 | iniset $SAHARA_CONF_FILE keystone_authtoken cafile $KEYSTONE_SSL_CA |
| 131 | |
| 132 | iniset $SAHARA_CONF_FILE DEFAULT debug $SAHARA_DEBUG |
| 133 | |
| 134 | iniset $SAHARA_CONF_FILE database connection `database_connection_url sahara` |
| 135 | |
| 136 | if is_service_enabled neutron; then |
| 137 | iniset $SAHARA_CONF_FILE DEFAULT use_neutron true |
| 138 | iniset $SAHARA_CONF_FILE DEFAULT use_floating_ips true |
| 139 | fi |
| 140 | |
| 141 | if is_service_enabled heat; then |
| 142 | iniset $SAHARA_CONF_FILE DEFAULT infrastructure_engine heat |
| 143 | else |
| 144 | iniset $SAHARA_CONF_FILE DEFAULT infrastructure_engine direct |
| 145 | fi |
| 146 | |
| 147 | iniset $SAHARA_CONF_FILE DEFAULT use_syslog $SYSLOG |
| 148 | |
| 149 | recreate_database sahara utf8 |
| 150 | $SAHARA_BIN_DIR/sahara-db-manage --config-file $SAHARA_CONF_FILE upgrade head |
| 151 | } |
| 152 | |
| 153 | # install_sahara() - Collect source and prepare |
| 154 | function install_sahara { |
| 155 | git_clone $SAHARA_REPO $SAHARA_DIR $SAHARA_BRANCH |
| 156 | setup_develop $SAHARA_DIR |
| 157 | } |
| 158 | |
| 159 | # start_sahara() - Start running processes, including screen |
| 160 | function start_sahara { |
| 161 | screen_it sahara "cd $SAHARA_DIR && $SAHARA_BIN_DIR/sahara-api --config-file $SAHARA_CONF_FILE" |
| 162 | } |
| 163 | |
| 164 | # stop_sahara() - Stop running processes |
| 165 | function stop_sahara { |
| 166 | # Kill the Sahara screen windows |
| 167 | screen -S $SCREEN_NAME -p sahara -X kill |
| 168 | } |
| 169 | |
| 170 | |
| 171 | # Restore xtrace |
| 172 | $XTRACE |
| 173 | |
| 174 | # Local variables: |
| 175 | # mode: shell-script |
| 176 | # End: |