From 95edd7af1412bc4654bf8fefa0c8f67332fac654 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Thu, 30 Aug 2018 14:03:59 -0500 Subject: [PATCH] Add fm-rest-api and fm-client to DevStack At the moment it just installs and partially configures it. Depends-On: https://review.openstack.org/610756 Change-Id: If74b81841f583ad6d3850cd12ee337c1b4a1a177 Signed-off-by: Dean Troyer --- devstack/files/api-paste.ini | 12 ++++ devstack/lib/stx-fault | 109 +++++++++++++++++++++++++++++++---- tox.ini | 8 ++- 3 files changed, 116 insertions(+), 13 deletions(-) create mode 100644 devstack/files/api-paste.ini diff --git a/devstack/files/api-paste.ini b/devstack/files/api-paste.ini new file mode 100644 index 00000000..e3176a2b --- /dev/null +++ b/devstack/files/api-paste.ini @@ -0,0 +1,12 @@ +[app:api_v1] +paste.app_factory=fm.api.app:app_factory + +[filter:authtoken] +acl_public_routes=/, /v1 +paste.filter_factory=fm.api.middleware.auth_token:AuthTokenMiddleware.factory + +[filter:request_id] +paste.filter_factory=oslo_middleware:RequestId.factory + +[pipeline:fm-api] +pipeline=request_id authtoken api_v1 diff --git a/devstack/lib/stx-fault b/devstack/lib/stx-fault index 83a6e30b..95944369 100644 --- a/devstack/lib/stx-fault +++ b/devstack/lib/stx-fault @@ -27,6 +27,23 @@ set -o xtrace # Defaults # -------- +FAULT_DIR=${GITDIR[$STX_FAULT_NAME]} +FAULT_CONF_DIR=/etc/fm +FM_RESTAPI_CONF=$FAULT_CONF_DIR/fm.conf +FM_RESTAPI_PASTE_INI=$FAULT_CONF_DIR/api-paste.ini +FM_RESTAPI_AUTH_CACHE_DIR=${FM_RESTAPI_AUTH_CACHE_DIR:-/var/cache/fault} + +FM_RESTAPI_DIR=${GITDIR[$STX_FAULT_NAME]}/fm-rest-api/fm + + +if is_service_enabled tls-proxy; then + FM_RESTAPI_SERVICE_PROTOCOL="https" +fi +FM_RESTAPI_SERVICE_PROTOCOL=${FM_RESTAPI_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL} +FM_RESTAPI_SERVICE_HOST=${FM_RESTAPI_SERVICE_HOST:-$SERVICE_HOST} +FM_RESTAPI_SERVICE_PORT=${FM_RESTAPI_SERVICE_PORT:-18002} +FM_RESTAPI_WORKERS=${FM_RESTAPI_WORKERS:-4} + PYTHON_BIN_DIR=$(get_python_exec_prefix) PYTHON_SITE_DIR=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") @@ -42,6 +59,9 @@ function cleanup_fault { if is_service_enabled fm-common; then cleanup_fm_common fi + if is_service_enabled fm-restapi; then + cleanup_fm_restapi + fi } function cleanup_fm_common { @@ -94,16 +114,66 @@ function cleanup_fm_mgr { popd } +function cleanup_fm_rest_api { + sudo rm -rf $FM_RESTAPI_AUTH_CACHE_DIR $FM_RESTAPI_CONF +} + function configure_fault { - : + if is_service_enabled fm-rest-api; then + configure_fm_rest_api + fi +} + +function configure_fm_rest_api { + sudo install -d -o $STACK_USER -m 755 $FAULT_CONF_DIR + + cp -p $FAULT_DIR/devstack/files/api-paste.ini $FM_RESTAPI_PASTE_INI + + configure_auth_token_middleware $FM_RESTAPI_CONF fm $FM_RESTAPI_AUTH_CACHE_DIR + + iniset $FM_RESTAPI_CONF database connection $(database_connection_url fm) + iniset $FM_RESTAPI_CONF api api_paste_config $FM_RESTAPI_PASTE_INI + iniset $FM_RESTAPI_CONF api api_workers $FM_RESTAPI_WORKERS + iniset $FM_RESTAPI_CONF api bind_host $FM_RESTAPI_SERVICE_HOST + iniset $FM_RESTAPI_CONF api bind_port $FM_RESTAPI_SERVICE_PORT + + iniset $FM_RESTAPI_CONF oslo_middleware enable_proxy_headers_parsing True + + if [ "$SYSLOG" != "False" ]; then + iniset $FM_RESTAPI_CONF DEFAULT use_syslog True + # stx specific? + iniset $FM_RESTAPI_CONF DEFAULT syslog_log_facility local2 + fi + + # Additional things set in stx config + iniset $FM_RESTAPI_CONF DEFAULT region_name RegionOne + iniset $FM_RESTAPI_CONF DEFAULT event_log_max_size 4000 + iniset $FM_RESTAPI_CONF DEFAULT system_name $(hostname) + iniset $FM_RESTAPI_CONF database idle_timeout 60 + iniset $FM_RESTAPI_CONF database max_pool_size 1 + iniset $FM_RESTAPI_CONF database max_overflow 20 + iniset $FM_RESTAPI_CONF keystone_authtoken region_name RegionOne + + # sysinv settings to move there... + iniset $FM_RESTAPI_CONF sysinv catalog_info platform:sysinv:internalURL + iniset $FM_RESTAPI_CONF sysinv os_region_name RegionOne } function create_fault_accounts { - : + if [[ "$ENABLED_SERVICES" =~ "fm-rest-api" ]]; then + create_service_user "fm" + get_or_create_service "fm" "faultmanagement" "Fault Management Service" + get_or_create_endpoint \ + "faultmanagement" \ + "$REGION_NAME" \ + "$FM_RESTAPI_SERVICE_PROTOCOL://$FM_RESTAPI_SERVICE_HOST:$FM_RESTAPI_SERVICE_PORT/v1" + fi } function create_fault_cache_dir { - : + # Create cache dir + sudo install -d -o $STACK_USER $FM_RESTAPI_AUTH_CACHE_DIR + rm -f $FM_RESTAPI_AUTH_CACHE_DIR/* } function create_fault_user_group { @@ -111,22 +181,26 @@ function create_fault_user_group { } function init_fault { - : + create_fault_cache_dir } function install_fault { if is_service_enabled fm-common; then install_fm_common + install_fm_client fi if is_service_enabled fm-api; then install_fm_api fi - if is_service_enabled fm-rest-api; then + if is_service_enabled fm-api; then install_fm_api fi if is_service_enabled fm-mgr; then install_fm_mgr fi + if is_service_enabled fm-rest-api; then + install_fm_rest_api + fi } function install_fm_api { @@ -140,6 +214,17 @@ function install_fm_api { popd } +function install_fm_client { + pushd ${GITDIR[$STX_FAULT_NAME]}/python-fmclient/fmclient + sudo python setup.py install \ + --root=/ \ + --install-lib=$PYTHON_SITE_DIR \ + --prefix=/usr \ + --install-data=/usr/share \ + --single-version-externally-managed + popd +} + function install_fm_common { local x version @@ -213,19 +298,19 @@ function install_fm_mgr { } function install_fm_rest_api { - : + setup_develop $FM_RESTAPI_DIR } function start_fault { - : + if is_service_enabled fm-api; then + run_process fm-api "$PYTHON_BIN_DIR/fm-api --config-file $FM_RESTAPI_CONF" + fi } function stop_fault { - : -} - -function stop_fault_api { - : + if is_service_enabled fm-api; then + stop_process fm_api + fi } $_XTRACE_STX_FAULT diff --git a/tox.ini b/tox.ini index e7d2cb65..bb0bba19 100644 --- a/tox.ini +++ b/tox.ini @@ -22,7 +22,8 @@ commands = -not -name \*.md \ \( \ -name \*.sh \ - -or -wholename \*/devstack/\* \ + -or -not -wholename \*/devstack/files/\* \ + -wholename \*/devstack/\* \ \) \ -print0 | xargs -0 bashate -v -iE006" bash -c "find {toxinidir} \ @@ -84,3 +85,8 @@ commands = rm -rf api-ref/build sphinx-build -W -b html -d api-ref/build/doctrees api-ref/source api-ref/build/html whitelist_externals = rm + +[testenv:functional] +basepython = python3 +whitelist_externals = cat +commands = cat /etc/fm/fm.conf