scriptharness.errorlists module

Error lists are used to parse output in scriptharness.log.OutputParser.

Each line of output is matched against each substring or regular expression in the error list. On a match, we determine the ‘level’ of that line. Levels are ints, and match the levels in the python logging module. Negative levels are ignored.

class scriptharness.errorlists.ErrorList(error_list, strict=True)

Bases: list

Error lists, to describe how to parse output. In object form for better validation.

An example error_list:

        "regex": re.compile("^Error: not actually an error!"),
    }, {
        "regex": re.compile("^Error:"),
        "level": logging.ERROR,
        "pre_context_lines": 5,
        "post_context_lines": 5
    }, {
        "substr": "Obscure error #94382",
            "This is a fatal program error."
        "exception": ScriptHarnessFatal

Any output line that matches the first regex will be ignored (discarded), because level is negative. Because the list is matched in order, the more specific regex is placed before the more general 2nd regex. If the order were reversed, the more specific regex would never match anything. The second regex sets the level to logging.ERROR for this line, and 5 lines above and 5 lines below this message.

Currently undecided whether we should support modification of ErrorLists (which would require validating any new items and recalculating pre and post context_lines) or having ErrorList inherit tuple and dealing with all the renaming. Most likely the former, but until then, the supported way of modifying an ErrorList is to create a new one.



If True, be more strict about well-formed error_lists.



The max number of lines the error_list defines in pre_context_lines.



The max number of lines the error_list defines in post_context_lines.


Validate an error_list. This is going to be a pain to unit test properly.

Parameters:error_list (list of dicts) – an error_list.
Returns:(pre_context_lines, post_context_lines) (tuple of int, int)
Raises:scriptharness.exceptions.ScriptHarnessException – if error_list is not well-formed.
scriptharness.errorlists.MAKE_ERROR_LIST = [{u'substr': u'No rule to make target ', u'level': 40}, {u'regex': <_sre.SRE_Pattern object at 0x7f1d8e4f4030>, u'level': 40}, {u'regex': <_sre.SRE_Pattern object at 0x7f1d8e5cfac0>, u'level': 40}, {u'regex': <_sre.SRE_Pattern object at 0x7f1d8e4fa120>, u'level': 40}, {u'regex': <_sre.SRE_Pattern object at 0x7f1d8e4fc1e0>, u'level': 40}, {u'regex': <_sre.SRE_Pattern object at 0x7f1d8e4c9130>, u'level': 30}, {u'regex': <_sre.SRE_Pattern object at 0x7f1d8e5b42a0>, u'level': 40}, {u'substr': u'Warning: ', u'level': 30}]

Make errors. These are prime candidates to add pre_context_lines to.

scriptharness.errorlists.SSH_ERROR_LIST = [{u'substr': u'Name or service not known', u'level': 40}, {u'substr': u'Could not resolve hostname', u'level': 40}, {u'substr': u'POSSIBLE BREAK-IN ATTEMPT', u'level': 30}, {u'substr': u'Network error:', u'level': 40}, {u'substr': u'Access denied', u'level': 40}, {u'substr': u'Authentication refused', u'level': 40}, {u'substr': u'Out of memory', u'level': 40}, {u'substr': u'Connection reset by peer', u'level': 30}, {u'substr': u'Host key verification failed', u'level': 40}, {u'substr': u'logging.WARNING:', u'level': 30}, {u'substr': u'rsync error:', u'level': 40}, {u'substr': u'Broken pipe:', u'level': 40}, {u'substr': u'Permission denied:', u'level': 40}, {u'substr': u'connection unexpectedly closed', u'level': 40}, {u'substr': u'Warning: Identity file', u'level': 40}, {u'substr': u'command-line line 0: Missing argument', u'level': 40}]

For ssh, scp, rsync over ssh.

scriptharness.errorlists.check_context_lines(context_lines, orig_context_lines, name, messages)

Verifies and returns the larger int of context_lines and orig_context_lines.

  • context_lines (value) – The value of pre_context_lines or post_context_lines to validate.
  • orig_context_lines (int) – The previous max int sent to check_context_lines
  • name (str) – The name of the field (pre_context_lines or post_context_lines)
  • messages (list) – The list of error messages so far.

If context_lines is a non-int or negative, an error is appended to messages and we return orig_context_lines. Otherwise, we return the max of context_lines or orig_context_lines.

Return type:


scriptharness.errorlists.check_ignore(strict, ignore, message, messages)

If the level of an error_check is negative, it will be ignored. There is currently no pre_context_lines or post_context_lines support for ignored lines. When self.strict is True, append an error to messages.

This function doesn’t do a whole lot anymore, other than remove the number of branches in validate_error_list.

  • strict (bool) – Whether the error-checking is strict or not.
  • ignore (bool) – True when ‘level’ is in error_check and negative.
  • message (str) – The message to append if ignore and strict.
  • messages (list) – The error messages so far.
scriptharness.errorlists.exactly_one(key1, key2, error_check, messages)

Make sure one, and only one, of key1 and key2 are in error_check. If that’s not the case, append an error message in messages.

  • key1 (str) – Dictionary key.
  • key2 (str) – Dictionary key.
  • error_check (dict) – a single item of error_list.
  • messages (list) – the list of error messages so far.

True if there is exactly one of the two keys in error_check.

Return type:


scriptharness.errorlists.verify_unicode(key, error_check, messages)

If key is in error_check, it must be of type six.text_type. If not, append an error message to messages.

  • key (str) – a dict key
  • error_check (dict) – a single item of error_list
  • messages (list) – The error messages so far