2018-12-10 09:19:36 +01:00
|
|
|
# Directory where this plugin.sh file is
|
|
|
|
TOBIKO_PLUGIN_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
|
|
|
|
|
|
|
2020-04-22 14:14:24 +02:00
|
|
|
function install_tobiko_deps {
|
2020-04-17 13:52:39 +02:00
|
|
|
if [ "${TOBIKO_BINDEP}" != "" ]; then
|
|
|
|
install_python3
|
|
|
|
install_bindep "${TOBIKO_DIR}/bindep.txt" test
|
|
|
|
fi
|
2018-12-10 09:19:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-17 08:09:44 +01:00
|
|
|
function configure_tobiko {
|
2019-12-03 17:13:06 +01:00
|
|
|
# Ensure any user can write to log file
|
|
|
|
local log_dir=$(dirname ${TOBIKO_LOG_FILE})
|
|
|
|
if ! [ -d "${log_dir}" ]; then
|
|
|
|
sudo mkdir -p "${log_dir}"
|
|
|
|
fi
|
|
|
|
if ! [ -w "${TOBIKO_LOG_FILE}" ]; then
|
|
|
|
sudo touch "${TOBIKO_LOG_FILE}"
|
|
|
|
sudo chmod ugo+rw "${TOBIKO_LOG_FILE}"
|
|
|
|
fi
|
|
|
|
|
2018-12-17 08:09:44 +01:00
|
|
|
# Write configuration to a new temporary file
|
2019-11-27 10:50:57 +01:00
|
|
|
local tobiko_conf_file=$(mktemp)
|
|
|
|
if [ -f "${TOBIKO_CONF_FILE}" ]; then
|
2018-12-17 08:09:44 +01:00
|
|
|
# Start from existing tobiko.conf file
|
2019-12-04 16:18:16 +01:00
|
|
|
cp "${TOBIKO_CONF_FILE}" "${tobiko_conf_file}"
|
2018-12-10 15:04:35 +01:00
|
|
|
fi
|
|
|
|
|
2019-11-27 10:50:57 +01:00
|
|
|
configure_tobiko_default "${tobiko_conf_file}"
|
|
|
|
configure_tobiko_cirros "${tobiko_conf_file}"
|
|
|
|
configure_tobiko_glance "${tobiko_conf_file}"
|
|
|
|
configure_tobiko_keystone "${tobiko_conf_file}"
|
|
|
|
configure_tobiko_nova "${tobiko_conf_file}"
|
|
|
|
configure_tobiko_neutron "${tobiko_conf_file}"
|
2018-12-10 15:04:35 +01:00
|
|
|
|
2019-11-27 10:50:57 +01:00
|
|
|
echo_summary "Apply changes to actual ${TOBIKO_CONF_FILE} file."
|
|
|
|
sudo mkdir -p $(dirname "${TOBIKO_CONF_FILE}")
|
|
|
|
sudo mv "${tobiko_conf_file}" "${TOBIKO_CONF_FILE}"
|
|
|
|
sudo chmod ugo+r "${TOBIKO_CONF_FILE}"
|
2018-12-10 15:04:35 +01:00
|
|
|
|
2019-11-27 10:50:57 +01:00
|
|
|
echo "${TOBIKO_CONF_FILE} file content:"
|
2019-05-08 15:30:16 +02:00
|
|
|
echo --------------------------------
|
2019-11-27 10:50:57 +01:00
|
|
|
cat "${TOBIKO_CONF_FILE}"
|
2019-05-08 15:30:16 +02:00
|
|
|
echo --------------------------------
|
2018-12-10 15:04:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-24 09:36:28 +02:00
|
|
|
function configure_tobiko_cirros {
|
2019-11-27 10:50:57 +01:00
|
|
|
echo_summary "Write [cirros] section to ${TOBIKO_CONF_FILE}"
|
|
|
|
local tobiko_conf_file=$1
|
|
|
|
|
|
|
|
iniset_nonempty "${tobiko_conf_file}" cirros name "${TOBIKO_CIRROS_IMAGE_NAME}"
|
|
|
|
iniset_nonempty "${tobiko_conf_file}" cirros url "${TOBIKO_CIRROS_IMAGE_URL}"
|
|
|
|
iniset_nonempty "${tobiko_conf_file}" cirros file "${TOBIKO_CIRROS_IMAGE_FILE}"
|
|
|
|
iniset_nonempty "${tobiko_conf_file}" cirros username "${TOBIKO_CIRROS_USERNAME}"
|
|
|
|
iniset_nonempty "${tobiko_conf_file}" cirros password "${TOBIKO_CIRROS_PASSWORD}"
|
2019-06-24 09:36:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-08 15:30:16 +02:00
|
|
|
function configure_tobiko_default {
|
2019-11-27 10:50:57 +01:00
|
|
|
echo_summary "Write [DEFAULT] section to ${TOBIKO_CONF_FILE}"
|
|
|
|
local tobiko_conf_file=$1
|
2019-05-08 15:30:16 +02:00
|
|
|
|
2019-11-27 10:50:57 +01:00
|
|
|
setup_logging "${tobiko_conf_file}"
|
|
|
|
iniset ${tobiko_conf_file} DEFAULT debug "${TOBIKO_DEBUG}"
|
|
|
|
iniset ${tobiko_conf_file} DEFAULT log_dir $(dirname "${TOBIKO_LOG_FILE}")
|
|
|
|
iniset ${tobiko_conf_file} DEFAULT log_file $(basename "${TOBIKO_LOG_FILE}")
|
2018-12-10 15:04:35 +01:00
|
|
|
}
|
|
|
|
|
2019-06-24 09:36:28 +02:00
|
|
|
|
|
|
|
function configure_tobiko_glance {
|
2019-11-27 10:50:57 +01:00
|
|
|
echo_summary "Write [glance] section to ${TOBIKO_CONF_FILE}"
|
|
|
|
local tobiko_conf_file=$1
|
2019-06-24 09:36:28 +02:00
|
|
|
|
2019-11-27 10:50:57 +01:00
|
|
|
iniset_nonempty "${tobiko_conf_file}" glance image_dir "${TOBIKO_GLANCE_IMAGE_DIR}"
|
2019-06-24 09:36:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-08 15:30:16 +02:00
|
|
|
function configure_tobiko_keystone {
|
2019-11-27 10:50:57 +01:00
|
|
|
echo_summary "Write [keystone] section to ${TOBIKO_CONF_FILE}"
|
|
|
|
local tobiko_conf_file=$1
|
2018-12-17 08:09:44 +01:00
|
|
|
|
2019-05-08 15:30:16 +02:00
|
|
|
local api_version=${IDENTITY_API_VERSION}
|
2019-10-01 08:32:00 +02:00
|
|
|
if [ "${api_version}" == '2' ]; then
|
2019-05-08 15:30:16 +02:00
|
|
|
local auth_url=${KEYSTONE_AUTH_URI/v2.0}
|
2018-12-17 08:09:44 +01:00
|
|
|
else
|
2019-05-08 15:30:16 +02:00
|
|
|
local auth_url=${KEYSTONE_AUTH_URI_V3:-${KEYSTONE_AUTH_URI/v3}}
|
2018-12-17 08:09:44 +01:00
|
|
|
fi
|
2018-12-10 15:04:35 +01:00
|
|
|
|
2019-05-08 15:30:16 +02:00
|
|
|
local project_id=$(get_or_create_project \
|
|
|
|
"${TOBIKO_KEYSTONE_PROJECT_NAME}" \
|
|
|
|
"${TOBIKO_KEYSTONE_PROJECT_DOMAIN_NAME}")
|
|
|
|
|
|
|
|
local user_id=$(get_or_create_user \
|
|
|
|
"${TOBIKO_KEYSTONE_USERNAME}" \
|
|
|
|
"${TOBIKO_KEYSTONE_PASSWORD}" \
|
|
|
|
"${TOBIKO_KEYSTONE_USER_DOMAIN_NAME}")
|
|
|
|
|
|
|
|
local user_project_role_id=$(get_or_add_user_project_role \
|
|
|
|
"${TOBIKO_KEYSTONE_USER_ROLE}" \
|
|
|
|
"${user_id}" \
|
|
|
|
"${project_id}")
|
|
|
|
|
|
|
|
local user_domain_role_id=$(get_or_add_user_domain_role \
|
|
|
|
"${TOBIKO_KEYSTONE_USER_ROLE}" \
|
|
|
|
"${user_id}" \
|
|
|
|
"${TOBIKO_KEYSTONE_USER_DOMAIN_NAME}")
|
|
|
|
|
2019-11-27 10:50:57 +01:00
|
|
|
iniset "${tobiko_conf_file}" keystone cloud_name "${TOBIKO_KEYSTONE_CLOUD_NAME}"
|
|
|
|
iniset "${tobiko_conf_file}" keystone api_version "${api_version}"
|
|
|
|
iniset "${tobiko_conf_file}" keystone auth_url "${auth_url}"
|
|
|
|
iniset "${tobiko_conf_file}" keystone username "${TOBIKO_KEYSTONE_USERNAME}"
|
|
|
|
iniset "${tobiko_conf_file}" keystone password "${TOBIKO_KEYSTONE_PASSWORD}"
|
|
|
|
iniset "${tobiko_conf_file}" keystone project_name "${TOBIKO_KEYSTONE_PROJECT_NAME}"
|
2019-05-08 15:30:16 +02:00
|
|
|
|
|
|
|
if [ "${api_version}" != '2' ]; then
|
2019-11-27 10:50:57 +01:00
|
|
|
iniset "${tobiko_conf_file}" keystone domain_name "${TOBIKO_KEYSTONE_DOMAIN_NAME}"
|
|
|
|
iniset "${tobiko_conf_file}" keystone user_domain_name \
|
2019-05-08 15:30:16 +02:00
|
|
|
"${TOBIKO_KEYSTONE_USER_DOMAIN_NAME}"
|
2019-11-27 10:50:57 +01:00
|
|
|
iniset "${tobiko_conf_file}" keystone project_domain_name \
|
2019-05-08 15:30:16 +02:00
|
|
|
"${TOBIKO_KEYSTONE_PROJECT_DOMAIN_NAME}"
|
2019-11-27 10:50:57 +01:00
|
|
|
iniset "${tobiko_conf_file}" keystone trust_id "${TOBIKO_KEYSTONE_TRUST_ID}"
|
2019-05-08 15:30:16 +02:00
|
|
|
fi
|
|
|
|
}
|
2018-12-10 15:04:35 +01:00
|
|
|
|
2019-04-03 10:16:28 +02:00
|
|
|
|
2019-05-08 15:30:16 +02:00
|
|
|
function configure_tobiko_nova {
|
2019-11-27 10:50:57 +01:00
|
|
|
echo_summary "Write [nova] section to ${TOBIKO_CONF_FILE}"
|
|
|
|
local tobiko_conf_file=$1
|
2019-04-03 10:16:28 +02:00
|
|
|
|
2019-05-08 15:30:16 +02:00
|
|
|
# Write key_file
|
|
|
|
local key_file=${TOBIKO_NOVA_KEY_FILE:-}
|
2020-04-17 20:15:21 +02:00
|
|
|
if [ "${key_file}" != "" ]; then
|
|
|
|
iniset "${tobiko_conf_file}" nova key_file "${key_file}"
|
|
|
|
fi
|
2018-12-10 15:04:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-08 15:30:16 +02:00
|
|
|
function configure_tobiko_neutron {
|
2019-11-27 10:50:57 +01:00
|
|
|
echo_summary "Write [neutron] section to ${TOBIKO_CONF_FILE}"
|
|
|
|
local tobiko_conf_file=$1
|
2019-05-08 15:30:16 +02:00
|
|
|
|
|
|
|
# Write floating network
|
|
|
|
local floating_network=${TOBIKO_NEUTRON_FLOATING_NETWORK}
|
|
|
|
if [ "${floating_network}" != "" ]; then
|
2020-02-19 15:58:23 +01:00
|
|
|
iniset "${tobiko_conf_file}" neutron floating_network "${floating_network}"
|
2018-12-17 08:09:44 +01:00
|
|
|
fi
|
2018-12-10 09:19:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-24 09:36:28 +02:00
|
|
|
function iniset_nonempty {
|
|
|
|
# Calls iniset only when option value is not an empty string
|
|
|
|
if [ -n "$4" ]; then
|
|
|
|
iniset "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-10 09:19:36 +01:00
|
|
|
if [[ "$1" == "stack" ]]; then
|
|
|
|
case "$2" in
|
|
|
|
install)
|
2020-04-22 14:14:24 +02:00
|
|
|
echo_summary "Installing Tobiko dependencies"
|
|
|
|
install_tobiko_deps
|
2018-12-10 09:19:36 +01:00
|
|
|
;;
|
|
|
|
test-config)
|
2020-04-22 14:14:24 +02:00
|
|
|
echo_summary "Configuring Tobiko test cases"
|
2018-12-17 08:09:44 +01:00
|
|
|
configure_tobiko
|
2018-12-10 09:19:36 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|