def setUp(self):
        yield super(NotificationErrorsTestCase, self).setUp()

        self.notifier = FakeNotifier()
        self.patch(notifier, 'get_notifier', lambda: self.notifier)
        self.fake_reactor = DummyReactor()
        self.oops_deferred = defer.Deferred()

        def publish(report):
            self.oops_deferred.callback(report)

        oops_config = configure_oops()
        # Should probably be an option to configure_oops?
        oops_timeline.install_hooks(oops_config)
        oops_config.publishers = [publish]

        self.ssfactory = StorageServerFactory(
            s3_host=None,
            s3_port=None,
            s3_key=None,
            s3_ssl=False,
            s3_secret=None,
            oops_config=oops_config,
            reactor=self.fake_reactor)

        protocol = StorageServer()
        protocol.factory = self.ssfactory
        protocol.working_caps = ["volumes", "generations"]
        protocol.logger = logging.getLogger("storage.server")
        protocol.session_id = uuid.uuid4()
        self.patch(self.ssfactory.content, 'get_user_by_id',
                   lambda *a: Failure(self.induced_error("Test error")))
示例#2
0
    def setUp(self):
        yield super(NotificationErrorsTestCase, self).setUp()

        self.notifier = FakeNotifier()
        self.patch(notifier, 'get_notifier', lambda: self.notifier)
        self.fake_reactor = DummyReactor()
        self.oops_deferred = defer.Deferred()

        def publish(report):
            self.oops_deferred.callback(report)

        oops_config = configure_oops()
        # Should probably be an option to configure_oops?
        oops_timeline.install_hooks(oops_config)
        oops_config.publishers = [publish]

        self.ssfactory = StorageServerFactory(s3_host=None,
                                              s3_port=None,
                                              s3_key=None,
                                              s3_ssl=False,
                                              s3_secret=None,
                                              oops_config=oops_config,
                                              reactor=self.fake_reactor)

        protocol = StorageServer()
        protocol.factory = self.ssfactory
        protocol.working_caps = ["volumes", "generations"]
        protocol.logger = logging.getLogger("storage.server")
        protocol.session_id = uuid.uuid4()
        self.patch(self.ssfactory.content, 'get_user_by_id',
                   lambda *a: Failure(self.induced_error("Test error")))
示例#3
0
    def configure(self, section_name=None, config_factory=oops.Config,
                  publisher_adapter=None, publisher_helpers=oops.publishers):
        """Configure the utility using the named section from the config.

        The 'error_reports' section is used if section_name is None.
        """
        if section_name is None:
            section_name = self._default_config_section
        self._oops_config = config_factory()
        # We use the timeline module
        oops_timeline.install_hooks(self._oops_config)
        #
        # What do we want in our reports?
        # Constants:
        self._oops_config.template['branch_nick'] = versioninfo.branch_nick
        self._oops_config.template['revision'] = versioninfo.revision
        reporter = config[self._default_config_section].oops_prefix
        if section_name != self._default_config_section:
            reporter = '%s-%s' % (reporter, section_name)
        self._oops_config.template['reporter'] = reporter
        # Should go in an HTTP module.
        self._oops_config.template['req_vars'] = {}
        # Exceptions, with the zope formatter.
        self._oops_config.on_create.append(attach_exc_info)
        # Ignore IUnloggedException exceptions
        self._oops_config.on_create.append(attach_ignore_from_exception)
        # Zope HTTP requests have lots of goodies.
        self._oops_config.on_create.append(attach_http_request)
        # We don't want session cookie values in the report - they contain
        # authentication keys.
        self._oops_config.on_create.append(filter_sessions_timeline)
        # We permit adding messages during the execution of a script (not
        # threadsafe - so only scripts) - a todo item is to only add this
        # for scripts (or to make it threadsafe)
        self._oops_config.on_create.append(self._attach_messages)
        # In the zope environment we track how long a script / http
        # request has been running for - this is useful data!
        self._oops_config.on_create.append(attach_adapter_duration)
        # Any previous OOPS reports generated this request.
        self._oops_config.on_create.append(attach_previous_oopsid)
        # And any active feature flags.
        self._oops_config.on_create.append(attach_feature_info)

        def adapted_publisher(publisher):
            if publisher_adapter is not None:
                return publisher_adapter(publisher)
            else:
                return publisher

        # Exposed for introspection by tests.  Don't expect modifying these
        # to be useful.
        self._main_publishers = []
        self._all_publishers = []
        # If amqp is configured we want to publish over amqp.
        if (config.error_reports.error_exchange and rabbit.is_configured()):
            exchange = config.error_reports.error_exchange
            routing_key = config.error_reports.error_queue_key
            self._main_publishers.append(adapted_publisher(oops_amqp.Publisher(
                rabbit.connect, exchange, routing_key)))
        # We want to publish reports to disk for gathering to the central
        # analysis server, but only if we haven't already published to rabbit.
        self._oops_datedir_repo = DateDirRepo(
            config[self._default_config_section].error_dir)
        self._main_publishers.append(
            adapted_publisher(self._oops_datedir_repo.publish))
        self._all_publishers.append(
            publisher_helpers.publish_with_fallback(*self._main_publishers))
        # And send everything within the zope application server (only for
        # testing).
        self._all_publishers.append(adapted_publisher(notify_publisher))
        self._oops_config.publisher = publisher_helpers.publish_to_many(
            *self._all_publishers)

        #
        # Reports are filtered if:
        #  - There is a key 'ignore':True in the report. This is set during
        #    _makeReport.
        self._oops_config.filters.append(
                operator.methodcaller('get', 'ignore'))
        #  - have a type listed in self._ignored_exceptions.
        self._oops_config.filters.append(
                lambda report: _get_type(report) in self._ignored_exceptions)
        #  - have a missing or offset REFERER header with a type listed in
        #    self._ignored_exceptions_for_offsite_referer
        self._oops_config.filters.append(self._filter_bad_urls_by_referer)
        #  - look like a deliberate DB outage, to cut down fastdowntime
        #    noise.
        self._oops_config.filters.append(self._filter_deliberate_db_outages)
