fault/devstack/lib/fault

398 lines
10 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
#
# SPDX-License-Identifier: Apache-2.0
#
# Copyright (c) 2019 Intel Corporation
#
# Copyright (c) 2022 Wind River Systems, Inc.
#
# lib/fault
# Functions to control the configuration and operation of the **fault** service
# Dependencies:
#
# - The update plugin must be enabled
# ``stack.sh`` calls the entry points in this order:
#
# - install_fault
# - configure_fault
# - init_fault
# - start_fault
# - stop_fault
# - cleanup_fault
_XTRACE_STX_FAULT=$(set +o | grep xtrace)
set -o xtrace
# Defaults
# --------
STX_FAULT_DIR=${GITDIR[$STX_FAULT_NAME]}
STX_FAULT_CONF_DIR=/etc/fm
GITDIR["fm-api"]=$STX_FAULT_DIR/fm-api
GITDIR["fm-client"]=$STX_FAULT_DIR/python-fmclient/fmclient
GITDIR["fm-core"]=$STX_FAULT_DIR/fm-common/sources
FM_RESTAPI_CONF=$STX_FAULT_CONF_DIR/fm.conf
FM_RESTAPI_PASTE_INI=$STX_FAULT_CONF_DIR/api-paste.ini
FM_EVENT_YAML=$STX_FAULT_CONF_DIR/events.yaml
FM_POLICY_YAML=$STX_FAULT_CONF_DIR/policy.yaml
FM_RESTAPI_AUTH_CACHE_DIR=${FM_RESTAPI_AUTH_CACHE_DIR:-/var/cache/fault}
FM_RESTAPI_DIR=$STX_FAULT_DIR/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}
# STX_INST_DIR should be a non-root-writable place to install build artifacts
STX_INST_DIR=${STX_INST_DIR:-/usr/local}
STX_BIN_DIR=${STX_BIN_DIR:-$STX_INST_DIR/bin}
STX_SBIN_DIR=${STX_SBIN_DIR:-$STX_INST_DIR/sbin}
# Set up so we don't use sudo for installs when not necessary
STX_SUDO="sudo"
[[ -w $STX_INST_DIR ]] && STX_SUDO="env"
PYTHON_SITE_DIR=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
# Functions
# ---------
function build_fm_common {
pushd ${GITDIR["fm-core"]}
local major minor version x
if [[ -z $1 || -z $2 ]]; then
# get fm-common version
read x version <<< $(grep '^Version: ' $STX_FAULT_DIR/fm-common/PKG-INFO)
major=${version%%.*}
minor=${version##*.}
else
major=$1
minor=$2
fi
# build
make MAJOR=$major MINOR=$minor
python setup.py build
popd
}
function build_fm_mgr {
pushd $STX_FAULT_DIR/fm-mgr/sources
local x version
local major minor version x
if [[ -z $1 || -z $2 ]]; then
# get fm-mgr version
read x version <<< $(grep '^Version: ' $STX_FAULT_DIR/fm-mgr/PKG-INFO)
local major=${version%%.*}
local minor=${version##*.}
else
major=$1
minor=$2
fi
# build
CPATH=$STX_INST_DIR/include LIBRARY_PATH=$STX_INST_DIR/lib make \
MAJOR=$major \
MINOR=$minor
popd
}
function cleanup_fault {
stop_fault
if is_service_enabled fm-client || is_service_enabled fm-common; then
cleanup_fm_client
fi
if is_service_enabled fm-api; then
cleanup_fm_api
fi
if is_service_enabled fm-mgr; then
cleanup_fm_mgr
fi
if is_service_enabled fm-rest-api; then
cleanup_fm_rest_api
fi
if is_service_enabled fm-common; then
cleanup_fm_common
fi
}
function cleanup_fm_api {
sudo pip uninstall -y fm_api
}
function cleanup_fm_client {
sudo pip uninstall -y fmclient
}
function cleanup_fm_common {
local x version
# get fm-common version
read x version <<< $(grep '^Version: ' $STX_FAULT_DIR/fm-common/PKG-INFO)
local major=${version%%.*}
local minor=${version##*.}
sudo rm /etc/ld.so.conf.d/stx-fault.conf
sudo pip uninstall -y fm-core
pushd $STX_FAULT_DIR/fm-common/sources
$STX_SUDO make \
DESTDIR=$STX_INST_DIR \
BINDIR=/bin \
LIBDIR=/lib \
INCDIR=/include \
MAJOR=$major \
MINOR=$minor \
clean
$STX_SUDO rm $STX_BIN_DIR/fm_db_sync_event_suppression.py \
$STX_INST_DIR/include/fmConfig.h \
$STX_INST_DIR/include/fmLog.h
popd
}
function cleanup_fm_mgr {
local x version
# get fm-mgr version
read x version <<< $(grep '^Version: ' $STX_FAULT_DIR/fm-mgr/PKG-INFO)
local major=${version%%.*}
local minor=${version##*.}
pushd $STX_FAULT_DIR/fm-mgr/sources
$STX_SUDO make \
DESTDIR=$STX_INST_DIR \
BINDIR=/bin \
MAJOR=$major \
MINOR=$minor \
clean
popd
}
function cleanup_fm_rest_api {
sudo pip uninstall -y fm
sudo rm -rf $FM_RESTAPI_AUTH_CACHE_DIR $FM_RESTAPI_CONF $FM_RESTAPI_PASTE_INI $FM_EVENT_YAML $FM_POLICY_YAML
dropdb -h 127.0.0.1 -Uroot fm
}
function configure_fault {
if is_service_enabled fm-mgr || is_service_enabled fm-rest-api; then
configure_fm_rest_api
create_fault_user_group
create_fault_accounts
fi
}
function configure_fm_rest_api {
sudo install -d -o $STACK_USER -m 755 $STX_FAULT_CONF_DIR
cp -p $STX_FAULT_DIR/devstack/files/api-paste.ini $FM_RESTAPI_PASTE_INI
cp -p $STX_FAULT_DIR/fm-doc/fm_doc/events.yaml $FM_EVENT_YAML
cp -p $STX_FAULT_DIR/fm-rest-api/fm/fm/policy.yaml $FM_POLICY_YAML
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 DEFAULT sql_connection $(database_connection_url fm)
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 {
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"
}
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 {
:
}
function init_fault {
create_fault_cache_dir
if is_service_enabled fm-rest-api && is_service_enabled config; then
init_rest_api
fi
}
function init_rest_api {
recreate_database fm
fm-dbsync --config-file $FM_RESTAPI_CONF
}
function install_fault {
if is_service_enabled fm-common; then
install_fm_common
fi
if is_service_enabled fm-client || is_service_enabled fm-common; then
install_fm_client
fi
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 && is_service_enabled config; then
install_fm_rest_api
fi
}
function install_fm_api {
setup_dev_lib "fm-api"
}
function install_fm_client {
setup_dev_lib "fm-client"
}
function install_fm_common {
pushd ${GITDIR["fm-core"]}
local major minor version x
# get fm-common version
read x version <<< $(grep '^Version: ' $STX_FAULT_DIR/fm-common/PKG-INFO)
major=${version%%.*}
minor=${version##*.}
build_fm_common $major $minor
# install to STX_INST_DIR
# Note that DESTDIR prefixes the other locations in the Makefile
$STX_SUDO make \
DESTDIR=$STX_INST_DIR \
BINDIR=/bin \
LIBDIR=/lib \
INCDIR=/include \
MAJOR=$major \
MINOR=$minor \
install
setup_dev_lib "fm-core"
# This _is_ still a little nasty, clean it up
$STX_SUDO install -m 755 fm_db_sync_event_suppression.py \
$STX_BIN_DIR/fm_db_sync_event_suppression.py
# install the headers that used by fm-mgr package
$STX_SUDO install -m 644 -p -D fmConfig.h $STX_INST_DIR/include/fmConfig.h
$STX_SUDO install -m 644 -p -D fmLog.h $STX_INST_DIR/include/fmLog.h
# Make sure we can find it later
# TODO: this should be managed better
echo $STX_INST_DIR/lib | sudo tee /etc/ld.so.conf.d/stx-fault.conf
sudo ldconfig
# in fm-common/sources/fmMsgServer.cpprequst get "getaddrinfo(host.c_str(),"
# hostname "controller" ip, so change hosname to controller
ADD_LINE="$HOST_IP controller"
grep "$ADD_LINE" /etc/hosts || sudo sed -i "/127.0.0.1 */a$ADD_LINE" /etc/hosts
popd
}
function install_fm_mgr {
pushd $STX_FAULT_DIR/fm-mgr/sources
local major minor version x
# get fm-mgr version
read x version <<< $(grep '^Version: ' $STX_FAULT_DIR/fm-mgr/PKG-INFO)
major=${version%%.*}
minor=${version##*.}
build_fm_mgr $major $minor
# install to STX_INST_DIR
# Note that DESTDIR prefixes the other locations in the Makefile
$STX_SUDO make \
DESTDIR=$STX_INST_DIR \
BINDIR=/bin \
MAJOR=$major \
MINOR=$minor \
install
popd
}
function install_fm_rest_api {
setup_develop $FM_RESTAPI_DIR
}
function start_fault {
if is_service_enabled fm-rest-api; then
run_process fm-rest-api "$STX_BIN_DIR/fm-api --config-file $FM_RESTAPI_CONF"
fi
if is_service_enabled fm-mgr; then
run_process fm-mgr "$STX_BIN_DIR/fmManager start -c $FM_RESTAPI_CONF"
fi
}
function stop_fault {
if is_service_enabled fm-rest-api; then
stop_process fm-rest-api
fi
if is_service_enabled fm-mgr; then
stop_process fm-mgr
fi
}
$_XTRACE_STX_FAULT