Add devstack sqlalchemy support for freezer

Currently , devstack makes use of elasticsearch as db backend
by default for freezer-api project. The patch add sqlachemy
support.

Change-Id: I2f6e08183c58772142d7d053c7f1887a2274e4bd
This commit is contained in:
gecong1973 2018-10-29 22:49:44 -07:00
parent 3df81de035
commit bffde587b9
2 changed files with 46 additions and 15 deletions

View File

@ -29,5 +29,10 @@ For example to make use of port 19090 use:
export FREEZER_API_PORT=19090
The plugin makes use of elasticsearch as db backend by default.
To use the sqlachemy set the following environment variable:
export FREEZER_BACKEND='sqlalchemy'
For more information, see:
https://docs.openstack.org/devstack/latest/plugins.html

View File

@ -62,7 +62,9 @@ function is_freezer_api_enabled {
function cleanup_freezer_api {
disable_apache_site freezer-api
sudo rm -f $(apache_site_config_for freezer-api)
if [[ "${FREEZER_BACKEND}" != "sqlalchemy" ]]; then
${TOP_DIR}/pkg/elasticsearch.sh uninstall
fi
sudo rm -rf $FREEZER_API_AUTH_CACHE_DIR $FREEZER_API_CONF_DIR
}
@ -71,8 +73,10 @@ function install_freezer_api {
git_clone $FREEZER_API_REPO $FREEZER_API_DIR $FREEZER_API_BRANCH
if [[ "${FREEZER_BACKEND}" != "sqlalchemy" ]]; then
${TOP_DIR}/pkg/elasticsearch.sh download
${TOP_DIR}/pkg/elasticsearch.sh install
fi
setup_develop $FREEZER_API_DIR
@ -110,7 +114,17 @@ function configure_freezer_api {
# make sure the stack user has the right permissions on the config folder
sudo chown -R $USER $FREEZER_API_CONF_DIR
if [[ "${FREEZER_BACKEND}" == "sqlalchemy" ]]; then
#set sqlalchemy configuration
iniset $FREEZER_API_CONF 'storage' backend sqlalchemy
iniset $FREEZER_API_CONF 'storage' driver sqlalchemy
iniset $FREEZER_API_CONF 'database' connection `database_connection_url freezer`
else
#set elasticsearch configuration
iniset $FREEZER_API_CONF 'storage' backend elasticsearch
iniset $FREEZER_API_CONF 'storage' driver elasticsearch
@ -118,6 +132,8 @@ function configure_freezer_api {
iniset $FREEZER_API_CONF 'elasticsearch' number_of_replicas 0
iniset $FREEZER_API_CONF 'elasticsearch' hosts http://$SERVICE_HOST:9200
fi
# create freezer_api_cache_dir
sudo mkdir -p $FREEZER_API_AUTH_CACHE_DIR/api
sudo chown $STACK_USER $FREEZER_API_AUTH_CACHE_DIR/api
@ -143,12 +159,19 @@ function configure_freezer_api {
# executed during: stack extra
function init_freezer_api {
if [[ "${FREEZER_BACKEND}" == "sqlalchemy" ]]; then
recreate_database freezer utf8
freezer-manage db sync
else
# this also waits for elasticsearch to start
${TOP_DIR}/pkg/elasticsearch.sh start
# put elasticsearch mappings
freezer-manage db update
freezer-manage db show
fi
}
@ -176,7 +199,10 @@ function start_freezer_api {
# executed during: stop
function stop_freezer_api {
if [[ "${FREEZER_BACKEND}" != "sqlalchemy" ]]; then
${TOP_DIR}/pkg/elasticsearch.sh stop
fi
if [[ "${FREEZER_API_SERVER_TYPE}" == "uwsgi" ]]; then
uwsgi --stop $FREEZER_API_UWSGI_MASTER_PIDFILE