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.
This commit is contained in:
Robert Schmidt
2025-08-14 14:55:04 +02:00
parent 089059e10a
commit 81a79980dd
2 changed files with 31 additions and 29 deletions
+7 -6
View File
@@ -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')
+24 -23
View File
@@ -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')