Exemplo n.º 1
0
    def check_db_sync_status(self):
        status = 0
        try:
            expand_version = upgrades.get_db_version(repo='expand_repo')
        except migration.exception.DBMigrationError:
            LOG.info('Your database is not currently under version '
                     'control or the database is already controlled. Your '
                     'first step is to run `keystone-manage db_sync '
                     '--expand`.')
            return 2
        try:
            migrate_version = upgrades.get_db_version(
                repo='data_migration_repo')
        except migration.exception.DBMigrationError:
            migrate_version = 0
        try:
            contract_version = upgrades.get_db_version(repo='contract_repo')
        except migration.exception.DBMigrationError:
            contract_version = 0

        repo = migrate.versioning.repository.Repository(
            upgrades.find_repo('expand_repo'))
        migration_script_version = int(max(repo.versions.versions))

        if (contract_version > migrate_version
                or migrate_version > expand_version):
            LOG.info('Your database is out of sync. For more information '
                     'refer to https://docs.openstack.org/keystone/'
                     'latest/admin/identity-upgrading.html')
            status = 1
        elif migration_script_version > expand_version:
            LOG.info('Your database is not up to date. Your first step is '
                     'to run `keystone-manage db_sync --expand`.')
            status = 2
        elif expand_version > migrate_version:
            LOG.info('Expand version is ahead of migrate. Your next step '
                     'is to run `keystone-manage db_sync --migrate`.')
            status = 3
        elif migrate_version > contract_version:
            LOG.info('Migrate version is ahead of contract. Your next '
                     'step is to run `keystone-manage db_sync --contract`.')
            status = 4
        elif (migration_script_version == expand_version == migrate_version ==
              contract_version):
            LOG.info('All db_sync commands are upgraded to the same '
                     'version and up-to-date.')
        LOG.info(
            'The latest installed migration script version is: '
            '%(script)d.\nCurrent repository versions:\nExpand: '
            '%(expand)d \nMigrate: %(migrate)d\nContract: '
            '%(contract)d', {
                'script': migration_script_version,
                'expand': expand_version,
                'migrate': migrate_version,
                'contract': contract_version
            })
        return status
Exemplo n.º 2
0
 def _set_db_sync_command_versions(self):
     self.expand(upgrades.INITIAL_VERSION + 1)
     self.migrate(upgrades.INITIAL_VERSION + 1)
     self.contract(upgrades.INITIAL_VERSION + 1)
     for version in (
         upgrades.get_db_version('expand'),
         upgrades.get_db_version('data_migration'),
         upgrades.get_db_version('contract'),
     ):
         self.assertEqual(upgrades.INITIAL_VERSION + 1, version)
def upgrade(migrate_engine):
    try:
        extension_version = upgrades.get_db_version(
            extension='endpoint_policy',
            engine=migrate_engine)
    except Exception:
        extension_version = 0

    # This migration corresponds to endpoint_policy extension migration 1. Only
    # update if it has not been run.
    if extension_version >= 1:
        return

    # Upgrade operations go here. Don't create your own engine; bind
    # migrate_engine to your metadata
    meta = sql.MetaData()
    meta.bind = migrate_engine

    endpoint_policy_table = sql.Table(
        'policy_association',
        meta,
        sql.Column('id', sql.String(64), primary_key=True),
        sql.Column('policy_id', sql.String(64),
                   nullable=False),
        sql.Column('endpoint_id', sql.String(64),
                   nullable=True),
        sql.Column('service_id', sql.String(64),
                   nullable=True),
        sql.Column('region_id', sql.String(64),
                   nullable=True),
        sql.UniqueConstraint('endpoint_id', 'service_id', 'region_id'),
        mysql_engine='InnoDB',
        mysql_charset='utf8')

    endpoint_policy_table.create(migrate_engine, checkfirst=True)
