Exemplo n.º 1
0
 def test_extension_federation_upgraded_values(self):
     abs_path = migration_helpers.find_migrate_repo(federation)
     migration.db_version_control(sql.get_engine(), abs_path)
     migration.db_sync(sql.get_engine(), abs_path, version=6)
     idp_table = sqlalchemy.Table("identity_provider",
                                  self.metadata,
                                  autoload=True)
     idps = [{'id': uuid.uuid4().hex,
              'enabled': True,
              'description': uuid.uuid4().hex,
              'remote_id': uuid.uuid4().hex},
             {'id': uuid.uuid4().hex,
              'enabled': True,
              'description': uuid.uuid4().hex,
              'remote_id': uuid.uuid4().hex}]
     for idp in idps:
         ins = idp_table.insert().values({'id': idp['id'],
                                          'enabled': idp['enabled'],
                                          'description': idp['description'],
                                          'remote_id': idp['remote_id']})
         self.engine.execute(ins)
     migration.db_sync(sql.get_engine(), abs_path)
     idp_remote_ids_table = sqlalchemy.Table("idp_remote_ids",
                                             self.metadata,
                                             autoload=True)
     for idp in idps:
         s = idp_remote_ids_table.select().where(
             idp_remote_ids_table.c.idp_id == idp['id'])
         remote = self.engine.execute(s).fetchone()
         self.assertEqual(idp['remote_id'],
                          remote['remote_id'],
                          'remote_ids must be preserved during the '
                          'migration from identity_provider table to '
                          'idp_remote_ids table')
def _sync_extension_repo(extension, version):
    if extension in MIGRATED_EXTENSIONS:
        raise exception.MigrationMovedFailure(extension=extension)

    init_version = 0
    engine = sql.get_engine()

    try:
        package_name = '.'.join((contrib.__name__, extension))
        package = importutils.import_module(package_name)
    except ImportError:
        raise ImportError(_("%s extension does not exist.")
                          % package_name)
    try:
        abs_path = find_migrate_repo(package)
        try:
            migration.db_version_control(sql.get_engine(), abs_path)
        # Register the repo with the version control API
        # If it already knows about the repo, it will throw
        # an exception that we can safely ignore
        except exceptions.DatabaseAlreadyControlledError:  # nosec
            pass
    except exception.MigrationNotProvided as e:
        print(e)
        sys.exit(1)

    _assert_not_schema_downgrade(extension=extension, version=version)

    migration.db_sync(engine, abs_path, version=version,
                      init_version=init_version, sanity_check=False)
Exemplo n.º 3
0
 def test_extension_initial(self):
     """When get the initial version of an extension, it's 0."""
     for name, extension in six.iteritems(EXTENSIONS):
         abs_path = migration_helpers.find_migrate_repo(extension)
         migration.db_version_control(sql.get_engine(), abs_path)
         version = migration_helpers.get_db_version(extension=name)
         self.assertEqual(0, version, "Migrate version for %s is not 0" % name)
Exemplo n.º 4
0
 def sync(self, version=None, current_version=None):
     """
     Place a database under migration control and upgrade/downgrade it,
     creating first if necessary.
     """
     if current_version not in (None, "None"):
         migration.db_version_control(db_api.get_engine(), db_migration.MIGRATE_REPO_PATH, version=current_version)
     migration.db_sync(db_api.get_engine(), db_migration.MIGRATE_REPO_PATH, version)
Exemplo n.º 5
0
 def test_extension_migrated(self):
     """When get the version after migrating an extension, it's not 0."""
     for name, extension in six.iteritems(EXTENSIONS):
         abs_path = migration_helpers.find_migrate_repo(extension)
         migration.db_version_control(sql.get_engine(), abs_path)
         migration.db_sync(sql.get_engine(), abs_path)
         version = migration_helpers.get_db_version(extension=name)
         self.assertTrue(version > 0, "Version for %s didn't change after migrated?" % name)
         # Verify downgrades cannot occur
         self.assertRaises(
             db_exception.DbMigrationError, migration_helpers._sync_extension_repo, extension=name, version=0
         )
