From 1419356ed88a622dd892afd876d109874985f0d0 Mon Sep 17 00:00:00 2001 From: djager Date: Mon, 13 Dec 2021 15:43:30 +0100 Subject: [PATCH] Allow to specify MySQL port for test environment In case for whatever reason there is already another MySQL server running on the standard port developers may want to run the MySQL test-server on a different port. This can be done by specifying an environment variable "ZUUL_MYSQL_PORT": export ZUUL_MYSQL_PORT=3307 tools/test-setup-docker.sh tox -e py3 Change-Id: Id32bac1a87619803d973b066762d525bd9a4f913 --- tests/base.py | 12 ++++++++++-- tools/docker-compose.yaml | 2 +- tox.ini | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/base.py b/tests/base.py index 3906e649c0..3d087178f1 100644 --- a/tests/base.py +++ b/tests/base.py @@ -4023,7 +4023,9 @@ class MySQLSchemaFixture(fixtures.Fixture): self.name = '%s_%s' % (random_bits, os.getpid()) self.passwd = uuid.uuid4().hex self.host = os.environ.get('ZUUL_MYSQL_HOST', '127.0.0.1') + self.port = int(os.environ.get('ZUUL_MYSQL_PORT', 3306)) db = pymysql.connect(host=self.host, + port=self.port, user="openstack_citest", passwd="openstack_citest", db="openstack_citest") @@ -4039,13 +4041,19 @@ class MySQLSchemaFixture(fixtures.Fixture): finally: db.close() - self.dburi = 'mysql+pymysql://{name}:{passwd}@{host}/{name}'.format( - name=self.name, passwd=self.passwd, host=self.host) + self.dburi = 'mysql+pymysql://{name}:{passwd}@{host}:{port}/{name}'\ + .format( + name=self.name, + passwd=self.passwd, + host=self.host, + port=self.port + ) self.addDetail('dburi', testtools.content.text_content(self.dburi)) self.addCleanup(self.cleanup) def cleanup(self): db = pymysql.connect(host=self.host, + port=self.port, user="openstack_citest", passwd="openstack_citest", db="openstack_citest") diff --git a/tools/docker-compose.yaml b/tools/docker-compose.yaml index edb5676fd4..fbf5ad2802 100644 --- a/tools/docker-compose.yaml +++ b/tools/docker-compose.yaml @@ -7,7 +7,7 @@ services: environment: - MYSQL_ROOT_PASSWORD=insecure_worker ports: - - "3306:3306" + - "${ZUUL_MYSQL_PORT:-3306}:3306" tmpfs: - /var/lib/mysql volumes: diff --git a/tox.ini b/tox.ini index 634d3a2ced..e4841e53dc 100644 --- a/tox.ini +++ b/tox.ini @@ -27,6 +27,7 @@ passenv = OS_STDOUT_CAPTURE YARN_REGISTRY ZUUL_MYSQL_HOST + ZUUL_MYSQL_PORT ZUUL_POSTGRES_HOST ZUUL_SCHEDULER_COUNT ZUUL_TEST_ROOT