示例#4
0
    def configure(self, section_name=None, config_factory=oops.Config,
            publisher_adapter=None):
        """Configure the utility using the named section from the config.

        The 'error_reports' section is used if section_name is None.
        """
        if section_name is None:
            section_name = self._default_config_section
        self._oops_config = config_factory()
        # We use the timeline module
        oops_timeline.install_hooks(self._oops_config)
        #
        # What do we want in our reports?
        # Constants:
        self._oops_config.template['branch_nick'] = versioninfo.branch_nick
        self._oops_config.template['revno'] = versioninfo.revno
        reporter = config[self._default_config_section].oops_prefix
        if section_name != self._default_config_section:
            reporter = '%s-%s' % (reporter, section_name)
        self._oops_config.template['reporter'] = reporter
        # Should go in an HTTP module.
        self._oops_config.template['req_vars'] = {}
        # Exceptions, with the zope formatter.
        self._oops_config.on_create.append(attach_exc_info)
        # Ignore IUnloggedException exceptions
        self._oops_config.on_create.append(attach_ignore_from_exception)
        # Zope HTTP requests have lots of goodies.
        self._oops_config.on_create.append(attach_http_request)
        # We don't want session cookie values in the report - they contain
        # authentication keys.
        self._oops_config.on_create.append(filter_sessions_timeline)
        # We permit adding messages during the execution of a script (not
        # threadsafe - so only scripts) - a todo item is to only add this
        # for scripts (or to make it threadsafe)
        self._oops_config.on_create.append(self._attach_messages)
        # In the zope environment we track how long a script / http
        # request has been running for - this is useful data!
        self._oops_config.on_create.append(attach_adapter_duration)
        # Any previous OOPS reports generated this request.
        self._oops_config.on_create.append(attach_previous_oopsid)
        # And any active feature flags.
        self._oops_config.on_create.append(attach_feature_info)

        def add_publisher(publisher):
            if publisher_adapter is not None:
                publisher = publisher_adapter(publisher)
            self._oops_config.publishers.append(publisher)

        # If amqp is configured we want to publish over amqp.
        if (config.error_reports.error_exchange and rabbit.is_configured()):
            exchange = config.error_reports.error_exchange
            routing_key = config.error_reports.error_queue_key
            amqp_publisher = oops_amqp.Publisher(
                rabbit.connect, exchange, routing_key)
            add_publisher(amqp_publisher)
        # We want to publish reports to disk for gathering to the central
        # analysis server, but only if we haven't already published to rabbit.
        self._oops_datedir_repo = DateDirRepo(
            config[self._default_config_section].error_dir)
        add_publisher(oops.publish_new_only(self._oops_datedir_repo.publish))
        # And send everything within the zope application server (only for
        # testing).
        add_publisher(notify_publisher)
        #
        # Reports are filtered if:
        #  - There is a key 'ignore':True in the report. This is set during
        #    _makeReport.
        self._oops_config.filters.append(
                operator.methodcaller('get', 'ignore'))
        #  - have a type listed in self._ignored_exceptions.
        self._oops_config.filters.append(
                lambda report: _get_type(report) in self._ignored_exceptions)
        #  - have a missing or offset REFERER header with a type listed in
        #    self._ignored_exceptions_for_offsite_referer
        self._oops_config.filters.append(self._filter_bad_urls_by_referer)