def setUp(self):
        self.consumed = []
        self.engine = sqlalchemy.create_engine("sqlite:///:memory:")
        init_buildapi_model(self.engine)

        hostname = os.environ.get('AMQP_HOSTNAME', 'localhost')
        userid = os.environ.get('AMQP_USERID', 'buildapi-test')
        password = os.environ.get('AMQP_PASSWORD', 'buildapi-test')
        self.config = {
            'mq.heartbeat_interval':
            '5',
            'mq.kombu_url':
            'amqp://%s:%s@%s//buildapi-test' % (userid, password, hostname),
            'mq.exchange':
            'buildapi-test',
            'mq.queue.web':
            'buildapi-test-q1',
            'mq.queue.agent':
            'buildapi-test-q2',
        }

        # this is the first place we try to connect, so if we get a socket
        # error here, then the rabbitmq server isn't present, so skip the test.
        try:
            self._cleanup()
        except socket.error:
            raise SkipTest("could not reach rabbitmq server on %s" % hostname)
Beispiel #2
0
    def setUp(self):
        self.engine = sqlalchemy.create_engine("sqlite:///:memory:")
        sql = open(os.path.join(os.path.dirname(os.path.dirname(__file__)), "state.sql")).read().split(";")
        for line in sql:
            line = line.strip()
            self.engine.execute(line)
        init_scheduler_model(self.engine)
        init_buildapi_model(self.engine)

        self.engine.execute('delete from jobrequests')

        # create a job request publisher that doesn't actually send anything
        config = {
            'mq.heartbeat_interval': '5',
            'mq.kombu_url': 'memory://',
            'mq.exchange': 'buildapi-test',
            'mq.queue.web': 'buildapi-test-q1',
            'mq.queue.agent': 'buildapi-test-q2',
        }
        self.g.mq = mq.LoggingJobRequestPublisher(self.engine, config)
        self.g.mq.send = mock.Mock()
Beispiel #3
0
    def setUp(self):
        self.consumed = []
        self.engine = sqlalchemy.create_engine("sqlite:///:memory:")
        init_buildapi_model(self.engine)

        hostname = os.environ.get('AMQP_HOSTNAME', 'localhost')
        userid = os.environ.get('AMQP_USERID', 'buildapi-test')
        password = os.environ.get('AMQP_PASSWORD', 'buildapi-test')
        self.config = {
            'mq.heartbeat_interval': '5',
            'mq.kombu_url': 'amqp://%s:%s@%s//buildapi-test' % (userid, password, hostname),
            'mq.exchange': 'buildapi-test',
            'mq.queue.web': 'buildapi-test-q1',
            'mq.queue.agent': 'buildapi-test-q2',
        }

        # this is the first place we try to connect, so if we get a socket
        # error here, then the rabbitmq server isn't present, so skip the test.
        try:
            self._cleanup()
        except socket.error:
            raise SkipTest("could not reach rabbitmq server on %s" % hostname)
Beispiel #4
0
def load_environment(global_conf, app_conf):
    """Configure the Pylons environment via the ``pylons.config``
    object
    """
    config = PylonsConfig()

    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, 'public'),
                 templates=[os.path.join(root, 'templates')])

    # Initialize config with the basic options
    config.init_app(global_conf, app_conf, package='buildapi', paths=paths)

    config['routes.map'] = make_map(config)
    config['pylons.app_globals'] = app_globals.Globals(config)
    config['pylons.h'] = buildapi.lib.helpers
    config['pylons.tmpl_context_attach_args'] = True

    # Setup cache object as early as possible
    import pylons
    pylons.cache._push_object(config['pylons.app_globals'].cache)

    # Create the Mako TemplateLookup, with the default auto-escaping
    config['pylons.app_globals'].mako_lookup = TemplateLookup(
        directories=paths['templates'],
        error_handler=handle_mako_error,
        module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
        input_encoding='utf-8',
        default_filters=['escape'],
        imports=['from webhelpers.html import escape'])

    # Setup the SQLAlchemy database engine
    scheduler_engine = engine_from_config(config, 'sqlalchemy.scheduler_db.')
    setup_engine(scheduler_engine)
    init_scheduler_model(scheduler_engine)

    status_engine = engine_from_config(config, 'sqlalchemy.status_db.')
    setup_engine(status_engine)
    init_status_model(status_engine)

    buildapi_engine = engine_from_config(config, 'sqlalchemy.buildapi_db.')
    setup_engine(buildapi_engine)
    init_buildapi_model(buildapi_engine)

    # CONFIGURATION OPTIONS HERE (note: all config options will override
    # any Pylons config options)

    # Create our AMQP message publisher
    if 'mq.kombu_url' in config and 'testing' not in config:
        config['pylons.app_globals'].mq = LoggingJobRequestPublisher(
            buildapi_engine, config)

        # And our consumer
        config[
            'pylons.app_globals'].mq_consumer = LoggingJobRequestDoneConsumer(
                buildapi_engine, config)
        thread.start_new_thread(config['pylons.app_globals'].mq_consumer.run,
                                ())
    else:
        config['pylons.app_globals'].mq = None

    return config
def load_environment(global_conf, app_conf):
    """Configure the Pylons environment via the ``pylons.config``
    object
    """
    config = PylonsConfig()

    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    paths = dict(
        root=root,
        controllers=os.path.join(root, "controllers"),
        static_files=os.path.join(root, "public"),
        templates=[os.path.join(root, "templates")],
    )

    # Initialize config with the basic options
    config.init_app(global_conf, app_conf, package="buildapi", paths=paths)

    config["routes.map"] = make_map(config)
    config["pylons.app_globals"] = app_globals.Globals(config)
    config["pylons.h"] = buildapi.lib.helpers
    config["pylons.tmpl_context_attach_args"] = True

    # Setup cache object as early as possible
    import pylons

    pylons.cache._push_object(config["pylons.app_globals"].cache)

    # Create the Mako TemplateLookup, with the default auto-escaping
    config["pylons.app_globals"].mako_lookup = TemplateLookup(
        directories=paths["templates"],
        error_handler=handle_mako_error,
        module_directory=os.path.join(app_conf["cache_dir"], "templates"),
        input_encoding="utf-8",
        default_filters=["escape"],
        imports=["from webhelpers.html import escape"],
    )

    # Setup the SQLAlchemy database engine
    scheduler_engine = engine_from_config(config, "sqlalchemy.scheduler_db.")
    setup_engine(scheduler_engine)
    init_scheduler_model(scheduler_engine)

    status_engine = engine_from_config(config, "sqlalchemy.status_db.")
    setup_engine(status_engine)
    init_status_model(status_engine)

    buildapi_engine = engine_from_config(config, "sqlalchemy.buildapi_db.")
    setup_engine(buildapi_engine)
    init_buildapi_model(buildapi_engine)

    # CONFIGURATION OPTIONS HERE (note: all config options will override
    # any Pylons config options)

    # Create our AMQP message publisher
    if "mq.kombu_url" in config and "testing" not in config:
        config["pylons.app_globals"].mq = LoggingJobRequestPublisher(buildapi_engine, config)

        # And our consumer
        config["pylons.app_globals"].mq_consumer = LoggingJobRequestDoneConsumer(buildapi_engine, config)
        thread.start_new_thread(config["pylons.app_globals"].mq_consumer.run, ())
    else:
        config["pylons.app_globals"].mq = None

    return config