Write exceptions to file 28/72328/6
authorSam Hague <shague@redhat.com>
Fri, 25 May 2018 18:17:06 +0000 (14:17 -0400)
committerJamo Luhrsen <jluhrsen@redhat.com>
Fri, 1 Jun 2018 20:42:55 +0000 (20:42 +0000)
Change-Id: Ic62ed4abea609f04564ec1f1011daf839e33c617
Signed-off-by: Sam Hague <shague@redhat.com>
csit/libraries/KarafKeywords.robot
csit/libraries/netvirt/excepts.py

index cece9c4490cc4594dbf90cc6d6f55239e0549004..749470b7d8b68ed6b93cd30ae622405d5f1b66f1 100644 (file)
@@ -247,6 +247,7 @@ Fail If Exceptions Found During Test
     \    ${cmd} =    Set Variable    sed '1,/ROBOT MESSAGE: Starting test ${test_name}/d' ${log_file}
     \    ${output} =    Get Karaf Log Lines From Test Start    ${ODL_SYSTEM_${i}_IP}    ${test_name}    ${cmd}
     \    ${exlist} =    Get and Verify Exceptions    ${output}
+    \    Write Exceptions Map To File    ${SUITE_NAME}.${TEST_NAME}    /tmp/odl${i}_exceptions.txt
     \    ${listlength} =    BuiltIn.Get Length    ${exlist}
     \    BuiltIn.Run Keyword If    ${listlength} != 0    BuiltIn.Fail    New exceptions found: ${listlength}
 
index 092f2b7005e5badf1d8ebbc3aa084a69feeb8dca..98859bf94090e4d905ced3c6663fdfac2d007649 100644 (file)
@@ -1,5 +1,7 @@
 import collections
+import errno
 import logging
+import os
 import re
 
 # Make sure to have unique matches in different lines
@@ -156,7 +158,7 @@ def get_exceptions(lines):
     The lines are parsed to create a list where all lines related to a timestamp
     are aggregated. Timestamped lines with exception (case insensitive) are copied
     to the exception map keyed to the index of the timestamp line. Each exception value
-    also has a 3 element list containing the last three WARN and ERROR lines.
+    also has a list containing WARN and ERROR lines proceeding the exception.
 
     :param list lines:
     :return OrderedDict _ex_map: map of exceptions
@@ -243,3 +245,32 @@ def verify_exceptions(lines):
         return
     get_exceptions(lines)
     return check_exceptions()
+
+
+def write_exceptions_map_to_file(testname, filename, mode="a+"):
+    """
+    Write the exceptions map to a file under the testname header. The output
+    will include all lines in the exception itself as well as any previous
+    contextual warning or error lines. The output will be appended or overwritten
+    depending on the mode parameter. It is assumed that the caller has called
+    verify_exceptions() earlier to populate the exceptions map, otherwise only
+    the testname and header will be printed to the file.
+
+    :param str testname: The name of the test
+    :param str filename: The file to open for writing
+    :param str mode: Append (a+) or overwrite (w+)
+    """
+    try:
+        os.makedirs(os.path.dirname(filename))
+    except OSError as exception:
+        if exception.errno != errno.EEXIST:
+            raise
+
+    with open(filename, mode) as fp:
+        fp.write("Starting test: {}\n".format(testname))
+        fp.write("{}\n".format("-" * 40))
+        for ex_idx, ex in _ex_map.items():
+            for exwe_index in ex.get("warnerr_list"):
+                for line in _ts_list[exwe_index]:
+                    fp.write(line)
+            fp.writelines(ex.get("lines"))