Skip to content

Commit

Permalink
Add checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
t-persson committed Aug 30, 2024
1 parent a151509 commit a127622
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/etos_test_runner/lib/log_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""ETR log area handler."""
import logging
import traceback
import hashlib
import time
from copy import deepcopy
from pathlib import Path
Expand Down Expand Up @@ -133,14 +134,21 @@ def upload_logs(self, logs):
:type logs: list
"""
for log in logs:
log["uri"] = self.__upload(
log["uri"], log["checksums"] = self.__upload(
self.etos.config.get("context"),
log["file"],
log["name"],
self.etos.config.get("main_suite_id"),
self.etos.config.get("sub_suite_id"),
)
event = {"event": "report", "data": {"url": log["uri"], "name": log["name"]}}
event = {
"event": "report",
"data": {
"url": log["uri"],
"name": log["name"],
"checksums": log["checksums"],
},
}
self.logger.info("Sending event: %r", event)
self.event_publisher.publish(event)
self.logs.append(log)
Expand Down Expand Up @@ -202,14 +210,22 @@ def upload_artifacts(self, artifacts):
artifact_created = self._artifact_created(artifacts)

for artifact in artifacts:
artifact["uri"] = self.__upload(
artifact["uri"], artifact["checksums"] = self.__upload(
self.etos.config.get("context"),
artifact["file"],
artifact["name"],
self.etos.config.get("main_suite_id"),
self.etos.config.get("sub_suite_id"),
)
event = {"event": "artifact", "data": {"url": artifact["uri"], "name": artifact["name"], "directory": self.suite_name}}
event = {
"event": "artifact",
"data": {
"url": artifact["uri"],
"name": artifact["name"],
"directory": self.suite_name,
"checksums": artifact["checksums"],
},
}
self.logger.info("Sending event: %r", event)
self.event_publisher.publish(event)
self.artifacts.append(artifact)
Expand Down Expand Up @@ -262,7 +278,10 @@ def __upload(
if upload.get("auth"):
upload["auth"] = self.__auth(**upload["auth"])

checksums = {}
with open(log, "rb") as log_file:
checksums["md5"] = hashlib.md5(log_file.read()).hexdigest()
log_file.seek(0)
for _ in range(3):
request_generator = self.__retry_upload(log_file=log_file, **upload)
try:
Expand All @@ -273,13 +292,14 @@ def __upload(
self.logger.info("Uploaded log %r.", log)
self.logger.info("Upload URI %r", upload["url"])
self.logger.info("Data: %r", data)
self.logger.info("Checksum(md5): %r", checksums["md5"])
break
break
except: # noqa pylint:disable=bare-except
self.logger.error("%r", traceback.format_exc())
self.logger.error("Failed to upload log!")
self.logger.error("Attempted upload of %r", log)
return upload["url"]
return upload["url"], checksums

def __retry_upload(
self, verb, url, log_file, timeout=None, as_json=True, **requests_kwargs
Expand Down

0 comments on commit a127622

Please sign in to comment.