コード例 #1
0
ファイル: env.py プロジェクト: pavera/placement
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.

    """
    try:
        connectable = placement_db.get_placement_engine()
    except db_exc.CantStartEngineError:
        # We are being called from a context where the database hasn't been
        # configured so we need to set up Config and config the database.
        # This is usually the alembic command line.
        config = cfg.ConfigOpts()
        conf.register_opts(config)
        config([], project="placement", default_config_files=None)
        placement_db.configure(config)
        connectable = placement_db.get_placement_engine()

    with connectable.connect() as connection:
        context.configure(connection=connection,
                          target_metadata=target_metadata)

        with context.begin_transaction():
            context.run_migrations()
コード例 #2
0
def init_application():
    # initialize the config system
    conffiles = _get_config_files()

    config = cfg.ConfigOpts()
    conf.register_opts(config)

    # This will raise cfg.RequiredOptError when a required option is not set
    # (notably the database connection string). We want this to be a hard fail
    # that prevents the application from starting. The error will show up in
    # the wsgi server's logs.
    _parse_args(config, [], default_config_files=conffiles)
    # initialize the logging system
    setup_logging(config)

    # configure database
    db_api.configure(config)

    # dump conf at debug if log_options
    if config.log_options:
        config.log_opt_values(logging.getLogger(__name__), logging.DEBUG)

    setup_profiler(config)

    # build and return our WSGI app
    return deploy.loadapp(config)
コード例 #3
0
 def __init__(self, conf_fixture, set_config=False):
     """Create a database fixture."""
     super(Database, self).__init__()
     if set_config:
         try:
             conf_fixture.register_opt(
                 cfg.StrOpt('connection'), group='placement_database')
         except cfg.DuplicateOptError:
             # already registered
             pass
         conf_fixture.config(connection='sqlite://',
                             group='placement_database')
     self.conf_fixture = conf_fixture
     self.get_engine = placement_db.get_placement_engine
     placement_db.configure(self.conf_fixture.conf)
コード例 #4
0
    def __init__(self, database='placement', connection=None):
        """Create a database fixture.

        :param database: The type of database: 'placement'
        :param connection: The connection string to use
        """
        super(Database, self).__init__()
        # NOTE(pkholkin): oslo_db.enginefacade is configured in tests the same
        # way as it is done for any other service that uses db
        global SESSION_CONFIGURED
        if not SESSION_CONFIGURED:
            placement_db.configure(CONF)
            SESSION_CONFIGURED = True
        self.database = database
        self.get_engine = placement_db.get_placement_engine
コード例 #5
0
ファイル: status.py プロジェクト: knodir/placement
def main():
    # Set up the configuration to configure the database.
    config = cfg.ConfigOpts()
    conf.register_opts(config)
    # Register cli opts before parsing args.
    upgradecheck.register_cli_options(config, Checks(config))
    # A slice of sys.argv is provided to pass the command line
    # arguments for processing, without the name of the calling
    # script ('placement-status'). If we were using
    # upgradecheck.main() directly, it would do it for us, but
    # we do not because of the need to configure the database
    # first.
    config(args=sys.argv[1:], project='placement')
    db_api.configure(config)
    return upgradecheck.run(config)
コード例 #6
0
ファイル: wsgi.py プロジェクト: Yikun/placement
def init_application():
    # initialize the config system
    conffile = _get_config_file()
    _parse_args([], default_config_files=[conffile])
    db_api.configure(conf.CONF)

    # initialize the logging system
    setup_logging(conf.CONF)

    # dump conf at debug if log_options
    if conf.CONF.log_options:
        conf.CONF.log_opt_values(logging.getLogger(__name__), logging.DEBUG)

    # build and return our WSGI app
    return deploy.loadapp(conf.CONF)
コード例 #7
0
ファイル: test_db_api.py プロジェクト: takanattie/placement
    def test_can_call_configure_twice(self, configure_mock):
        """This test asserts that configure can be safely called twice
        which may happen if placement is run under mod_wsgi and the
        wsgi application is reloaded.
        """
        db_api.configure(self.conf_fixture.conf)
        configure_mock.assert_called_once()

        # a second invocation of configure on a transaction context
        # should raise an exception so mock this and assert its not
        # called on a second invocation of db_api's configure function
        configure_mock.side_effect = TypeError()

        db_api.configure(self.conf_fixture.conf)
        # Note we have not reset the mock so it should
        # have been called once from the first invocation of
        # db_api.configure and the second invocation should not
        # have called it again
        configure_mock.assert_called_once()
コード例 #8
0
ファイル: manage.py プロジェクト: knodir/placement
def main():
    config = cfg.ConfigOpts()
    conf.register_opts(config)
    command_opts = setup_commands(config)
    config.register_cli_opts(command_opts)
    config(sys.argv[1:],
           project='placement',
           version=version_info.version_string(),
           default_config_files=None)
    db_api.configure(config)

    try:
        func = config.command.func
        return_code = func()
        # If return_code ends up None we assume 0.
        sys.exit(return_code or 0)
    except cfg.NoSuchOptError:
        config.print_help()
        sys.exit(1)
コード例 #9
0
ファイル: wsgi.py プロジェクト: cdent/placement2
def init_application():
    # initialize the config system
    conffile = _get_config_file()
    _parse_args([], default_config_files=[conffile])
    db_api.configure(conf.CONF)

    # initialize the logging system
    setup_logging(conf.CONF)

    # dump conf at debug (log_options option comes from oslo.service)
    # FIXME(mriedem): This is gross but we don't have a public hook into
    # oslo.service to register these options, so we are doing it manually for
    # now; remove this when we have a hook method into oslo.service.
    conf.CONF.register_opts(service_opts.service_opts)
    if conf.CONF.log_options:
        conf.CONF.log_opt_values(
            logging.getLogger(__name__),
            logging.DEBUG)

    # build and return our WSGI app
    return deploy.loadapp(conf.CONF)