Пример #1
0
def run_migrations_online():
    set_mysql_engine()
    try:
        extra_args = {}
        if hasattr(neutron_config.database, 'mysql_enable_ndb'):
            extra_args = {
                mysql_enable_ndb: neutron_config.database.mysql_enable_ndb
            }
        engine = session.create_engine(
            sql_connection=neutron_config.database.connection, **extra_args)
    except NameError:
        # This permits this plugin to work with older Neutron versions
        # that don't support the extended 'create_engine' call syntax
        engine = session.create_engine(neutron_config.database.connection)

    with engine.connect() as connection:
        context.configure(connection=connection,
                          target_metadata=target_metadata,
                          include_object=include_object,
                          version_table=VPP_VERSION_TABLE)

        try:
            with context.begin_transaction():
                context.run_migrations()
        finally:
            connection.close()
            engine.dispose()
Пример #2
0
def run_migrations_online():
    set_mysql_engine()
    try:
        extra_args = {}
        if hasattr(neutron_config.database, 'mysql_enable_ndb'):
            extra_args = {
                mysql_enable_ndb: neutron_config.database.mysql_enable_ndb}
        engine = session.create_engine(
            sql_connection=neutron_config.database.connection,
            **extra_args)
    except NameError:
        # This permits this plugin to work with older Neutron versions
        # that don't support the extended 'create_engine' call syntax
        engine = session.create_engine(neutron_config.database.connection)

    with engine.connect() as connection:
        context.configure(
            connection=connection,
            target_metadata=target_metadata,
            include_object=include_object,
            version_table=VPP_VERSION_TABLE
        )

        try:
            with context.begin_transaction():
                context.run_migrations()
        finally:
            connection.close()
            engine.dispose()
Пример #3
0
def main(argv):
    """Main function.

    :param argv: Argument list
    :type argv: List[str]
    :returns: POSIX exit code
    :rtype: int
    """
    program = os.path.basename(argv[0])
    if len(argv) < 2:
        usage(program)
        return os.EX_USAGE
    elif len(argv) < 3 or argv[2] != 'morph':
        print('DRY-RUN, WILL NOT COMMIT TRANSACTION')

    db_engine = session.create_engine(argv[1])
    db_maker = session.get_maker(db_engine, autocommit=False)
    db_session = db_maker(bind=db_engine)

    to_network_type = 'geneve'
    for network_type in ('gre', 'vxlan'):
        n_morphed = morph_networks(db_session, network_type, to_network_type)
        print('Morphed {} networks of type {} to {}.'.format(
            n_morphed, network_type, to_network_type))

    if len(argv) < 3 or argv[2] != 'morph':
        print('DRY-RUN, WILL NOT COMMIT TRANSACTION')
        return os.EX_USAGE

    db_session.commit()
    db_session.close()
    db_engine.dispose()
    return os.EX_OK
Пример #4
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    set_mysql_engine()
    connection = config.attributes.get('connection')
    new_engine = connection is None
    if new_engine:
        engine = session.create_engine(neutron_config.database.connection)
        connection = engine.connect()
    context.configure(
        connection=connection,
        target_metadata=target_metadata,
        include_object=include_object,
        process_revision_directives=autogen.process_revision_directives
    )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        if new_engine:
            connection.close()
            engine.dispose()
Пример #5
0
    def provisioned_engine(self, base_url, ident):
        """Return a provisioned engine.

        Given the URL of a particular database backend and the string
        name of a particular 'database' within that backend, return
        an Engine instance whose connections will refer directly to the
        named database.

        For hostname-based URLs, this typically involves switching just the
        'database' portion of the URL with the given name and creating
        an engine.

        For URLs that instead deal with DSNs, the rules may be more custom;
        for example, the engine may need to connect to the root URL and
        then emit a command to switch to the named database.

        """

        url = sa_url.make_url(str(base_url))
        url.database = ident
        return session.create_engine(
            url,
            logging_name="%s@%s" % (self.drivername, ident),
            **self.default_engine_kwargs
        )
