Skip to content

Commit 89ce7f6

Browse files
authored
Merge pull request mozilla-releng#696 from bhearsum/upload-all
feat: upload all artifacts even when SIGTERM is received
2 parents fcfa9ab + e83e4cd commit 89ce7f6

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/scriptworker/worker.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"""
88
import asyncio
99
import logging
10-
import os
1110
import signal
1211
import socket
1312
import sys
@@ -135,11 +134,9 @@ async def invoke(self, context):
135134
reclaim_fut = context.event_loop.create_task(reclaim_task(context, context.task))
136135
try:
137136
status = await do_run_task(context, self._run_cancellable, self._to_cancellable_process)
138-
artifacts_paths = filepaths_in_dir(context.config["artifact_dir"])
139137
except WorkerShutdownDuringTask:
140-
shutdown_artifact_paths = [os.path.join("public", "logs", log_file) for log_file in ["chain_of_trust.log", "live_backing.log"]]
141-
artifacts_paths = [path for path in shutdown_artifact_paths if os.path.isfile(os.path.join(context.config["artifact_dir"], path))]
142138
status = STATUSES["worker-shutdown"]
139+
artifacts_paths = filepaths_in_dir(context.config["artifact_dir"])
143140
status = worst_level(status, await do_upload(context, artifacts_paths))
144141
await complete_task(context, status)
145142
reclaim_fut.cancel()

tests/test_worker.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,12 @@ async def run(coroutine):
246246

247247
@pytest.mark.asyncio
248248
async def test_run_tasks_timeout(context, successful_queue, mocker):
249+
expected_args = [(context, ["one", "public/two", "public/logs/live_backing.log"]), None]
250+
251+
async def fake_upload(*args, **kwargs):
252+
assert args == expected_args.pop(0)
253+
return 0
254+
249255
temp_dir = os.path.join(context.config["work_dir"], "timeout")
250256
task = {"foo": "bar", "credentials": {"a": "b"}, "task": {"task_defn": True}}
251257
context.config["task_script"] = (sys.executable, TIMEOUT_SCRIPT, temp_dir)
@@ -259,6 +265,7 @@ async def claim_work(*args, **kwargs):
259265
mocker.patch.object(worker, "reclaim_task", new=noop_async)
260266
mocker.patch.object(worker, "generate_cot", new=noop_sync)
261267
mocker.patch.object(worker, "prepare_to_run_task", new=noop_sync)
268+
mocker.patch("scriptworker.worker.filepaths_in_dir", create_sync(["one", "public/two", "public/logs/live_backing.log"]))
262269
mocker.patch.object(worker, "upload_artifacts", new=noop_async)
263270
mocker.patch.object(worker, "complete_task", new=noop_async)
264271
status = await worker.run_tasks(context)
@@ -267,6 +274,12 @@ async def claim_work(*args, **kwargs):
267274

268275
@pytest.mark.asyncio
269276
async def test_run_tasks_killed(context, successful_queue, mocker):
277+
expected_args = [(context, ["one", "public/two", "public/logs/live_backing.log"]), None]
278+
279+
async def fake_upload(*args, **kwargs):
280+
assert args == expected_args.pop(0)
281+
return 0
282+
270283
temp_dir = os.path.join(context.config["work_dir"], "killed")
271284
task = {"foo": "bar", "credentials": {"a": "b"}, "task": {"task_defn": True}}
272285
context.config["task_script"] = (sys.executable, KILLED_SCRIPT, temp_dir)
@@ -280,6 +293,7 @@ async def claim_work(*args, **kwargs):
280293
mocker.patch.object(worker, "reclaim_task", new=noop_async)
281294
mocker.patch.object(worker, "generate_cot", new=noop_sync)
282295
mocker.patch.object(worker, "prepare_to_run_task", new=noop_sync)
296+
mocker.patch("scriptworker.worker.filepaths_in_dir", create_sync(["one", "public/two", "public/logs/live_backing.log"]))
283297
mocker.patch.object(worker, "upload_artifacts", new=noop_async)
284298
mocker.patch.object(worker, "complete_task", new=noop_async)
285299
status = await worker.run_tasks(context)
@@ -418,13 +432,20 @@ async def test_run_tasks_cancel_cot(context, mocker):
418432

419433
@pytest.mark.asyncio
420434
async def test_run_tasks_cancel_run_tasks(context, mocker):
435+
expected_args = [(context, ["one", "public/two", "public/logs/live_backing.log"]), None]
436+
437+
async def fake_upload(*args, **kwargs):
438+
assert args == expected_args.pop(0)
439+
return 0
440+
421441
mocker.patch("scriptworker.worker.claim_work", create_async(_MOCK_CLAIM_WORK_RETURN))
422442
mocker.patch("scriptworker.worker.reclaim_task", noop_async)
423443
mocker.patch("scriptworker.worker.run_task", noop_async)
424444
mocker.patch("scriptworker.worker.generate_cot", noop_sync)
425445
mocker.patch("scriptworker.worker.cleanup", noop_sync)
446+
mocker.patch("scriptworker.worker.filepaths_in_dir", create_sync(["one", "public/two", "public/logs/live_backing.log"]))
426447
mocker.patch("os.path.isfile", create_sync(True))
427-
mocker.patch("scriptworker.worker.do_upload", new=create_async(result=0))
448+
mocker.patch("scriptworker.worker.do_upload", new=fake_upload)
428449

429450
mock_prepare_task = mocker.patch("scriptworker.worker.prepare_to_run_task")
430451
mock_complete_task = mocker.patch("scriptworker.worker.complete_task")

0 commit comments

Comments
 (0)