Exemplo n.º 4
0
def upgrade(migrate_engine):
    try:
        extension_version = upgrades.get_db_version(extension='oauth1',
                                                    engine=migrate_engine)
    except Exception:
        extension_version = 0

    # This migration corresponds to oauth extension migration 5. Only
    # update if it has not been run.
    if extension_version >= 5:
        return

    # Upgrade operations go here. Don't create your own engine; bind
    # migrate_engine to your metadata
    meta = sql.MetaData()
    meta.bind = migrate_engine

    consumer_table = sql.Table(
        'consumer', meta,
        sql.Column('id', sql.String(64), primary_key=True, nullable=False),
        sql.Column('description', sql.String(64), nullable=True),
        sql.Column('secret', sql.String(64), nullable=False),
        sql.Column('extra', sql.Text(), nullable=False))
    consumer_table.create(migrate_engine, checkfirst=True)

    request_token_table = sql.Table(
        'request_token', meta,
        sql.Column('id', sql.String(64), primary_key=True, nullable=False),
        sql.Column('request_secret', sql.String(64), nullable=False),
        sql.Column('verifier', sql.String(64), nullable=True),
        sql.Column('authorizing_user_id', sql.String(64), nullable=True),
        sql.Column('requested_project_id', sql.String(64), nullable=False),
        sql.Column('role_ids', sql.Text(), nullable=True),
        sql.Column('consumer_id',
                   sql.String(64),
                   sql.ForeignKey('consumer.id'),
                   nullable=False,
                   index=True),
        sql.Column('expires_at', sql.String(64), nullable=True))
    request_token_table.create(migrate_engine, checkfirst=True)

    access_token_table = sql.Table(
        'access_token', meta,
        sql.Column('id', sql.String(64), primary_key=True, nullable=False),
        sql.Column('access_secret', sql.String(64), nullable=False),
        sql.Column('authorizing_user_id',
                   sql.String(64),
                   nullable=False,
                   index=True),
        sql.Column('project_id', sql.String(64), nullable=False),
        sql.Column('role_ids', sql.Text(), nullable=False),
        sql.Column('consumer_id',
                   sql.String(64),
                   sql.ForeignKey('consumer.id'),
                   nullable=False,
                   index=True),
        sql.Column('expires_at', sql.String(64), nullable=True))
    access_token_table.create(migrate_engine, checkfirst=True)
def upgrade(migrate_engine):
    try:
        extension_version = upgrades.get_db_version(
            extension='endpoint_filter',
            engine=migrate_engine)
    except Exception:
        extension_version = 0

    # This migration corresponds to endpoint_filter extension migration 2. Only
    # update if it has not been run.
    if extension_version >= 2:
        return

    # Upgrade operations go here. Don't create your own engine; bind
    # migrate_engine to your metadata
    meta = sql.MetaData()
    meta.bind = migrate_engine

    EP_GROUP_ID = 'endpoint_group_id'
    PROJECT_ID = 'project_id'

    endpoint_filtering_table = sql.Table(
        'project_endpoint',
        meta,
        sql.Column(
            'endpoint_id',
            sql.String(64),
            primary_key=True,
            nullable=False),
        sql.Column(
            'project_id',
            sql.String(64),
            primary_key=True,
            nullable=False))
    endpoint_filtering_table.create(migrate_engine, checkfirst=True)

    endpoint_group_table = sql.Table(
        'endpoint_group',
        meta,
        sql.Column('id', sql.String(64), primary_key=True),
        sql.Column('name', sql.String(255), nullable=False),
        sql.Column('description', sql.Text, nullable=True),
        sql.Column('filters', sql.Text(), nullable=False))
    endpoint_group_table.create(migrate_engine, checkfirst=True)

    project_endpoint_group_table = sql.Table(
        'project_endpoint_group',
        meta,
        sql.Column(EP_GROUP_ID, sql.String(64),
                   sql.ForeignKey('endpoint_group.id'), nullable=False),
        sql.Column(PROJECT_ID, sql.String(64), nullable=False),
        sql.PrimaryKeyConstraint(EP_GROUP_ID, PROJECT_ID))
    project_endpoint_group_table.create(migrate_engine, checkfirst=True)
Exemplo n.º 6
0
def upgrade(migrate_engine):
    try:
        extension_version = upgrades.get_db_version(
            extension='endpoint_filter', engine=migrate_engine)
    except Exception:
        extension_version = 0

    # This migration corresponds to endpoint_filter extension migration 2. Only
    # update if it has not been run.
    if extension_version >= 2:
        return

    # Upgrade operations go here. Don't create your own engine; bind
    # migrate_engine to your metadata
    meta = sql.MetaData()
    meta.bind = migrate_engine

    EP_GROUP_ID = 'endpoint_group_id'
    PROJECT_ID = 'project_id'

    endpoint_filtering_table = sql.Table(
        'project_endpoint', meta,
        sql.Column('endpoint_id',
                   sql.String(64),
                   primary_key=True,
                   nullable=False),
        sql.Column('project_id',
                   sql.String(64),
                   primary_key=True,
                   nullable=False))
    endpoint_filtering_table.create(migrate_engine, checkfirst=True)

    endpoint_group_table = sql.Table(
        'endpoint_group', meta,
        sql.Column('id', sql.String(64), primary_key=True),
        sql.Column('name', sql.String(255), nullable=False),
        sql.Column('description', sql.Text, nullable=True),
        sql.Column('filters', sql.Text(), nullable=False))
    endpoint_group_table.create(migrate_engine, checkfirst=True)

    project_endpoint_group_table = sql.Table(
        'project_endpoint_group', meta,
        sql.Column(EP_GROUP_ID,
                   sql.String(64),
                   sql.ForeignKey('endpoint_group.id'),
                   nullable=False),
        sql.Column(PROJECT_ID, sql.String(64), nullable=False),
        sql.PrimaryKeyConstraint(EP_GROUP_ID, PROJECT_ID))
    project_endpoint_group_table.create(migrate_engine, checkfirst=True)
