]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Remove xen storage manager tables
authorMike Perez <thingee@gmail.com>
Wed, 31 Jul 2013 22:26:46 +0000 (15:26 -0700)
committerMike Perez <thingee@gmail.com>
Thu, 1 Aug 2013 16:40:46 +0000 (09:40 -0700)
This removes the unused tables sm_backend_config, sm_flavors and
sm_volume. In addition, they're removed from the database API.

Change-Id: I02ff6434c2d6928f2e2b08053f6dcb6178edd773
Fixes: bug #1206962
cinder/db/api.py
cinder/db/sqlalchemy/api.py
cinder/db/sqlalchemy/migrate_repo/versions/016_drop_sm_tables.py [new file with mode: 0644]
cinder/db/sqlalchemy/models.py
cinder/tests/test_migrations.py

index 0866a5dfeb681abfb76a3d56f34081da87f9b95f..12357d69f95e609529cf82277f7ad9f53c363694 100644 (file)
@@ -472,93 +472,6 @@ def volume_glance_metadata_copy_from_volume_to_volume(context,
         src_volume_id,
         volume_id)
 
-###################
-
-
-def sm_backend_conf_create(context, values):
-    """Create a new SM Backend Config entry."""
-    return IMPL.sm_backend_conf_create(context, values)
-
-
-def sm_backend_conf_update(context, sm_backend_conf_id, values):
-    """Update a SM Backend Config entry."""
-    return IMPL.sm_backend_conf_update(context, sm_backend_conf_id, values)
-
-
-def sm_backend_conf_delete(context, sm_backend_conf_id):
-    """Delete a SM Backend Config."""
-    return IMPL.sm_backend_conf_delete(context, sm_backend_conf_id)
-
-
-def sm_backend_conf_get(context, sm_backend_conf_id):
-    """Get a specific SM Backend Config."""
-    return IMPL.sm_backend_conf_get(context, sm_backend_conf_id)
-
-
-def sm_backend_conf_get_by_sr(context, sr_uuid):
-    """Get a specific SM Backend Config."""
-    return IMPL.sm_backend_conf_get_by_sr(context, sr_uuid)
-
-
-def sm_backend_conf_get_all(context):
-    """Get all SM Backend Configs."""
-    return IMPL.sm_backend_conf_get_all(context)
-
-
-####################
-
-
-def sm_flavor_create(context, values):
-    """Create a new SM Flavor entry."""
-    return IMPL.sm_flavor_create(context, values)
-
-
-def sm_flavor_update(context, sm_flavor_id, values):
-    """Update a SM Flavor entry."""
-    return IMPL.sm_flavor_update(context, values)
-
-
-def sm_flavor_delete(context, sm_flavor_id):
-    """Delete a SM Flavor."""
-    return IMPL.sm_flavor_delete(context, sm_flavor_id)
-
-
-def sm_flavor_get(context, sm_flavor):
-    """Get a specific SM Flavor."""
-    return IMPL.sm_flavor_get(context, sm_flavor)
-
-
-def sm_flavor_get_all(context):
-    """Get all SM Flavors."""
-    return IMPL.sm_flavor_get_all(context)
-
-
-####################
-
-
-def sm_volume_create(context, values):
-    """Create a new child Zone entry."""
-    return IMPL.sm_volume_create(context, values)
-
-
-def sm_volume_update(context, volume_id, values):
-    """Update a child Zone entry."""
-    return IMPL.sm_volume_update(context, values)
-
-
-def sm_volume_delete(context, volume_id):
-    """Delete a child Zone."""
-    return IMPL.sm_volume_delete(context, volume_id)
-
-
-def sm_volume_get(context, volume_id):
-    """Get a specific child Zone."""
-    return IMPL.sm_volume_get(context, volume_id)
-
-
-def sm_volume_get_all(context):
-    """Get all child Zones."""
-    return IMPL.sm_volume_get_all(context)
 
 ###################
 
index 4a1f62b114f67ecfbe803070f2f561aaa8919a55..493dc40a01c8e6db06b1a6ba6eee98555bd88880 100644 (file)
@@ -1878,165 +1878,6 @@ def volume_glance_metadata_delete_by_snapshot(context, snapshot_id):
                 'updated_at': literal_column('updated_at')})
 
 
