diff --git a/devstack/README.rst b/devstack/README.rst new file mode 100644 index 00000000..11cf0c81 --- /dev/null +++ b/devstack/README.rst @@ -0,0 +1,39 @@ +============================= +Enabling Masakari in DevStack +============================= + +To enable Masakari in DevStack, perform the following steps: + + +Download DevStack +================= + +.. sourcecode:: bash + + export DEVSTACK_DIR=~/devstack + git clone git://git.openstack.org/openstack-dev/devstack.git $DEVSTACK_DIR + +Enable the Masakari plugin +========================== + +Enable the plugin by adding the following section to ``$DEVSTACK_DIR/local.conf`` + +.. sourcecode:: bash + + [[local|localrc]] + enable_plugin masakari git://git.openstack.org/openstack/masakari + +Optionally, a git refspec (branch or tag or commit) may be provided as follows: + +.. sourcecode:: bash + + [[local|localrc]] + enable_plugin masakari git://git.openstack.org/openstack/masakari + +Run the DevStack utility +======================== + +.. sourcecode:: bash + + cd $DEVSTACK_DIR + ./stack.sh diff --git a/devstack/plugin.sh b/devstack/plugin.sh new file mode 100644 index 00000000..a03e42f8 --- /dev/null +++ b/devstack/plugin.sh @@ -0,0 +1,202 @@ +#!/bin/bash +# +# lib/masakari +# Functions to control the configuration and operation of the **Masakari** service + +# Dependencies: +# ``functions`` file +# ``DEST``, ``STACK_USER`` must be defined +# ``SERVICE_{HOST|PROTOCOL|TOKEN}`` must be defined + +# ``stack.sh`` calls the entry points in this order: +# +# install_masakari +# configure_masakari +# init_masakari +# start_masakari +# stop_masakari +# cleanup_masakari + +# Save trace setting +XTRACE=$(set +o | grep xtrace) +set +o xtrace + +# Functions +# --------- + +# Test if any Masakari services are enabled +# is_masakari_enabled +function is_masakari_enabled { + [[ ,${ENABLED_SERVICES} =~ ,"masakari-api" ]] && return 0 + return 1 +} + +# setup_masakari_logging() - Adds logging configuration to conf files +function setup_masakari_logging { + local CONF=$1 + iniset $CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL + iniset $CONF DEFAULT use_syslog $SYSLOG + if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then + # Add color to logging output + setup_colorized_logging $CONF DEFAULT tenant user + fi +} + +# create_masakari_accounts() - Set up common required masakari accounts + +# Tenant User Roles +# ------------------------------------------------------------------ +# service masakari admin # if enabled + +function create_masakari_accounts { + if [[ "$ENABLED_SERVICES" =~ "masakari" ]]; then + + create_service_user "masakari" + + if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then + + local masakari_service=$(get_or_create_service "masakari" \ + "ha" "OpenStack High Availability") + get_or_create_endpoint $masakari_service \ + "$REGION_NAME" \ + "http://$SERVICE_HOST:$MASAKARI_SERVICE_PORT/v1/\$(tenant_id)s" \ + "http://$SERVICE_HOST:$MASAKARI_SERVICE_PORT/v1/\$(tenant_id)s" \ + "http://$SERVICE_HOST:$MASAKARI_SERVICE_PORT/v1/\$(tenant_id)s" + fi + fi +} + +# stack.sh entry points +# --------------------- + +# cleanup_masakari() - Remove residual data files, anything left over from previous +# runs that a clean run would need to clean up +function cleanup_masakari { +# Clean up dirs + rm -fr $MASAKARI_AUTH_CACHE_DIR/* + rm -fr $MASAKARI_CONF_DIR/* +} + +# iniset_conditional() - Sets the value in the inifile, but only if it's +# actually got a value +function iniset_conditional { + local FILE=$1 + local SECTION=$2 + local OPTION=$3 + local VALUE=$4 + + if [[ -n "$VALUE" ]]; then + iniset ${FILE} ${SECTION} ${OPTION} ${VALUE} + fi +} + +# configure_masakari() - Set config files, create data dirs, etc +function configure_masakari { + setup_develop $MASAKARI_DIR + + # Create the masakari conf dir and cache dirs if they don't exist + sudo install -d -o $STACK_USER ${MASAKARI_CONF_DIR} ${MASAKARI_AUTH_CACHE_DIR} + + # Copy api-paste file over to the masakari conf dir + cp $MASAKARI_LOCAL_API_PASTE_INI $MASAKARI_API_PASTE_INI + + # Copy policy.json file over to the masakari conf dir + cp $MASAKARI_LOCAL_POLICY_JSON $MASAKARI_POLICY_JSON + + # (Re)create masakari conf files + rm -f $MASAKARI_CONF + + # (Re)create masakari api conf file if needed + if is_service_enabled masakari-api; then + oslo-config-generator --namespace keystonemiddleware.auth_token \ + --namespace masakari \ + --namespace oslo.db \ + > $MASAKARI_CONF + + # Set common configuration values (but only if they're defined) + iniset $MASAKARI_CONF DEFAULT masakari_api_workers "$API_WORKERS" + iniset $MASAKARI_CONF database connection `database_connection_url masakari` + setup_masakari_logging $MASAKARI_CONF + + configure_auth_token_middleware $MASAKARI_CONF masakari $MASAKARI_AUTH_CACHE_DIR + fi +} + +# install_masakari() - Collect source and prepare +function install_masakari { + setup_develop $MASAKARI_DIR +} + +# init_masakari() - Initializes Masakari Database as a Service +function init_masakari { + # (Re)Create masakari db + recreate_database masakari + + # Initialize the masakari database + $MASAKARI_MANAGE db sync + + # Add an admin user to the 'tempest' alt_demo tenant. + # This is needed to test the guest_log functionality. + # The first part mimics the tempest setup, so make sure we have that. + ALT_USERNAME=${ALT_USERNAME:-alt_demo} + ALT_TENANT_NAME=${ALT_TENANT_NAME:-alt_demo} + get_or_create_project ${ALT_TENANT_NAME} default + get_or_create_user ${ALT_USERNAME} "$ADMIN_PASSWORD" "default" "alt_demo@example.com" + get_or_add_user_project_role Member ${ALT_USERNAME} ${ALT_TENANT_NAME} + + # The second part adds an admin user to the tenant. + ADMIN_ALT_USERNAME=${ADMIN_ALT_USERNAME:-admin_${ALT_USERNAME}} + get_or_create_user ${ADMIN_ALT_USERNAME} "$ADMIN_PASSWORD" "default" "admin_alt_demo@example.com" + get_or_add_user_project_role admin ${ADMIN_ALT_USERNAME} ${ALT_TENANT_NAME} +} + +# start_masakari() - Start running processes, including screen +function start_masakari { + run_process masakari-api "$MASAKARI_BIN_DIR/masakari-api --config-file=$MASAKARI_CONF --debug" +} + +# stop_masakari() - Stop running processes +function stop_masakari { + # Kill the masakari screen windows + local serv + for serv in masakari-api; do + stop_process $serv + done +} + +# Dispatcher for masakari plugin +if is_service_enabled masakari; then + if [[ "$1" == "stack" && "$2" == "install" ]]; then + echo_summary "Installing Masakari" + install_masakari + elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then + echo_summary "Configuring Masakari" + configure_masakari + + if is_service_enabled key; then + create_masakari_accounts + fi + + elif [[ "$1" == "stack" && "$2" == "extra" ]]; then + # Initialize masakari + init_masakari + + # Start the masakari API and masakari taskmgr components + echo_summary "Starting Masakari" + start_masakari + fi + + if [[ "$1" == "unstack" ]]; then + stop_masakari + cleanup_masakari + fi +fi + +# Restore xtrace +$XTRACE + +# Tell emacs to use shell-script-mode +## Local variables: +## mode: shell-script +## End: + diff --git a/devstack/settings b/devstack/settings new file mode 100644 index 00000000..2dc3410f --- /dev/null +++ b/devstack/settings @@ -0,0 +1,35 @@ +# Settings needed for Masakari plugin +# ----------------------------------- + +# Set up default directories +MASAKARI_DIR=${MASAKARI_DIR:-${DEST}/masakari} +MASAKARI_REPO=${GIT_BASE}/openstack/masakari.git} +MASAKARI_BRANCH=${MASAKARI_BRANCH:-master} + +# Set up configuration directory and files +MASAKARI_CONF_DIR=${MASAKARI_CONF_DIR:-/etc/masakari} +MASAKARI_CONF=${MASAKARI_CONF:-${MASAKARI_CONF_DIR}/masakari.conf} +MASAKARI_API_PASTE_INI=${MASAKARI_API_PASTE_INI:-${MASAKARI_CONF_DIR}/api-paste.ini} +MASAKARI_POLICY_JSON=${MASAKARI_POLICY_JSON:-${MASAKARI_CONF_DIR}/policy.json} + +MASAKARI_LOCAL_CONF_DIR=${MASAKARI_LOCAL_CONF_DIR:-${MASAKARI_DIR}/etc/masakari} +MASAKARI_LOCAL_API_PASTE_INI=${MASAKARI_LOCAL_API_PASTE_INI:-${MASAKARI_LOCAL_CONF_DIR}/api-paste.ini} +MASAKARI_LOCAL_POLICY_JSON=${MASAKARI_LOCAL_POLICY_JSON:-${MASAKARI_LOCAL_CONF_DIR}/policy.json} +MASAKARI_AUTH_CACHE_DIR=${MASAKARI_AUTH_CACHE_DIR:-/var/cache/masakari} + +# Support entry points installation of console scripts +if [[ -d $MASAKARI_DIR/bin ]]; then + MASAKARI_BIN_DIR=$MASAKARI_DIR/bin +else + MASAKARI_BIN_DIR=$(get_python_exec_prefix) +fi +MASAKARI_MANAGE=$MASAKARI_BIN_DIR/masakari-manage + +# Public facing bits +MASAKARI_SERVICE_PORT=${MANILA_SERVICE_PORT:-15868} + +# Tell Tempest this project is present +TEMPEST_SERVICES+=,masakari + +enable_service masakari masakari-api +