mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Replace _jid_dir() with salt.utils.jid.jid_dir()
This commit is contained in:
parent
c278b1f52c
commit
c872f12f9c
@ -12,7 +12,6 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import time
|
import time
|
||||||
import hashlib
|
|
||||||
import bisect
|
import bisect
|
||||||
|
|
||||||
# Import salt libs
|
# Import salt libs
|
||||||
@ -49,21 +48,7 @@ def _job_dir():
|
|||||||
'''
|
'''
|
||||||
Return root of the jobs cache directory
|
Return root of the jobs cache directory
|
||||||
'''
|
'''
|
||||||
return os.path.join(__opts__['cachedir'],
|
return os.path.join(__opts__['cachedir'], 'jobs')
|
||||||
'jobs')
|
|
||||||
|
|
||||||
|
|
||||||
def _jid_dir(jid):
|
|
||||||
'''
|
|
||||||
Return the jid_dir for the given job id
|
|
||||||
'''
|
|
||||||
if six.PY3:
|
|
||||||
jhash = getattr(hashlib, __opts__['hash_type'])(jid.encode('utf-8')).hexdigest()
|
|
||||||
else:
|
|
||||||
jhash = getattr(hashlib, __opts__['hash_type'])(str(jid)).hexdigest()
|
|
||||||
return os.path.join(_job_dir(),
|
|
||||||
jhash[:2],
|
|
||||||
jhash[2:])
|
|
||||||
|
|
||||||
|
|
||||||
def _walk_through(job_dir):
|
def _walk_through(job_dir):
|
||||||
@ -106,26 +91,26 @@ def prep_jid(nocache=False, passed_jid=None, recurse_count=0):
|
|||||||
else:
|
else:
|
||||||
jid = passed_jid
|
jid = passed_jid
|
||||||
|
|
||||||
jid_dir_ = _jid_dir(jid)
|
jid_dir = salt.utils.jid.jid_dir(jid, _job_dir(), __opts__['hash_type'])
|
||||||
|
|
||||||
# Make sure we create the jid dir, otherwise someone else is using it,
|
# Make sure we create the jid dir, otherwise someone else is using it,
|
||||||
# meaning we need a new jid.
|
# meaning we need a new jid.
|
||||||
if not os.path.isdir(jid_dir_):
|
if not os.path.isdir(jid_dir):
|
||||||
try:
|
try:
|
||||||
os.makedirs(jid_dir_)
|
os.makedirs(jid_dir)
|
||||||
except OSError:
|
except OSError:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
if passed_jid is None:
|
if passed_jid is None:
|
||||||
return prep_jid(nocache=nocache, recurse_count=recurse_count+1)
|
return prep_jid(nocache=nocache, recurse_count=recurse_count+1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with salt.utils.fopen(os.path.join(jid_dir_, 'jid'), 'wb+') as fn_:
|
with salt.utils.fopen(os.path.join(jid_dir, 'jid'), 'wb+') as fn_:
|
||||||
if six.PY2:
|
if six.PY2:
|
||||||
fn_.write(jid)
|
fn_.write(jid)
|
||||||
else:
|
else:
|
||||||
fn_.write(bytes(jid, 'utf-8'))
|
fn_.write(bytes(jid, 'utf-8'))
|
||||||
if nocache:
|
if nocache:
|
||||||
with salt.utils.fopen(os.path.join(jid_dir_, 'nocache'), 'wb+') as fn_:
|
with salt.utils.fopen(os.path.join(jid_dir, 'nocache'), 'wb+') as fn_:
|
||||||
fn_.write(b'')
|
fn_.write(b'')
|
||||||
except IOError:
|
except IOError:
|
||||||
log.warning('Could not write out jid file for job {0}. Retrying.'.format(jid))
|
log.warning('Could not write out jid file for job {0}. Retrying.'.format(jid))
|
||||||
@ -146,7 +131,7 @@ def returner(load):
|
|||||||
if load['jid'] == 'req':
|
if load['jid'] == 'req':
|
||||||
load['jid'] = prep_jid(nocache=load.get('nocache', False))
|
load['jid'] = prep_jid(nocache=load.get('nocache', False))
|
||||||
|
|
||||||
jid_dir = _jid_dir(load['jid'])
|
jid_dir = salt.utils.jid.jid_dir(load['jid'], _job_dir(), __opts__['hash_type'])
|
||||||
if os.path.exists(os.path.join(jid_dir, 'nocache')):
|
if os.path.exists(os.path.join(jid_dir, 'nocache')):
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -206,7 +191,7 @@ def save_load(jid, clear_load, minions=None, recurse_count=0):
|
|||||||
log.error(err)
|
log.error(err)
|
||||||
raise salt.exceptions.SaltCacheError(err)
|
raise salt.exceptions.SaltCacheError(err)
|
||||||
|
|
||||||
jid_dir = _jid_dir(jid)
|
jid_dir = salt.utils.jid.jid_dir(jid, _job_dir(), __opts__['hash_type'])
|
||||||
|
|
||||||
serial = salt.payload.Serial(__opts__)
|
serial = salt.payload.Serial(__opts__)
|
||||||
|
|
||||||
@ -259,7 +244,7 @@ def save_minions(jid, minions, syndic_id=None):
|
|||||||
)
|
)
|
||||||
serial = salt.payload.Serial(__opts__)
|
serial = salt.payload.Serial(__opts__)
|
||||||
|
|
||||||
jid_dir = _jid_dir(jid)
|
jid_dir = salt.utils.jid.jid_dir(jid, _job_dir(), __opts__['hash_type'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not os.path.exists(jid_dir):
|
if not os.path.exists(jid_dir):
|
||||||
@ -298,7 +283,7 @@ def get_load(jid):
|
|||||||
'''
|
'''
|
||||||
Return the load data that marks a specified jid
|
Return the load data that marks a specified jid
|
||||||
'''
|
'''
|
||||||
jid_dir = _jid_dir(jid)
|
jid_dir = salt.utils.jid.jid_dir(jid, _job_dir(), __opts__['hash_type'])
|
||||||
load_fn = os.path.join(jid_dir, LOAD_P)
|
load_fn = os.path.join(jid_dir, LOAD_P)
|
||||||
if not os.path.exists(jid_dir) or not os.path.exists(load_fn):
|
if not os.path.exists(jid_dir) or not os.path.exists(load_fn):
|
||||||
return {}
|
return {}
|
||||||
@ -330,7 +315,7 @@ def get_jid(jid):
|
|||||||
'''
|
'''
|
||||||
Return the information returned when the specified job id was executed
|
Return the information returned when the specified job id was executed
|
||||||
'''
|
'''
|
||||||
jid_dir = _jid_dir(jid)
|
jid_dir = salt.utils.jid.jid_dir(jid, _job_dir(), __opts__['hash_type'])
|
||||||
serial = salt.payload.Serial(__opts__)
|
serial = salt.payload.Serial(__opts__)
|
||||||
|
|
||||||
ret = {}
|
ret = {}
|
||||||
@ -458,7 +443,7 @@ def update_endtime(jid, time):
|
|||||||
|
|
||||||
Endtime is stored as a plain text string
|
Endtime is stored as a plain text string
|
||||||
'''
|
'''
|
||||||
jid_dir = _jid_dir(jid)
|
jid_dir = salt.utils.jid.jid_dir(jid, _job_dir(), __opts__['hash_type'])
|
||||||
try:
|
try:
|
||||||
if not os.path.exists(jid_dir):
|
if not os.path.exists(jid_dir):
|
||||||
os.makedirs(jid_dir)
|
os.makedirs(jid_dir)
|
||||||
@ -474,7 +459,7 @@ def get_endtime(jid):
|
|||||||
|
|
||||||
Returns False if no endtime is present
|
Returns False if no endtime is present
|
||||||
'''
|
'''
|
||||||
jid_dir = _jid_dir(jid)
|
jid_dir = salt.utils.jid.jid_dir(jid, _job_dir(), __opts__['hash_type'])
|
||||||
etpath = os.path.join(jid_dir, ENDTIME)
|
etpath = os.path.join(jid_dir, ENDTIME)
|
||||||
if not os.path.exists(etpath):
|
if not os.path.exists(etpath):
|
||||||
return False
|
return False
|
||||||
|
Loading…
Reference in New Issue
Block a user