Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug 1400258 - write cot logs to live_backing.log #317

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/scriptworker/cot/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -1274,9 +1274,6 @@ async def populate_jsone_context(chain, parent_link, decision_link, tasks_for):
'Unknown cot_product_type "{}" for cot_product "{}"!'.format(chain.context.config["cot_product_type"], chain.context.config["cot_product"])
)

log.debug("{} json-e context:".format(parent_link.name))
# format_json() breaks on lambda values; use pprint.pformat here.
log.debug(pprint.pformat(jsone_context))
return jsone_context


Expand Down Expand Up @@ -1820,7 +1817,6 @@ def get_source_url(obj):
"""
source_env_prefix = obj.context.config["source_env_prefix"]
task = obj.task
log.debug("Getting source url for {} {}...".format(obj.name, obj.task_id))
repo = get_repo(obj.task, source_env_prefix=source_env_prefix)
source = task["metadata"]["source"]
if repo and not verify_repo_matches_url(repo, source):
Expand Down Expand Up @@ -1912,7 +1908,7 @@ async def verify_chain_of_trust(chain, *, check_task=False):
CoTError: on failure

"""
log_path = os.path.join(chain.context.config["task_log_dir"], "chain_of_trust.log")
log_path = os.path.join(chain.context.config["task_log_dir"], "live_backing.log")
scriptworker_log = logging.getLogger("scriptworker")
with contextual_log_handler(
chain.context,
Expand Down Expand Up @@ -1944,7 +1940,7 @@ async def verify_chain_of_trust(chain, *, check_task=False):
raise
else:
raise CoTError(str(exc))
log.info("Good.")
log.info("taskId %s passes chain of trust verification.", chain.task_id)


# verify_cot_cmdln {{{1
Expand All @@ -1970,10 +1966,6 @@ async def _async_verify_cot_cmdln(opts, tmp):
context.config["github_oauth_token"] = os.environ.get("SCRIPTWORKER_GITHUB_OAUTH_TOKEN")
cot = ChainOfTrust(context, opts.task_type, task_id=opts.task_id)
await verify_chain_of_trust(cot, check_task=True)
log.info(format_json(cot.dependent_task_ids()))
log.info("{} : {}".format(cot.name, cot.task_id))
for link in cot.links:
log.info("{} : {}".format(link.name, link.task_id))


def verify_cot_cmdln(args=None, event_loop=None):
Expand Down
2 changes: 1 addition & 1 deletion src/scriptworker/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def get_log_filehandle(context: Any) -> Iterator[IO[str]]:
"""
log_file_name = get_log_filename(context)
makedirs(context.config["task_log_dir"])
with open(log_file_name, "w", encoding="utf-8") as filehandle:
with open(log_file_name, "a", encoding="utf-8") as filehandle:
yield filehandle


Expand Down
1 change: 0 additions & 1 deletion src/scriptworker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,6 @@ async def download_file(context, url, abs_filename, session=None, chunk_size=128
if not chunk:
break
fd.write(chunk)
log.info("Done")


# get_loggable_url {{{1
Expand Down
2 changes: 1 addition & 1 deletion src/scriptworker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async def invoke(self, context):
status = await do_run_task(context, self._run_cancellable, self._to_cancellable_process)
artifacts_paths = filepaths_in_dir(context.config["artifact_dir"])
except WorkerShutdownDuringTask:
shutdown_artifact_paths = [os.path.join("public", "logs", log_file) for log_file in ["chain_of_trust.log", "live_backing.log"]]
shutdown_artifact_paths = [os.path.join("public", "logs", log_file) for log_file in ["live_backing.log"]]
artifacts_paths = [path for path in shutdown_artifact_paths if os.path.isfile(os.path.join(context.config["artifact_dir"], path))]
status = STATUSES["worker-shutdown"]
status = worst_level(status, await do_upload(context, artifacts_paths))
Expand Down
10 changes: 0 additions & 10 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,8 @@ async def test_shutdown():
async with get_context(partial_config) as context:
result = await create_task(context, task_id, task_id)
assert result["status"]["state"] == "pending"
fake_cot_log = os.path.join(context.config["artifact_dir"], "public", "logs", "chain_of_trust.log")
fake_other_artifact = os.path.join(context.config["artifact_dir"], "public", "artifact.apk")

with open(fake_cot_log, "w") as file:
file.write("CoT logs")
with open(fake_other_artifact, "w") as file:
file.write("unrelated artifact")
cancel_fut = asyncio.ensure_future(do_shutdown(context))
Expand All @@ -277,24 +274,17 @@ async def test_shutdown():
assert status["status"]["runs"][0]["state"] == "exception"
assert status["status"]["runs"][0]["reasonResolved"] == "worker-shutdown"
log_url = context.queue.buildUrl("getArtifact", task_id, 0, "public/logs/live_backing.log")
cot_log_url = context.queue.buildUrl("getArtifact", task_id, 0, "public/logs/chain_of_trust.log")
other_artifact_url = context.queue.buildUrl("getArtifact", task_id, 0, "public/artifact.apk")
log_path = os.path.join(context.config["work_dir"], "log")
cot_log_path = os.path.join(context.config["work_dir"], "cot_log")
other_artifact_path = os.path.join(context.config["work_dir"], "artifact.apk")
await utils.download_file(context, log_url, log_path)
await utils.download_file(context, cot_log_url, cot_log_path)
with pytest.raises(Download404):
await utils.download_file(context, other_artifact_url, other_artifact_path)

with open(log_path) as fh:
contents = fh.read()
assert contents.rstrip() == "running task script\nAutomation Error: python exited with signal -15"

with open(cot_log_path) as fh:
contents = fh.read()
assert contents.rstrip() == "CoT logs"


# empty_queue {{{1
@pytest.mark.parametrize("context_function", [get_context, get_temp_creds_context])
Expand Down