Skip to contentSkip to conversation

resulttool/merge: enhance merge and control testseries

PATCH New Yeoh Ee Peng 1 participant 4 messages Apr 4, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 resulttool/merge: enhance merge and control testseries

v01:
Enable merging results where both base and target are directory.

v02:
Follow suggestion from RP to reused the existing resultutils code base where it will merge results to flat file. Refactor resultutils code base to enable merging results where both base and target are directory. Add control for creation of testseries configuration.

v03:
Follow suggestion from RP to breakdown the patches to ease reviewing. Enable resultutils library to control the adding of "TESTSERIES" configuration as well as allow adding extra configurations when needed. Enable store to add "EXECUTED_BY" configuration to track who executed each results file.
Enable merge to control the adding of "TESTSERIES" configuration as well as allow adding "EXECUTED_BY" configuration when needed.

Yeoh Ee Peng (3):
resulttool/resultutils: Enable add extra configurations to results resulttool/store: Enable add EXECUTED_BY config to results resulttool/merge: Enable control TESTSERIES and extra configurations

 scripts/lib/resulttool/merge.py       | 20 ++++++++++++++------
 scripts/lib/resulttool/resultutils.py | 19 ++++++++++++-------
 scripts/lib/resulttool/store.py       |  7 ++++++-
 3 files changed, 32 insertions(+), 14 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/3 resulttool/resultutils: Enable add extra configurations to results

Current resultutils library always add "TESTSERIES" configuration to results. Enhance this to allow control of adding "TESTSERIES" configuration as well as allow adding extra configurations when needed.

---
 scripts/lib/resulttool/resultutils.py | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
scripts/lib/resulttool/resultutils.py +12 -7
index 153f2b8..bfbd381 100644
@@ -39,10 +39,12 @@ store_map = {
     "manual": ['TEST_TYPE', 'TEST_MODULE', 'MACHINE', 'IMAGE_BASENAME']
 }
 
+extra_configs = {'TESTSERIES': ''}
+
 #
 # Load the json file and append the results data into the provided results dict
 #
-def append_resultsdata(results, f, configmap=store_map):
+def append_resultsdata(results, f, configmap=store_map, configs=extra_configs):
     if type(f) is str:
         with open(f, "r") as filedata:
             data = json.load(filedata)
@@ -51,12 +53,15 @@ def append_resultsdata(results, f, configmap=store_map):
     for res in data:
         if "configuration" not in data[res] or "result" not in data[res]:
             raise ValueError("Test results data without configuration or result section?")
-        if "TESTSERIES" not in data[res]["configuration"]:
-            data[res]["configuration"]["TESTSERIES"] = os.path.basename(os.path.dirname(f))
+        for config in configs:
+            if config == "TESTSERIES" and "TESTSERIES" not in data[res]["configuration"]:
+                data[res]["configuration"]["TESTSERIES"] = os.path.basename(os.path.dirname(f))
+                continue
+            if config not in data[res]["configuration"]:
+                data[res]["configuration"][config] = configs[config]
         testtype = data[res]["configuration"].get("TEST_TYPE")
         if testtype not in configmap:
             raise ValueError("Unknown test type %s" % testtype)
-        configvars = configmap[testtype]
         testpath = "/".join(data[res]["configuration"].get(i) for i in configmap[testtype])
         if testpath not in results:
             results[testpath] = {}
@@ -72,16 +77,16 @@ def append_resultsdata(results, f, configmap=store_map):
 # Walk a directory and find/load results data
 # or load directly from a file
 #
-def load_resultsdata(source, configmap=store_map):
+def load_resultsdata(source, configmap=store_map, configs=extra_configs):
     results = {}
     if os.path.isfile(source):
-        append_resultsdata(results, source, configmap)
+        append_resultsdata(results, source, configmap, configs)
         return results
     for root, dirs, files in os.walk(source):
         for name in files:
             f = os.path.join(root, name)
             if name == "testresults.json":
-                append_resultsdata(results, f, configmap)
+                append_resultsdata(results, f, configmap, configs)
     return results
 
 def filter_resultsdata(results, resultid):
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/3 resulttool/store: Enable add EXECUTED_BY config to results

