def test_get_engine_no_such_engine():
    conf = mox.Mox().CreateMockAnything()
    conf.database.connection = 'no-such-engine://localhost'
    try:
        storage.get_engine(conf)
    except RuntimeError as err:
        assert 'no-such-engine' in unicode(err)
Ejemplo n.º 2
0
 def test_get_engine_no_such_engine(self):
     conf = mock.Mock()
     conf.database.connection = 'no-such-engine://localhost'
     try:
         storage.get_engine(conf)
     except RuntimeError as err:
         self.assertIn('no-such-engine', unicode(err))
Ejemplo n.º 3
0
def test_get_engine_no_such_engine():
    conf = mox.Mox().CreateMockAnything()
    conf.metering_storage_engine = 'no-such-engine'
    try:
        storage.get_engine(conf)
    except RuntimeError as err:
        assert 'no-such-engine' in unicode(err)
Ejemplo n.º 4
0
def test_get_engine_no_such_engine():
    conf = mox.Mox().CreateMockAnything()
    conf.database_connection = 'no-such-engine://localhost'
    try:
        storage.get_engine(conf)
    except RuntimeError as err:
        assert 'no-such-engine' in unicode(err)
Ejemplo n.º 5
0
    def start(self):
        super(CollectorService, self).start()

        storage.register_opts(cfg.CONF)
        self.storage_engine = storage.get_engine(cfg.CONF)
        self.storage_conn = self.storage_engine.get_connection(cfg.CONF)

        self.ext_manager = extension_manager.ActivatedExtensionManager(
            namespace=self.COLLECTOR_NAMESPACE,
            disabled_names=cfg.CONF.disabled_notification_listeners,
            )

        if not list(self.ext_manager):
            LOG.warning('Failed to load any notification handlers for %s',
                        self.COLLECTOR_NAMESPACE)

        self.ext_manager.map(self._setup_subscription)

        # Set ourselves up as a separate worker for the metering data,
        # since the default for service is to use create_consumer().
        self.conn.create_worker(
            cfg.CONF.metering_topic,
            rpc_dispatcher.RpcDispatcher([self]),
            'ceilometer.collector.' + cfg.CONF.metering_topic,
            )
Ejemplo n.º 6
0
    def init_host(self):
        # Use the nova configuration flags to get
        # a connection to the RPC mechanism nova
        # is using.
        self.connection = nova_rpc.create_connection()

        storage.register_opts(cfg.CONF)
        self.storage_engine = storage.get_engine(cfg.CONF)
        self.storage_conn = self.storage_engine.get_connection(cfg.CONF)

        self.compute_handler = dispatcher.NotificationDispatcher(
            COMPUTE_COLLECTOR_NAMESPACE,
            self._publish_counter,
            )
        # FIXME(dhellmann): Should be using create_worker(), except
        # that notification messages do not conform to the RPC
        # invocation protocol (they do not include a "method"
        # parameter).
        self.connection.declare_topic_consumer(
            topic='%s.info' % flags.FLAGS.notification_topics[0],
            callback=self.compute_handler.notify)

        # Set ourselves up as a separate worker for the metering data,
        # since the default for manager is to use create_consumer().
        self.connection.create_worker(
            cfg.CONF.metering_topic,
            rpc_dispatcher.RpcDispatcher([self]),
            'ceilometer.collector.' + cfg.CONF.metering_topic,
            )

        self.connection.consume_in_thread()
Ejemplo n.º 7
0
def setup_app(pecan_config=None, extra_hooks=None):
    storage_engine = storage.get_engine(cfg.CONF)
    # FIXME: Replace DBHook with a hooks.TransactionHook
    app_hooks = [hooks.ConfigHook(),
                 hooks.DBHook(
                     storage_engine,
                     storage_engine.get_connection(cfg.CONF),
                 ),
                 hooks.PipelineHook(),
                 hooks.TranslationHook()]
    if extra_hooks:
        app_hooks.extend(extra_hooks)

    if not pecan_config:
        pecan_config = get_pecan_config()

    pecan.configuration.set_config(dict(pecan_config), overwrite=True)

    app = pecan.make_app(
        pecan_config.app.root,
        static_root=pecan_config.app.static_root,
        template_path=pecan_config.app.template_path,
        debug=CONF.debug,
        force_canonical=getattr(pecan_config.app, 'force_canonical', True),
        hooks=app_hooks,
        wrap_app=middleware.ParsableErrorMiddleware,
        guess_content_type_from_ext=False
    )

    if pecan_config.app.enable_acl:
        return acl.install(app, cfg.CONF)

    return app
