示例#1
0
def make_dict(data, pod_re, objref_dict):
    """
    Given the log file and the failed pod name, returns a dictionary
    containing the namespace, UID, and other information associated with the pod
    and a bool indicating if the pod name string is in the log file.

    This dictionary is lifted from the line with the ObjectReference
    """
    pod_in_file = False

    lines = unicode(jinja2.escape(data)).split('\n')
    for line in lines:
        if pod_re.search(line):
            pod_in_file = True
            objref = regex.objref(line)
            containerID = regex.containerID(line)
            if containerID and not objref_dict.get("ContainerID"):
                objref_dict["ContainerID"] = containerID.group(1)
            if objref:
                objref_dict_re = objref.group(1)
                objref_dict_re = re.sub(r'(\w+):', r'"\1": ', objref_dict_re)
                objref_dict_re = objref_dict_re.replace('"', '"')
                objref_dict_re = json.loads(objref_dict_re)
                objref_dict_re.update(objref_dict)
                return objref_dict_re, pod_in_file

    return objref_dict, pod_in_file
示例#2
0
def make_dict(data, pod_re, objref_dict):
    """
    Given the log file and the failed pod name, returns a dictionary
    containing the namespace, UID, and other information associated with the pod
    and a bool indicating if the pod name string is in the log file.

    This dictionary is lifted from the line with the ObjectReference
    """
    pod_in_file = False

    lines = unicode(jinja2.escape(data)).split('\n')
    for line in lines:
        if pod_re.search(line):
            pod_in_file = True
            objref = regex.objref(line)
            containerID = regex.containerID(line)
            if containerID and not objref_dict.get("ContainerID"):
                objref_dict["ContainerID"] = containerID.group(1)
            if objref:
                objref_dict_re = objref.group(1)
                objref_dict_re = re.sub(r'(\w+):', r'"\1": ', objref_dict_re)
                objref_dict_re = objref_dict_re.replace('"', '"')
                objref_dict_re = json.loads(objref_dict_re)
                objref_dict_re.update(objref_dict)
                return objref_dict_re, pod_in_file

    return objref_dict, pod_in_file
示例#3
0
 def test_containerID(self):
     for text, matches in [
         ('the ContainerID:ab123cd', True),
         ('ContainerID:}]}', False),
         ('ContainerID:', False),
     ]:
         self.assertEqual(bool(regex.containerID(text).group(1)), matches,
             'containerID(%r).group(1) should be %r' % (text, matches))
示例#4
0
 def test_containerID(self):
     for text, matches in [
         ('the ContainerID:ab123cd', True),
         ('ContainerID:}]}', False),
         ('ContainerID:', False),
     ]:
         self.assertEqual(bool(regex.containerID(text).group(1)), matches,
             'containerID(%r).group(1) should be %r' % (text, matches))