Пример #6
0
    def provisioned_engine(self, base_url, ident):
        """Return a provisioned engine.

        Given the URL of a particular database backend and the string
        name of a particular 'database' within that backend, return
        an Engine instance whose connections will refer directly to the
        named database.

        For hostname-based URLs, this typically involves switching just the
        'database' portion of the URL with the given name and creating
        an engine.

        For URLs that instead deal with DSNs, the rules may be more custom;
        for example, the engine may need to connect to the root URL and
        then emit a command to switch to the named database.

        """

        url = sa_url.make_url(str(base_url))
        url.database = ident
        return session.create_engine(
            url,
            logging_name="%s@%s" % (self.drivername, ident),
            **self.default_engine_kwargs
        )
Пример #7
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    set_mysql_engine()
    connection = config.attributes.get('connection')
    new_engine = connection is None
    if new_engine:
        engine = session.create_engine(neutron_config.database.connection)
        connection = engine.connect()
    context.configure(
        connection=connection,
        target_metadata=target_metadata,
        include_object=include_object,
        process_revision_directives=autogen.process_revision_directives)

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        if new_engine:
            connection.close()
            engine.dispose()
Пример #8
0
    def __call__(self,
                 connection_url,
                 save_tables=False,
                 tunnel_type=None,
                 vxlan_udp_port=None):
        engine = session.create_engine(connection_url)
        metadata = sa.MetaData()
        check_db_schema_version(engine, metadata)

        if hasattr(self, 'define_ml2_tables'):
            self.define_ml2_tables(metadata)

        # Autoload the ports table to ensure that foreign keys to it and
        # the network table can be created for the new tables.
        sa.Table('ports', metadata, autoload=True, autoload_with=engine)
        metadata.create_all(engine)

        self.migrate_network_segments(engine, metadata)
        if tunnel_type:
            self.migrate_tunnels(engine, tunnel_type, vxlan_udp_port)
        self.migrate_vlan_allocations(engine)
        self.migrate_port_bindings(engine, metadata)

        if hasattr(self, 'drop_old_tables'):
            self.drop_old_tables(engine, save_tables)
Пример #9
0
 def __enter__(self):
     self.new_engine = self.connection is None
     if self.new_engine:
         self.engine = session.create_engine(
             sql_connection=self.sql_connection,
             mysql_enable_ndb=self.mysql_enable_ndb)
         self.connection = self.engine.connect()
     return self.connection
Пример #10
0
 def __init__(self, db_connection, library_path, login, slot_id):
     self.dry_run = False
     self.db_engine = session.create_engine(db_connection)
     self._session_creator = scoping.scoped_session(
         orm.sessionmaker(bind=self.db_engine, autocommit=True))
     self.crypto_plugin = p11_crypto.P11CryptoPlugin(CONF)
     self.plugin_name = utils.generate_fullname_for(self.crypto_plugin)
     self.pkcs11 = self.crypto_plugin.pkcs11
     self.session = self.pkcs11.get_session()
Пример #11
0
    def setUp(self):
        super(DBManageTestCase, self).setUp()
        self.sbehaviors = secret_behaviors.SecretBehaviors(self.client)
        self.cbehaviors = container_behaviors.ContainerBehaviors(self.client)

        db_url = BCONF.sql_connection

        time.sleep(5)
        # Setup session for tests to query DB
        engine = session.create_engine(db_url)
        self.conn = engine.connect()
Пример #12
0
    def setUp(self):
        super(DBManageTestCase, self).setUp()
        self.sbehaviors = secret_behaviors.SecretBehaviors(self.client)
        self.cbehaviors = container_behaviors.ContainerBehaviors(self.client)

        db_url = BCONF.sql_connection

        time.sleep(5)
        # Setup session for tests to query DB
        engine = session.create_engine(db_url)
        self.conn = engine.connect()
Пример #13
0
    def test_mysql_opportunistically(self):
        connect_string = oslo_utils.get_connect_string(self.BACKEND,
            "openstack_citest", user="******",
            passwd="openstack_citest")
        engine = session.create_engine(connect_string)
        config = self._get_alembic_config(connect_string)
        self.engines["mysqlcitest"] = engine
        self.test_databases["mysqlcitest"] = connect_string

        # build a fully populated mysql database with all the tables
        self._reset_databases()
        self._walk_versions(config, engine, False, False)
