Exemplo n.º 1
0
    def test_configure(self):
        """Test ErrorReportingUtility.setConfigSection()."""
        utility = ErrorReportingUtility()
        # The ErrorReportingUtility uses the config.error_reports section
        # by default.
        self.assertEqual(config.error_reports.oops_prefix, utility.oops_prefix)
        self.assertEqual(config.error_reports.error_dir,
                         utility._oops_datedir_repo.root)
        # Some external processes may extend the reporter/prefix with
        # extra information.
        utility.configure(section_name='branchscanner')
        self.assertEqual('T-branchscanner', utility.oops_prefix)

        # The default error section can be restored.
        utility.configure()
        self.assertEqual(config.error_reports.oops_prefix, utility.oops_prefix)

        # We should have had two publishers set up:
        self.assertEqual(2, len(utility._all_publishers))
        # - a fallback publisher chaining a rabbit publisher and a datedir
        #   publisher
        self.assertIsInstance(utility._main_publishers[0], oops_amqp.Publisher)
        self.assertEqual(utility._main_publishers[1],
                         utility._oops_datedir_repo.publish)
        # - a notify publisher
        self.assertEqual(utility._all_publishers[1], notify_publisher)
Exemplo n.º 2
0
def make_error_utility(pid=None):
    """Make an error utility for logging errors from bzr."""
    if pid is None:
        pid = os.getpid()
    error_utility = ErrorReportingUtility()
    error_utility.configure('bzr_lpserve')
    return error_utility
Exemplo n.º 3
0
    def test_configure(self):
        """Test ErrorReportingUtility.setConfigSection()."""
        utility = ErrorReportingUtility()
        # The ErrorReportingUtility uses the config.error_reports section
        # by default.
        self.assertEqual(config.error_reports.oops_prefix, utility.oops_prefix)
        self.assertEqual(config.error_reports.error_dir,
                         utility._oops_datedir_repo.root)
        # Some external processes may extend the reporter/prefix with
        # extra information.
        utility.configure(section_name='branchscanner')
        self.assertEqual('T-branchscanner', utility.oops_prefix)

        # The default error section can be restored.
        utility.configure()
        self.assertEqual(config.error_reports.oops_prefix, utility.oops_prefix)

        # We should have had three publishers setup:
        oops_config = utility._oops_config
        self.assertEqual(3, len(oops_config.publishers))
        # - a rabbit publisher
        self.assertIsInstance(oops_config.publishers[0], oops_amqp.Publisher)
        # - a datedir publisher wrapped in a publish_new_only wrapper
        datedir_repo = utility._oops_datedir_repo
        publisher = oops_config.publishers[1].func_closure[0].cell_contents
        self.assertEqual(publisher, datedir_repo.publish)
        # - a notify publisher
        self.assertEqual(oops_config.publishers[2], notify_publisher)
Exemplo n.º 4
0
def make_error_utility(pid=None):
    """Make an error utility for logging errors from bzr."""
    if pid is None:
        pid = os.getpid()
    error_utility = ErrorReportingUtility()
    error_utility.configure('bzr_lpserve')
    return error_utility
Exemplo n.º 5
0
    def test_configure(self):
        """Test ErrorReportingUtility.setConfigSection()."""
        utility = ErrorReportingUtility()
        # The ErrorReportingUtility uses the config.error_reports section
        # by default.
        self.assertEqual(config.error_reports.oops_prefix,
            utility.oops_prefix)
        self.assertEqual(config.error_reports.error_dir,
            utility._oops_datedir_repo.root)
        # Some external processes may extend the reporter/prefix with
        # extra information.
        utility.configure(section_name='branchscanner')
        self.assertEqual('T-branchscanner', utility.oops_prefix)

        # The default error section can be restored.
        utility.configure()
        self.assertEqual(config.error_reports.oops_prefix,
            utility.oops_prefix)

        # We should have had three publishers setup:
        oops_config = utility._oops_config
        self.assertEqual(3, len(oops_config.publishers))
        # - a rabbit publisher
        self.assertIsInstance(oops_config.publishers[0], oops_amqp.Publisher)
        # - a datedir publisher wrapped in a publish_new_only wrapper
        datedir_repo = utility._oops_datedir_repo
        publisher = oops_config.publishers[1].func_closure[0].cell_contents
        self.assertEqual(publisher, datedir_repo.publish)
        # - a notify publisher
        self.assertEqual(oops_config.publishers[2], notify_publisher)
