From b55ca354463a387d79e265701dd78cf3a51e457f Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Mon, 24 Jul 2017 11:30:35 -0400 Subject: [PATCH] Provide hints when nova-manage db sync fails to sync cell0 Lots of people get tripped up on the error message when syncing cell0 fails and the question asked is confusing and possibly misleading, so this change includes several questions for troubleshooting and also dumps the actual error message. Related-Bug: #1706118 Change-Id: I865f76705f10493152af50b9842c6fedc563fea4 (cherry picked from commit 05f3d9d39b7b95fac343ba431855482a5d96584a) --- nova/cmd/manage.py | 13 ++++++++++--- nova/tests/unit/test_nova_manage.py | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index e468b1cc50c3..5434a93aeb01 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -69,6 +69,7 @@ from oslo_utils import importutils from oslo_utils import uuidutils import prettytable +import six import six.moves.urllib.parse as urlparse from sqlalchemy.engine import url as sqla_url @@ -642,9 +643,15 @@ class DbCommands(object): except exception.CellMappingNotFound: print(_('WARNING: cell0 mapping not found - not' ' syncing cell0.')) - except Exception: - print(_('ERROR: could not access cell mapping database - has' - ' api db been created?')) + except Exception as e: + print(_("""ERROR: Could not access cell0. +Has the nova_api database been created? +Has the nova_cell0 database been created? +Has "nova-manage api_db sync" been run? +Has "nova-manage cell_v2 map_cell0" been run? +Is [api_database]/connection set in nova.conf? +Is the cell0 database connection URL correct? +Error: %s""") % six.text_type(e)) return migration.db_sync(version) def version(self): diff --git a/nova/tests/unit/test_nova_manage.py b/nova/tests/unit/test_nova_manage.py index 25d250add98f..ccb0da8108da 100644 --- a/nova/tests/unit/test_nova_manage.py +++ b/nova/tests/unit/test_nova_manage.py @@ -558,6 +558,27 @@ Archiving.....stopped ] mock_db_sync.assert_has_calls(db_sync_calls) + @mock.patch.object(objects.CellMapping, 'get_by_uuid', + side_effect=test.TestingException('invalid connection')) + def test_sync_cell0_unknown_error(self, mock_get_by_uuid): + """Asserts that a detailed error message is given when an unknown + error occurs trying to get the cell0 cell mapping. + """ + self.commands.sync() + mock_get_by_uuid.assert_called_once_with( + test.MatchType(context.RequestContext), + objects.CellMapping.CELL0_UUID) + expected = """ERROR: Could not access cell0. +Has the nova_api database been created? +Has the nova_cell0 database been created? +Has "nova-manage api_db sync" been run? +Has "nova-manage cell_v2 map_cell0" been run? +Is [api_database]/connection set in nova.conf? +Is the cell0 database connection URL correct? +Error: invalid connection +""" + self.assertEqual(expected, self.output.getvalue()) + def _fake_db_command(self, migrations=None): if migrations is None: mock_mig_1 = mock.MagicMock(__name__="mock_mig_1")