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