Exemplo n.º 6
0
def report_oops(message=None,
                properties=None,
                info=None,
                transaction_manager=None):
    """Record an oops for the current exception.

    This must only be called while handling an exception.

    Searches for 'URL', 'url', or 'baseurl' properties, in order of
    preference, to use as the linked URL of the OOPS report.

    :param message: custom explanatory error message. Do not use
        str(exception) to fill in this parameter, it should only be
        set when a human readable error has been explicitly generated.

    :param properties: Properties to record in the OOPS report.
    :type properties: An iterable of (name, value) tuples.

    :param info: Exception info.
    :type info: The return value of `sys.exc_info()`.

    :param transaction_manager: A transaction manager. If specified,
        further commit() calls will be logged.
    """
    # Get the current exception info first of all.
    if info is None:
        info = sys.exc_info()

    # Collect properties to report.
    if properties is None:
        properties = []
    else:
        properties = list(properties)

    if message is not None:
        properties.append(('error-explanation', message))

    # Find a candidate for the request URL.
    def find_url():
        for name in 'URL', 'url', 'baseurl':
            for key, value in properties:
                if key == name:
                    return value
        return None

    url = find_url()

    # Create the dummy request object.
    request = ScriptRequest(properties, url)
    error_utility = ErrorReportingUtility()
    error_utility.configure(section_name='checkwatches')
    error_utility.raising(info, request)
    return request
Exemplo n.º 7
0
def report_oops(message=None, properties=None, info=None,
                transaction_manager=None):
    """Record an oops for the current exception.

    This must only be called while handling an exception.

    Searches for 'URL', 'url', or 'baseurl' properties, in order of
    preference, to use as the linked URL of the OOPS report.

    :param message: custom explanatory error message. Do not use
        str(exception) to fill in this parameter, it should only be
        set when a human readable error has been explicitly generated.

    :param properties: Properties to record in the OOPS report.
    :type properties: An iterable of (name, value) tuples.

    :param info: Exception info.
    :type info: The return value of `sys.exc_info()`.

    :param transaction_manager: A transaction manager. If specified,
        further commit() calls will be logged.
    """
    # Get the current exception info first of all.
    if info is None:
        info = sys.exc_info()

    # Collect properties to report.
    if properties is None:
        properties = []
    else:
        properties = list(properties)

    if message is not None:
        properties.append(('error-explanation', message))

    # Find a candidate for the request URL.
    def find_url():
        for name in 'URL', 'url', 'baseurl':
            for key, value in properties:
                if key == name:
                    return value
        return None
    url = find_url()

    # Create the dummy request object.
    request = ScriptRequest(properties, url)
    error_utility = ErrorReportingUtility()
    error_utility.configure(section_name='checkwatches')
    error_utility.raising(info, request)
    return request
Exemplo n.º 8
0
def log_exception(message, *args):
    """Write the current exception traceback into the Mailman log file.

    This is really just a convenience function for a refactored chunk of
    common code.

    :param message: The message to appear in the xmlrpc and error logs. It
        may be a format string.
    :param args: Optional arguments to be interpolated into a format string.
    """
    error_utility = ErrorReportingUtility()
    error_utility.configure(section_name='mailman')
    error_utility.raising(sys.exc_info())
    out_file = StringIO()
    traceback.print_exc(file=out_file)
    traceback_text = out_file.getvalue()
    syslog('xmlrpc', message, *args)
    syslog('error', message, *args)
    syslog('error', traceback_text)
Exemplo n.º 9
0
def log_exception(message, *args):
    """Write the current exception traceback into the Mailman log file.

    This is really just a convenience function for a refactored chunk of
    common code.

    :param message: The message to appear in the xmlrpc and error logs. It
        may be a format string.
    :param args: Optional arguments to be interpolated into a format string.
    """
    error_utility = ErrorReportingUtility()
    error_utility.configure(section_name="mailman")
    error_utility.raising(sys.exc_info())
    out_file = StringIO()
    traceback.print_exc(file=out_file)
    traceback_text = out_file.getvalue()
    syslog("xmlrpc", message, *args)
    syslog("error", message, *args)
    syslog("error", traceback_text)
Exemplo n.º 10
0
def make_error_utility():
    """Make an error utility for logging errors from codebrowse."""
    error_utility = ErrorReportingUtility()
    error_utility.configure('codebrowse')
    return error_utility
Exemplo n.º 11
0
 def _log(self, exc):
     """Log the exception in a log file and as an OOPS."""
     Runner._log(self, exc)
     error_utility = ErrorReportingUtility()
     error_utility.configure(section_name='mailman')
     error_utility.raising(sys.exc_info())
Exemplo n.º 12
0
def make_error_utility():
    """Make an error utility for logging errors from codebrowse."""
    error_utility = ErrorReportingUtility()
    error_utility.configure('codebrowse')
    return error_utility
Exemplo n.º 13
0
 def _log(self, exc):
     """Log the exception in a log file and as an OOPS."""
     Runner._log(self, exc)
     error_utility = ErrorReportingUtility()
     error_utility.configure(section_name="mailman")
     error_utility.raising(sys.exc_info())