diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index 38a3f33c6b06..f7f945b64ae3 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -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 diff --git a/nova/tests/unit/test_nova_manage.py b/nova/tests/unit/test_nova_manage.py index 9ef27f965408..ad9d1836761c 100644 --- a/nova/tests/unit/test_nova_manage.py +++ b/nova/tests/unit/test_nova_manage.py @@ -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):