From 19e9a068445a1f21ad43372302d6d872a776f307 Mon Sep 17 00:00:00 2001 From: Yuriy Zveryanskyy Date: Thu, 11 Jul 2013 14:33:14 +0300 Subject: [PATCH] Remove unused migration_* methods from db api. There is migration_* group of methods in cinder db api. These methods not used by cinder, they inherited from nova code. Add migration script for drop unused 'migrations' table. blueprint db-cleanup Change-Id: I4a352fd9acb28bb86072884438af454c86559e71 --- cinder/db/api.py | 28 -------- cinder/db/sqlalchemy/api.py | 64 ------------------- .../versions/015_drop_migrations_table.py | 63 ++++++++++++++++++ cinder/db/sqlalchemy/models.py | 19 ------ cinder/tests/test_migrations.py | 16 +++++ 5 files changed, 79 insertions(+), 111 deletions(-) create mode 100644 cinder/db/sqlalchemy/migrate_repo/versions/015_drop_migrations_table.py diff --git a/cinder/db/api.py b/cinder/db/api.py index 468a8e04c..0866a5dfe 100644 --- a/cinder/db/api.py +++ b/cinder/db/api.py @@ -145,34 +145,6 @@ def service_update(context, service_id, values): return IMPL.service_update(context, service_id, values) -################### -def migration_update(context, id, values): - """Update a migration instance.""" - return IMPL.migration_update(context, id, values) - - -def migration_create(context, values): - """Create a migration record.""" - return IMPL.migration_create(context, values) - - -def migration_get(context, migration_id): - """Finds a migration by the id.""" - return IMPL.migration_get(context, migration_id) - - -def migration_get_by_instance_and_status(context, instance_uuid, status): - """Finds a migration by the instance uuid its migrating.""" - return IMPL.migration_get_by_instance_and_status(context, - instance_uuid, - status) - - -def migration_get_all_unconfirmed(context, confirm_window): - """Finds all unconfirmed migrations within the confirmation window.""" - return IMPL.migration_get_all_unconfirmed(context, confirm_window) - - ################### diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 285068620..4a1f62b11 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -1512,70 +1512,6 @@ def snapshot_metadata_update(context, snapshot_id, metadata, delete): ################### -@require_admin_context -def migration_create(context, values): - migration = models.Migration() - migration.update(values) - migration.save() - return migration - - -@require_admin_context -def migration_update(context, id, values): - session = get_session() - with session.begin(): - migration = _migration_get(context, id, session=session) - migration.update(values) - migration.save(session=session) - return migration - - -@require_admin_context -def _migration_get(context, id, session=None): - result = model_query(context, models.Migration, session=session, - read_deleted="yes").\ - filter_by(id=id).\ - first() - - if not result: - raise exception.MigrationNotFound(migration_id=id) - - return result - - -@require_admin_context -def migration_get(context, id): - return _migration_get(context, id) - - -@require_admin_context -def migration_get_by_instance_and_status(context, instance_uuid, status): - result = model_query(context, models.Migration, read_deleted="yes").\ - filter_by(instance_uuid=instance_uuid).\ - filter_by(status=status).\ - first() - - if not result: - raise exception.MigrationNotFoundByStatus(instance_id=instance_uuid, - status=status) - - return result - - -@require_admin_context -def migration_get_all_unconfirmed(context, confirm_window): - confirm_window = timeutils.utcnow() - datetime.timedelta( - seconds=confirm_window) - - return model_query(context, models.Migration, read_deleted="yes").\ - filter(models.Migration.updated_at <= confirm_window).\ - filter_by(status="finished").\ - all() - - -################## - - @require_admin_context def volume_type_create(context, values): """Create a new instance type. In order to pass in extra specs, diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/015_drop_migrations_table.py b/cinder/db/sqlalchemy/migrate_repo/versions/015_drop_migrations_table.py new file mode 100644 index 000000000..2de50be94 --- /dev/null +++ b/cinder/db/sqlalchemy/migrate_repo/versions/015_drop_migrations_table.py @@ -0,0 +1,63 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# 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 Boolean, Column, DateTime, Integer +from sqlalchemy import MetaData, String, Table + +from cinder.openstack.common import log as logging + +LOG = logging.getLogger(__name__) + + +TABLE_NAME = 'migrations' + + +def upgrade(migrate_engine): + meta = MetaData() + meta.bind = migrate_engine + table = Table(TABLE_NAME, meta, autoload=True) + try: + table.drop() + except Exception: + LOG.error(_("migrations table not dropped")) + raise + + +def downgrade(migrate_engine): + meta = MetaData() + meta.bind = migrate_engine + + table = Table( + TABLE_NAME, meta, + Column('created_at', DateTime(timezone=False)), + Column('updated_at', DateTime(timezone=False)), + Column('deleted_at', DateTime(timezone=False)), + Column('deleted', Boolean), + Column('id', Integer, primary_key=True, nullable=False), + + Column('source_compute', String(length=255)), + Column('dest_compute', String(length=255)), + Column('dest_host', String(length=255)), + Column('old_instance_type_id', Integer), + Column('new_instance_type_id', Integer), + Column('instance_uuid', String(length=255), nullable=True), + Column('status', String(length=255)), + mysql_engine='InnoDB' + ) + + try: + table.create() + except Exception: + LOG.error(_("Table |%s| not created"), repr(table)) + raise diff --git a/cinder/db/sqlalchemy/models.py b/cinder/db/sqlalchemy/models.py index 8ae1aec21..8bbe663db 100644 --- a/cinder/db/sqlalchemy/models.py +++ b/cinder/db/sqlalchemy/models.py @@ -332,24 +332,6 @@ class IscsiTarget(BASE, CinderBase): 'IscsiTarget.deleted==False)') -class Migration(BASE, CinderBase): - """Represents a running host-to-host migration.""" - __tablename__ = 'migrations' - id = Column(Integer, primary_key=True, nullable=False) - # NOTE(tr3buchet): the ____compute variables are instance['host'] - source_compute = Column(String(255)) - dest_compute = Column(String(255)) - # NOTE(tr3buchet): dest_host, btw, is an ip address - dest_host = Column(String(255)) - old_instance_type_id = Column(Integer()) - new_instance_type_id = Column(Integer()) - instance_uuid = Column(String(255), - ForeignKey('instances.uuid'), - nullable=True) - #TODO(_cerberus_): enum - status = Column(String(255)) - - class SMFlavors(BASE, CinderBase): """Represents a flavor for SM volumes.""" __tablename__ = 'sm_flavors' @@ -427,7 +409,6 @@ def register_models(): """ from sqlalchemy import create_engine models = (Backup, - Migration, Service, SMBackendConf, SMFlavors, diff --git a/cinder/tests/test_migrations.py b/cinder/tests/test_migrations.py index 306cd6927..74c0c8757 100644 --- a/cinder/tests/test_migrations.py +++ b/cinder/tests/test_migrations.py @@ -800,3 +800,19 @@ class TestMigrations(test.TestCase): metadata, autoload=True) self.assertTrue('_name_id' not in volumes.c) + + def test_migration_015(self): + """Test removing migrations table works correctly.""" + for (key, engine) in self.engines.items(): + migration_api.version_control(engine, + TestMigrations.REPOSITORY, + migration.INIT_VERSION) + migration_api.upgrade(engine, TestMigrations.REPOSITORY, 15) + + self.assertFalse(engine.dialect.has_table(engine.connect(), + "migrations")) + + migration_api.downgrade(engine, TestMigrations.REPOSITORY, 14) + + self.assertTrue(engine.dialect.has_table(engine.connect(), + "migrations")) -- 2.45.2