summaryrefslogtreecommitdiffstats
path: root/scripts/lib/resulttool/store.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/resulttool/store.py')
-rw-r--r--scripts/lib/resulttool/store.py125
1 files changed, 0 insertions, 125 deletions
diff --git a/scripts/lib/resulttool/store.py b/scripts/lib/resulttool/store.py
deleted file mode 100644
index b143334e69..0000000000
--- a/scripts/lib/resulttool/store.py
+++ /dev/null
@@ -1,125 +0,0 @@
1# resulttool - store test results
2#
3# Copyright (c) 2019, Intel Corporation.
4# Copyright (c) 2019, Linux Foundation
5#
6# SPDX-License-Identifier: GPL-2.0-only
7#
8
9import tempfile
10import os
11import subprocess
12import json
13import shutil
14import scriptpath
15scriptpath.add_bitbake_lib_path()
16scriptpath.add_oe_lib_path()
17import resulttool.resultutils as resultutils
18import oeqa.utils.gitarchive as gitarchive
19
20
21def store(args, logger):
22 tempdir = tempfile.mkdtemp(prefix='testresults.')
23 try:
24 configvars = resultutils.extra_configvars.copy()
25 if args.executed_by:
26 configvars['EXECUTED_BY'] = args.executed_by
27 if args.extra_test_env:
28 configvars['EXTRA_TEST_ENV'] = args.extra_test_env
29 results = {}
30 logger.info('Reading files from %s' % args.source)
31 if resultutils.is_url(args.source) or os.path.isfile(args.source):
32 resultutils.append_resultsdata(results, args.source, configvars=configvars)
33 else:
34 for root, dirs, files in os.walk(args.source):
35 for name in files:
36 f = os.path.join(root, name)
37 if name == "testresults.json":
38 resultutils.append_resultsdata(results, f, configvars=configvars)
39 elif args.all:
40 dst = f.replace(args.source, tempdir + "/")
41 os.makedirs(os.path.dirname(dst), exist_ok=True)
42 shutil.copyfile(f, dst)
43
44 revisions = {}
45
46 if not results and not args.all:
47 if args.allow_empty:
48 logger.info("No results found to store")
49 return 0
50 logger.error("No results found to store")
51 return 1
52
53 # Find the branch/commit/commit_count and ensure they all match
54 for suite in results:
55 for result in results[suite]:
56 config = results[suite][result]['configuration']['LAYERS']['meta']
57 revision = (config['commit'], config['branch'], str(config['commit_count']))
58 if revision not in revisions:
59 revisions[revision] = {}
60 if suite not in revisions[revision]:
61 revisions[revision][suite] = {}
62 revisions[revision][suite][result] = results[suite][result]
63
64 logger.info("Found %d revisions to store" % len(revisions))
65
66 for r in revisions:
67 results = revisions[r]
68 if args.revision and r[0] != args.revision:
69 logger.info('skipping %s as non-matching' % r[0])
70 continue
71 keywords = {'commit': r[0], 'branch': r[1], "commit_count": r[2]}
72 subprocess.check_call(["find", tempdir, "-name", "testresults.json", "!", "-path", "./.git/*", "-delete"])
73 resultutils.save_resultsdata(results, tempdir, ptestlogs=True)
74
75 logger.info('Storing test result into git repository %s' % args.git_dir)
76
77 excludes = []
78 if args.logfile_archive:
79 excludes = ['*.log', "*.log.zst"]
80
81 tagname = gitarchive.gitarchive(tempdir, args.git_dir, False, False,
82 "Results of {branch}:{commit}", "branch: {branch}\ncommit: {commit}", "{branch}",
83 False, "{branch}/{commit_count}-g{commit}/{tag_number}",
84 'Test run #{tag_number} of {branch}:{commit}', '',
85 excludes, [], False, keywords, logger)
86
87 if args.logfile_archive:
88 logdir = args.logfile_archive + "/" + tagname
89 shutil.copytree(tempdir, logdir)
90 os.chmod(logdir, 0o755)
91 for root, dirs, files in os.walk(logdir):
92 for name in files:
93 if not name.endswith(".log"):
94 continue
95 f = os.path.join(root, name)
96 subprocess.run(["zstd", f, "--rm"], check=True, capture_output=True)
97 finally:
98 subprocess.check_call(["rm", "-rf", tempdir])
99
100 return 0
101
102def register_commands(subparsers):
103 """Register subcommands from this plugin"""
104 parser_build = subparsers.add_parser('store', help='store test results into a git repository',
105 description='takes a results file or directory of results files and stores '
106 'them into the destination git repository, splitting out the results '
107 'files as configured',
108 group='setup')
109 parser_build.set_defaults(func=store)
110 parser_build.add_argument('source',
111 help='source file/directory/URL that contain the test result files to be stored')
112 parser_build.add_argument('git_dir',
113 help='the location of the git repository to store the results in')
114 parser_build.add_argument('-a', '--all', action='store_true',
115 help='include all files, not just testresults.json files')
116 parser_build.add_argument('-e', '--allow-empty', action='store_true',
117 help='don\'t error if no results to store are found')
118 parser_build.add_argument('-x', '--executed-by', default='',
119 help='add executed-by configuration to each result file')
120 parser_build.add_argument('-t', '--extra-test-env', default='',
121 help='add extra test environment data to each result file configuration')
122 parser_build.add_argument('-r', '--revision', default='',
123 help='only store data for the specified revision')
124 parser_build.add_argument('-l', '--logfile-archive', default='',
125 help='directory to separately archive log files along with a copy of the results')