1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-30 12:29:55 +00:00

oeqa/postactions: Separate artefact collection from test result collection

Combining the test result collection and artefact collection hasn't worked out
well as the data has different life cycles, the artefacts can be large and
we need to be able to clean them up on a different timescale.

Separate them out to be controlled by a separate variable, OEQA_ARTEFACT_DIR.
Also rework the code to inject a directory with a date/time and random component
to allow builds to run in parallel. Pass function arguments to avoid re-reading
variables.

(From OE-Core rev: e1cf7e94c3fcbe7dbc29e4286f0e1014b95964a9)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie
2024-07-17 14:29:20 +01:00
parent 00bb1202d2
commit fdcaf1cce9
2 changed files with 36 additions and 33 deletions
+6
View File
@@ -97,3 +97,9 @@ def get_json_result_dir(d):
if custom_json_result_dir: if custom_json_result_dir:
json_result_dir = custom_json_result_dir json_result_dir = custom_json_result_dir
return json_result_dir return json_result_dir
def get_artefact_dir(d):
custom_json_result_dir = d.getVar("OEQA_ARTEFACT_DIR")
if custom_json_result_dir:
return custom_json_result_dir
return os.path.join(d.getVar("LOG_DIR"), 'oeqa-artefacts')
+29 -32
View File
@@ -7,23 +7,20 @@
# Run a set of actions after tests. The runner provides internal data # Run a set of actions after tests. The runner provides internal data
# dictionary as well as test context to any action to run. # dictionary as well as test context to any action to run.
from oeqa.utils import get_json_result_dir import datetime
import io
def create_artifacts_directory(d, tc): import os
import shutil import stat
import subprocess
local_artifacts_dir = os.path.join(get_json_result_dir(d), "artifacts") import tempfile
if os.path.isdir(local_artifacts_dir): from oeqa.utils import get_artefact_dir
shutil.rmtree(local_artifacts_dir)
os.makedirs(local_artifacts_dir)
################################################################## ##################################################################
# Host/target statistics # Host/target statistics
################################################################## ##################################################################
def get_target_disk_usage(d, tc): def get_target_disk_usage(d, tc, artifacts_list, outputdir):
output_file = os.path.join(get_json_result_dir(d), "artifacts", "target_disk_usage.txt") output_file = os.path.join(outputdir, "target_disk_usage.txt")
try: try:
(status, output) = tc.target.run('df -h') (status, output) = tc.target.run('df -h')
with open(output_file, 'w') as f: with open(output_file, 'w') as f:
@@ -32,10 +29,10 @@ def get_target_disk_usage(d, tc):
except Exception as e: except Exception as e:
bb.warn(f"Can not get target disk usage: {e}") bb.warn(f"Can not get target disk usage: {e}")
def get_host_disk_usage(d, tc): def get_host_disk_usage(d, tc, artifacts_list, outputdir):
import subprocess import subprocess
output_file = os.path.join(get_json_result_dir(d), "artifacts", "host_disk_usage.txt") output_file = os.path.join(outputdir, "host_disk_usage.txt")
try: try:
with open(output_file, 'w') as f: with open(output_file, 'w') as f:
output = subprocess.run(['df', '-hl'], check=True, text=True, stdout=f, env={}) output = subprocess.run(['df', '-hl'], check=True, text=True, stdout=f, env={})
@@ -61,24 +58,19 @@ def get_artifacts_list(target, raw_list):
return result return result
def retrieve_test_artifacts(target, artifacts_list, target_dir): def list_and_fetch_failed_tests_artifacts(d, tc, artifacts_list, outputdir):
import io, subprocess artifacts_list = get_artifacts_list(tc.target, artifacts_list)
local_artifacts_dir = os.path.join(target_dir, "artifacts")
try:
cmd = "tar zcf - " + " ".join(artifacts_list)
(status, output) = target.run(cmd, raw = True)
if status != 0 or not output:
raise Exception("Error while fetching compressed artifacts")
p = subprocess.run(["tar", "zxf", "-", "-C", local_artifacts_dir], input=output)
except Exception as e:
bb.warn(f"Can not retrieve {artifact_path} from test target: {e}")
def list_and_fetch_failed_tests_artifacts(d, tc):
artifacts_list = get_artifacts_list(tc.target, d.getVar("TESTIMAGE_FAILED_QA_ARTIFACTS"))
if not artifacts_list: if not artifacts_list:
bb.warn("Could not load artifacts list, skip artifacts retrieval") bb.warn("Could not load artifacts list, skip artifacts retrieval")
else: return
retrieve_test_artifacts(tc.target, artifacts_list, get_json_result_dir(d)) try:
cmd = "tar zcf - " + " ".join(artifacts_list)
(status, output) = tc.target.run(cmd, raw = True)
if status != 0 or not output:
raise Exception("Error while fetching compressed artifacts")
p = subprocess.run(["tar", "zxf", "-", "-C", outputdir], input=output)
except Exception as e:
bb.warn(f"Can not retrieve {artifact_path} from test target: {e}")
################################################################## ##################################################################
@@ -91,12 +83,17 @@ def run_failed_tests_post_actions(d, tc):
if not artifacts: if not artifacts:
return return
outputdir = get_artefact_dir(d)
os.makedirs(outputdir, exist_ok=True)
datestr = datetime.datetime.now().strftime('%Y%m%d')
outputdir = tempfile.mkdtemp(prefix='oeqa-target-artefacts-%s-' % datestr, dir=outputdir)
os.chmod(outputdir, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)
post_actions=[ post_actions=[
create_artifacts_directory,
list_and_fetch_failed_tests_artifacts, list_and_fetch_failed_tests_artifacts,
get_target_disk_usage, get_target_disk_usage,
get_host_disk_usage get_host_disk_usage
] ]
for action in post_actions: for action in post_actions:
action(d, tc) action(d, tc, artifacts, outputdir)