Пример #14
0
    def test_mysql_opportunistically(self):
        connect_string = oslo_utils.get_connect_string(self.BACKEND,
            "openstack_citest", user="******",
            passwd="openstack_citest")
        engine = session.create_engine(connect_string)
        config = self._get_alembic_config(connect_string)
        self.engines["mysqlcitest"] = engine
        self.test_databases["mysqlcitest"] = connect_string

        # build a fully populated mysql database with all the tables
        self._reset_databases()
        self._walk_versions(config, engine, False, False)
Пример #15
0
def run_migrations_online():
    set_mysql_engine()
    engine = session.create_engine(neutron_config.database.connection)

    connection = engine.connect()
    context.configure(connection=connection, target_metadata=target_metadata, version_table=FWAAS_VERSION_TABLE)
    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
        engine.dispose()
 def __init__(self, db_connection, library_path, login, slot_id):
     self.dry_run = False
     self.db_engine = session.create_engine(db_connection)
     self._session_creator = scoping.scoped_session(
         orm.sessionmaker(
             bind=self.db_engine,
             autocommit=True
         )
     )
     self.crypto_plugin = p11_crypto.P11CryptoPlugin(CONF)
     self.plugin_name = utils.generate_fullname_for(self.crypto_plugin)
     self.pkcs11 = self.crypto_plugin.pkcs11
     self.session = self.pkcs11.get_session()
Пример #17
0
 def __init__(self, conf):
     self.dry_run = False
     self.db_engine = session.create_engine(conf.sql_connection)
     self._session_creator = scoping.scoped_session(
         orm.sessionmaker(bind=self.db_engine, autocommit=True))
     self.crypto_plugin = p11_crypto.P11CryptoPlugin(conf)
     self.pkcs11 = self.crypto_plugin.pkcs11
     self.plugin_name = utils.generate_fullname_for(self.crypto_plugin)
     self.hsm_session = self.pkcs11.get_session()
     self.new_mkek_label = self.crypto_plugin.mkek_label
     self.new_hmac_label = self.crypto_plugin.hmac_label
     self.new_mkek = self.crypto_plugin._get_master_key(self.new_mkek_label)
     self.new_mkhk = self.crypto_plugin._get_master_key(self.new_hmac_label)
Пример #18
0
def run_migrations_online():
    set_mysql_engine()
    engine = session.create_engine(neutron_config.database.connection)

    connection = engine.connect()
    context.configure(connection=connection,
                      target_metadata=target_metadata,
                      version_table=FWAAS_VERSION_TABLE)
    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
        engine.dispose()
Пример #19
0
    def test_postgresql_opportunistically(self):
        # add this to the global lists to make reset work with it, it's removed
        # automatically in tearDown so no need to clean it up here.
        connect_string = oslo_utils.get_connect_string(self.BACKEND,
                                                       "openstack_citest",
                                                       "openstack_citest",
                                                       "openstack_citest")
        engine = session.create_engine(connect_string)
        config = self._get_alembic_config(connect_string)
        self.engines["postgresqlcitest"] = engine
        self.test_databases["postgresqlcitest"] = connect_string

        # build a fully populated postgresql database with all the tables
        self._reset_databases()
        self._walk_versions(config, engine, False, False)
