Fix update_cell to ignore existing identical cells
The recent cell duplication filter makes it impossible to do update_cell on an existing cell with identical details. If we're updating a cell by uuid and specify the exact same parameters, we shouldn't signal failure. Change-Id: I2faaec94444bc7d29fda1facd22e0da3bc6f01f9 Closes-Bug: #1744780
This commit is contained in:
parent
4e3b07430d
commit
0467b537bf
|
@ -932,8 +932,12 @@ class CellV2Commands(object):
|
|||
return transport_url
|
||||
|
||||
def _non_unique_transport_url_database_connection_checker(self, ctxt,
|
||||
transport_url, database_connection):
|
||||
cell_mapping, transport_url, database_connection):
|
||||
for cell in objects.CellMappingList.get_all(ctxt):
|
||||
if cell_mapping and cell.uuid == cell_mapping.uuid:
|
||||
# If we're looking for a specific cell, then don't check
|
||||
# that one for same-ness to allow idempotent updates
|
||||
continue
|
||||
if (cell.database_connection == database_connection or
|
||||
cell.transport_url == transport_url):
|
||||
print(_('The specified transport_url and/or '
|
||||
|
@ -1320,7 +1324,7 @@ class CellV2Commands(object):
|
|||
'in the configuration file.'))
|
||||
return 1
|
||||
if (self._non_unique_transport_url_database_connection_checker(ctxt,
|
||||
transport_url, database_connection)):
|
||||
None, transport_url, database_connection)):
|
||||
return 2
|
||||
cell_mapping_uuid = uuidutils.generate_uuid()
|
||||
cell_mapping = objects.CellMapping(
|
||||
|
@ -1464,7 +1468,7 @@ class CellV2Commands(object):
|
|||
db_connection = db_connection or CONF.database.connection
|
||||
|
||||
if (self._non_unique_transport_url_database_connection_checker(ctxt,
|
||||
transport_url, db_connection)):
|
||||
cell_mapping, transport_url, db_connection)):
|
||||
# We use the return code 3 before 2 to avoid changing the
|
||||
# semantic meanings of return codes.
|
||||
return 3
|
||||
|
|
|
@ -1556,22 +1556,31 @@ class CellV2CommandsTestCase(test.NoDBTestCase):
|
|||
|
||||
def test_non_unique_transport_url_database_connection_checker(self):
|
||||
ctxt = context.RequestContext()
|
||||
objects.CellMapping(context=ctxt, uuid=uuidsentinel.cell1,
|
||||
cell1 = objects.CellMapping(context=ctxt, uuid=uuidsentinel.cell1,
|
||||
name='cell1',
|
||||
transport_url='fake://mq1',
|
||||
database_connection='fake:///db1').create()
|
||||
database_connection='fake:///db1')
|
||||
cell1.create()
|
||||
objects.CellMapping(context=ctxt, uuid=uuidsentinel.cell2,
|
||||
name='cell2',
|
||||
transport_url='fake://mq2',
|
||||
database_connection='fake:///db2').create()
|
||||
resultf = self.commands.\
|
||||
_non_unique_transport_url_database_connection_checker(
|
||||
ctxt, 'fake://mq3', 'fake:///db3')
|
||||
ctxt, None,
|
||||
'fake://mq3', 'fake:///db3')
|
||||
resultt = self.commands.\
|
||||
_non_unique_transport_url_database_connection_checker(
|
||||
ctxt, 'fake://mq1', 'fake:///db1')
|
||||
ctxt, None,
|
||||
'fake://mq1', 'fake:///db1')
|
||||
resultd = self.commands.\
|
||||
_non_unique_transport_url_database_connection_checker(
|
||||
ctxt, cell1,
|
||||
'fake://mq1', 'fake:///db1')
|
||||
|
||||
self.assertFalse(resultf)
|
||||
self.assertTrue(resultt)
|
||||
self.assertFalse(resultd)
|
||||
self.assertIn('exists', self.output.getvalue())
|
||||
|
||||
def test_create_cell_use_params(self):
|
||||
|
|
Loading…
Reference in New Issue