From 59e6d1228e264a50a20839bd55a2ee88c88cbb26 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Sat, 14 Oct 2023 07:54:45 -0700 Subject: [PATCH] Add option to use in-container pg_dump in tests The pg_dump command is picky about client/server versions, so to make it easier for developers to run tests locally using the pgsql container, provida an option to use pg_dump from the container instead of whatever version is installed locally, which may not match. Change-Id: I9add7af40b8f8d92a88d983eacbc59a01f0e7b9f --- tests/unit/test_database.py | 6 ++++-- tools/test-setup-docker.sh | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_database.py b/tests/unit/test_database.py index 3453f9f728..f9c0366cdb 100644 --- a/tests/unit/test_database.py +++ b/tests/unit/test_database.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +import os import re import subprocess @@ -226,8 +227,9 @@ class TestPostgresqlDatabase(DBBaseTestCase): def test_migration(self): # Test that SQLAlchemy create_all produces the same output as # a full migration run. + pg_dump = os.environ.get("ZUUL_TEST_PG_DUMP", "pg_dump") sqlalchemy_out = subprocess.check_output( - f"pg_dump -h {self.db.host} -U {self.db.name} -s {self.db.name}", + f"{pg_dump} -h {self.db.host} -U {self.db.name} -s {self.db.name}", shell=True, env={'PGPASSWORD': self.db.passwd} ) @@ -246,7 +248,7 @@ class TestPostgresqlDatabase(DBBaseTestCase): self.connection.onLoad(self.zk_client) alembic_out = subprocess.check_output( - f"pg_dump -h {self.db.host} -U {self.db.name} -s {self.db.name}", + f"{pg_dump} -h {self.db.host} -U {self.db.name} -s {self.db.name}", shell=True, env={'PGPASSWORD': self.db.passwd} ) diff --git a/tools/test-setup-docker.sh b/tools/test-setup-docker.sh index 1601b11a7f..bd692d1e52 100755 --- a/tools/test-setup-docker.sh +++ b/tools/test-setup-docker.sh @@ -62,4 +62,8 @@ ${ROOTCMD} ${MYSQL} -e "CREATE USER 'openstack_citest'@'%' identified by 'openst ${ROOTCMD} ${MYSQL} -e "GRANT ALL PRIVILEGES ON *.* TO 'openstack_citest'@'%' WITH GRANT OPTION;" ${ROOTCMD} ${MYSQL} -u openstack_citest -popenstack_citest -e "SET default_storage_engine=MYISAM; DROP DATABASE IF EXISTS openstack_citest; CREATE DATABASE openstack_citest CHARACTER SET utf8;" +set +x echo "Finished" + +echo "Set this variable to use the in-container pg_dump command:" +echo 'export ZUUL_TEST_PG_DUMP="docker exec -t zuul-test-postgres pg_dump"'