Exemplo n.º 1
0
    def test_wsgi_middleware_enable_via_python(self, mock_profiler_init):
        request = mock.MagicMock()
        request.get_response.return_value = "yeah!"
        request.url = "someurl"
        request.host_url = "someurl"
        request.path = "path"
        request.query_string = "query"
        request.method = "method"
        request.scheme = "scheme"
        hmac_key = "super_secret_key2"

        pack = utils.signed_pack({"base_id": "1", "parent_id": "2"}, hmac_key)
        request.headers = {
            "a": "1",
            "b": "2",
            "X-Trace-Info": pack[0],
            "X-Trace-HMAC": pack[1]
        }

        web.enable("super_secret_key1,super_secret_key2")
        middleware = web.WsgiMiddleware("app", enabled=True)
        self.assertEqual("yeah!", middleware(request))
        mock_profiler_init.assert_called_once_with(hmac_key=hmac_key,
                                                   base_id="1",
                                                   parent_id="2")
Exemplo n.º 2
0
def init_from_conf(conf, context, project, service, host):
    """Initialize notifier from service configuration

    :param conf: service configuration
    :param context: request context
    :param project: project name (keystone, cinder etc.)
    :param service: service name that will be profiled
    :param host: hostname or host IP address that the service will be
                 running on.
    """
    connection_str = conf.profiler.connection_string
    kwargs = {}
    if connection_str.startswith("messaging"):
        kwargs = {
            "messaging": oslo_messaging,
            "transport": oslo_messaging.get_transport(conf)
        }
    _notifier = notifier.create(connection_str,
                                context=context,
                                project=project,
                                service=service,
                                host=host,
                                conf=conf,
                                **kwargs)
    notifier.set(_notifier)
    web.enable(conf.profiler.hmac_keys)
Exemplo n.º 3
0
    def test_wsgi_middleware_enable_via_python(self, mock_profiler_init):
        request = mock.MagicMock()
        request.get_response.return_value = "yeah!"
        request.url = "someurl"
        request.host_url = "someurl"
        request.path = "path"
        request.query_string = "query"
        request.method = "method"
        request.scheme = "scheme"
        hmac_key = "super_secret_key2"

        pack = utils.signed_pack({"base_id": "1", "parent_id": "2"}, hmac_key)
        request.headers = {
            "a": "1",
            "b": "2",
            "X-Trace-Info": pack[0],
            "X-Trace-HMAC": pack[1]
        }

        web.enable("super_secret_key1,super_secret_key2")
        middleware = web.WsgiMiddleware("app", enabled=True)
        self.assertEqual("yeah!", middleware(request))
        mock_profiler_init.assert_called_once_with(hmac_key=hmac_key,
                                                   base_id="1",
                                                   parent_id="2")
Exemplo n.º 4
0
def setup_profiler(binary, host):
    if CONF.profiler.enabled:
        _notifier = notifier.create(
            "Messaging", messaging, context.get_admin_context().to_dict(),
            rpc.TRANSPORT, "trove", binary, host)
        notifier.set(_notifier)
        web.enable(CONF.profiler.hmac_keys)
        LOG.warn(_LW("The OpenStack Profiler is enabled. Using one of the "
                     "hmac_keys specified in the trove.conf file "
                     "(typically in /etc/trove), a trace can be made of all "
                     "requests. Only an admin user can retrieve the trace "
                     "information, however.\n"
                     "To disable the profiler, add the following to the "
                     "configuration file:\n"
                     "[profiler]\n"
                     "enabled=false"))
    else:
        web.disable()
Exemplo n.º 5
0
def setup_profiler(binary, host):
    if CONF.profiler.enabled:
        _notifier = notifier.create(
            "Messaging", messaging, context.get_admin_context().to_dict(),
            rpc.TRANSPORT, "trove", binary, host)
        notifier.set(_notifier)
        web.enable(CONF.profiler.hmac_keys)
        LOG.warning(_LW("The OpenStack Profiler is enabled. Using one"
                        " of the hmac_keys specified in the trove.conf file "
                        "(typically in /etc/trove), a trace can be made of "
                        "all requests. Only an admin user can retrieve "
                        "the trace information, however.\n"
                        "To disable the profiler, add the following to the "
                        "configuration file:\n"
                        "[profiler]\n"
                        "enabled=false"))
    else:
        web.disable()
Exemplo n.º 6
0
def init_from_conf(conf, context, project, service, host):
    """Initialize notifier from service configuration

    :param conf: service configuration
    :param context: request context
    :param project: project name (keystone, cinder etc.)
    :param service: service name that will be profiled
    :param host: hostname or host IP address that the service will be
                 running on.
    """
    connection_str = conf.profiler.connection_string
    _notifier = notifier.create(connection_str,
                                context=context,
                                project=project,
                                service=service,
                                host=host,
                                conf=conf)
    notifier.set(_notifier)
    web.enable(conf.profiler.hmac_keys)
