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

Commit

Permalink
stabilize onefuzz jobs containers download (#953)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmc-msft authored Jun 2, 2021
1 parent 1822acf commit c46abbc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
28 changes: 28 additions & 0 deletions src/cli/onefuzz/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from six.moves import input # workaround for static analysis

from .__version__ import __version__
from .azcopy import azcopy_sync
from .backend import Backend, BackendConfig, ContainerWrapper, wait
from .ssh import build_ssh_command, ssh_connect, temp_file

Expand Down Expand Up @@ -970,6 +971,33 @@ def list(
results[container] = self.onefuzz.containers.files.list(container).files
return results

def download(
self, job_id: UUID_EXPANSION, *, output: Optional[primitives.Directory] = None
) -> None:
to_download = {}
tasks = self.onefuzz.tasks.list(job_id=job_id, state=None)
if not tasks:
raise Exception("no tasks with job_id:%s" % job_id)

for task in tasks:
for container in task.config.containers:
info = self.onefuzz.containers.get(container.name)
name = os.path.join(container.type.name, container.name)
to_download[name] = info.sas_url

if output is None:
output = primitives.Directory(os.getcwd())

for name in to_download:
outdir = os.path.join(output, name)
if not os.path.exists(outdir):
os.makedirs(outdir)
self.logger.info("downloading: %s", name)
# security note: the src for azcopy comes from the server which is
# trusted in this context, while the destination is provided by the
# user
azcopy_sync(to_download[name], outdir)

def delete(
self,
job_id: UUID_EXPANSION,
Expand Down
22 changes: 1 addition & 21 deletions src/cli/onefuzz/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

from onefuzz.api import UUID_EXPANSION, Command, Onefuzz

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

to_download = {}
tasks = self.onefuzz.tasks.list(job_id=job_id, state=None)
if not tasks:
raise Exception("no tasks with job_id:%s" % job_id)

for task in tasks:
for container in task.config.containers:
info = self.onefuzz.containers.get(container.name)
name = os.path.join(container.type.name, container.name)
to_download[name] = info.sas_url

for name in to_download:
outdir = os.path.join(output, name)
if not os.path.exists(outdir):
os.makedirs(outdir)
self.logger.info("downloading: %s", name)
# security note: the src for azcopy comes from the server which is
# trusted in this context, while the destination is provided by the
# user
azcopy_sync(to_download[name], outdir)
self.onefuzz.jobs.containers.download(job_id, output=output)


class DebugLog(Command):
Expand Down

0 comments on commit c46abbc

Please sign in to comment.