-####################
-
-
-@require_admin_context
-def sm_backend_conf_create(context, values):
-    backend_conf = models.SMBackendConf()
-    backend_conf.update(values)
-    backend_conf.save()
-    return backend_conf
-
-
-@require_admin_context
-def sm_backend_conf_update(context, sm_backend_id, values):
-    session = get_session()
-    with session.begin():
-        backend_conf = model_query(context, models.SMBackendConf,
-                                   session=session,
-                                   read_deleted="yes").\
-            filter_by(id=sm_backend_id).\
-            first()
-
-        if not backend_conf:
-            raise exception.NotFound(
-                _("No backend config with id %s") % sm_backend_id)
-
-        backend_conf.update(values)
-        backend_conf.save(session=session)
-    return backend_conf
-
-
-@require_admin_context
-def sm_backend_conf_delete(context, sm_backend_id):
-    # FIXME(sirp): for consistency, shouldn't this just mark as deleted with
-    # `purge` actually deleting the record?
-    session = get_session()
-    with session.begin():
-        model_query(context, models.SMBackendConf, session=session,
-                    read_deleted="yes").\
-            filter_by(id=sm_backend_id).\
-            delete()
-
-
-@require_admin_context
-def sm_backend_conf_get(context, sm_backend_id):
-    result = model_query(context, models.SMBackendConf, read_deleted="yes").\
-        filter_by(id=sm_backend_id).\
-        first()
-
-    if not result:
-        raise exception.NotFound(_("No backend config with id "
-                                   "%s") % sm_backend_id)
-
-    return result
-
-
-@require_admin_context
-def sm_backend_conf_get_by_sr(context, sr_uuid):
-    return model_query(context, models.SMBackendConf, read_deleted="yes").\
-        filter_by(sr_uuid=sr_uuid).\
-        first()
-
-
-@require_admin_context
-def sm_backend_conf_get_all(context):
-    return model_query(context, models.SMBackendConf, read_deleted="yes").\
-        all()
-
-
-####################
-
-
-def _sm_flavor_get_query(context, sm_flavor_label, session=None):
-    return model_query(context, models.SMFlavors, session=session,
-                       read_deleted="yes").\
-        filter_by(label=sm_flavor_label)
-
-
-@require_admin_context
-def sm_flavor_create(context, values):
-    sm_flavor = models.SMFlavors()
-    sm_flavor.update(values)
-    sm_flavor.save()
-    return sm_flavor
-
-
-@require_admin_context
-def sm_flavor_update(context, sm_flavor_label, values):
-    sm_flavor = sm_flavor_get(context, sm_flavor_label)
-    sm_flavor.update(values)
-    sm_flavor.save()
-    return sm_flavor
-
-
-@require_admin_context
-def sm_flavor_delete(context, sm_flavor_label):
-    session = get_session()
-    with session.begin():
-        _sm_flavor_get_query(context, sm_flavor_label).delete()
-
-
-@require_admin_context
-def sm_flavor_get(context, sm_flavor_label):
-    result = _sm_flavor_get_query(context, sm_flavor_label).first()
-
-    if not result:
-        raise exception.NotFound(
-            _("No sm_flavor called %s") % sm_flavor_label)
-
-    return result
-
-
-@require_admin_context
-def sm_flavor_get_all(context):
-    return model_query(context, models.SMFlavors, read_deleted="yes").all()
-
-
-###############################
-
-
-def _sm_volume_get_query(context, volume_id, session=None):
-    return model_query(context, models.SMVolume, session=session,
-                       read_deleted="yes").\
-        filter_by(id=volume_id)
-
-
-def sm_volume_create(context, values):
-    sm_volume = models.SMVolume()
-    sm_volume.update(values)
-    sm_volume.save()
-    return sm_volume
-
-
-def sm_volume_update(context, volume_id, values):
-    sm_volume = sm_volume_get(context, volume_id)
-    sm_volume.update(values)
-    sm_volume.save()
-    return sm_volume
-
-
-def sm_volume_delete(context, volume_id):
-    session = get_session()
-    with session.begin():
-        _sm_volume_get_query(context, volume_id, session=session).delete()
-
-
-def sm_volume_get(context, volume_id):
-    result = _sm_volume_get_query(context, volume_id).first()
-
-    if not result:
-        raise exception.NotFound(
-            _("No sm_volume with id %s") % volume_id)
-
-    return result
-
-
-def sm_volume_get_all(context):
-    return model_query(context, models.SMVolume, read_deleted="yes").all()
-
-
 ###############################
 
 
diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/016_drop_sm_tables.py b/cinder/db/sqlalchemy/migrate_repo/versions/016_drop_sm_tables.py
new file mode 100644 (file)
index 0000000..5b51f65
--- /dev/null
@@ -0,0 +1,101 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2013 OpenStack LLC.
+#
+#    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, ForeignKey
+from sqlalchemy import Integer, MetaData, String, Table
+
+from cinder.openstack.common import log as logging
+
+LOG = logging.getLogger(__name__)
+
+
+def upgrade(migrate_engine):
+    meta = MetaData()
+    meta.bind = migrate_engine
+
+    sm_backend_config = Table('sm_backend_config', meta, autoload=True)
+    sm_flavors = Table('sm_flavors', meta, autoload=True)
+    sm_volume = Table('sm_volume', meta, autoload=True)
+
+    tables = [sm_volume, sm_backend_config, sm_flavors]
+
+    for table in tables:
+        try:
+            table.drop()
+        except Exception:
+            LOG.exception(_('Exception while dropping table %s.'),
+                          repr(table))
+            raise
+
+
+def downgrade(migrate_engine):
+    meta = MetaData()
+    meta.bind = migrate_engine
+
+    Table('volumes', meta, autoload=True)
+
+    sm_backend_config = Table(
+        'sm_backend_config', meta,
+        Column('created_at', DateTime),
+        Column('updated_at', DateTime),
+        Column('deleted_at', DateTime),
+        Column('deleted', Boolean),
+        Column('id', Integer, primary_key=True, nullable=False),
+        Column('flavor_id', Integer, ForeignKey('sm_flavors.id'),
+               nullable=False),
+        Column('sr_uuid', String(length=255)),
+        Column('sr_type', String(length=255)),
+        Column('config_params', String(length=2047)),
+        mysql_engine='InnoDB'
+    )
+
+    sm_flavors = Table(
+        'sm_flavors', meta,
+        Column('created_at', DateTime),
+        Column('updated_at', DateTime),
+        Column('deleted_at', DateTime),
+        Column('deleted', Boolean),
+        Column('id', Integer, primary_key=True, nullable=False),
+        Column('label', String(length=255)),
+        Column('description', String(length=255)),
+        mysql_engine='InnoDB'
+    )
+
+    sm_volume = Table(
+        'sm_volume', meta,
+        Column('created_at', DateTime),
+        Column('updated_at', DateTime),
+        Column('deleted_at', DateTime),
+        Column('deleted', Boolean),
+        Column('id', String(length=36),
+               ForeignKey('volumes.id'),
+               primary_key=True,
+               nullable=False),
+        Column('backend_id', Integer, ForeignKey('sm_backend_config.id'),
+               nullable=False),
+        Column('vdi_uuid', String(length=255)),
+        mysql_engine='InnoDB'
+    )
+
+    tables = [sm_flavors, sm_backend_config, sm_volume]
+
+    for table in tables:
+        try:
+            table.create()
+        except Exception:
+            LOG.exception(_('Exception while creating table %s.'),
+                          repr(table))
+            raise
index 8bbe663dbede5fdd9c86c299bb9f9487fcc5f682..e9265e3d01c3e1ef5f3c76d22c607327e7482095 100644 (file)
@@ -332,32 +332,6 @@ class IscsiTarget(BASE, CinderBase):
                           'IscsiTarget.deleted==False)')
 
 
-class SMFlavors(BASE, CinderBase):
-    """Represents a flavor for SM volumes."""
-    __tablename__ = 'sm_flavors'
-    id = Column(Integer(), primary_key=True)
-    label = Column(String(255))
-    description = Column(String(255))
-
-
-class SMBackendConf(BASE, CinderBase):
-    """Represents the connection to the backend for SM."""
-    __tablename__ = 'sm_backend_config'
-    id = Column(Integer(), primary_key=True)
-    flavor_id = Column(Integer, ForeignKey('sm_flavors.id'), nullable=False)
-    sr_uuid = Column(String(255))
-    sr_type = Column(String(255))
-    config_params = Column(String(2047))
-
-
-class SMVolume(BASE, CinderBase):
-    __tablename__ = 'sm_volume'
-    id = Column(String(36), ForeignKey(Volume.id), primary_key=True)
-    backend_id = Column(Integer, ForeignKey('sm_backend_config.id'),
-                        nullable=False)
-    vdi_uuid = Column(String(255))
-
-
 class Backup(BASE, CinderBase):
     """Represents a backup of a volume to Swift."""
     __tablename__ = 'backups'
@@ -410,9 +384,6 @@ def register_models():
     from sqlalchemy import create_engine
     models = (Backup,
               Service,
-              SMBackendConf,
-              SMFlavors,
-              SMVolume,
               Volume,
               VolumeMetadata,
               SnapshotMetadata,
index 74c0c87571ca4c77024ef9be1c8be9bb58450b02..18ea31c8edbfb5b158976aa50124025bb11532f5 100644 (file)
@@ -816,3 +816,29 @@ class TestMigrations(test.TestCase):
 
             self.assertTrue(engine.dialect.has_table(engine.connect(),
                                                      "migrations"))
+
+    def test_migration_016(self):
+        """Test that dropping xen storage manager tables 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)
+            metadata = sqlalchemy.schema.MetaData()
+            metadata.bind = engine
+
+            migration_api.upgrade(engine, TestMigrations.REPOSITORY, 16)
+            self.assertFalse(engine.dialect.has_table(engine.connect(),
+                                                      'sm_flavors'))
+            self.assertFalse(engine.dialect.has_table(engine.connect(),
+                                                      'sm_backend_config'))
+            self.assertFalse(engine.dialect.has_table(engine.connect(),
+                                                      'sm_volume'))
+
+            migration_api.downgrade(engine, TestMigrations.REPOSITORY, 15)
+            self.assertTrue(engine.dialect.has_table(engine.connect(),
+                                                     'sm_flavors'))
+            self.assertTrue(engine.dialect.has_table(engine.connect(),
+                                                     'sm_backend_config'))
+            self.assertTrue(engine.dialect.has_table(engine.connect(),
+                                                     'sm_volume'))