From 5cad8ac7736618a875d9e6d6dd29d8db5f81fcd8 Mon Sep 17 00:00:00 2001
From: Julia Kreger <juliaashleykreger@gmail.com>
Date: Thu, 29 Jun 2023 09:13:18 -0700
Subject: [PATCH] Unit tests: Isolate mysql test migrations

All database migration testing in opestack is done through
an opportunistic worker model, where if the database is available
and correctly configured for testing, i.e. openstack-citest user
and access appropriately granted, then the tests will create and
test migrations.

However, this has been problematic with mysql as of recent, as we
have seen a long standing migration issue boil to the surface often
with tests.

As a result, we're isolating that test down to it's own job so we
can limit the blast damage. This also helps us isolate is it all
of the tests, or is it just soley isolated down to the mysql test
run class, which is an additional data point.

By default, we continue to run Postgres migration tests in the
main jobs, as they haven't been impacted by this issue.

Change-Id: Iefc044c31ef029e400a7dad294504175a4462638
---
 tox.ini                 | 7 ++++++-
 zuul.d/ironic-jobs.yaml | 8 ++++++++
 zuul.d/project.yaml     | 2 ++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/tox.ini b/tox.ini
index 2666e5b32e..afab8c6b21 100644
--- a/tox.ini
+++ b/tox.ini
@@ -22,7 +22,7 @@ deps =
   -r{toxinidir}/requirements.txt
   -r{toxinidir}/test-requirements.txt
 commands =
-    stestr run --slowest --parallel-class {posargs}
+    stestr run --slowest --parallel-class --exclude-regex TestMigrationsMySQL {posargs}
 passenv = http_proxy
           HTTP_PROXY
           https_proxy
@@ -84,6 +84,11 @@ envdir = {toxworkdir}/venv
 commands =
   oslopolicy-sample-generator --config-file=tools/policy/ironic-policy-generator.conf
 
+[testenv:mysql-migrations]
+sitepackages = False
+commands =
+    stestr run --slowest --parallel-class TestMigrationsMySQL {posargs}
+
 [testenv:debug]
 commands = oslo_debug_helper -t ironic/tests/unit {posargs}
 
diff --git a/zuul.d/ironic-jobs.yaml b/zuul.d/ironic-jobs.yaml
index e7045535fe..f7620cfc74 100644
--- a/zuul.d/ironic-jobs.yaml
+++ b/zuul.d/ironic-jobs.yaml
@@ -683,6 +683,14 @@
     vars:
       tox_envlist: unit-with-driver-libs
 
+- job:
+    name: ironic-tox-unit-mysql-migrations
+    parent: openstack-tox
+    description: |
+      Run MySQL based data model migrations separate to isolate failures.
+    vars:
+      tox_envlist: mysql-migrations
+
 - job:
     name: ironic-inspector-tempest-discovery-fast-track
     description: ironic-inspector-tempest-discovery-fast-track
diff --git a/zuul.d/project.yaml b/zuul.d/project.yaml
index 60fe7fbce7..4009f4f605 100644
--- a/zuul.d/project.yaml
+++ b/zuul.d/project.yaml
@@ -9,6 +9,7 @@
       - release-notes-jobs-python3
     check:
       jobs:
+        - ironic-tox-unit-mysql-migrations
         - ironic-tox-unit-with-driver-libs
         - ironic-cross-sushy:
             voting: false
@@ -65,6 +66,7 @@
             voting: false
     gate:
       jobs:
+        - ironic-tox-unit-mysql-migrations
         - ironic-tox-unit-with-driver-libs
         - ironic-tempest-functional-python3
         # NOTE(rpittau) disabled until we fix the tests