From f781409f366904362b36bb8047fc371c17301c5e Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Mon, 23 Jan 2017 08:49:59 -0800 Subject: [PATCH] Only warn about hostmappings during ocata upgrade The check and subsequent hard failure for HostMapping records in API migration 30 is inconvenient at times during a new setup where we have flavors in place but no hosts yet. Since we can now check for and warn about missing HostMapping records in our upgrade status command, this patch lowers the lack of host mappings check from a failure to a warning. This migration was really just to make sure you ran the simple setup command, and the cell mapping check does that for us. Change-Id: I8b757fa7c805ec6f4d578ecb6f33d3f1ceff29fc --- .../migrate_repo/versions/030_require_cell_setup.py | 13 ++++++++----- nova/tests/unit/db/test_sqlalchemy_migration.py | 6 +++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/nova/db/sqlalchemy/api_migrations/migrate_repo/versions/030_require_cell_setup.py b/nova/db/sqlalchemy/api_migrations/migrate_repo/versions/030_require_cell_setup.py index fe3822e19c02..e59b12433abf 100644 --- a/nova/db/sqlalchemy/api_migrations/migrate_repo/versions/030_require_cell_setup.py +++ b/nova/db/sqlalchemy/api_migrations/migrate_repo/versions/030_require_cell_setup.py @@ -10,12 +10,15 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo_log import log as logging from sqlalchemy import MetaData, Table, func, select from nova import exception -from nova.i18n import _ +from nova.i18n import _, _LW from nova import objects +LOG = logging.getLogger(__name__) + def upgrade(migrate_engine): meta = MetaData() @@ -51,7 +54,7 @@ def upgrade(migrate_engine): host_mappings = Table('host_mappings', meta, autoload=True) count = select([func.count()]).select_from(host_mappings).scalar() if count == 0: - msg = _('No host mappings were found, but are required for Ocata. ' - 'Please run nova-manage cell_v2 simple_cell_setup before ' - 'continuing.') - raise exception.ValidationError(detail=msg) + msg = _LW('No host mappings were found, but are required for Ocata. ' + 'Please run nova-manage cell_v2 simple_cell_setup before ' + 'continuing.') + LOG.warning(msg) diff --git a/nova/tests/unit/db/test_sqlalchemy_migration.py b/nova/tests/unit/db/test_sqlalchemy_migration.py index 442c9f115030..46fa133f9dad 100644 --- a/nova/tests/unit/db/test_sqlalchemy_migration.py +++ b/nova/tests/unit/db/test_sqlalchemy_migration.py @@ -437,9 +437,9 @@ class TestNewtonCellsCheck(test.NoDBTestCase): database_connection='fake') cell1.create() - self.assertRaisesRegex(exception.ValidationError, - 'host mappings', - self.migration.upgrade, self.engine) + with mock.patch.object(self.migration, 'LOG') as log: + self.migration.upgrade(self.engine) + self.assertTrue(log.warning.called) def test_upgrade_with_required_mappings(self): self._flavor_me()