resulttool/merge: Enable merge results to one file
PATCH 1/1 resulttool/merge: Enable merge results to one file
QA team execute extra testing that create multiple test result files, where these test result files need to be merged into a single file under certain use case.
Enable merge to allow merging results into a single test result file.
--- scripts/lib/resulttool/merge.py | 29 ++++++++++++- scripts/lib/resulttool/resultutils.py | 76 +++++++++++++++++++++++++---------- 2 files changed, 82 insertions(+), 23 deletions(-)
scripts/lib/resulttool/merge.py +27 -2
@@ -17,6 +17,26 @@ import json import resulttool.resultutils as resultutils def merge(args, logger): + if args.merge_to_one: + if os.path.isdir(args.target_results): + target_results = resultutils.load_results(args.target_results) + else: + target_results = resultutils.append_results({}, args.target_results) + if os.path.isdir(args.base_results): + base_results = resultutils.load_results(args.base_results) + results = resultutils.append_results(target_results, base_results) + else: + results = resultutils.append_results(target_results, args.base_results) + + target_file_dir = os.path.join(os.path.dirname(args.target_results), 'merged_results/testresults.json') + if os.path.isdir(args.target_results): + target_file_dir = os.path.join(args.target_results, 'merged_results/testresults.json') + if args.merge_to_one_dir: + target_file_dir = os.path.join(args.merge_to_one_dir, 'testresults.json') + resultutils.make_directory_and_write_json_file(target_file_dir, results) + logger.info('Merged results to %s' % target_file_dir) + return 0 + 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)
@@ -26,7 +46,7 @@ def merge(args, logger): if os.path.exists(args.target_results): resultutils.append_resultsdata(results, args.target_results, configmap=resultutils.flatten_map) 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 +59,9 @@ 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('-o', '--merge-to-one', action='store_true', + help='merge results into one file only, does not add any new configurations to results ' + 'and does not create additional directory structure which based on configurations') + parser_build.add_argument('-d', '--merge-to-one-dir', default='', + help='target directory to merge results into one file, default directory was based on ' + 'target_results directory')
scripts/lib/resulttool/resultutils.py +55 -21
105 lines not on this page · raw message
Signature · 1 line
2.7.4
Quoted 17 lines · Yeoh Ee Peng
QA team execute extra testing that create multiple test result files, where these test result files need to be merged into a single file under certain use case.
Enable merge to allow merging results into a single test result file.
Signed-off-by Yeoh Ee Peng <[email protected]>--- scripts/lib/resulttool/merge.py | 29 ++++++++++++- scripts/lib/resulttool/resultutils.py | 76 +++++++++++++++++++++++++---------- 2 files changed, 82 insertions(+), 23 deletions(-)scripts/lib/resulttool/merge.py +0
-0
scripts/lib/resulttool/merge.py import json · line 24
Quoted 8 lines
scripts/lib/resulttool/merge.py +5
-0@@ -17,6 +17,26 @@ import json import resulttool.resultutils as resultutils def merge(args, logger): + if args.merge_to_one: + if os.path.isdir(args.target_results): + target_results = resultutils.load_results(args.target_results) + else: + target_results = resultutils.append_results({}, args.target_results)
Looking at load_resultsdata:
def load_resultsdata(source, configmap=store_map):
results = {}
if os.path.isfile(source):
append_resultsdata(results, source, configmap) return results
The code above can therefore be simplified to:
target_results = resultutils.load_results(args.target_results)
?
scripts/lib/resulttool/merge.py import json · line 29
Quoted 5 lines
scripts/lib/resulttool/merge.py +5
-0+ if os.path.isdir(args.base_results): + base_results = resultutils.load_results(args.base_results) + results = resultutils.append_results(target_results, base_results) + else: + results = resultutils.append_results(target_results, args.base_results)
Again, I'm not sure you need to differentiate between a file and a directory given the way the code works internally?
scripts/lib/resulttool/merge.py import json · line 38
Quoted 9 lines
scripts/lib/resulttool/merge.py +9
-0+ + target_file_dir = os.path.join(os.path.dirname(args.target_results), 'merged_results/testresults.json') + if os.path.isdir(args.target_results): + target_file_dir = os.path.join(args.target_results, 'merged_results/testresults.json') + if args.merge_to_one_dir: + target_file_dir = os.path.join(args.merge_to_one_dir, 'testresults.json') + resultutils.make_directory_and_write_json_file(target_file_dir, results) + logger.info('Merged results to %s' % target_file_dir) + return 0
Isn't this similar to calling load_resultsdata with the 'flatten' mapping, i.e. resultutils.flatten_map?
That would match the code already in the merge command:
results = resultutils.load_resultsdata(args.base_results, configmap=resultutils.flatten_map)
if os.path.exists(args.target_results):
resultutils.append_resultsdata(results, args.target_results, configmap=resultutils.flatten_map)
resultutils.save_resultsdata(results, os.path.dirname(args.target_results), fn=os.path.basename(args.target_results))
i.e. if you call:
"resulttool merge XXXX merged_results/testresults.json"
it should merge the results from XXXX into the results file specified?
In other words, doesn't the tool already support this?
Cheers,
Richard
Hi RP,
Yes, you are right, I missed the current feature to merge to flat file. Thanks for your inputs and sharing.
After we tested the merge to flat file features, these are our findings.
1) Existing merge could not support use case where both base and target are directory. Traceback (most recent call last):
File "/home/poky/scripts/resulttool", line 93, in <module>
sys.exit(main())
File "/home/poky/scripts/resulttool", line 87, in main
ret = args.func(args, logger)
File "/home/poky/scripts/lib/resulttool/merge.py", line 22, in merge
resultutils.append_resultsdata(results, args.base_results, configmap=resultutils.store_map)
File "/home/poky/scripts/lib/resulttool/resultutils.py", line 47, in append_resultsdata
with open(f, "r") as filedata:
IsADirectoryError: [Errno 21] Is a directory: '<path_to_base_results>'
2) Existing merge will always create testseries configuration where this configuration has important implication to report and regression.
For current QA process, we need the merge to be more flexible where it will allow merge where both base and target are directory, furthermore we need control over when we want to create the testseries configuration.
To fulfill both of these requirements, we tried the below:
Previously the append_resultsdata function only allow append the results data to the map_results data (where map_results data wrapped the results data with configuration map as the key).
Initially, we tried to implement an extra function where it will enable append one map_results to another map_results data. But we abandoned this alternative as this new append function will be pretty much a duplicated function to the original append_resultsdata, and these will create two append functions which they might be both hard to maintain and confusing. Thus, we tried to refactor the append function to enable a single append function to be used for most of the situation. Furthermore, since the map_results were only needed by report and regression, we pulled the instructions used to turn results data to map_results data to another function. Finally, we renamed the functions and arguments to clearly seperated the functions using results data from the one using map_results data.
The new patches are at below:
http://lists.openembedded.org/pipermail/openembedded-core/2019-March/280547.html
http://lists.openembedded.org/pipermail/openembedded-core/2019-March/280548.html
Please let us know if you have any more inputs or questions. Thank you very much for your attention and help!
Best regards,
Yeoh Ee Peng
-----Original Message-----
From: Richard Purdie [mailto:[email protected]]
Sent: Tuesday, March 26, 2019 8:52 PM
To: Yeoh, Ee Peng <[email protected]>; [email protected]
Subject: Re: [OE-core] [PATCH] resulttool/merge: Enable merge results to one file
Quoted 18 lines · Yeoh Ee Peng
QA team execute extra testing that create multiple test result files, where these test result files need to be merged into a single file under certain use case.
Enable merge to allow merging results into a single test result file.
Signed-off-by Yeoh Ee Peng <[email protected]>--- scripts/lib/resulttool/merge.py | 29 ++++++++++++- scripts/lib/resulttool/resultutils.py | 76 +++++++++++++++++++++++++---------- 2 files changed, 82 insertions(+), 23 deletions(-)(quoted diff) +0
-0
b/scripts/lib/resulttool/merge.pyindex 3e4b7a3..90b3cb3 100644
scripts/lib/resulttool/merge.py import json · line 25
Quoted 9 lines
scripts/lib/resulttool/merge.py +6
-0@@ -17,6 +17,26 @@ import json import resulttool.resultutils as resultutils def merge(args, logger): + if args.merge_to_one: + if os.path.isdir(args.target_results): + target_results = resultutils.load_results(args.target_results) + else: + target_results = resultutils.append_results({}, + args.target_results)
Looking at load_resultsdata:
def load_resultsdata(source, configmap=store_map):
results = {}
if os.path.isfile(source):
append_resultsdata(results, source, configmap) return results
The code above can therefore be simplified to:
target_results = resultutils.load_results(args.target_results)
?
scripts/lib/resulttool/merge.py import json
Quoted 6 lines
scripts/lib/resulttool/merge.py +6
-0+ if os.path.isdir(args.base_results): + base_results = resultutils.load_results(args.base_results) + results = resultutils.append_results(target_results, base_results) + else: + results = resultutils.append_results(target_results, + args.base_results)
Again, I'm not sure you need to differentiate between a file and a directory given the way the code works internally?
scripts/lib/resulttool/merge.py import json · line 38
Quoted 9 lines
scripts/lib/resulttool/merge.py +9
-0+ + target_file_dir = os.path.join(os.path.dirname(args.target_results), 'merged_results/testresults.json') + if os.path.isdir(args.target_results): + target_file_dir = os.path.join(args.target_results, 'merged_results/testresults.json') + if args.merge_to_one_dir: + target_file_dir = os.path.join(args.merge_to_one_dir, 'testresults.json') + resultutils.make_directory_and_write_json_file(target_file_dir, results) + logger.info('Merged results to %s' % target_file_dir) + return 0
Isn't this similar to calling load_resultsdata with the 'flatten' mapping, i.e. resultutils.flatten_map?
That would match the code already in the merge command:
results = resultutils.load_resultsdata(args.base_results, configmap=resultutils.flatten_map)
if os.path.exists(args.target_results):
resultutils.append_resultsdata(results, args.target_results, configmap=resultutils.flatten_map)
resultutils.save_resultsdata(results, os.path.dirname(args.target_results), fn=os.path.basename(args.target_results))
i.e. if you call:
"resulttool merge XXXX merged_results/testresults.json"
it should merge the results from XXXX into the results file specified?
In other words, doesn't the tool already support this?
Cheers,
Richard