Beispiel #1
0
 def test_parse_empty_lines(self):
     """Test that it doesn't fail when files are empty"""
     matched_lines, hilight_words = kubelet_parser.parse(
         [], ["error", "fatal", "failed", "build timed out"], filters, {})
     self.assertEqual(matched_lines, [])
     self.assertEqual(hilight_words,
                      ["error", "fatal", "failed", "build timed out"])
Beispiel #2
0
def digest(data, objref_dict=None, filters=None, error_re=regex.error_re,
    skip_fmt=lambda l: '... skipping %d lines ...' % l):
    # pylint: disable=too-many-arguments
    """
    Given a build log, return a chunk of HTML code suitable for
    inclusion in a <pre> tag, with "interesting" errors highlighted.

    This is similar to the output of `grep -C4` with an appropriate regex.
    """
    if isinstance(data, str):  # the test mocks return str instead of unicode
        data = data.decode('utf8', 'replace')
    lines = unicode(jinja2.escape(truncate(data))).split('\n')

    if filters is None:
        filters = {'Namespace': '', 'UID': '', 'pod': '', 'ContainerID':''}

    highlight_words = regex.default_words

    if filters["pod"]:
        highlight_words = [filters["pod"]]

    if not (filters["UID"] or filters["Namespace"] or filters["ContainerID"]):
        matched_lines = [n for n, line in enumerate(lines) if error_re.search(line)]
    else:
        matched_lines, highlight_words = kubelet_parser.parse(lines,
            highlight_words, filters, objref_dict)

    output = log_html(lines, matched_lines, highlight_words, skip_fmt)
    output.append('')

    return '\n'.join(output)
 def test_parse_pod_RE(self):
     """Test for initial pod filtering"""
     filters["pod"] = "pod"
     matched_lines, hilight_words = kubelet_parser.parse(
         lines, ["pod"], filters, {"UID": "", "Namespace": ""})
     self.assertEqual(matched_lines, [1])
     self.assertEqual(hilight_words, ["pod"])
 def test_parse_error_re(self):
     """Test for build-log.txt filtering by error_re"""
     matched_lines, hilight_words = kubelet_parser.parse(
         lines, ["error", "fatal", "failed", "build timed out"], filters, {})
     self.assertEqual(matched_lines, [4])
     self.assertEqual(
         hilight_words, ["error", "fatal", "failed", "build timed out"])
 def test_parse_empty_lines(self):
     """Test that it doesn't fail when files are empty"""
     matched_lines, hilight_words = kubelet_parser.parse(
         [], ["error", "fatal", "failed", "build timed out"], filters, {})
     self.assertEqual(matched_lines, [])
     self.assertEqual(
         hilight_words, ["error", "fatal", "failed", "build timed out"])
Beispiel #6
0
def digest(data, skip_fmt=lambda l: '... skipping %d lines ...' % l,
      objref_dict=None, filters=None, error_re=regex.error_re):
    """
    Given a build log, return a chunk of HTML code suitable for
    inclusion in a <pre> tag, with "interesting" errors hilighted.

    This is similar to the output of `grep -C4` with an appropriate regex.
    """
    lines = unicode(jinja2.escape(data)).split('\n')

    if filters is None:
        filters = {'Namespace': '', 'UID': '', 'pod': ''}

    hilight_words = ["error", "fatal", "failed", "build timed out"]
    if filters["pod"]:
        hilight_words = [filters["pod"]]

    if not (filters["UID"] or filters["Namespace"]):
        matched_lines = [n for n, line in enumerate(lines) if error_re.search(line)]
    else:
        matched_lines, hilight_words = kubelet_parser.parse(lines,
            hilight_words, filters, objref_dict)

    output = log_html(lines, matched_lines, hilight_words, skip_fmt)

    return '\n'.join(output)
Beispiel #7
0
 def test_parse_pod_RE(self):
     """Test for initial pod filtering"""
     filters["pod"] = "pod"
     matched_lines, highlight_words = kubelet_parser.parse(
         lines, ["pod"], filters, {})
     self.assertEqual(matched_lines, [1])
     self.assertEqual(highlight_words, ["pod"])
Beispiel #8
0
def digest(data,
           skip_fmt=lambda l: '... skipping %d lines ...' % l,
           objref_dict=None,
           filters=None,
           error_re=regex.error_re):
    """
    Given a build log, return a chunk of HTML code suitable for
    inclusion in a <pre> tag, with "interesting" errors hilighted.

    This is similar to the output of `grep -C4` with an appropriate regex.
    """
    lines = unicode(jinja2.escape(data)).split('\n')

    if filters is None:
        filters = {'Namespace': '', 'UID': '', 'pod': ''}

    hilight_words = ["error", "fatal", "failed", "build timed out"]
    if filters["pod"]:
        hilight_words = [filters["pod"]]

    if not (filters["UID"] or filters["Namespace"]):
        matched_lines = [
            n for n, line in enumerate(lines) if error_re.search(line)
        ]
    else:
        matched_lines, hilight_words = kubelet_parser.parse(
            lines, hilight_words, filters, objref_dict)

    output = log_html(lines, matched_lines, hilight_words, skip_fmt)

    return '\n'.join(output)
