]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Remove unused migration_* methods from db api.
authorYuriy Zveryanskyy <yzveryanskyy@mirantis.com>
Thu, 11 Jul 2013 11:33:14 +0000 (14:33 +0300)
committerMike Perez <thingee@gmail.com>
Thu, 1 Aug 2013 16:27:47 +0000 (09:27 -0700)
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
cinder/db/sqlalchemy/api.py
cinder/db/sqlalchemy/migrate_repo/versions/015_drop_migrations_table.py [new file with mode: 0644]
cinder/db/sqlalchemy/models.py
cinder/tests/test_migrations.py

index 468a8e04cb723f8226e51864d5f774b09cea1826..0866a5dfeb681abfb76a3d56f34081da87f9b95f 100644 (file)
@@ -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)
-
-
 ###################
 
 
index 285068620adbdcd24149780a79326a8431a376f8..4a1f62b114f67ecfbe803070f2f561aaa8919a55 100644 (file)
@@ -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 (file)
index 0000000..2de50be
--- /dev/null
@@ -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
index 8ae1aec219877eec3bb64d8967be4e2f3c084b33..8bbe663dbede5fdd9c86c299bb9f9487fcc5f682 100644 (file)
@@ -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,
index 306cd69273b639719708b171bd664454ba1fad4c..74c0c87571ca4c77024ef9be1c8be9bb58450b02 100644 (file)
@@ -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"))