From 81a79980dd7729de4d502d9c9e62289df20bd330 Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Fri, 8 Aug 2025 09:47:05 +0200 Subject: [PATCH] AnalyzeBuildLogs(): only analyze one file at a time Will be used in a follow-up commit to simplify analysis of log files and HTML file printing. --- ci-scripts/cls_cluster.py | 13 +++++----- ci-scripts/cls_containerize.py | 47 +++++++++++++++++----------------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/ci-scripts/cls_cluster.py b/ci-scripts/cls_cluster.py index 6634a3e8e7..ace1545fbc 100644 --- a/ci-scripts/cls_cluster.py +++ b/ci-scripts/cls_cluster.py @@ -412,12 +412,13 @@ class Cluster: self.cmd.close() # Analyze the logs - collectInfo = cls_containerize.AnalyzeBuildLogs(log_files, status) - for img in collectInfo: - for f in collectInfo[img]: - status = status and collectInfo[img][f]['status'] - if not status: - logging.debug(collectInfo) + collectInfo = {} + for image, lf in log_files: + files = {} + idx = 'Target Image Creation' + files[idx] = cls_containerize.AnalyzeBuildLogs(image, lf) + status = status and files[idx]['status'] + collectInfo[image] = files if status: logging.info('\u001B[1m Building OAI Image(s) Pass\u001B[0m') diff --git a/ci-scripts/cls_containerize.py b/ci-scripts/cls_containerize.py index adc270cabb..9af086308a 100644 --- a/ci-scripts/cls_containerize.py +++ b/ci-scripts/cls_containerize.py @@ -82,28 +82,23 @@ def CreateTag(ranCommitID, ranBranch, ranAllowMerge): tagToUse = f'develop-{shortCommit}' return tagToUse -def AnalyzeBuildLogs(logfiles, globalStatus): - collectInfo = {} - for image, lf in logfiles: - files = {} - errorandwarnings = {} - committed = False - tagged = False - with open(lf, mode='r') as inputfile: - for line in inputfile: - lineHasTag = re.search(f'Successfully tagged {image}:', str(line)) is not None - lineHasTag2 = re.search(f'naming to docker.io/library/{image}:', str(line)) is not None - tagged = tagged or lineHasTag or lineHasTag2 - # the OpenShift Cluster builder prepends image registry URL - lineHasCommit = re.search(r'COMMIT [a-zA-Z0-9\.:/\-]*' + image, str(line)) is not None - committed = committed or lineHasCommit - errorandwarnings['errors'] = 0 if committed or tagged else 1 - errorandwarnings['warnings'] = 0 - errorandwarnings['status'] = committed or tagged - logging.info(f"Analyzing {image}, file {lf}: {errorandwarnings}") - files['Target Image Creation'] = errorandwarnings - collectInfo[image] = files - return collectInfo +def AnalyzeBuildLogs(image, lf): + errorandwarnings = {} + committed = False + tagged = False + with open(lf, mode='r') as inputfile: + for line in inputfile: + lineHasTag = re.search(f'Successfully tagged {image}:', str(line)) is not None + lineHasTag2 = re.search(f'naming to docker.io/library/{image}:', str(line)) is not None + tagged = tagged or lineHasTag or lineHasTag2 + # the OpenShift Cluster builder prepends image registry URL + lineHasCommit = re.search(r'COMMIT [a-zA-Z0-9\.:/\-]*' + image, str(line)) is not None + committed = committed or lineHasCommit + errorandwarnings['errors'] = 0 if committed or tagged else 1 + errorandwarnings['warnings'] = 0 + errorandwarnings['status'] = committed or tagged + logging.info(f"Analyzing {image}, file {lf}: {errorandwarnings}") + return errorandwarnings def GetImageName(ssh, svcName, file): ret = ssh.run(f"docker compose -f {file} config --format json {svcName} | jq -r '.services.\"{svcName}\".image'", silent=True) @@ -467,7 +462,13 @@ class Containerize(): cmd.close() # Analyze the logs - collectInfo = AnalyzeBuildLogs(log_files, status) + collectInfo = {} + for name, lf in log_files: + files = {} + idx = 'Target Image Creation' + files[idx] = AnalyzeBuildLogs(name, lf) + status = status and files[idx]['status'] + collectInfo[name] = files if status: logging.info('\u001B[1m Building OAI Image(s) Pass\u001B[0m')