In reply to Yeoh Ee Peng

Current results stored does not have information needed to trace who executed the tests. Enable store to add EXECUTED_BY configuration to results file in order to track who executed the tests.

---
 scripts/lib/resulttool/store.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
scripts/lib/resulttool/store.py +6 -1
index 5e33716..7e89692 100644
@@ -27,13 +27,16 @@ import oeqa.utils.gitarchive as gitarchive
 def store(args, logger):
     tempdir = tempfile.mkdtemp(prefix='testresults.')
     try:
+        configs = resultutils.extra_configs.copy()
+        if args.executed_by:
+            configs['EXECUTED_BY'] = args.executed_by
         results = {}
         logger.info('Reading files from %s' % args.source)
         for root, dirs,  files in os.walk(args.source):
             for name in files:
                 f = os.path.join(root, name)
                 if name == "testresults.json":
-                    resultutils.append_resultsdata(results, f)
+                    resultutils.append_resultsdata(results, f, configs=configs)
                 elif args.all:
                     dst = f.replace(args.source, tempdir + "/")
                     os.makedirs(os.path.dirname(dst), exist_ok=True)
@@ -96,4 +99,6 @@ def register_commands(subparsers):
                               help='include all files, not just testresults.json files')
     parser_build.add_argument('-e', '--allow-empty', action='store_true',
                               help='don\'t error if no results to store are found')
+    parser_build.add_argument('-x', '--executed-by', default='',
+                              help='add executed-by configuration to each result file')
 
Signature · 1 line
2.7.4
#3 lore raw

PATCH 3/3 resulttool/merge: Enable control TESTSERIES and extra configurations

In reply to Yeoh Ee Peng

Current QA team need to merge test result files from multiple sources. Adding TESTSERIES configuration too early will have negative implication to report and regression. Enable control to add TESTSERIES when needed. Also enable adding EXECUTED_BY configuration when needed.

---
 scripts/lib/resulttool/merge.py | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
scripts/lib/resulttool/merge.py +14 -6
index 3e4b7a3..d40a72d 100644
@@ -17,16 +17,21 @@ import json
 import resulttool.resultutils as resultutils
 
 def merge(args, logger):
+    configs = {}
+    if not args.not_add_testseries:
+        configs = resultutils.extra_configs.copy()
+    if args.executed_by:
+        configs['EXECUTED_BY'] = args.executed_by
     if os.path.isdir(args.target_results):
-        results = resultutils.load_resultsdata(args.target_results, configmap=resultutils.store_map)
-        resultutils.append_resultsdata(results, args.base_results, configmap=resultutils.store_map)
+        results = resultutils.load_resultsdata(args.target_results, configmap=resultutils.store_map, configs=configs)
+        resultutils.append_resultsdata(results, args.base_results, configmap=resultutils.store_map, configs=configs)
         resultutils.save_resultsdata(results, args.target_results)
     else:
-        results = resultutils.load_resultsdata(args.base_results, configmap=resultutils.flatten_map)
+        results = resultutils.load_resultsdata(args.base_results, configmap=resultutils.flatten_map, configs=configs)
         if os.path.exists(args.target_results):
-            resultutils.append_resultsdata(results, args.target_results, configmap=resultutils.flatten_map)
+            resultutils.append_resultsdata(results, args.target_results, configmap=resultutils.flatten_map, configs=configs)
         resultutils.save_resultsdata(results, os.path.dirname(args.target_results), fn=os.path.basename(args.target_results))
-
+    logger.info('Merged results to %s' % os.path.dirname(args.target_results))
     return 0
 
 def register_commands(subparsers):
@@ -39,4 +44,7 @@ def register_commands(subparsers):
                               help='the results file/directory to import')
     parser_build.add_argument('target_results',
                               help='the target file or directory to merge the base_results with')
-
+    parser_build.add_argument('-t', '--not-add-testseries', action='store_true',
+                              help='do not add testseries configuration to results')
+    parser_build.add_argument('-x', '--executed-by', default='',
+                              help='add executed-by configuration to each result file')
Signature · 1 line
2.7.4