From 9bed01d2f6cff1fb7d4f2191ac9e37f91cfb382c Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Thu, 16 May 2024 00:25:57 +0900 Subject: [PATCH] Use specific element to detect database backend ... instead of using the whole url string. The url string may include the pattern and the current logic is not robust enough to ignore wired naming. Change-Id: I80c59c67773f868b45f1ff3b34877c1bab73b225 --- ironic/cmd/status.py | 2 +- ironic/tests/unit/cmd/test_status.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ironic/cmd/status.py b/ironic/cmd/status.py index 5e56be5520..f3940ff5cd 100644 --- a/ironic/cmd/status.py +++ b/ironic/cmd/status.py @@ -97,7 +97,7 @@ class Checks(upgradecheck.UpgradeCommands): def _check_allocations_table(self): msg = None engine = enginefacade.reader.get_engine() - if 'mysql' not in str(engine.url): + if 'mysql' != str(engine.url.get_backend_name()): # This test only applies to mysql and database schema # selection. return upgradecheck.Result(upgradecheck.Code.SUCCESS) diff --git a/ironic/tests/unit/cmd/test_status.py b/ironic/tests/unit/cmd/test_status.py index 8f404c6d31..42ebe339c0 100644 --- a/ironic/tests/unit/cmd/test_status.py +++ b/ironic/tests/unit/cmd/test_status.py @@ -16,6 +16,7 @@ from unittest import mock from oslo_db import sqlalchemy from oslo_upgradecheck.upgradecheck import Code +from sqlalchemy.engine import url as sa_url from ironic.cmd import dbsync from ironic.cmd import status @@ -60,7 +61,8 @@ class TestUpgradeChecks(db_base.DbTestCase): def test__check_allocations_table_latin1(self, mock_reader): mock_engine = mock.Mock() mock_res = mock.Mock() - mock_engine.url = '..mysql..' + mock_engine.url = sa_url.make_url( + 'mysql+pymysql://ironic:pass@192.0.2.10/ironic') mock_res.all.return_value = ( '... ENGINE=InnoDB DEFAULT CHARSET=latin1', ) @@ -86,7 +88,8 @@ class TestUpgradeChecks(db_base.DbTestCase): def test__check_allocations_table_myiasm(self, mock_reader): mock_engine = mock.Mock() mock_res = mock.Mock() - mock_engine.url = '..mysql..' + mock_engine.url = sa_url.make_url( + 'mysql+pymysql://ironic:pass@192.0.2.10/ironic') mock_res.all.return_value = ( '... ENGINE=MyIASM DEFAULT CHARSET=utf8', ) @@ -114,7 +117,8 @@ class TestUpgradeChecks(db_base.DbTestCase): def test__check_allocations_table_myiasm_both(self, mock_reader): mock_engine = mock.Mock() mock_res = mock.Mock() - mock_engine.url = '..mysql..' + mock_engine.url = sa_url.make_url( + 'mysql+pymysql://ironic:pass@192.0.2.10/ironic') mock_res.all.return_value = ( '... ENGINE=MyIASM DEFAULT CHARSET=latin1', )