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
def test_objref(self): for text, matches in [ ('Event(api.ObjectReference{Kind:\"Pod\"}) failed', True), ('{Pod:\"abc\", Namespace:\"pod abc\"}', False), ('Jan 1: Event(api.ObjectReference{Kind:\"Pod\", Podname:\"abc\"}) failed', True), ]: self.assertEqual(bool(regex.objref(text)), matches, 'objref(%r) should be %r' % (text, matches))
def test_objref(self): for text, matches in [ ('api.ObjectReference{Kind:"Pod"} failed', True), ('{Pod:"abc", Namespace:\"pod abc\"}', False), ('Jan 1: Event(api.ObjectReference{Kind:"Pod", Podname:"abc"}) failed', True), ]: self.assertEqual(bool(regex.objref(text)), matches, 'objref(%r) should be %r' % (text, matches))
def make_dict(data, pod_re): """ Given the log file and the failed pod name, returns a dictionary containing the namespace, UID, and other information associated with the pod. This dictionary is lifted from the line with the ObjectReference """ lines = unicode(jinja2.escape(data)).split('\n') for line in lines: if pod_re.search(line): objref = regex.objref(line) if objref: objref_dict = objref.group(1) objref_dict = re.sub(r'(\w+):', r'"\1": ', objref_dict) objref_dict = objref_dict.replace('"', '"') return json.loads(objref_dict)