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
This commit is contained in:
djager 2021-12-13 15:43:30 +01:00
parent 02efa8fb28
commit 1419356ed8
3 changed files with 12 additions and 3 deletions

View File

@ -4023,7 +4023,9 @@ class MySQLSchemaFixture(fixtures.Fixture):
self.name = '%s_%s' % (random_bits, os.getpid()) self.name = '%s_%s' % (random_bits, os.getpid())
self.passwd = uuid.uuid4().hex self.passwd = uuid.uuid4().hex
self.host = os.environ.get('ZUUL_MYSQL_HOST', '127.0.0.1') 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, db = pymysql.connect(host=self.host,
port=self.port,
user="openstack_citest", user="openstack_citest",
passwd="openstack_citest", passwd="openstack_citest",
db="openstack_citest") db="openstack_citest")
@ -4039,13 +4041,19 @@ class MySQLSchemaFixture(fixtures.Fixture):
finally: finally:
db.close() db.close()
self.dburi = 'mysql+pymysql://{name}:{passwd}@{host}/{name}'.format( self.dburi = 'mysql+pymysql://{name}:{passwd}@{host}:{port}/{name}'\
name=self.name, passwd=self.passwd, host=self.host) .format(
name=self.name,
passwd=self.passwd,
host=self.host,
port=self.port
)
self.addDetail('dburi', testtools.content.text_content(self.dburi)) self.addDetail('dburi', testtools.content.text_content(self.dburi))
self.addCleanup(self.cleanup) self.addCleanup(self.cleanup)
def cleanup(self): def cleanup(self):
db = pymysql.connect(host=self.host, db = pymysql.connect(host=self.host,
port=self.port,
user="openstack_citest", user="openstack_citest",
passwd="openstack_citest", passwd="openstack_citest",
db="openstack_citest") db="openstack_citest")

View File

@ -7,7 +7,7 @@ services:
environment: environment:
- MYSQL_ROOT_PASSWORD=insecure_worker - MYSQL_ROOT_PASSWORD=insecure_worker
ports: ports:
- "3306:3306" - "${ZUUL_MYSQL_PORT:-3306}:3306"
tmpfs: tmpfs:
- /var/lib/mysql - /var/lib/mysql
volumes: volumes:

View File

@ -27,6 +27,7 @@ passenv =
OS_STDOUT_CAPTURE OS_STDOUT_CAPTURE
YARN_REGISTRY YARN_REGISTRY
ZUUL_MYSQL_HOST ZUUL_MYSQL_HOST
ZUUL_MYSQL_PORT
ZUUL_POSTGRES_HOST ZUUL_POSTGRES_HOST
ZUUL_SCHEDULER_COUNT ZUUL_SCHEDULER_COUNT
ZUUL_TEST_ROOT ZUUL_TEST_ROOT