Merge "Fix formatting non-templated cell URLs with no config"

This commit is contained in:
Zuul 2018-10-17 13:05:01 +00:00 committed by Gerrit Code Review
commit ca6c32f279
2 changed files with 25 additions and 6 deletions

View File

@ -129,9 +129,10 @@ class CellMapping(base.NovaTimestampObject, base.NovaObject):
@staticmethod
def _format_db_url(url):
if CONF.database.connection is None and '{' in url:
LOG.error('Cell mapping database_connection is a template, but '
'[database]/connection is not set')
if CONF.database.connection is None:
if '{' in url:
LOG.error('Cell mapping database_connection is a template, '
'but [database]/connection is not set')
return url
try:
return CellMapping._format_url(url, CONF.database.connection)
@ -142,9 +143,10 @@ class CellMapping(base.NovaTimestampObject, base.NovaObject):
@staticmethod
def _format_mq_url(url):
if CONF.transport_url is None and '{' in url:
LOG.error('Cell mapping transport_url is a template, but '
'[DEFAULT]/transport_url is not set')
if CONF.transport_url is None:
if '{' in url:
LOG.error('Cell mapping transport_url is a template, but '
'[DEFAULT]/transport_url is not set')
return url
try:
return CellMapping._format_url(url, CONF.transport_url)

View File

@ -247,6 +247,23 @@ class _TestCellMappingObject(object):
self.assertEqual(varurl, mapping_obj.database_connection)
self.assertEqual(varurl, mapping_obj.transport_url)
@mock.patch.object(cell_mapping.CellMapping, '_get_by_uuid_from_db')
@mock.patch.object(cell_mapping.CellMapping, '_format_url')
def test_non_formatted_url_with_no_base(self, mock_format, mock_get):
# Make sure we just pass through the template URL if the base
# URLs are not set, i.e. we don't try to format the URL to a template.
url = 'foo'
self.flags(transport_url=None)
self.flags(connection=None, group='database')
db_mapping = get_db_mapping(transport_url=url,
database_connection=url)
mock_get.return_value = db_mapping
mapping_obj = objects.CellMapping().get_by_uuid(self.context,
db_mapping['uuid'])
self.assertEqual(url, mapping_obj.database_connection)
self.assertEqual(url, mapping_obj.transport_url)
mock_format.assert_not_called()
class TestCellMappingObject(test_objects._LocalTest,
_TestCellMappingObject):