def upgrade(migrate_engine):
    try:
        extension_version = upgrades.get_db_version(
            extension='endpoint_policy', engine=migrate_engine)
    except Exception:
        extension_version = 0

    # This migration corresponds to endpoint_policy extension migration 1. Only
    # update if it has not been run.
    if extension_version >= 1:
        return

    # Upgrade operations go here. Don't create your own engine; bind
    # migrate_engine to your metadata
    meta = sql.MetaData()
    meta.bind = migrate_engine

    endpoint_policy_table = sql.Table('policy_association',
                                      meta,
                                      sql.Column('id',
                                                 sql.String(64),
                                                 primary_key=True),
                                      sql.Column('policy_id',
                                                 sql.String(64),
                                                 nullable=False),
                                      sql.Column('endpoint_id',
                                                 sql.String(64),
                                                 nullable=True),
                                      sql.Column('service_id',
                                                 sql.String(64),
                                                 nullable=True),
                                      sql.Column('region_id',
                                                 sql.String(64),
                                                 nullable=True),
                                      sql.UniqueConstraint(
                                          'endpoint_id', 'service_id',
                                          'region_id'),
                                      mysql_engine='InnoDB',
                                      mysql_charset='utf8')

    endpoint_policy_table.create(migrate_engine, checkfirst=True)
Exemplo n.º 8
0
def upgrade(migrate_engine):
    try:
        extension_version = upgrades.get_db_version(
            extension='revoke',
            engine=migrate_engine)
    except Exception:
        extension_version = 0

    # This migration corresponds to revoke extension migration 2. Only
    # update if it has not been run.
    if extension_version >= 2:
        return

    # Upgrade operations go here. Don't create your own engine; bind
    # migrate_engine to your metadata
    meta = sql.MetaData()
    meta.bind = migrate_engine

    service_table = sql.Table(
        'revocation_event',
        meta,
        sql.Column('id', sql.String(64), primary_key=True),
        sql.Column('domain_id', sql.String(64)),
        sql.Column('project_id', sql.String(64)),
        sql.Column('user_id', sql.String(64)),
        sql.Column('role_id', sql.String(64)),
        sql.Column('trust_id', sql.String(64)),
        sql.Column('consumer_id', sql.String(64)),
        sql.Column('access_token_id', sql.String(64)),
        sql.Column('issued_before', sql.DateTime(), nullable=False),
        sql.Column('expires_at', sql.DateTime()),
        sql.Column('revoked_at', sql.DateTime(), index=True, nullable=False),
        sql.Column('audit_id', sql.String(32), nullable=True),
        sql.Column('audit_chain_id', sql.String(32), nullable=True))

    service_table.create(migrate_engine, checkfirst=True)
Exemplo n.º 9
0
 def main():
     assert_not_extension(CONF.command.extension)
     print(upgrades.get_db_version())
