returners.local_cache: fix endless loop on OSError

I was getting a "Permission denied" OSError when running as a non-root
user, from the example provided at
https://docs.saltstack.com/en/latest/ref/runners/all/salt.runners.pillar.html#salt.runners.pillar.show_pillar:

    import salt.config
    import salt.runner
    opts = salt.config.master_config('/etc/salt/master')
    runner = salt.runner.RunnerClient(opts)
    pillar = runner.cmd('pillar.show_pillar')
    print(pillar)

This patch passes on the increased `recurse_count` argument, so it will
eventually abort after 5 retries.
This commit is contained in:
Daniel Hahler 2015-09-30 21:09:08 +02:00 committed by rallytime
parent ccbba8656b
commit fd485e2396

View file

@ -125,8 +125,7 @@ def prep_jid(nocache=False, passed_jid=None, recurse_count=0):
except OSError:
time.sleep(0.1)
if passed_jid is None:
recurse_count += recurse_count
return prep_jid(nocache=nocache)
return prep_jid(nocache=nocache, recurse_count=recurse_count+1)
try:
with salt.utils.fopen(os.path.join(jid_dir_, 'jid'), 'wb+') as fn_:
@ -137,8 +136,8 @@ def prep_jid(nocache=False, passed_jid=None, recurse_count=0):
except IOError:
log.warn('Could not write out jid file for job {0}. Retrying.'.format(jid))
time.sleep(0.1)
recurse_count += recurse_count
return prep_jid(passed_jid=jid, nocache=nocache)
return prep_jid(passed_jid=jid, nocache=nocache,
recurse_count=recurse_count+1)
return jid