Alberto Donato has proposed merging ~ack/maas:perftest-create-db-each-test into
maas:master.
Commit message:
perftests: create database before each test
Requested reviews:
MAAS Maintainers (maas-maintainers)
For more details, see:
https://code.launchpad.net/~ack/maas/+git/maas/+merge/433993
--
Your team MAAS Maintainers is requested to review the proposed merge of
~ack/maas:perftest-create-db-each-test into maas:master.
diff --git a/src/maastesting/pytest/django.py b/src/maastesting/pytest/django.py
index 5848532..986a7b5 100644
--- a/src/maastesting/pytest/django.py
+++ b/src/maastesting/pytest/django.py
@@ -169,14 +169,16 @@ def ensuremaasdb(templatemaasdb, pytestconfig, worker_id):
database = development.DATABASES["default"]
database["NAME"] = dbname
cluster = pytestconfig.stash[cluster_stash]
- if dbname not in cluster.databases:
- template = pytestconfig.stash[db_template_stash]
- with cluster.lock.exclusive:
- with connect(cluster) as conn:
- with conn.cursor() as cursor:
- cursor.execute(
- f'CREATE DATABASE "{dbname}" WITH TEMPLATE "{template}"'
- )
+ template = pytestconfig.stash[db_template_stash]
+ with (
+ cluster.lock.exclusive,
+ connect(cluster) as conn,
+ conn.cursor() as cursor,
+ ):
+ cursor.execute(f"DROP DATABASE IF EXISTS {dbname}")
+ cursor.execute(
+ f'CREATE DATABASE "{dbname}" WITH TEMPLATE "{template}"'
+ )
yield
database["NAME"] = "no_such_db"
--
Mailing list: https://launchpad.net/~sts-sponsors
Post to : [email protected]
Unsubscribe : https://launchpad.net/~sts-sponsors
More help : https://help.launchpad.net/ListHelp