Merge "do not use str(url) to stringify a URL for subsequent use"

This commit is contained in:
Zuul 2024-05-15 20:05:28 +00:00 committed by Gerrit Code Review
commit d467edac49
2 changed files with 7 additions and 6 deletions

@ -83,7 +83,7 @@ def db_sync(version=None, database='main', context=None):
# string using a mix of url encode styles for different parts of the url.
# since we are updating the alembic config parser instance we need to
# escape '%' to '%%' to account for ConfigParser's string interpolation.
url = str(engine.url).replace('%', '%%')
url = engine.url.render_as_string(hide_password=False).replace('%', '%%')
config.set_main_option('sqlalchemy.url', url)
# apply anything later

@ -16,6 +16,7 @@ from unittest import mock
import urllib
from alembic.runtime import migration as alembic_migration
from sqlalchemy.engine import url as sa_url
from nova.db.api import api as api_db_api
from nova.db.main import api as main_db_api
@ -69,11 +70,11 @@ class TestDBSync(test.NoDBTestCase):
def test_db_sync(self, mock_get_engine, mock_find_conf, mock_upgrade):
# return an encoded URL to mimic sqlalchemy
mock_get_engine.return_value.url = (
'mysql+pymysql://nova:pass@192.168.24.3/nova?'
'read_default_file=%2Fetc%2Fmy.cnf.d%2Fnova.cnf'
'&read_default_group=nova'
)
mock_get_engine.return_value.url = sa_url.make_url(
'mysql+pymysql://nova:pass@192.168.24.3/nova?'
'read_default_file=%2Fetc%2Fmy.cnf.d%2Fnova.cnf'
'&read_default_group=nova'
)
migration.db_sync()