summaryrefslogtreecommitdiff
path: root/nova/db
diff options
context:
space:
mode:
authorDan Smith <dansmith@redhat.com>2016-03-07 07:35:03 -0800
committerDan Smith <dansmith@redhat.com>2016-03-16 12:55:01 -0700
commit4d0915568a1011ddee7317ddfb237be0803e7790 (patch)
treea1202eb7360842f46b93d83d2503e2dc44d86736 /nova/db
parent10b50d50ec9020ac383b57bf0bd79603d5040772 (diff)
downloadnova-4d0915568a1011ddee7317ddfb237be0803e7790.tar.gz
Add Newton sanity check migration
This migration enforces that all of our Mitaka online migrations have been completed before we roll forward. This mirrors migration 291 for kilo that we used to ensure correctness before migrating into Liberty. Depends-On: Ibc02acc60b1023039f2613f8949b95d55169fd30 Change-Id: I9591f0b9227e30d4df2fada82fe236e474fc07b4
Diffstat (limited to 'nova/db')
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/330_enforce_mitaka_online_migrations.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/330_enforce_mitaka_online_migrations.py b/nova/db/sqlalchemy/migrate_repo/versions/330_enforce_mitaka_online_migrations.py
new file mode 100644
index 0000000000..652a0e919a
--- /dev/null
+++ b/nova/db/sqlalchemy/migrate_repo/versions/330_enforce_mitaka_online_migrations.py
@@ -0,0 +1,47 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from sqlalchemy import MetaData, Table, func, select
+
+from nova import exception
+from nova.i18n import _
+
+
+WARNING_MSG = _('There are still %(count)i unmigrated records in '
+ 'the %(table)s table. Migration cannot continue '
+ 'until all records have been migrated.')
+
+
+def upgrade(migrate_engine):
+ meta = MetaData(migrate_engine)
+ compute_nodes = Table('compute_nodes', meta, autoload=True)
+ aggregates = Table('aggregates', meta, autoload=True)
+
+ for table in (compute_nodes, aggregates):
+ count = select([func.count()]).select_from(table).where(
+ table.c.uuid == None).execute().scalar() # NOQA
+ if count > 0:
+ msg = WARNING_MSG % {
+ 'count': count,
+ 'table': table.name,
+ }
+ raise exception.ValidationError(detail=msg)
+
+ pci_devices = Table('pci_devices', meta, autoload=True)
+ count = select([func.count()]).select_from(pci_devices).where(
+ pci_devices.c.parent_addr == None).execute().scalar() # NOQA
+ if count > 0:
+ msg = WARNING_MSG % {
+ 'count': count,
+ 'table': pci_devices.name,
+ }
+ raise exception.ValidationError(detail=msg)