Fix configure_for_func_testing script

Following fixes are done in the script:-
- Use openstack_citest as db user as done in CI[1] as
  with root as db user it fails configure it.
- Use MYSQL_USER var instead of hardcoded root user
- Fix Syntax Error in CREATE USER psql command by using
  quotes for DATABASE_PASSWORD
- Swith to root user for running psql command as without
  it, it asks for stack user password which is not configured,
  same is done in devstack[2].
- Create variable DATABASE_NAME for database name and use
  at all required places.

[1] https://review.opendev.org/c/openstack/neutron/+/814009/
[2] https://opendev.org/openstack/devstack/src/branch/master/lib/databases/postgresql#L90

Change-Id: Ieb523e3afdf69fff87ea9062ed857c37a8d56f5c
(cherry picked from commit 28df8470f6)
This commit is contained in:
yatinkarel 2022-02-25 14:23:21 +05:30 committed by Rodolfo Alonso Hernandez
parent 8409ab821e
commit c12e70fe6c
1 changed files with 9 additions and 8 deletions

View File

@ -21,7 +21,8 @@ set -e
IS_GATE=${IS_GATE:-False}
USE_CONSTRAINT_ENV=${USE_CONSTRAINT_ENV:-True}
MYSQL_USER=${MYSQL_USER:-root}
DATABASE_USER=${DATABASE_USER:-${MYSQL_USER}}
DATABASE_USER=${DATABASE_USER:-openstack_citest}
DATABASE_NAME=${DATABASE_NAME:-openstack_citest}
if [[ "$IS_GATE" != "True" ]] && [[ "$#" -lt 1 ]]; then
@ -152,7 +153,7 @@ function _install_databases {
# Avoid attempting to configure the db if it appears to already
# have run. The setup as currently defined is not idempotent.
if mysql openstack_citest > /dev/null 2>&1 < /dev/null; then
if mysql ${DATABASE_NAME} > /dev/null 2>&1 < /dev/null; then
echo_summary "DB config appears to be complete, skipping."
return 0
fi
@ -174,27 +175,27 @@ function _install_databases {
configure_database_postgresql
fi
# Set up the 'openstack_citest' user and database in each backend
# Set up the '${DATABASE_USER}' user and '${DATABASE_NAME}' database in each backend
tmp_dir=$(mktemp -d)
trap "rm -rf $tmp_dir" EXIT
cat << EOF > $tmp_dir/mysql.sql
CREATE DATABASE openstack_citest;
CREATE DATABASE ${DATABASE_NAME};
CREATE USER '${DATABASE_USER}'@'localhost' IDENTIFIED BY '${MYSQL_PASSWORD}';
GRANT ALL PRIVILEGES ON *.* TO '${DATABASE_USER}'@'localhost';
FLUSH PRIVILEGES;
EOF
/usr/bin/mysql -u root -p"$MYSQL_PASSWORD" < $tmp_dir/mysql.sql
/usr/bin/mysql -u $MYSQL_USER -p"$MYSQL_PASSWORD" < $tmp_dir/mysql.sql
if [[ "$install_pg" == "True" ]]; then
cat << EOF > $tmp_dir/postgresql.sql
CREATE USER ${DATABASE_USER} WITH CREATEDB LOGIN PASSWORD ${DATABASE_PASSWORD};
CREATE DATABASE ${DATABASE_USER} WITH OWNER ${DATABASE_USER};
CREATE USER ${DATABASE_USER} WITH CREATEDB LOGIN PASSWORD '${DATABASE_PASSWORD}';
CREATE DATABASE ${DATABASE_NAME} WITH OWNER ${DATABASE_USER};
EOF
# User/group postgres needs to be given access to tmp_dir
setfacl -m g:postgres:rwx $tmp_dir
sudo -u postgres /usr/bin/psql --file=$tmp_dir/postgresql.sql
sudo -u root sudo -u postgres /usr/bin/psql --file=$tmp_dir/postgresql.sql
fi
}