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 |
Sergey Lukjanov | a90898d | 2014-08-05 16:14:12 +0400 | [diff] [blame] | 10 | # install_python_saharaclient |
Sergey Lukjanov | 7ff8443 | 2014-03-10 20:04:51 +0400 | [diff] [blame] | 11 | # configure_sahara |
| 12 | # start_sahara |
| 13 | # stop_sahara |
| 14 | # cleanup_sahara |
| 15 | |
| 16 | # Save trace setting |
| 17 | XTRACE=$(set +o | grep xtrace) |
| 18 | set +o xtrace |
| 19 | |
| 20 | |
| 21 | # Defaults |
| 22 | # -------- |
| 23 | |
| 24 | # Set up default repos |
| 25 | SAHARA_REPO=${SAHARA_REPO:-${GIT_BASE}/openstack/sahara.git} |
| 26 | SAHARA_BRANCH=${SAHARA_BRANCH:-master} |
| 27 | |
Sergey Lukjanov | a90898d | 2014-08-05 16:14:12 +0400 | [diff] [blame] | 28 | SAHARA_PYTHONCLIENT_REPO=${SAHARA_PYTHONCLIENT_REPO:-${GIT_BASE}/openstack/python-saharaclient.git} |
| 29 | SAHARA_PYTHONCLIENT_BRANCH=${SAHARA_PYTHONCLIENT_BRANCH:-master} |
| 30 | |
Sergey Lukjanov | 7ff8443 | 2014-03-10 20:04:51 +0400 | [diff] [blame] | 31 | # Set up default directories |
| 32 | SAHARA_DIR=$DEST/sahara |
Sergey Lukjanov | a90898d | 2014-08-05 16:14:12 +0400 | [diff] [blame] | 33 | SAHARA_PYTHONCLIENT_DIR=$DEST/python-saharaclient |
| 34 | |
Sergey Lukjanov | 7ff8443 | 2014-03-10 20:04:51 +0400 | [diff] [blame] | 35 | SAHARA_CONF_DIR=${SAHARA_CONF_DIR:-/etc/sahara} |
| 36 | SAHARA_CONF_FILE=${SAHARA_CONF_DIR}/sahara.conf |
Sergey Lukjanov | 7ff8443 | 2014-03-10 20:04:51 +0400 | [diff] [blame] | 37 | |
| 38 | SAHARA_SERVICE_HOST=${SAHARA_SERVICE_HOST:-$SERVICE_HOST} |
| 39 | SAHARA_SERVICE_PORT=${SAHARA_SERVICE_PORT:-8386} |
| 40 | SAHARA_SERVICE_PROTOCOL=${SAHARA_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL} |
| 41 | |
| 42 | SAHARA_AUTH_CACHE_DIR=${SAHARA_AUTH_CACHE_DIR:-/var/cache/sahara} |
| 43 | |
Sergey Lukjanov | 10f4161 | 2014-04-25 11:42:41 +0400 | [diff] [blame] | 44 | SAHARA_ENABLED_PLUGINS=${SAHARA_ENABLED_PLUGINS:-vanilla,hdp,fake} |
| 45 | |
Sergey Lukjanov | 7ff8443 | 2014-03-10 20:04:51 +0400 | [diff] [blame] | 46 | # Support entry points installation of console scripts |
| 47 | if [[ -d $SAHARA_DIR/bin ]]; then |
| 48 | SAHARA_BIN_DIR=$SAHARA_DIR/bin |
| 49 | else |
| 50 | SAHARA_BIN_DIR=$(get_python_exec_prefix) |
| 51 | fi |
| 52 | |
| 53 | # Tell Tempest this project is present |
| 54 | TEMPEST_SERVICES+=,sahara |
| 55 | |
Sergey Lukjanov | 7ff8443 | 2014-03-10 20:04:51 +0400 | [diff] [blame] | 56 | # Functions |
| 57 | # --------- |
| 58 | |
| 59 | # create_sahara_accounts() - Set up common required sahara accounts |
| 60 | # |
| 61 | # Tenant User Roles |
| 62 | # ------------------------------ |
| 63 | # service sahara admin |
| 64 | function create_sahara_accounts { |
| 65 | |
Dean Troyer | 16ef976 | 2014-08-19 19:31:34 -0500 | [diff] [blame] | 66 | local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") |
| 67 | local admin_role=$(openstack role list | awk "/ admin / { print \$2 }") |
Sergey Lukjanov | 7ff8443 | 2014-03-10 20:04:51 +0400 | [diff] [blame] | 68 | |
Dean Troyer | 16ef976 | 2014-08-19 19:31:34 -0500 | [diff] [blame] | 69 | local sahara_user=$(get_or_create_user "sahara" \ |
| 70 | "$SERVICE_PASSWORD" $service_tenant) |
| 71 | get_or_add_user_role $admin_role $sahara_user $service_tenant |
Sergey Lukjanov | 7ff8443 | 2014-03-10 20:04:51 +0400 | [diff] [blame] | 72 | |
| 73 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then |
Bartosz Górski | 0abde39 | 2014-02-28 14:15:19 +0100 | [diff] [blame] | 74 | |
Dean Troyer | 16ef976 | 2014-08-19 19:31:34 -0500 | [diff] [blame] | 75 | local sahara_service=$(get_or_create_service "sahara" \ |
Bartosz Górski | 0abde39 | 2014-02-28 14:15:19 +0100 | [diff] [blame] | 76 | "data_processing" "Sahara Data Processing") |
Dean Troyer | 16ef976 | 2014-08-19 19:31:34 -0500 | [diff] [blame] | 77 | get_or_create_endpoint $sahara_service \ |
Bartosz Górski | 0abde39 | 2014-02-28 14:15:19 +0100 | [diff] [blame] | 78 | "$REGION_NAME" \ |
| 79 | "$SAHARA_SERVICE_PROTOCOL://$SAHARA_SERVICE_HOST:$SAHARA_SERVICE_PORT/v1.1/\$(tenant_id)s" \ |
| 80 | "$SAHARA_SERVICE_PROTOCOL://$SAHARA_SERVICE_HOST:$SAHARA_SERVICE_PORT/v1.1/\$(tenant_id)s" \ |
| 81 | "$SAHARA_SERVICE_PROTOCOL://$SAHARA_SERVICE_HOST:$SAHARA_SERVICE_PORT/v1.1/\$(tenant_id)s" |
Sergey Lukjanov | 7ff8443 | 2014-03-10 20:04:51 +0400 | [diff] [blame] | 82 | fi |
| 83 | } |
| 84 | |
| 85 | # cleanup_sahara() - Remove residual data files, anything left over from |
| 86 | # previous runs that would need to clean up. |
| 87 | function cleanup_sahara { |
| 88 | |
| 89 | # Cleanup auth cache dir |
| 90 | sudo rm -rf $SAHARA_AUTH_CACHE_DIR |
| 91 | } |
| 92 | |
| 93 | # configure_sahara() - Set config files, create data dirs, etc |
| 94 | function configure_sahara { |
| 95 | |
| 96 | if [[ ! -d $SAHARA_CONF_DIR ]]; then |
| 97 | sudo mkdir -p $SAHARA_CONF_DIR |
| 98 | fi |
| 99 | sudo chown $STACK_USER $SAHARA_CONF_DIR |
| 100 | |
| 101 | # Copy over sahara configuration file and configure common parameters. |
Sergey Lukjanov | 51ebda6 | 2014-03-12 22:26:12 +0400 | [diff] [blame] | 102 | cp $SAHARA_DIR/etc/sahara/sahara.conf.sample $SAHARA_CONF_FILE |
Sergey Lukjanov | 7ff8443 | 2014-03-10 20:04:51 +0400 | [diff] [blame] | 103 | |
| 104 | # Create auth cache dir |
| 105 | sudo mkdir -p $SAHARA_AUTH_CACHE_DIR |
| 106 | sudo chown $STACK_USER $SAHARA_AUTH_CACHE_DIR |
| 107 | rm -rf $SAHARA_AUTH_CACHE_DIR/* |
| 108 | |
Brant Knudson | 0595237 | 2014-09-19 17:22:22 -0500 | [diff] [blame] | 109 | configure_auth_token_middleware $SAHARA_CONF_FILE sahara $SAHARA_AUTH_CACHE_DIR |
Sergey Lukjanov | 7ff8443 | 2014-03-10 20:04:51 +0400 | [diff] [blame] | 110 | |
Vitaly Gridnev | e50fcb1 | 2014-08-11 12:01:12 +0000 | [diff] [blame] | 111 | # Set configuration to send notifications |
| 112 | |
| 113 | if is_service_enabled ceilometer; then |
| 114 | iniset $SAHARA_CONF_FILE DEFAULT enable_notifications "true" |
| 115 | iniset $SAHARA_CONF_FILE DEFAULT notification_driver "messaging" |
| 116 | iniset_rpc_backend sahara $SAHARA_CONF_FILE DEFAULT |
| 117 | fi |
| 118 | |
Sergey Lukjanov | 3cd59e1 | 2014-03-25 00:06:31 +0400 | [diff] [blame] | 119 | iniset $SAHARA_CONF_FILE DEFAULT verbose True |
| 120 | iniset $SAHARA_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
Sergey Lukjanov | 7ff8443 | 2014-03-10 20:04:51 +0400 | [diff] [blame] | 121 | |
Sergey Lukjanov | 10f4161 | 2014-04-25 11:42:41 +0400 | [diff] [blame] | 122 | iniset $SAHARA_CONF_FILE DEFAULT plugins $SAHARA_ENABLED_PLUGINS |
| 123 | |
Sergey Lukjanov | 7ff8443 | 2014-03-10 20:04:51 +0400 | [diff] [blame] | 124 | iniset $SAHARA_CONF_FILE database connection `database_connection_url sahara` |
| 125 | |
| 126 | if is_service_enabled neutron; then |
| 127 | iniset $SAHARA_CONF_FILE DEFAULT use_neutron true |
| 128 | iniset $SAHARA_CONF_FILE DEFAULT use_floating_ips true |
| 129 | fi |
| 130 | |
| 131 | if is_service_enabled heat; then |
| 132 | iniset $SAHARA_CONF_FILE DEFAULT infrastructure_engine heat |
| 133 | else |
| 134 | iniset $SAHARA_CONF_FILE DEFAULT infrastructure_engine direct |
| 135 | fi |
| 136 | |
| 137 | iniset $SAHARA_CONF_FILE DEFAULT use_syslog $SYSLOG |
| 138 | |
Luigi Toscano | b4bef1f | 2014-04-03 19:24:57 +0200 | [diff] [blame] | 139 | # Format logging |
| 140 | if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then |
| 141 | setup_colorized_logging $SAHARA_CONF_FILE DEFAULT |
| 142 | fi |
| 143 | |
Sergey Lukjanov | 7ff8443 | 2014-03-10 20:04:51 +0400 | [diff] [blame] | 144 | recreate_database sahara utf8 |
| 145 | $SAHARA_BIN_DIR/sahara-db-manage --config-file $SAHARA_CONF_FILE upgrade head |
| 146 | } |
| 147 | |
| 148 | # install_sahara() - Collect source and prepare |
| 149 | function install_sahara { |
| 150 | git_clone $SAHARA_REPO $SAHARA_DIR $SAHARA_BRANCH |
| 151 | setup_develop $SAHARA_DIR |
| 152 | } |
| 153 | |
Sergey Lukjanov | a90898d | 2014-08-05 16:14:12 +0400 | [diff] [blame] | 154 | # install_python_saharaclient() - Collect source and prepare |
| 155 | function install_python_saharaclient { |
| 156 | git_clone $SAHARA_PYTHONCLIENT_REPO $SAHARA_PYTHONCLIENT_DIR $SAHARA_PYTHONCLIENT_BRANCH |
| 157 | setup_develop $SAHARA_PYTHONCLIENT_DIR |
| 158 | } |
| 159 | |
Sergey Lukjanov | 7ff8443 | 2014-03-10 20:04:51 +0400 | [diff] [blame] | 160 | # start_sahara() - Start running processes, including screen |
| 161 | function start_sahara { |
Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 162 | run_process sahara "$SAHARA_BIN_DIR/sahara-all --config-file $SAHARA_CONF_FILE" |
Sergey Lukjanov | 7ff8443 | 2014-03-10 20:04:51 +0400 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | # stop_sahara() - Stop running processes |
| 166 | function stop_sahara { |
| 167 | # Kill the Sahara screen windows |
| 168 | screen -S $SCREEN_NAME -p sahara -X kill |
| 169 | } |
| 170 | |
| 171 | |
| 172 | # Restore xtrace |
| 173 | $XTRACE |
| 174 | |
| 175 | # Local variables: |
| 176 | # mode: shell-script |
| 177 | # End: |