diff options
Diffstat (limited to 'meta/lib/oeqa/utils/postactions.py')
-rw-r--r-- | meta/lib/oeqa/utils/postactions.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/meta/lib/oeqa/utils/postactions.py b/meta/lib/oeqa/utils/postactions.py new file mode 100644 index 0000000000..09c338ef68 --- /dev/null +++ b/meta/lib/oeqa/utils/postactions.py | |||
@@ -0,0 +1,68 @@ | |||
1 | # | ||
2 | # Copyright OpenEmbedded Contributors | ||
3 | # | ||
4 | # SPDX-License-Identifier: MIT | ||
5 | # | ||
6 | |||
7 | # Run a set of actions after tests. The runner provides internal data | ||
8 | # dictionary as well as test context to any action to run. | ||
9 | |||
10 | from oeqa.utils import get_json_result_dir | ||
11 | |||
12 | ################################################################## | ||
13 | # Artifacts retrieval | ||
14 | ################################################################## | ||
15 | |||
16 | def get_artifacts_list(target, raw_list): | ||
17 | result = [] | ||
18 | # Passed list may contains patterns in paths, expand them directly on target | ||
19 | for raw_path in raw_list.split(): | ||
20 | cmd = f"for p in {raw_path}; do if [ -e $p ]; then echo $p; fi; done" | ||
21 | try: | ||
22 | status, output = target.run(cmd) | ||
23 | if status != 0 or not output: | ||
24 | raise Exception() | ||
25 | result += output.split() | ||
26 | except: | ||
27 | bb.note(f"No file/directory matching path {raw_path}") | ||
28 | |||
29 | return result | ||
30 | |||
31 | def retrieve_test_artifacts(target, artifacts_list, target_dir): | ||
32 | import shutil | ||
33 | |||
34 | local_artifacts_dir = os.path.join(target_dir, "artifacts") | ||
35 | if os.path.isdir(local_artifacts_dir): | ||
36 | shutil.rmtree(local_artifacts_dir) | ||
37 | |||
38 | os.makedirs(local_artifacts_dir) | ||
39 | for artifact_path in artifacts_list: | ||
40 | if not os.path.isabs(artifact_path): | ||
41 | bb.warn(f"{artifact_path} is not an absolute path") | ||
42 | continue | ||
43 | try: | ||
44 | dest_dir = os.path.join(local_artifacts_dir, os.path.dirname(artifact_path[1:])) | ||
45 | os.makedirs(dest_dir, exist_ok=True) | ||
46 | target.copyFrom(artifact_path, dest_dir) | ||
47 | except Exception as e: | ||
48 | bb.warn(f"Can not retrieve {artifact_path} from test target: {e}") | ||
49 | |||
50 | def list_and_fetch_failed_tests_artifacts(d, tc): | ||
51 | artifacts_list = get_artifacts_list(tc.target, d.getVar("TESTIMAGE_FAILED_QA_ARTIFACTS")) | ||
52 | if not artifacts_list: | ||
53 | bb.warn("Could not load artifacts list, skip artifacts retrieval") | ||
54 | else: | ||
55 | retrieve_test_artifacts(tc.target, artifacts_list, get_json_result_dir(d)) | ||
56 | |||
57 | |||
58 | ################################################################## | ||
59 | # General post actions runner | ||
60 | ################################################################## | ||
61 | |||
62 | def run_failed_tests_post_actions(d, tc): | ||
63 | post_actions=[ | ||
64 | list_and_fetch_failed_tests_artifacts | ||
65 | ] | ||
66 | |||
67 | for action in post_actions: | ||
68 | action(d, tc) | ||