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)
-
-
###################
###################
-@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,
--- /dev/null
+# 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
'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'
"""
from sqlalchemy import create_engine
models = (Backup,
- Migration,
Service,
SMBackendConf,
SMFlavors,
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"))