Exemplo n.º 7
0
def setup(conf, binary, host):
    if conf.profiler.enabled:

        # Note(wangxiyuan): OSprofiler now support some kind of backends, such
        # as Ceilometer, ElasticSearch, Messaging and MongoDB.
        # 1. Ceilometer is only used for data collection, and Messaging is only
        # used for data transfer. So Ceilometer only works when Messaging is
        # enabled.
        # 2. ElasticSearch and MongoDB support both data collection and
        # transfer. So they can be used standalone.
        # 3. Choose which backend depends on the config option
        # "connection_string" , and the default value is "messaging://".
        backend_uri = conf.profiler.connection_string
        if "://" not in backend_uri:
            backend_uri += "://"
        parsed_connection = urlparse.urlparse(backend_uri)
        backend_type = parsed_connection.scheme
        if backend_type == "messaging":
            import oslo_messaging
            _notifier = notifier.create(
                backend_uri, oslo_messaging, {},
                oslo_messaging.get_notification_transport(conf), "Zaqar",
                binary, host)
        else:
            _notifier = notifier.create(backend_uri,
                                        project="Zaqar",
                                        service=binary,
                                        host=host)
        notifier.set(_notifier)
        LOG.warning("OSProfiler is enabled.\nIt means that person who "
                    "knows any of hmac_keys that are specified in "
                    "/etc/zaqar/zaqar.conf can trace his requests. \n In "
                    "real life only operator can read this file so there "
                    "is no security issue. Note that even if person can "
                    "trigger profiler, only admin user can retrieve trace "
                    "information.\n"
                    "To disable OSprofiler set in zaqar.conf:\n"
                    "[profiler]\nenabled=false")
        web.enable(conf.profiler.hmac_keys)
    else:
        web.disable()
Exemplo n.º 8
0
def init_from_conf(conf, context, project, service, host):
    """Initialize notifier from service configuration

    :param conf: service configuration
    :param context: request context
    :param project: project name (keystone, cinder etc.)
    :param service: service name that will be profiled
    :param host: hostname or host IP address that the service will be
                 running on.
    """
    connection_str = conf.profiler.connection_string
    _notifier = notifier.create(
        connection_str,
        messaging=oslo_messaging,
        context=context,
        transport=oslo_messaging.get_transport(conf),
        project=project,
        service=service,
        host=host)
    notifier.set(_notifier)
    web.enable(conf.profiler.hmac_keys)
Exemplo n.º 9
0
def setup(conf, binary, host):
    if conf.profiler.enabled:

        # Note(wangxiyuan): OSprofiler now support some kind of backends, such
        # as Ceilometer, ElasticSearch, Messaging and MongoDB.
        # 1. Ceilometer is only used for data collection, and Messaging is only
        # used for data transfer. So Ceilometer only works when Messaging is
        # enabled.
        # 2. ElasticSearch and MongoDB support both data collection and
        # transfer. So they can be used standalone.
        # 3. Choose which backend depends on the config option
        # "connection_string" , and the default value is "messaging://".
        backend_uri = conf.profiler.connection_string
        if "://" not in backend_uri:
            backend_uri += "://"
        parsed_connection = urlparse.urlparse(backend_uri)
        backend_type = parsed_connection.scheme
        if backend_type == "messaging":
            import oslo_messaging
            _notifier = notifier.create(
                backend_uri, oslo_messaging, {},
                oslo_messaging.get_notification_transport(conf),
                "Zaqar", binary, host)
        else:
            _notifier = notifier.create(backend_uri, project="Zaqar",
                                        service=binary, host=host)
        notifier.set(_notifier)
        LOG.warning("OSProfiler is enabled.\nIt means that person who "
                    "knows any of hmac_keys that are specified in "
                    "/etc/zaqar/zaqar.conf can trace his requests. \n In "
                    "real life only operator can read this file so there "
                    "is no security issue. Note that even if person can "
                    "trigger profiler, only admin user can retrieve trace "
                    "information.\n"
                    "To disable OSprofiler set in zaqar.conf:\n"
                    "[profiler]\nenabled=false")
        web.enable(conf.profiler.hmac_keys)
    else:
        web.disable()
Exemplo n.º 10
0
 def tearDown(self):
     web.enable()
     super(WebMiddlewareTestCase, self).tearDown()
Exemplo n.º 11
0
 def test_enabled(self):
     web.disable()
     web.enable()
     self.assertTrue(web._ENABLED)
Exemplo n.º 12
0
def enable_web_trace(conf=None):
    if conf is None:
        conf = cfg.CONF
    if conf.profiler.enabled:
        web.enable(conf.profiler.hmac_keys)
Exemplo n.º 13
0
def enable_web_trace(conf=None):
    if conf is None:
        conf = cfg.CONF
    if conf.profiler.enabled:
        web.enable(conf.profiler.hmac_keys)
Exemplo n.º 14
0
 def tearDown(self):
     web.enable()
     super(WebMiddlewareTestCase, self).tearDown()
Exemplo n.º 15
0
 def test_enabled(self):
     web.disable()
     web.enable()
     self.assertTrue(web._ENABLED)
Exemplo n.º 16
0
 def test_enabled(self):
     web.disable()
     web.enable()
     self.assertFalse(web._DISABLED)