stabilize onefuzz jobs containers download (#953)

This commit is contained in:
bmc-msft
2021-06-02 13:29:20 -04:00
committed by GitHub
parent 1822acf943
commit c46abbcec3
2 changed files with 29 additions and 21 deletions

View File

@ -30,6 +30,7 @@ from pydantic import BaseModel
from six.moves import input # workaround for static analysis from six.moves import input # workaround for static analysis
from .__version__ import __version__ from .__version__ import __version__
from .azcopy import azcopy_sync
from .backend import Backend, BackendConfig, ContainerWrapper, wait from .backend import Backend, BackendConfig, ContainerWrapper, wait
from .ssh import build_ssh_command, ssh_connect, temp_file from .ssh import build_ssh_command, ssh_connect, temp_file
@ -970,6 +971,33 @@ class JobContainers(Endpoint):
results[container] = self.onefuzz.containers.files.list(container).files results[container] = self.onefuzz.containers.files.list(container).files
return results 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( def delete(
self, self,
job_id: UUID_EXPANSION, job_id: UUID_EXPANSION,

View File

@ -22,7 +22,6 @@ from onefuzztypes.primitives import Container, Directory
from onefuzz.api import UUID_EXPANSION, Command, Onefuzz from onefuzz.api import UUID_EXPANSION, Command, Onefuzz
from .azcopy import azcopy_sync
from .backend import wait from .backend import wait
from .rdp import rdp_connect from .rdp import rdp_connect
from .ssh import ssh_connect from .ssh import ssh_connect
@ -337,26 +336,7 @@ class DebugJob(Command):
def download_files(self, job_id: UUID_EXPANSION, output: Directory) -> None: def download_files(self, job_id: UUID_EXPANSION, output: Directory) -> None:
"""Download the containers by container type for each task in the specified job""" """Download the containers by container type for each task in the specified job"""
to_download = {} self.onefuzz.jobs.containers.download(job_id, output=output)
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)
class DebugLog(Command): class DebugLog(Command):