Exemplo n.º 6
0
def _sync_repo(repo_name):
    abs_path = find_repo(repo_name)
    with sql.session_for_write() as session:
        engine = session.get_bind()
        # Register the repo with the version control API
        # If it already knows about the repo, it will throw
        # an exception that we can safely ignore
        try:
            migration.db_version_control(engine, abs_path)
        except (migration.exception.DbMigrationError, exceptions.DatabaseAlreadyControlledError):  # nosec
            pass
        init_version = get_init_version(abs_path=abs_path)
        migration.db_sync(engine, abs_path, init_version=init_version, sanity_check=False)
Exemplo n.º 7
0
def _sync_extension_repo(extension, version):
    init_version = 0
    engine = sql.get_engine()

    try:
        package_name = '.'.join((contrib.__name__, extension))
        package = importutils.import_module(package_name)
    except ImportError:
        raise ImportError(_("%s extension does not exist.")
                          % package_name)
    try:
        abs_path = find_migrate_repo(package)
        try:
            migration.db_version_control(sql.get_engine(), abs_path)
        # Register the repo with the version control API
        # If it already knows about the repo, it will throw
        # an exception that we can safely ignore
        except exceptions.DatabaseAlreadyControlledError:
            pass
    except exception.MigrationNotProvided as e:
        print(e)
        sys.exit(1)

    _assert_not_schema_downgrade(extension=extension, version=version)

    try:
        migration.db_sync(engine, abs_path, version=version,
                          init_version=init_version)
    except ValueError:
        # NOTE(marco-fargetta): ValueError is raised from the sanity check (
        # verifies that tables are utf8 under mysql). The federation_protocol,
        # identity_provider and mapping tables were not initially built with
        # InnoDB and utf8 as part of the table arguments when the migration
        # was initially created. Bug #1426334 is a scenario where the deployer
        # can get wedged, unable to upgrade or downgrade.
        # This is a workaround to "fix" those tables if we're under MySQL and
        # the version is before the 6 because before the tables were introduced
        # before and patched when migration 5 was available
        if engine.name == 'mysql' and \
           int(six.text_type(get_db_version(extension))) < 6:
            _fix_federation_tables(engine)
            # The migration is applied again after the fix
            migration.db_sync(engine, abs_path, version=version,
                              init_version=init_version)
        else:
            raise
def _sync_extension_repo(extension, version):
    init_version = 0
    try:
        package_name = '.'.join((contrib.__name__, extension))
        package = importutils.import_module(package_name)
    except ImportError:
        raise ImportError(_("%s extension does not exist.")
                          % package_name)
    try:
        abs_path = find_migrate_repo(package)
        try:
            migration.db_version_control(sql.get_engine(), abs_path)
        # Register the repo with the version control API
        # If it already knows about the repo, it will throw
        # an exception that we can safely ignore
        except exceptions.DatabaseAlreadyControlledError:
            pass
    except exception.MigrationNotProvided as e:
        print(e)
        sys.exit(1)
    migration.db_sync(sql.get_engine(), abs_path, version=version,
                      init_version=init_version)
Exemplo n.º 9
0
    def test_db_version_control(self):
        with test_utils.nested(
            mock.patch.object(migration, '_find_migrate_repo'),
            mock.patch.object(versioning_api, 'version_control'),
        ) as (mock_find_repo, mock_version_control):
            mock_find_repo.return_value = self.return_value

            version = migration.db_version_control(
                self.engine, self.path, self.test_version)

            self.assertEqual(self.test_version, version)
            mock_version_control.assert_called_once_with(
                self.engine, self.return_value, self.test_version)
Exemplo n.º 10
0
 def version_control(self, version=None):
     """Place a database under migration control"""
     migration.db_version_control(db_api.get_engine(),
                                  db_migration.MIGRATE_REPO_PATH,
                                  version)
Exemplo n.º 11
0
def db_version_control(engine, version=None):
    path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "migrate_repo")
    return oslo_migration.db_version_control(engine, path, version)
Exemplo n.º 12
0
 def version_control(self, version=None):
     """Place a database under migration control"""
     migration.db_version_control(db_api.get_engine(),
                                  db_migration.MIGRATE_REPO_PATH, version)
Exemplo n.º 13
0
def db_version_control(engine, version=None):
    path = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                        'migrate_repo')
    return oslo_migration.db_version_control(engine, path, version)