resulttool improvements
cover resulttool improvements
Implements 2 improvements to resulttool:
1) Result files can be loaded over http or https
2) Adds a new subcommand to extract logs from result data
Joshua Watt (2):
resulttool: Load results from URL
resulttool: Add log subcommand
scripts/lib/resulttool/log.py | 56 +++++++++++++++++++++++++++ scripts/lib/resulttool/merge.py | 8 ++-- scripts/lib/resulttool/regression.py | 6 +-- scripts/lib/resulttool/report.py | 2 +- scripts/lib/resulttool/resultutils.py | 23 +++++++++-- scripts/lib/resulttool/store.py | 4 +- scripts/resulttool | 2 + 7 files changed, 87 insertions(+), 14 deletions(-) create mode 100644 scripts/lib/resulttool/log.py
Signature · 1 line
2.20.1
PATCH 1/2 resulttool: Load results from URL
Adds support for resulttool to load JSON files directly from a http://
or https:// URL
--- scripts/lib/resulttool/merge.py | 8 ++++---- scripts/lib/resulttool/regression.py | 4 ++-- scripts/lib/resulttool/report.py | 2 +- scripts/lib/resulttool/resultutils.py | 23 +++++++++++++++++++---- scripts/lib/resulttool/store.py | 4 ++-- 5 files changed, 28 insertions(+), 13 deletions(-)
scripts/lib/resulttool/merge.py +4 -4
@@ -17,7 +17,7 @@ import json import resulttool.resultutils as resultutils def merge(args, logger): - if os.path.isdir(args.target_results): + if resultutils.is_url(args.target_results) or 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) resultutils.save_resultsdata(results, args.target_results)
@@ -31,12 +31,12 @@ def merge(args, logger): def register_commands(subparsers): """Register subcommands from this plugin""" - parser_build = subparsers.add_parser('merge', help='merge test result files/directories', - description='merge the results from multiple files/directories into the target file or directory', + parser_build = subparsers.add_parser('merge', help='merge test result files/directories/URLs', + description='merge the results from multiple files/directories/URLs into the target file or directory', group='setup') parser_build.set_defaults(func=merge) parser_build.add_argument('base_results', - help='the results file/directory to import') + help='the results file/directory/URL to import') parser_build.add_argument('target_results', help='the target file or directory to merge the base_results with')
scripts/lib/resulttool/regression.py +2 -2
@@ -161,9 +161,9 @@ def register_commands(subparsers): group='analysis') parser_build.set_defaults(func=regression) parser_build.add_argument('base_result', - help='base result file/directory for the comparison') + help='base result file/directory/URL for the comparison') parser_build.add_argument('target_result', - help='target result file/directory to compare with') + help='target result file/directory/URL to compare with') parser_build.add_argument('-b', '--base-result-id', default='', help='(optional) filter the base results to this result ID') parser_build.add_argument('-t', '--target-result-id', default='',
scripts/lib/resulttool/report.py +1 -1
@@ -143,7 +143,7 @@ def register_commands(subparsers): group='analysis') parser_build.set_defaults(func=report) parser_build.add_argument('source_dir', - help='source file/directory that contain the test result files to summarise') + help='source file/directory/URL that contain the test result files to summarise') parser_build.add_argument('--branch', '-B', default='master', help="Branch to find commit in") parser_build.add_argument('--commit', help="Revision to report") parser_build.add_argument('-t', '--tag', default='',
scripts/lib/resulttool/resultutils.py +19 -4
@@ -16,6 +16,8 @@ import os import json import scriptpath import copy +import urllib +import posixpath scriptpath.add_oe_lib_path() flatten_map = {
@@ -40,20 +42,33 @@ store_map = { "manual": ['TEST_TYPE', 'TEST_MODULE', 'MACHINE', 'IMAGE_BASENAME'] } +def is_url(p): + """ + Helper for determining if the given path is a URL + """ + return p.startswith('http://') or p.startswith('https://') + # # Load the json file and append the results data into the provided results dict # def append_resultsdata(results, f, configmap=store_map): if type(f) is str: - with open(f, "r") as filedata: - data = json.load(filedata) + if is_url(f): + with urllib.request.urlopen(f) as response: + data = json.loads(response.read().decode('utf-8')) + url = urllib.parse.urlparse(f) + testseries = posixpath.basename(posixpath.dirname(url.path)) + else: + with open(f, "r") as filedata: + data = json.load(filedata) + testseries = os.path.basename(os.path.dirname(f)) else: data = f 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)) + data[res]["configuration"]["TESTSERIES"] = testseries testtype = data[res]["configuration"].get("TEST_TYPE") if testtype not in configmap: raise ValueError("Unknown test type %s" % testtype)
@@ -69,7 +84,7 @@ def append_resultsdata(results, f, configmap=store_map): # def load_resultsdata(source, configmap=store_map): results = {} - if os.path.isfile(source): + if is_url(source) or os.path.isfile(source): append_resultsdata(results, source, configmap) return results for root, dirs, files in os.walk(source):
scripts/lib/resulttool/store.py +2 -2
@@ -29,7 +29,7 @@ def store(args, logger): try: results = {} logger.info('Reading files from %s' % args.source) - if os.path.isfile(args.source): + if resultutils.is_url(args.source) or os.path.isfile(args.source): resultutils.append_resultsdata(results, args.source) else: for root, dirs, files in os.walk(args.source):
@@ -92,7 +92,7 @@ def register_commands(subparsers): group='setup') parser_build.set_defaults(func=store) parser_build.add_argument('source', - help='source file or directory that contain the test result files to be stored') + help='source file/directory/URL that contain the test result files to be stored') parser_build.add_argument('git_dir', help='the location of the git repository to store the results in') parser_build.add_argument('-a', '--all', action='store_true',
Signature · 1 line
2.20.1
PATCH 2/2 resulttool: Add log subcommand
In reply to Joshua WattAdds a subcommand for dumping various logs from test results
--- scripts/lib/resulttool/log.py | 56 ++++++++++++++++++++++++++++ scripts/lib/resulttool/regression.py | 2 +- scripts/resulttool | 2 + 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 scripts/lib/resulttool/log.py
scripts/lib/resulttool/log.py new file +56 -0
@@ -0,0 +1,56 @@ +# resulttool - Show logs +# +# Copyright (c) 2019 Garmin International +# +# This program is free software; you can redistribute it and/or modify it +# under the terms and conditions of the GNU General Public License, +# version 2, as published by the Free Software Foundation. +# +# This program is distributed in the hope it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +import resulttool.resultutils as resultutils + +def show_ptest(result, ptest, logger): + if 'ptestresult.sections' in result: + if ptest in result['ptestresult.sections'] and 'log' in result['ptestresult.sections'][ptest]: + print(result['ptestresult.sections'][ptest]['log']) + return 0 + + print("ptest '%s' not found" % ptest) + return 1 + +def log(args, logger): + results = resultutils.load_resultsdata(args.source) + for path in results: + for res in results[path]: + if 'result' not in results[path][res]: + continue + r = results[path][res]['result'] + + if args.raw: + if 'ptestresult.rawlogs' in r: + print(r['ptestresult.rawlogs']['log']) + else: + print('Raw logs not found') + return 1 + + for ptest in args.ptest: + if not show_ptest(r, ptest, logger): + return 1 + +def register_commands(subparsers): + """Register subcommands from this plugin""" + parser = subparsers.add_parser('log', help='show logs', + description='show the logs from test results', + group='analysis') + parser.set_defaults(func=log) + parser.add_argument('source', + help='the results file/directory/URL to import') + parser.add_argument('--ptest', action='append', default=[], + help='show logs for a ptest') + parser.add_argument('--raw', action='store_true', + help='show raw logs') +
scripts/lib/resulttool/regression.py +1 -1
@@ -64,7 +64,7 @@ def regression_common(args, logger, base_results, target_results): if a in target_results: base = list(base_results[a].keys()) target = list(target_results[a].keys()) - # We may have multiple base/targets which are for different configurations. Start by + # We may have multiple base/targets which are for different configurations. Start by # removing any pairs which match for c in base.copy(): for b in target.copy():
scripts/resulttool +2 -0
@@ -49,6 +49,7 @@ import resulttool.store import resulttool.regression import resulttool.report import resulttool.manualexecution +import resulttool.log logger = scriptutils.logger_create('resulttool') def main():
@@ -66,6 +67,7 @@ def main(): subparsers.add_subparser_group('analysis', 'analysis', 100) resulttool.regression.register_commands(subparsers) resulttool.report.register_commands(subparsers) + resulttool.log.register_commands(subparsers) args = parser.parse_args() if args.debug:
Signature · 1 line
2.20.1
Re: [PATCH 2/2] resulttool: Add log subcommand
Quoted 77 lines · Joshua Watt
Adds a subcommand for dumping various logs from test results
Signed-off-by Joshua Watt <[email protected]>--- scripts/lib/resulttool/log.py | 56 ++++++++++++++++++++++++++++ scripts/lib/resulttool/regression.py | 2 +- scripts/resulttool | 2 + 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 scripts/lib/resulttool/log.pyscripts/lib/resulttool/log.py new file +56
-0@@ -0,0 +1,56 @@ +# resulttool - Show logs +# +# Copyright (c) 2019 Garmin International +# +# This program is free software; you can redistribute it and/or modify it +# under the terms and conditions of the GNU General Public License, +# version 2, as published by the Free Software Foundation. +# +# This program is distributed in the hope it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +import resulttool.resultutils as resultutils + +def show_ptest(result, ptest, logger): + if 'ptestresult.sections' in result: + if ptest in result['ptestresult.sections'] and 'log' in result['ptestresult.sections'][ptest]: + print(result['ptestresult.sections'][ptest]['log']) + return 0 + + print("ptest '%s' not found" % ptest) + return 1 + +def log(args, logger): + results = resultutils.load_resultsdata(args.source) + for path in results: + for res in results[path]: + if 'result' not in results[path][res]: + continue + r = results[path][res]['result'] + + if args.raw: + if 'ptestresult.rawlogs' in r: + print(r['ptestresult.rawlogs']['log']) + else: + print('Raw logs not found') + return 1 + + for ptest in args.ptest: + if not show_ptest(r, ptest, logger): + return 1 + +def register_commands(subparsers): + """Register subcommands from this plugin""" + parser = subparsers.add_parser('log', help='show logs', + description='show the logs from test results', + group='analysis') + parser.set_defaults(func=log) + parser.add_argument('source', + help='the results file/directory/URL to import') + parser.add_argument('--ptest', action='append', default=[], + help='show logs for a ptest') + parser.add_argument('--raw', action='store_true', + help='show raw logs') +scripts/lib/resulttool/regression.py +0
-0
scripts/lib/resulttool/regression.py def regression_common(args, logger, base_results, target_results): · line 67
Quoted 5 lines
scripts/lib/resulttool/regression.py +1
-1@@ -64,7 +64,7 @@ def regression_common(args, logger, base_results, target_results): if a in target_results: base = list(base_results[a].keys()) target = list(target_results[a].keys()) - # We may have multiple base/targets which are for different configurations. Start by + # We may have multiple base/targets which are for different configurations. Start by
This change looks the same to me so what am I missing?
- Armin
Quoted 23 lines
scripts/lib/resulttool/regression.py +0
-0# removing any pairs which match for c in base.copy(): for b in target.copy():scripts/resulttool +2
-0@@ -49,6 +49,7 @@ import resulttool.store import resulttool.regression import resulttool.report import resulttool.manualexecution +import resulttool.log logger = scriptutils.logger_create('resulttool') def main():@@ -66,6 +67,7 @@ def main(): subparsers.add_subparser_group('analysis', 'analysis', 100) resulttool.regression.register_commands(subparsers) resulttool.report.register_commands(subparsers) + resulttool.log.register_commands(subparsers) args = parser.parse_args() if args.debug:
Re: [PATCH 2/2] resulttool: Add log subcommand
Quoted 87 lines · On Fri, Apr 19, 2019, 12:05 AM akuster808 <[email protected]> wrote:
Review
Quoted 11 lines · Joshua Watt
Adds a subcommand for dumping various logs from test results
Signed-off-by Joshua Watt <[email protected]>--- scripts/lib/resulttool/log.py | 56 ++++++++++++++++++++++++++++ scripts/lib/resulttool/regression.py | 2 +- scripts/resulttool | 2 + 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 scripts/lib/resulttool/log.py(quoted diff) +0
-0
b/scripts/lib/resulttool/log.pyscripts/lib/resulttool/log.py line 5
Quoted 10 lines
new file mode 100644
index 00000000000..5584f2d0a99scripts/lib/resulttool/log.py new file +5
-0@@ -0,0 +1,56 @@ +# resulttool - Show logs +# +# Copyright (c) 2019 Garmin International +# +# This program is free software; you can redistribute it and/or modifyit
scripts/lib/resulttool/log.py
Quoted 6 lines
scripts/lib/resulttool/log.py new file +6
-0+# under the terms and conditions of the GNU General Public License, +# version 2, as published by the Free Software Foundation. +# +# This program is distributed in the hope it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public Licensefor
scripts/lib/resulttool/log.py
Quoted 7 lines
scripts/lib/resulttool/log.py new file +7
-0+# more details. +# +import resulttool.resultutils as resultutils + +def show_ptest(result, ptest, logger): + if 'ptestresult.sections' in result: + if ptest in result['ptestresult.sections'] and 'log' inresult['ptestresult.sections'][ptest]:
Quoted 19 lines
scripts/lib/resulttool/log.py new file +19
-0+ print(result['ptestresult.sections'][ptest]['log']) + return 0 + + print("ptest '%s' not found" % ptest) + return 1 + +def log(args, logger): + results = resultutils.load_resultsdata(args.source) + for path in results: + for res in results[path]: + if 'result' not in results[path][res]: + continue + r = results[path][res]['result'] + + if args.raw: + if 'ptestresult.rawlogs' in r: + print(r['ptestresult.rawlogs']['log']) + else: + print('Raw logs not found')scripts/lib/resulttool/log.py
Quoted 10 lines
scripts/lib/resulttool/log.py new file +10
-0+ return 1 + + for ptest in args.ptest: + if not show_ptest(r, ptest, logger): + return 1 + +def register_commands(subparsers): + """Register subcommands from this plugin""" + parser = subparsers.add_parser('log', help='show logs', + description='show the logsfrom test results',
Review
Quoted 10 lines
scripts/lib/resulttool/log.py new file +9
-0+ group='analysis') + parser.set_defaults(func=log) + parser.add_argument('source', + help='the results file/directory/URL to import') + parser.add_argument('--ptest', action='append', default=[], + help='show logs for a ptest') + parser.add_argument('--raw', action='store_true', + help='show raw logs') +(quoted diff) +0
-0
b/scripts/lib/resulttool/regression.pyscripts/lib/resulttool/regression.py def regression_common(args, logger, base_results,
Quoted 4 lines
index
aecb9da9ce5..fa90ab1e522100644scripts/lib/resulttool/regression.py +0
-0@@ -64,7 +64,7 @@ def regression_common(args, logger, base_results,
target_results):
Quoted 9 lines
scripts/lib/resulttool/regression.py def regression_common(args, logger, base_results, target_results):
Quoted 4 lines
scripts/lib/resulttool/regression.py +0
-1if a in target_results: base = list(base_results[a].keys()) target = list(target_results[a].keys()) - # We may have multiple base/targets which are for differentconfigurations. Start by
scripts/lib/resulttool/regression.py def regression_common(args, logger, base_results, · line 67
Quoted 1 line
scripts/lib/resulttool/regression.py +1
-0+ # We may have multiple base/targets which are for differentconfigurations. Start by
This change looks the same to me so what am I missing?
It stripped off trailing whitespace and I missed removing it when staging.
- Armin
Quoted 26 lines
Quoted 23 lines
scripts/lib/resulttool/regression.py +0
-0# removing any pairs which match for c in base.copy(): for b in target.copy():scripts/resulttool +2
-0@@ -49,6 +49,7 @@ import resulttool.store import resulttool.regression import resulttool.report import resulttool.manualexecution +import resulttool.log logger = scriptutils.logger_create('resulttool') def main():@@ -66,6 +67,7 @@ def main(): subparsers.add_subparser_group('analysis', 'analysis', 100) resulttool.regression.register_commands(subparsers) resulttool.report.register_commands(subparsers) + resulttool.log.register_commands(subparsers) args = parser.parse_args() if args.debug: