nova-manage cell_v2 map_cell0 exit 0
This command used to always return 1 because it was returning a data structure used by another CLI function. Now it exits 0 if the cell0 mapping was created succesfully or was already there. Closes-Bug: #1656017 Change-Id: Ie66de8425bb8f65dc9eab9d0da809e94f6d72b1b
This commit is contained in:
parent
3ec43d81c3
commit
aa7b6ebbb2
|
@ -1094,7 +1094,7 @@ class CellV2Commands(object):
|
|||
return 1
|
||||
ctxt = context.RequestContext()
|
||||
try:
|
||||
cell0_mapping = self.map_cell0()
|
||||
cell0_mapping = self._map_cell0()
|
||||
except db_exc.DBDuplicateEntry:
|
||||
print(_('Cell0 is already setup'))
|
||||
cell0_mapping = objects.CellMapping.get_by_uuid(
|
||||
|
@ -1131,6 +1131,18 @@ class CellV2Commands(object):
|
|||
|
||||
This command creates a cell mapping for this special cell which
|
||||
requires a database to store the instance data.
|
||||
|
||||
Returns 0 if cell0 created successfully or already setup.
|
||||
"""
|
||||
try:
|
||||
self._map_cell0(database_connection=database_connection)
|
||||
except db_exc.DBDuplicateEntry:
|
||||
print(_('Cell0 is already setup'))
|
||||
return 0
|
||||
|
||||
def _map_cell0(self, database_connection=None):
|
||||
"""Faciliate creation of a cell mapping for cell0.
|
||||
See map_cell0 for more.
|
||||
"""
|
||||
def cell0_default_connection():
|
||||
# If no database connection is provided one is generated
|
||||
|
|
|
@ -1113,6 +1113,18 @@ class CellV2CommandsTestCase(test.NoDBTestCase):
|
|||
self.assertEqual('none:///', cell_mapping.transport_url)
|
||||
self.assertEqual(database_connection, cell_mapping.database_connection)
|
||||
|
||||
@mock.patch.object(manage.CellV2Commands, '_map_cell0', new=mock.Mock())
|
||||
def test_map_cell0_returns_0_on_successful_create(self):
|
||||
self.assertEqual(0, self.commands.map_cell0())
|
||||
|
||||
@mock.patch.object(manage.CellV2Commands, '_map_cell0')
|
||||
def test_map_cell0_returns_0_if_cell0_already_exists(self, _map_cell0):
|
||||
_map_cell0.side_effect = db_exc.DBDuplicateEntry
|
||||
exit_code = self.commands.map_cell0()
|
||||
self.assertEqual(0, exit_code)
|
||||
output = self.output.getvalue().strip()
|
||||
self.assertEqual('Cell0 is already setup', output)
|
||||
|
||||
def test_map_cell0_default_database(self):
|
||||
CONF.set_default('connection',
|
||||
'fake://netloc/nova_api',
|
||||
|
|
Loading…
Reference in New Issue