Gracefully close db connections in tests

In order to prevent warnings in the mysql service we should gracefully
close the db connections in the tests.

Change-Id: I1b319764bf12d32ee2d04dd1c023c651ff3d8a17
This commit is contained in:
Tobias Henkel 2019-01-12 14:44:11 +01:00
parent b107af0c05
commit f5e1fc6219
No known key found for this signature in database
GPG Key ID: 03750DEC158E5FA2
1 changed files with 18 additions and 11 deletions

View File

@ -2115,13 +2115,17 @@ class MySQLSchemaFixture(fixtures.Fixture):
user="openstack_citest",
passwd="openstack_citest",
db="openstack_citest")
cur = db.cursor()
cur.execute("create database %s" % self.name)
cur.execute("create user '{user}'@'' identified by '{passwd}'".format(
user=self.name, passwd=self.passwd))
cur.execute("grant all on {name}.* to '{name}'@''".format(
name=self.name))
cur.execute("flush privileges")
try:
with db.cursor() as cur:
cur.execute("create database %s" % self.name)
cur.execute(
"create user '{user}'@'' identified by '{passwd}'".format(
user=self.name, passwd=self.passwd))
cur.execute("grant all on {name}.* to '{name}'@''".format(
name=self.name))
cur.execute("flush privileges")
finally:
db.close()
self.dburi = 'mysql+pymysql://{name}:{passwd}@{host}/{name}'.format(
name=self.name, passwd=self.passwd, host=self.host)
@ -2133,10 +2137,13 @@ class MySQLSchemaFixture(fixtures.Fixture):
user="openstack_citest",
passwd="openstack_citest",
db="openstack_citest")
cur = db.cursor()
cur.execute("drop database %s" % self.name)
cur.execute("drop user '%s'@''" % self.name)
cur.execute("flush privileges")
try:
with db.cursor() as cur:
cur.execute("drop database %s" % self.name)
cur.execute("drop user '%s'@''" % self.name)
cur.execute("flush privileges")
finally:
db.close()
class PostgresqlSchemaFixture(fixtures.Fixture):