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
This commit is contained in:
Takashi Kajinami 2024-05-16 00:25:57 +09:00
parent 5717c7e599
commit 9bed01d2f6
2 changed files with 8 additions and 4 deletions

View File

@ -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)

View File

@ -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',
)