Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit c46abbc

Browse files
authored
stabilize onefuzz jobs containers download (#953)
1 parent 1822acf commit c46abbc

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

src/cli/onefuzz/api.py

+28
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from six.moves import input # workaround for static analysis
3131

3232
from .__version__ import __version__
33+
from .azcopy import azcopy_sync
3334
from .backend import Backend, BackendConfig, ContainerWrapper, wait
3435
from .ssh import build_ssh_command, ssh_connect, temp_file
3536

@@ -970,6 +971,33 @@ def list(
970971
results[container] = self.onefuzz.containers.files.list(container).files
971972
return results
972973

974+
def download(
975+
self, job_id: UUID_EXPANSION, *, output: Optional[primitives.Directory] = None
976+
) -> None:
977+
to_download = {}
978+
tasks = self.onefuzz.tasks.list(job_id=job_id, state=None)
979+
if not tasks:
980+
raise Exception("no tasks with job_id:%s" % job_id)
981+
982+
for task in tasks:
983+
for container in task.config.containers:
984+
info = self.onefuzz.containers.get(container.name)
985+
name = os.path.join(container.type.name, container.name)
986+
to_download[name] = info.sas_url
987+
988+
if output is None:
989+
output = primitives.Directory(os.getcwd())
990+
991+
for name in to_download:
992+
outdir = os.path.join(output, name)
993+
if not os.path.exists(outdir):
994+
os.makedirs(outdir)
995+
self.logger.info("downloading: %s", name)
996+
# security note: the src for azcopy comes from the server which is
997+
# trusted in this context, while the destination is provided by the
998+
# user
999+
azcopy_sync(to_download[name], outdir)
1000+
9731001
def delete(
9741002
self,
9751003
job_id: UUID_EXPANSION,

src/cli/onefuzz/debug.py

+1-21
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
from onefuzz.api import UUID_EXPANSION, Command, Onefuzz
2424

25-
from .azcopy import azcopy_sync
2625
from .backend import wait
2726
from .rdp import rdp_connect
2827
from .ssh import ssh_connect
@@ -337,26 +336,7 @@ def libfuzzer_execs_sec(
337336
def download_files(self, job_id: UUID_EXPANSION, output: Directory) -> None:
338337
"""Download the containers by container type for each task in the specified job"""
339338

340-
to_download = {}
341-
tasks = self.onefuzz.tasks.list(job_id=job_id, state=None)
342-
if not tasks:
343-
raise Exception("no tasks with job_id:%s" % job_id)
344-
345-
for task in tasks:
346-
for container in task.config.containers:
347-
info = self.onefuzz.containers.get(container.name)
348-
name = os.path.join(container.type.name, container.name)
349-
to_download[name] = info.sas_url
350-
351-
for name in to_download:
352-
outdir = os.path.join(output, name)
353-
if not os.path.exists(outdir):
354-
os.makedirs(outdir)
355-
self.logger.info("downloading: %s", name)
356-
# security note: the src for azcopy comes from the server which is
357-
# trusted in this context, while the destination is provided by the
358-
# user
359-
azcopy_sync(to_download[name], outdir)
339+
self.onefuzz.jobs.containers.download(job_id, output=output)
360340

361341

362342
class DebugLog(Command):

0 commit comments

Comments
 (0)