Add migration_type and hidden to Migration database model
This adds an enumeration for migration_type to the schema. It does not do any data translation in the schema migration, and allows the column to be nullable so that we don't have to act on existing migrations. This means that any outstanding migrations in the database will need to be handled lazily by the upper layers. This also adds a flag called hidden, defaulting to False. Since we are using this new type field to record potentially admin-initiated actions, it is desirable to allow them to be hidden from regular users at times. This adds that field to the database so that we can support that in the migration APIs. Related to blueprint robustify-evacuate Change-Id: I133d46d146415e19f5c120dfa3e37090291b1298
This commit is contained in:
parent
4f4168bc72
commit
5c151d0807
|
@ -4436,6 +4436,12 @@ def migration_get_all_by_filters(context, filters):
|
|||
host = filters["host"]
|
||||
query = query.filter(or_(models.Migration.source_compute == host,
|
||||
models.Migration.dest_compute == host))
|
||||
if "migration_type" in filters:
|
||||
migtype = filters["migration_type"]
|
||||
query = query.filter(models.Migration.migration_type == migtype)
|
||||
if "hidden" in filters:
|
||||
hidden = filters["hidden"]
|
||||
query = query.filter(models.Migration.hidden == hidden)
|
||||
return query.all()
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
# 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, Column, Table
|
||||
from sqlalchemy import Enum, Boolean
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta = MetaData(bind=migrate_engine)
|
||||
migrations = Table('migrations', meta, autoload=True)
|
||||
shadow_migrations = Table('shadow_migrations', meta, autoload=True)
|
||||
|
||||
enum = Enum('migration', 'resize', 'live-migration', 'evacuation',
|
||||
metadata=meta, name='migration_type')
|
||||
enum.create()
|
||||
|
||||
migration_type = Column('migration_type', enum, nullable=True)
|
||||
|
||||
if not hasattr(migrations.c, 'migration_type'):
|
||||
migrations.create_column(migration_type)
|
||||
if not hasattr(shadow_migrations.c, 'migration_type'):
|
||||
shadow_migrations.create_column(migration_type.copy())
|
||||
|
||||
hidden = Column('hidden', Boolean, default=False)
|
||||
if not hasattr(migrations.c, 'hidden'):
|
||||
migrations.create_column(hidden)
|
||||
if not hasattr(shadow_migrations.c, 'hidden'):
|
||||
shadow_migrations.create_column(hidden.copy())
|
|
@ -733,6 +733,10 @@ class Migration(BASE, NovaBase):
|
|||
instance_uuid = Column(String(36), ForeignKey('instances.uuid'))
|
||||
# TODO(_cerberus_): enum
|
||||
status = Column(String(255))
|
||||
migration_type = Column(Enum('migration', 'resize', 'live-migration',
|
||||
'evacuate'),
|
||||
nullable=True)
|
||||
hidden = Column(Boolean, default=False)
|
||||
|
||||
instance = orm.relationship("Instance", foreign_keys=instance_uuid,
|
||||
primaryjoin='and_(Migration.instance_uuid == '
|
||||
|
|
|
@ -1281,7 +1281,8 @@ class MigrationTestCase(test.TestCase):
|
|||
self.assertEqual(migration['instance_uuid'], instance['uuid'])
|
||||
|
||||
def test_get_migrations_by_filters(self):
|
||||
filters = {"status": "migrating", "host": "host3"}
|
||||
filters = {"status": "migrating", "host": "host3",
|
||||
"migration_type": None, "hidden": False}
|
||||
migrations = db.migration_get_all_by_filters(self.ctxt, filters)
|
||||
self.assertEqual(2, len(migrations))
|
||||
for migration in migrations:
|
||||
|
|
|
@ -680,6 +680,19 @@ class NovaMigrationsCheckers(test_migrations.ModelsMigrationsSync,
|
|||
self.assertTableNotExists(engine, 'shadow_iscsi_targets')
|
||||
self.assertTableNotExists(engine, 'shadow_volumes')
|
||||
|
||||
def _pre_upgrade_293(self, engine):
|
||||
migrations = oslodbutils.get_table(engine, 'migrations')
|
||||
fake_migration = {}
|
||||
migrations.insert().execute(fake_migration)
|
||||
|
||||
def _check_293(self, engine, data):
|
||||
self.assertColumnExists(engine, 'migrations', 'migration_type')
|
||||
self.assertColumnExists(engine, 'shadow_migrations', 'migration_type')
|
||||
migrations = oslodbutils.get_table(engine, 'migrations')
|
||||
fake_migration = migrations.select().execute().first()
|
||||
self.assertIsNone(fake_migration.migration_type)
|
||||
self.assertFalse(fake_migration.hidden)
|
||||
|
||||
|
||||
class TestNovaMigrationsSQLite(NovaMigrationsCheckers,
|
||||
test_base.DbTestCase,
|
||||
|
|
Loading…
Reference in New Issue