Ejemplo n.º 8
0
    def init_host(self):
        # Use the nova configuration flags to get
        # a connection to the RPC mechanism nova
        # is using.
        self.connection = rpc.create_connection()

        storage.register_opts(cfg.CONF)
        self.storage_engine = storage.get_engine(cfg.CONF)
        self.storage_conn = self.storage_engine.get_connection(cfg.CONF)

        self.handler = dispatcher.NotificationDispatcher(
            COLLECTOR_NAMESPACE,
            self._publish_counter,
        )
        # FIXME(dhellmann): Should be using create_worker(), except
        # that notification messages do not conform to the RPC
        # invocation protocol (they do not include a "method"
        # parameter).
        for topic in self.handler.topics:
            self.connection.declare_topic_consumer(
                topic=topic,
                queue_name="ceilometer.notifications",
                callback=functools.partial(self.handler.notify, topic))

        # Set ourselves up as a separate worker for the metering data,
        # since the default for manager is to use create_consumer().
        self.connection.create_worker(
            cfg.CONF.metering_topic,
            rpc_dispatcher.RpcDispatcher([self]),
            'ceilometer.collector.' + cfg.CONF.metering_topic,
        )

        self.connection.consume_in_thread()
Ejemplo n.º 9
0
def setup_app(pecan_config=None, extra_hooks=None):
    storage_engine = storage.get_engine(cfg.CONF)
    # FIXME: Replace DBHook with a hooks.TransactionHook
    app_hooks = [
        hooks.ConfigHook(),
        hooks.DBHook(
            storage_engine,
            storage_engine.get_connection(cfg.CONF),
        ),
        hooks.PipelineHook(),
        hooks.TranslationHook()
    ]
    if extra_hooks:
        app_hooks.extend(extra_hooks)

    if not pecan_config:
        pecan_config = get_pecan_config()

    pecan.configuration.set_config(dict(pecan_config), overwrite=True)

    app = pecan.make_app(
        pecan_config.app.root,
        static_root=pecan_config.app.static_root,
        template_path=pecan_config.app.template_path,
        debug=CONF.debug,
        force_canonical=getattr(pecan_config.app, 'force_canonical', True),
        hooks=app_hooks,
        wrap_app=middleware.ParsableErrorMiddleware,
    )

    if pecan_config.app.enable_acl:
        return acl.install(app, cfg.CONF)

    return app
Ejemplo n.º 10
0
    def init_host(self):
        # Use the nova configuration flags to get
        # a connection to the RPC mechanism nova
        # is using.
        self.connection = rpc.create_connection()

        storage.register_opts(cfg.CONF)
        self.storage_engine = storage.get_engine(cfg.CONF)
        self.storage_conn = self.storage_engine.get_connection(cfg.CONF)

        self.handlers = self._load_plugins(self.COLLECTOR_NAMESPACE)

        if not self.handlers:
            LOG.warning('Failed to load any notification handlers for %s',
                        self.plugin_namespace)

        # FIXME(dhellmann): Should be using create_worker(), except
        # that notification messages do not conform to the RPC
        # invocation protocol (they do not include a "method"
        # parameter).
        # FIXME(dhellmann): Break this out into its own method
        # so we can test the subscription logic.
        for handler in self.handlers:
            LOG.debug('Event types: %r', handler.get_event_types())
            for exchange_topic in handler.get_exchange_topics(cfg.CONF):
                for topic in exchange_topic.topics:
                    self.connection.declare_topic_consumer(
                        queue_name="ceilometer.notifications",
                        topic=topic,
                        exchange_name=exchange_topic.exchange,
                        callback=self.process_notification,
                        )

        # Set ourselves up as a separate worker for the metering data,
        # since the default for manager is to use create_consumer().
        self.connection.create_worker(
            cfg.CONF.metering_topic,
            rpc_dispatcher.RpcDispatcher([self]),
            'ceilometer.collector.' + cfg.CONF.metering_topic,
            )

        self.connection.consume_in_thread()
Ejemplo n.º 11
0
 def init_host(self):
     storage.register_opts(CONF)
     self.storage_engine = storage.get_engine(CONF)
     self.storage_conn = self.storage_engine.get_connection(CONF)
     self.price_list = price.PriceList() 
     self.items = CONF.supported_items
     self.db_api = db.get_api()
     self.db_api.configure_db()
     self.price_counter = price.PriceCounter(self.db_api)
     # Create scoped token for admin.
     unscoped_token = nova_client.token_create(CONF.admin_user,
                                               CONF.admin_password)
     tenants = nova_client.tenant_list_for_token(unscoped_token.id)
     token = nova_client.token_create(CONF.admin_user,
                                      CONF.admin_password,
                                      tenants[0].id)
     self.cred = {"username": CONF.admin_user,
                  "password": CONF.admin_password,
                  "tenant_id": tenants[0].id,
                  "token": token}
     return
