summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Bauza <sbauza@redhat.com>2017-06-06 23:28:59 +0200
committerSylvain Bauza <sbauza@redhat.com>2017-06-07 16:19:07 +0200
commit6041572a4c95428f6b13a8d7569090b315a3abd1 (patch)
tree0261511d6d5bee655e1eac9b93c458185dc81ad9
parent47774935ac0145f6ccb058163248bfeefef93e8d (diff)
Fix cell0 naming when QS params on the connection
We had a problem when the nova connection string included parameters on the query string like charset encoding. Note that the connection string necessarly needs to be RFC1738 compliant as per Sqlalchemy rules, so it's totally safe to just unquote what the SQLA helper method gives us as a result. Also removed a tested connection string since it wasn't RFC1738 compatible. Change-Id: I45fe9b92e8d93a0099d33bb0070e9d4e540595ac Closes-Bug: #1696001 (cherry picked from commit 9a33092fa9b0c65b37b9fdc860f5a571908d7a69)
Notes
Notes (review): Verified+1: IBM PowerKVM CI <kvmpower@linux.vnet.ibm.com> Code-Review+2: Matt Riedemann <mriedem.os@gmail.com> Code-Review+2: Claudiu Belu <cbelu@cloudbasesolutions.com> Workflow+1: Claudiu Belu <cbelu@cloudbasesolutions.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Fri, 09 Jun 2017 13:04:33 +0000 Reviewed-on: https://review.openstack.org/471790 Project: openstack/nova Branch: refs/heads/stable/ocata
-rw-r--r--nova/cmd/manage.py11
-rw-r--r--nova/tests/unit/test_nova_manage.py15
2 files changed, 12 insertions, 14 deletions
diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py
index 00856c3..b760290 100644
--- a/nova/cmd/manage.py
+++ b/nova/cmd/manage.py
@@ -1152,19 +1152,16 @@ class CellV2Commands(object):
1152 # based on the database connection url. 1152 # based on the database connection url.
1153 # The cell0 database will use the same database scheme and 1153 # The cell0 database will use the same database scheme and
1154 # netloc as the main database, with a related path. 1154 # netloc as the main database, with a related path.
1155 # NOTE(sbauza): The URL has to be RFC1738 compliant in order to
1156 # be usable by sqlalchemy.
1155 connection = CONF.database.connection 1157 connection = CONF.database.connection
1156 # sqlalchemy has a nice utility for parsing database connection 1158 # sqlalchemy has a nice utility for parsing database connection
1157 # URLs so we use that here to get the db name so we don't have to 1159 # URLs so we use that here to get the db name so we don't have to
1158 # worry about parsing and splitting a URL which could have special 1160 # worry about parsing and splitting a URL which could have special
1159 # characters in the password, which makes parsing a nightmare. 1161 # characters in the password, which makes parsing a nightmare.
1160 url = sqla_url.make_url(connection) 1162 url = sqla_url.make_url(connection)
1161 cell0_db_name = url.database + '_cell0' 1163 url.database = url.database + '_cell0'
1162 # We need to handle multiple occurrences of the substring, e.g. if 1164 return urlparse.unquote(str(url))
1163 # the username and db name are both 'nova' we need to only replace
1164 # the last one, which is the database name in the URL, not the
1165 # username.
1166 connection = connection.rstrip(url.database)
1167 return connection + cell0_db_name
1168 1165
1169 dbc = database_connection or cell0_default_connection() 1166 dbc = database_connection or cell0_default_connection()
1170 ctxt = context.RequestContext() 1167 ctxt = context.RequestContext()
diff --git a/nova/tests/unit/test_nova_manage.py b/nova/tests/unit/test_nova_manage.py
index d920828..cc7cba3 100644
--- a/nova/tests/unit/test_nova_manage.py
+++ b/nova/tests/unit/test_nova_manage.py
@@ -1140,16 +1140,17 @@ class CellV2CommandsTestCase(test.NoDBTestCase):
1140 self.assertEqual('fake://netloc/nova_cell0', 1140 self.assertEqual('fake://netloc/nova_cell0',
1141 cell_mapping.database_connection) 1141 cell_mapping.database_connection)
1142 1142
1143 @ddt.data('mysql+pymysql://nova:abcd0123:AB@controller/nova', 1143 @ddt.data('mysql+pymysql://nova:abcd0123:AB@controller/%s',
1144 'mysql+pymysql://nova:abcd0123?AB@controller/nova', 1144 'mysql+pymysql://nova:abcd0123?AB@controller/%s',
1145 'mysql+pymysql://nova:abcd0123@AB@controller/nova', 1145 'mysql+pymysql://nova:abcd0123@AB@controller/%s',
1146 'mysql+pymysql://nova:abcd0123/AB@controller/nova', 1146 'mysql+pymysql://nova:abcd0123/AB@controller/%s',
1147 'mysql+pymysql://test:abcd0123%AB@controller/nova') 1147 'mysql+pymysql://test:abcd0123/AB@controller/%s?charset=utf8')
1148 def test_map_cell0_default_database_special_characters(self, 1148 def test_map_cell0_default_database_special_characters(self,
1149 decoded_connection): 1149 connection):
1150 """Tests that a URL with special characters, like in the credentials, 1150 """Tests that a URL with special characters, like in the credentials,
1151 is handled properly. 1151 is handled properly.
1152 """ 1152 """
1153 decoded_connection = connection % 'nova'
1153 self.flags(connection=decoded_connection, group='database') 1154 self.flags(connection=decoded_connection, group='database')
1154 ctxt = context.RequestContext() 1155 ctxt = context.RequestContext()
1155 self.commands.map_cell0() 1156 self.commands.map_cell0()
@@ -1158,7 +1159,7 @@ class CellV2CommandsTestCase(test.NoDBTestCase):
1158 self.assertEqual('cell0', cell_mapping.name) 1159 self.assertEqual('cell0', cell_mapping.name)
1159 self.assertEqual('none:///', cell_mapping.transport_url) 1160 self.assertEqual('none:///', cell_mapping.transport_url)
1160 self.assertEqual( 1161 self.assertEqual(
1161 decoded_connection + '_cell0', 1162 connection % 'nova_cell0',
1162 cell_mapping.database_connection) 1163 cell_mapping.database_connection)
1163 # Delete the cell mapping for the next iteration. 1164 # Delete the cell mapping for the next iteration.
1164 cell_mapping.destroy() 1165 cell_mapping.destroy()