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
This commit is contained in:
James E. Blair
2023-10-14 07:54:45 -07:00
parent bd11c4ff79
commit 59e6d1228e
2 changed files with 8 additions and 2 deletions

View File

@@ -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}
)

View File

@@ -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"'