Allow for using build UUID as temp job dir name
This lets us use the build UUID as the job temp dir name so that the finger log streamer can search the job root dir to find the requested log by build ID. Also, since the JobDir parameters aren't really optional, just make that explicit. Change-Id: Ifeb9f37c6c9c1ce792079e63a6c507461081f03c
This commit is contained in:
parent
a457b47589
commit
4dd45f5e1b
|
@ -80,7 +80,15 @@ class JobDirPlaybook(object):
|
|||
|
||||
|
||||
class JobDir(object):
|
||||
def __init__(self, root=None, keep=False):
|
||||
def __init__(self, root, keep, build_uuid):
|
||||
'''
|
||||
:param str root: Root directory for the individual job directories.
|
||||
Can be None to use the default system temp root directory.
|
||||
:param bool keep: If True, do not delete the job directory.
|
||||
:param str build_uuid: The unique build UUID. If supplied, this will
|
||||
be used as the temp job directory name. Using this will help the
|
||||
log streaming daemon find job logs.
|
||||
'''
|
||||
# root
|
||||
# ansible
|
||||
# trusted.cfg
|
||||
|
@ -89,7 +97,12 @@ class JobDir(object):
|
|||
# src
|
||||
# logs
|
||||
self.keep = keep
|
||||
self.root = tempfile.mkdtemp(dir=root)
|
||||
if root:
|
||||
tmpdir = root
|
||||
else:
|
||||
tmpdir = tempfile.gettempdir()
|
||||
self.root = os.path.join(tmpdir, build_uuid)
|
||||
os.mkdir(self.root, 0o700)
|
||||
# Work
|
||||
self.work_root = os.path.join(self.root, 'work')
|
||||
os.makedirs(self.work_root)
|
||||
|
@ -533,8 +546,9 @@ class AnsibleJob(object):
|
|||
|
||||
def execute(self):
|
||||
try:
|
||||
self.jobdir = JobDir(root=self.executor_server.jobdir_root,
|
||||
keep=self.executor_server.keep_jobdir)
|
||||
self.jobdir = JobDir(self.executor_server.jobdir_root,
|
||||
self.executor_server.keep_jobdir,
|
||||
str(self.job.unique))
|
||||
self._execute()
|
||||
except Exception:
|
||||
self.log.exception("Exception while executing job")
|
||||
|
|
Loading…
Reference in New Issue