Run cell0 db migrations during nova-manage simple_cell_setup

In order for the cell0 database to be usable it needs to have db
migrations run against it. Since the simple_cell_setup attempts to be
the one command necessary to upgrade to cellsv2 it should also handle
the db migrations.

Partially-Implements: bp cells-cell0
Change-Id: I9bbaa4c92503222c9fd015fe075926b50f3dcc8c
Depends-On: I090d5994c3077d86c60457e4c16a03d35e0c409c
This commit is contained in:
Andrew Laski 2016-08-31 17:43:05 -04:00
parent dd44096a04
commit edf04686bc
2 changed files with 21 additions and 6 deletions

View File

@ -1218,11 +1218,15 @@ class CellV2Commands(object):
if CONF.cells.enable:
print('CellsV1 users cannot use this simplified setup command')
return 2
ctxt = context.RequestContext()
try:
self.map_cell0()
cell0_mapping = self.map_cell0()
except db_exc.DBDuplicateEntry:
print('Already setup, nothing to do.')
return 0
# Run migrations so cell0 is usable
with context.target_cell(ctxt, cell0_mapping):
migration.db_sync(None, context=ctxt)
cell_uuid = self._map_cell_and_hosts(transport_url)
if cell_uuid is None:
# There are no compute hosts which means no cell_mapping was
@ -1270,6 +1274,7 @@ class CellV2Commands(object):
transport_url="none:///",
database_connection=dbc)
cell_mapping.create()
return cell_mapping
def _get_and_map_instances(self, ctxt, cell_mapping, limit, marker):
filters = {}

View File

@ -1124,7 +1124,7 @@ class CellV2CommandsTestCase(test.TestCase):
self.assertEqual('fake://netloc/nova_api_cell0',
cell_mapping.database_connection)
def _test_migrate_simple_command(self):
def _test_migrate_simple_command(self, first_call=True):
ctxt = context.RequestContext()
CONF.set_default('connection',
'fake://netloc/nova_api',
@ -1147,10 +1147,20 @@ class CellV2CommandsTestCase(test.TestCase):
transport_url = "fake://guest:devstack@127.0.0.1:9999/"
cell_uuid = uuidsentinel.cell
with mock.patch.object(uuidutils, 'generate_uuid',
return_value=cell_uuid):
r = self.commands.simple_cell_setup(transport_url)
@mock.patch('nova.db.migration.db_sync')
@mock.patch.object(uuidutils, 'generate_uuid',
return_value=cell_uuid)
def _test(mock_gen_uuid, mock_db_sync):
result = self.commands.simple_cell_setup(transport_url)
if first_call:
mock_db_sync.assert_called_once_with(
None, context=test.MatchType(context.RequestContext))
else:
mock_db_sync.assert_not_called()
return result
r = _test()
self.assertEqual(0, r)
# Check cell0 from default
@ -1176,7 +1186,7 @@ class CellV2CommandsTestCase(test.TestCase):
def test_simple_command_multiple(self):
self._test_migrate_simple_command()
with mock.patch.object(self.commands, '_map_cell_and_hosts') as m:
self._test_migrate_simple_command()
self._test_migrate_simple_command(first_call=False)
self.assertFalse(m.called)
def test_simple_command_cellsv1(self):