do not use str(url) to stringify a URL for subsequent use
The str(url) function in SQLAlchemy hides the password. For a URL string that is to be re-used, use render_as_string(hide_password=False). Change-Id: I2ab28da5cc2b9ed3a1588259b2e94320662816bb
This commit is contained in:
parent
5095336689
commit
acbe3e28e5
@ -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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user