devstack/lib/stack
Mathieu Mitchell fa55cb5f97 Ensure valid service names are passed to stack_install_service
Currently, stack_install_service will accept any service name. This is
problematic because a project plugin can pass an invalid name without
noticing. This has been the case in ironic-inspector[0].

This commit ensures that stack_install_service will not silently fail
when passing an invalid service name.

[0] https://review.openstack.org/#/c/424680/

Change-Id: I1a8105bdbaf4aecb630df08da416808bf7180824
Closes-Bug: #1659042
2017-08-01 18:22:35 +00:00

41 lines
1.4 KiB
Bash

#!/bin/bash
#
# lib/stack
#
# These functions are code snippets pulled out of ``stack.sh`` for easier
# re-use by Grenade. They can assume the same environment is available
# as in the lower part of ``stack.sh``, namely a valid stackrc has been sourced
# as well as all of the ``lib/*`` files for the services have been sourced.
#
# For clarity, all functions declared here that came from ``stack.sh``
# shall be named with the prefix ``stack_``.
# Functions
# ---------
# Generic service install handles venv creation if configured for service
# stack_install_service service
function stack_install_service {
local service=$1
if type install_${service} >/dev/null 2>&1; then
# FIXME(dhellmann): Needs to be python3-aware at some point.
if [[ ${USE_VENV} = True && -n ${PROJECT_VENV[$service]:-} ]]; then
rm -rf ${PROJECT_VENV[$service]}
source $TOP_DIR/tools/build_venv.sh ${PROJECT_VENV[$service]} ${ADDITIONAL_VENV_PACKAGES//,/ }
export PIP_VIRTUAL_ENV=${PROJECT_VENV[$service]:-}
# Install other OpenStack prereqs that might come from source repos
install_oslo
install_keystonemiddleware
fi
install_${service}
if [[ ${USE_VENV} = True && -n ${PROJECT_VENV[$service]:-} ]]; then
unset PIP_VIRTUAL_ENV
fi
else
echo "No function declared with name 'install_${service}'."
exit 1
fi
}