Пример #20
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.
    """
    engine = session.create_engine(get_sqlalchemy_url())
    connection = engine.connect()
    context.configure(connection=connection, target_metadata=target_metadata)

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
Пример #21
0
    def test_postgresql_opportunistically(self):
        # add this to the global lists to make reset work with it, it's removed
        # automatically in tearDown so no need to clean it up here.
        connect_string = oslo_utils.get_connect_string(self.BACKEND,
                                                       "openstack_citest",
                                                       "openstack_citest",
                                                       "openstack_citest")
        engine = session.create_engine(connect_string)
        config = self._get_alembic_config(connect_string)
        self.engines["postgresqlcitest"] = engine
        self.test_databases["postgresqlcitest"] = connect_string

        # build a fully populated postgresql database with all the tables
        self._reset_databases()
        self._walk_versions(config, engine, False, False)
Пример #22
0
    def setUp(self):
        super(MySQLModeTestCase, self).setUp()

        self.engine = session.create_engine(self.engine.url,
                                            mysql_sql_mode=self.mysql_mode)
        self.connection = self.engine.connect()

        meta = MetaData()
        meta.bind = self.engine
        self.test_table = Table(_TABLE_NAME + "mode", meta,
                                Column('id', Integer, primary_key=True),
                                Column('bar', String(255)))
        self.test_table.create()

        self.addCleanup(self.test_table.drop)
        self.addCleanup(self.connection.close)
Пример #23
0
    def setUp(self):
        super(MySQLModeTestCase, self).setUp()
        mode_engine = session.create_engine(
            self.engine.url,
            mysql_sql_mode=self.mysql_mode)
        self.connection = mode_engine.connect()

        meta = MetaData()
        self.test_table = Table(_TABLE_NAME + "mode", meta,
                                Column('id', Integer, primary_key=True),
                                Column('bar', String(255)))
        self.test_table.create(self.connection)

        def cleanup():
            self.test_table.drop(self.connection)
            self.connection.close()
            mode_engine.dispose()
        self.addCleanup(cleanup)
Пример #24
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    url = CONF.pdns_database.connection
    engine = session.create_engine(url)
    connection = engine.connect()

    context.configure(
        connection=connection,
        target_metadata=target_metadata
    )

    with context.begin_transaction():
        context.run_migrations()
Пример #25
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    engine = session.create_engine(neutron_config.database.connection)
    connection = engine.connect()
    context.configure(connection=connection,
                      target_metadata=None,
                      version_table=VERSION_TABLE)

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
        engine.dispose()
Пример #26
0
def _is_backend_avail(backend,
                      user="******",
                      passwd="openstack_citest",
                      database="openstack_citest"):
        # is_backend_avail will be soon deprecated from oslo_db
        # thats why its added here
        try:
            connect_uri = oslo_utils.get_connect_string(backend, user=user,
                                                        passwd=passwd,
                                                        database=database)
            engine = session.create_engine(connect_uri)
            connection = engine.connect()
        except Exception:
            # intentionally catch all to handle exceptions even if we don't
            # have any backend code loaded.
            return False
        else:
            connection.close()
            engine.dispose()
            return True
Пример #27
0
def _is_backend_avail(backend,
                      user="******",
                      passwd="openstack_citest",
                      database="openstack_citest"):
        # is_backend_avail will be soon deprecated from oslo_db
        # thats why its added here
        try:
            connect_uri = oslo_utils.get_connect_string(backend, user=user,
                                                        passwd=passwd,
                                                        database=database)
            engine = session.create_engine(connect_uri)
            connection = engine.connect()
        except Exception:
            # intentionally catch all to handle exceptions even if we don't
            # have any backend code loaded.
            return False
        else:
            connection.close()
            engine.dispose()
            return True
Пример #28
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    set_mysql_engine()
    engine = session.create_engine(neutron_config.database.connection)

    connection = engine.connect()
    context.configure(connection=connection,
                      target_metadata=target_metadata,
                      include_object=include_object)

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
        engine.dispose()
Пример #29
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    engine = session.create_engine(neutron_config.database.connection)
    connection = engine.connect()
    context.configure(
        connection=connection,
        target_metadata=None,
        version_table=VERSION_TABLE
    )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
        engine.dispose()
Пример #30
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    set_mysql_engine()
    engine = session.create_engine(congress_config.database.connection)

    connection = engine.connect()
    context.configure(
        connection=connection,
        target_metadata=target_metadata
    )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
Пример #31
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    set_mysql_engine()
    engine = session.create_engine(vnfsvc_config.database.connection)

    connection = engine.connect()
    context.configure(
        connection=connection,
        target_metadata=target_metadata
    )

    try:
        with context.begin_transaction():
            context.run_migrations(active_plugins=active_plugins,
                                   options=build_options())
    finally:
        connection.close()
Пример #32
0
    def __call__(self, connection_url, save_tables=False, tunnel_type=None,
                 vxlan_udp_port=None):
        engine = session.create_engine(connection_url)
        metadata = sa.MetaData()
        check_db_schema_version(engine, metadata)

        if hasattr(self, 'define_ml2_tables'):
            self.define_ml2_tables(metadata)

        # Autoload the ports table to ensure that foreign keys to it and
        # the network table can be created for the new tables.
        sa.Table('ports', metadata, autoload=True, autoload_with=engine)
        metadata.create_all(engine)

        self.migrate_network_segments(engine, metadata)
        if tunnel_type:
            self.migrate_tunnels(engine, tunnel_type, vxlan_udp_port)
        self.migrate_vlan_allocations(engine)
        self.migrate_port_bindings(engine, metadata)

        if hasattr(self, 'drop_old_tables'):
            self.drop_old_tables(engine, save_tables)
Пример #33
0
 def __init__(self, conf):
     self.dry_run = False
     self.db_engine = session.create_engine(conf.sql_connection)
     self._session_creator = scoping.scoped_session(
         orm.sessionmaker(
             bind=self.db_engine,
             autocommit=True
         )
     )
     self.crypto_plugin = p11_crypto.P11CryptoPlugin(conf)
     self.pkcs11 = self.crypto_plugin.pkcs11
     self.plugin_name = utils.generate_fullname_for(self.crypto_plugin)
     self.hsm_session = self.pkcs11.get_session()
     self.new_mkek_label = self.crypto_plugin.mkek_label
     self.new_hmac_label = self.crypto_plugin.hmac_label
     self.new_mkek_type = self.crypto_plugin.mkek_key_type
     self.new_hmac_type = self.crypto_plugin.hmac_key_type
     self.new_mkek = self.crypto_plugin._get_master_key(
         self.new_mkek_type,
         self.new_mkek_label)
     self.new_mkhk = self.crypto_plugin._get_master_key(
         self.new_hmac_type,
         self.new_hmac_label)
Пример #34
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    set_mysql_engine()
    connection = config.attributes.get('connection')
    new_engine = connection is None
    if new_engine:
        engine = session.create_engine(neutron_config.database.connection)
        connection = engine.connect()
    context.configure(connection=connection,
                      target_metadata=target_metadata,
                      version_table='netforce_version')

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        if new_engine:
            connection.close()
            engine.dispose()
Пример #35
0
 def _fixture(self, sql_mode):
     return session.create_engine(self.engine.url, mysql_sql_mode=sql_mode)
Пример #36
0
 def _setUp(self):
     self._engine = session.create_engine('sqlite:///:memory:')
     self.Session = sa.orm.sessionmaker(bind=self._engine)
     self.external_id = 'EXTERNAL_ID'
     models.BASE.metadata.create_all(self._engine)
     self._load_sample_data()
Пример #37
0
 def _setUp(self):
     self._engine = session.create_engine('sqlite:///:memory:')
     self.Session = sa.orm.sessionmaker(bind=self._engine)
     self.external_id = 'EXTERNAL_ID'
     models.BASE.metadata.create_all(self._engine)
     self._load_sample_data()
Пример #38
0
 def __enter__(self):
     self.new_engine = self.connection is None
     if self.new_engine:
         self.engine = session.create_engine(self.connection_url)
         self.connection = self.engine.connect()
     return self.connection
Пример #39
0
 def __enter__(self):
     self.new_engine = self.connection is None
     if self.new_engine:
         self.engine = session.create_engine(self.connection_url)
         self.connection = self.engine.connect()
     return self.connection
Пример #40
0
 def _fixture(self, **kw):
     return session.create_engine("sqlite://", **kw)
Пример #41
0
 def _fixture(self, **kw):
     return session.create_engine("sqlite://", **kw)
Пример #42
0
 def provisioned_engine(self, base_url, ident):
     return session.create_engine(
         self._provisioned_database_url(base_url, ident))
Пример #43
0
 def provisioned_engine(self, base_url, ident):
     return session.create_engine(
         self._provisioned_database_url(base_url, ident))
Пример #44
0
 def _fixture(self, sql_mode):
     return session.create_engine(self.engine.url, mysql_sql_mode=sql_mode)
Пример #45
0
 def version(self):
     engine = db_session.create_engine(self.db_url)
     with engine.connect() as conn:
         context = alembic_migration.MigrationContext.configure(conn)
         return context.get_current_revision()