Ejemplo n.º 12
0
 def init_host(self):
     storage.register_opts(CONF)
     self.storage_engine = storage.get_engine(CONF)
     self.storage_conn = self.storage_engine.get_connection(CONF)
     self.price_list = price.PriceList()
     self.items = CONF.supported_items
     self.db_api = db.get_api()
     self.db_api.configure_db()
     self.price_counter = price.PriceCounter(self.db_api)
     # Create scoped token for admin.
     unscoped_token = nova_client.token_create(CONF.admin_user,
                                               CONF.admin_password)
     tenants = nova_client.tenant_list_for_token(unscoped_token.id)
     token = nova_client.token_create(CONF.admin_user, CONF.admin_password,
                                      tenants[0].id)
     self.cred = {
         "username": CONF.admin_user,
         "password": CONF.admin_password,
         "tenant_id": tenants[0].id,
         "token": token
     }
     return
Ejemplo n.º 13
0
def attach_config():
    flask.request.cfg = cfg.CONF
    storage_engine = storage.get_engine(cfg.CONF)
    flask.request.storage_engine = storage_engine
    flask.request.storage_conn = storage_engine.get_connection(cfg.CONF)
Ejemplo n.º 14
0
 def before(self, state):
     storage_engine = storage.get_engine(state.request.cfg)
     state.request.storage_engine = storage_engine
     state.request.storage_conn = storage_engine.get_connection(
         state.request.cfg)
Ejemplo n.º 15
0
 def test_get_engine(self):
     conf = mox.Mox().CreateMockAnything()
     conf.database = mox.Mox().CreateMockAnything()
     conf.database.connection = 'log://localhost'
     engine = storage.get_engine(conf)
     self.assertIsInstance(engine, impl_log.LogStorage)
Ejemplo n.º 16
0
 def attach_storage():
     storage_engine = storage.get_engine(conf)
     flask.request.storage_engine = storage_engine
     flask.request.storage_conn = \
         storage_engine.get_connection(conf)
Ejemplo n.º 17
0
def get_storage_connection(conf):
    storage.register_opts(conf)
    storage_engine = storage.get_engine(conf)
    return storage_engine.get_connection(conf)
Ejemplo n.º 18
0
    def start(self):
        super(CollectorService, self).start()

        storage.register_opts(cfg.CONF)
        self.storage_engine = storage.get_engine(cfg.CONF)
        self.storage_conn = self.storage_engine.get_connection(cfg.CONF)
Ejemplo n.º 19
0
 def attach_storage():
     storage_engine = storage.get_engine(conf)
     flask.request.storage_engine = storage_engine
     flask.request.storage_conn = \
         storage_engine.get_connection(conf)
Ejemplo n.º 20
0
def get_storage_connection(conf):
    storage.register_opts(conf)
    storage_engine = storage.get_engine(conf)
    return storage_engine.get_connection(conf)
Ejemplo n.º 21
0
 def test_get_engine(self):
     conf = mock.Mock()
     conf.database.connection = 'log://localhost'
     engine = storage.get_engine(conf)
     self.assertIsInstance(engine, impl_log.LogStorage)
Ejemplo n.º 22
0
    def start(self):
        super(CollectorService, self).start()

        storage.register_opts(cfg.CONF)
        self.storage_engine = storage.get_engine(cfg.CONF)
        self.storage_conn = self.storage_engine.get_connection(cfg.CONF)
Ejemplo n.º 23
0
 def test_get_engine(self):
     conf = mox.Mox().CreateMockAnything()
     conf.database = mox.Mox().CreateMockAnything()
     conf.database.connection = 'log://localhost'
     engine = storage.get_engine(conf)
     self.assertIsInstance(engine, impl_log.LogStorage)
Ejemplo n.º 24
0
 def before(self, state):
     storage_engine = storage.get_engine(state.request.cfg)
     state.request.storage_engine = storage_engine
     state.request.storage_conn = storage_engine.get_connection(
         state.request.cfg)
Ejemplo n.º 25
0
def attach_config():
    flask.request.cfg = cfg.CONF
    storage_engine = storage.get_engine(cfg.CONF)
    flask.request.storage_engine = storage_engine
    flask.request.storage_conn = storage_engine.get_connection(cfg.CONF)
Ejemplo n.º 26
0
def test_get_engine():
    conf = mox.Mox().CreateMockAnything()
    conf.metering_storage_engine = 'log'
    engine = storage.get_engine(conf)
    assert isinstance(engine, impl_log.LogStorage)