Exemplo n.º 10
0
def upgrade(migrate_engine):
    try:
        extension_version = upgrades.get_db_version(extension="federation", engine=migrate_engine)
    except Exception:
        extension_version = 0

    # This migration corresponds to federation extension migration 8. Only
    # update if it has not been run.
    if extension_version >= 8:
        return

    # Upgrade operations go here. Don't create your own engine; bind
    # migrate_engine to your metadata
    meta = sql.MetaData()
    meta.bind = migrate_engine

    idp_table = sql.Table(
        "identity_provider",
        meta,
        sql.Column("id", sql.String(64), primary_key=True),
        sql.Column("enabled", sql.Boolean, nullable=False),
        sql.Column("description", sql.Text(), nullable=True),
        mysql_engine="InnoDB",
        mysql_charset="utf8",
    )
    idp_table.create(migrate_engine, checkfirst=True)

    federation_protocol_table = sql.Table(
        "federation_protocol",
        meta,
        sql.Column("id", sql.String(64), primary_key=True),
        sql.Column(
            "idp_id", sql.String(64), sql.ForeignKey("identity_provider.id", ondelete="CASCADE"), primary_key=True
        ),
        sql.Column("mapping_id", sql.String(64), nullable=False),
        mysql_engine="InnoDB",
        mysql_charset="utf8",
    )
    federation_protocol_table.create(migrate_engine, checkfirst=True)

    mapping_table = sql.Table(
        "mapping",
        meta,
        sql.Column("id", sql.String(64), primary_key=True),
        sql.Column("rules", sql.Text(), nullable=False),
        mysql_engine="InnoDB",
        mysql_charset="utf8",
    )
    mapping_table.create(migrate_engine, checkfirst=True)

    relay_state_prefix_default = CONF.saml.relay_state_prefix
    sp_table = sql.Table(
        "service_provider",
        meta,
        sql.Column("auth_url", sql.String(256), nullable=False),
        sql.Column("id", sql.String(64), primary_key=True),
        sql.Column("enabled", sql.Boolean, nullable=False),
        sql.Column("description", sql.Text(), nullable=True),
        sql.Column("sp_url", sql.String(256), nullable=False),
        sql.Column(_RELAY_STATE_PREFIX, sql.String(256), nullable=False, server_default=relay_state_prefix_default),
        mysql_engine="InnoDB",
        mysql_charset="utf8",
    )
    sp_table.create(migrate_engine, checkfirst=True)

    idp_table = sql.Table("identity_provider", meta, autoload=True)
    remote_id_table = sql.Table(
        "idp_remote_ids",
        meta,
        sql.Column("idp_id", sql.String(64), sql.ForeignKey("identity_provider.id", ondelete="CASCADE")),
        sql.Column("remote_id", sql.String(255), primary_key=True),
        mysql_engine="InnoDB",
        mysql_charset="utf8",
    )
    remote_id_table.create(migrate_engine, checkfirst=True)
def upgrade(migrate_engine):
    try:
        extension_version = upgrades.get_db_version(extension='federation',
                                                    engine=migrate_engine)
    except Exception:
        extension_version = 0

    # This migration corresponds to federation extension migration 8. Only
    # update if it has not been run.
    if extension_version >= 8:
        return

    # Upgrade operations go here. Don't create your own engine; bind
    # migrate_engine to your metadata
    meta = sql.MetaData()
    meta.bind = migrate_engine

    idp_table = sql.Table('identity_provider',
                          meta,
                          sql.Column('id', sql.String(64), primary_key=True),
                          sql.Column('enabled', sql.Boolean, nullable=False),
                          sql.Column('description', sql.Text(), nullable=True),
                          mysql_engine='InnoDB',
                          mysql_charset='utf8')
    idp_table.create(migrate_engine, checkfirst=True)

    federation_protocol_table = sql.Table(
        'federation_protocol',
        meta,
        sql.Column('id', sql.String(64), primary_key=True),
        sql.Column('idp_id',
                   sql.String(64),
                   sql.ForeignKey('identity_provider.id', ondelete='CASCADE'),
                   primary_key=True),
        sql.Column('mapping_id', sql.String(64), nullable=False),
        mysql_engine='InnoDB',
        mysql_charset='utf8')
    federation_protocol_table.create(migrate_engine, checkfirst=True)

    mapping_table = sql.Table('mapping',
                              meta,
                              sql.Column('id',
                                         sql.String(64),
                                         primary_key=True),
                              sql.Column('rules', sql.Text(), nullable=False),
                              mysql_engine='InnoDB',
                              mysql_charset='utf8')
    mapping_table.create(migrate_engine, checkfirst=True)

    relay_state_prefix_default = CONF.saml.relay_state_prefix
    sp_table = sql.Table('service_provider',
                         meta,
                         sql.Column('auth_url',
                                    sql.String(256),
                                    nullable=False),
                         sql.Column('id', sql.String(64), primary_key=True),
                         sql.Column('enabled', sql.Boolean, nullable=False),
                         sql.Column('description', sql.Text(), nullable=True),
                         sql.Column('sp_url', sql.String(256), nullable=False),
                         sql.Column(_RELAY_STATE_PREFIX,
                                    sql.String(256),
                                    nullable=False,
                                    server_default=relay_state_prefix_default),
                         mysql_engine='InnoDB',
                         mysql_charset='utf8')
    sp_table.create(migrate_engine, checkfirst=True)

    idp_table = sql.Table('identity_provider', meta, autoload=True)
    remote_id_table = sql.Table('idp_remote_ids',
                                meta,
                                sql.Column(
                                    'idp_id', sql.String(64),
                                    sql.ForeignKey('identity_provider.id',
                                                   ondelete='CASCADE')),
                                sql.Column('remote_id',
                                           sql.String(255),
                                           primary_key=True),
                                mysql_engine='InnoDB',
                                mysql_charset='utf8')
    remote_id_table.create(migrate_engine, checkfirst=True)
Exemplo n.º 12
0
 def main():
     assert_not_extension(CONF.command.extension)
     print(upgrades.get_db_version())