Beispiel #9
0
def digest(data,
           objref_dict=None,
           filters=None,
           error_re=regex.error_re,
           skip_fmt=lambda l: '... skipping %d lines ...' % l):
    # pylint: disable=too-many-arguments
    """
    Given a build log, return a chunk of HTML code suitable for
    inclusion in a <pre> tag, with "interesting" errors hilighted.

    This is similar to the output of `grep -C4` with an appropriate regex.
    """
    if isinstance(data, str):  # the test mocks return str instead of unicode
        data = data.decode('utf8', 'replace')
    lines = unicode(jinja2.escape(truncate(data))).split('\n')

    if filters is None:
        filters = {'Namespace': '', 'UID': '', 'pod': '', 'ContainerID': ''}

    hilight_words = ["error", "fatal", "fail", "failed", "build timed out"]
    if filters["pod"]:
        hilight_words = [filters["pod"]]

    if not (filters["UID"] or filters["Namespace"] or filters["ContainerID"]):
        matched_lines = [
            n for n, line in enumerate(lines) if error_re.search(line)
        ]
    else:
        matched_lines, hilight_words = kubelet_parser.parse(
            lines, hilight_words, filters, objref_dict)

    output = log_html(lines, matched_lines, hilight_words, skip_fmt)
    output.append('')

    return '\n'.join(output)
Beispiel #10
0
 def test_parse_error_re(self):
     """Test for build-log.txt filtering by error_re"""
     matched_lines, hilight_words = kubelet_parser.parse(
         lines, ["error", "fatal", "failed", "build timed out"], filters,
         {})
     self.assertEqual(matched_lines, [4])
     self.assertEqual(hilight_words,
                      ["error", "fatal", "failed", "build timed out"])
 def test_parse_filters(self):
     """Test for filters"""
     filters["pod"] = "pod"
     filters["UID"] = "on"
     filters["Namespace"] = "on"
     matched_lines, hilight_words = kubelet_parser.parse(
         lines, ["pod"], filters, {"UID": "uid", "Namespace": "podName"})
     self.assertEqual(matched_lines, [1, 2, 5, 6])
     self.assertEqual(hilight_words, ["pod", "podName", "uid"])
 def test_parse_filters(self):
     """Test for filters"""
     filters["pod"] = "pod"
     filters["UID"] = "on"
     filters["Namespace"] = "on"
     matched_lines, hilight_words = kubelet_parser.parse(lines,
         ["pod"], filters, {"UID":"uid", "Namespace":"podName", "ContainerID":""})
     self.assertEqual(matched_lines, [1, 2, 5, 6])
     self.assertEqual(hilight_words, ["pod", "podName", "uid"])
Beispiel #13
0
def digest(data, skip_fmt=lambda l: '... skipping %d lines ...' % l, filters={"uid":"", "pod":""},
    error_re=re.compile(r'\b(error|fatal|failed|build timed out)\b', re.IGNORECASE)):
    """
    Given a build log, return a chunk of HTML code suitable for
    inclusion in a <pre> tag, with "interesting" errors hilighted.

    This is similar to the output of `grep -C4` with an appropriate regex.
    """
    lines = unicode(jinja2.escape(data)).split('\n')

    hilight_words=["error", "fatal", "failed", "build timed out"]
    if filters["pod"]:
        hilight_words = [filters["pod"]]

    if not filters["uid"]:
        matched_lines = [n for n, line in enumerate(lines) if error_re.search(line)]
    else:
        matched_lines, hilight_words = kubelet_parser.parse(lines, error_re, 
            hilight_words, filters)

    output = []
    CONTEXT = 4

    matched_lines.append(len(lines))  # sentinel value

    last_match = None
    for match in matched_lines:
        if last_match is not None:
            previous_end = min(match, last_match + CONTEXT + 1)
            output.extend(lines[last_match + 1: previous_end])
        else:
            previous_end = 0
        skip_amount = match - previous_end - CONTEXT
        if skip_amount > 1:
            output.append('<span class="skip">%s</span>' % skip_fmt(skip_amount))
        elif skip_amount == 1:  # pointless say we skipped 1 line
            output.append(lines[previous_end])
        if match == len(lines):
            break
        output.extend(lines[max(previous_end, match - CONTEXT): match])
        output.append(hilight(lines[match], hilight_words))
        last_match = match

    return '\n'.join(output)