Skip to content

Commit

Permalink
bug 1400258 - write cot verification logs to live_backing.log
Browse files Browse the repository at this point in the history
Fixes #179.
  • Loading branch information
escapewindow committed Mar 20, 2019
1 parent 6c36984 commit b707ae8
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 18 deletions.
2 changes: 1 addition & 1 deletion scriptworker/cot/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -2192,7 +2192,7 @@ async def verify_chain_of_trust(chain):
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, path=log_path, log_obj=scriptworker_log,
Expand Down
2 changes: 1 addition & 1 deletion scriptworker/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def get_log_filehandle(context):
"""
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
12 changes: 0 additions & 12 deletions scriptworker/test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,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 @@ -289,28 +286,19 @@ async def test_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.skipif(os.environ.get("NO_TESTS_OVER_WIRE"), reason=SKIP_REASON)
Expand Down
6 changes: 3 additions & 3 deletions scriptworker/test/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ async def test_run_tasks_cancel_cot(context, mocker):

mock_prepare_task.assert_called_once()
mock_complete_task.assert_called_once_with(mock.ANY, STATUSES['worker-shutdown'])
mock_do_upload.assert_called_once_with(context, ['public/logs/chain_of_trust.log', 'public/logs/live_backing.log'])
mock_do_upload.assert_called_once_with(context, ['public/logs/live_backing.log'])


@pytest.mark.asyncio
Expand Down Expand Up @@ -445,7 +445,7 @@ async def mock_run_task(_, to_cancellable_process):
assert task_process.stopped_due_to_worker_shutdown
mock_prepare_task.assert_called_once()
mock_complete_task.assert_called_once_with(mock.ANY, STATUSES['worker-shutdown'])
mock_do_upload.assert_called_once_with(context, ['public/logs/chain_of_trust.log', 'public/logs/live_backing.log'])
mock_do_upload.assert_called_once_with(context, ['public/logs/live_backing.log'])


@pytest.mark.asyncio
Expand Down Expand Up @@ -527,7 +527,7 @@ async def mock_do_run_task(_, __, to_cancellable_process):

mock_prepare_task.assert_called_once()
mock_complete_task.assert_called_once_with(mock.ANY, STATUSES['worker-shutdown'])
mock_do_upload.assert_called_once_with(context, ['public/logs/chain_of_trust.log', 'public/logs/live_backing.log'])
mock_do_upload.assert_called_once_with(context, ['public/logs/live_backing.log'])


@pytest.mark.asyncio
Expand Down
2 changes: 1 addition & 1 deletion scriptworker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async def invoke(self, context):
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']]
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']
Expand Down

0 comments on commit b707ae8

Please sign in to comment.