db: Add the migration_context to the instance_extra table

We will save data that needs to be persisted for the duration of an
instance migration in this column, as described in more detail in the
linked BP.

Follow-on patches will introduce the objects plumbing for this.

Change-Id: I6faaa843b6587ad972a8df187e50a5b4e91540c8
Related-blueprint: migration-fix-resource-tracking
This commit is contained in:
Nikola Dipanov 2015-08-25 12:40:35 +01:00
parent e29fda6735
commit ed252e5fd3
4 changed files with 38 additions and 1 deletions

View File

@ -2721,7 +2721,8 @@ def instance_extra_get_by_instance_uuid(context, instance_uuid,
query = model_query(context, models.InstanceExtra).\
filter_by(instance_uuid=instance_uuid)
if columns is None:
columns = ['numa_topology', 'pci_requests', 'flavor', 'vcpu_model']
columns = ['numa_topology', 'pci_requests', 'flavor', 'vcpu_model',
'migration_context']
for column in columns:
query = query.options(undefer(column))
instance_extra = query.first()

View File

@ -0,0 +1,32 @@
# 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 Column
from sqlalchemy import MetaData
from sqlalchemy import Table
from sqlalchemy import Text
BASE_TABLE_NAME = 'instance_extra'
NEW_COLUMN_NAME = 'migration_context'
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
for prefix in ('', 'shadow_'):
table = Table(prefix + BASE_TABLE_NAME, meta, autoload=True)
new_column = Column(NEW_COLUMN_NAME, Text, nullable=True)
if not hasattr(table.c, NEW_COLUMN_NAME):
table.create_column(new_column)

View File

@ -364,6 +364,7 @@ class InstanceExtra(BASE, NovaBase):
pci_requests = orm.deferred(Column(Text))
flavor = orm.deferred(Column(Text))
vcpu_model = orm.deferred(Column(Text))
migration_context = orm.deferred(Column(Text))
instance = orm.relationship(Instance,
backref=orm.backref('extra',
uselist=False),

View File

@ -791,6 +791,9 @@ class NovaMigrationsCheckers(test_migrations.ModelsMigrationsSync,
def _check_299(self, engine, data):
self.assertColumnExists(engine, 'services', 'version')
def _check_300(self, engine, data):
self.assertColumnExists(engine, 'instance_extra', 'migration_context')
class TestNovaMigrationsSQLite(NovaMigrationsCheckers,
test_base.DbTestCase,