Merge pull request #50328 from rallytime/fix-48734

Fix issue with salt-run jobs.list_jobs where Target: unknown-target
This commit is contained in:
Mike Place 2018-11-13 12:49:57 -07:00 committed by GitHub
commit c1dde7e9b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 4 deletions

View file

@ -103,10 +103,12 @@ def store_job(opts, load, event=None, mminion=None):
log.error(emsg)
raise KeyError(emsg)
try:
mminion.returners[savefstr](load['jid'], load)
except KeyError as e:
log.error("Load does not contain 'jid': %s", e)
if job_cache != 'local_cache':
try:
mminion.returners[savefstr](load['jid'], load)
except KeyError as e:
log.error("Load does not contain 'jid': %s", e)
mminion.returners[fstr](load)
if (opts.get('job_cache_store_endtime')

View file

@ -37,3 +37,40 @@ class ManageTest(ShellCase):
'''
ret = self.run_run_plus('jobs.list_jobs')
self.assertIsInstance(ret['return'], dict)
class LocalCacheTargetTest(ShellCase):
'''
Test that a job stored in the local_cache has target information
'''
def test_target_info(self):
'''
This is a test case for issue #48734
PR #43454 fixed an issue where "jobs.lookup_jid" was not working
correctly with external job caches. However, this fix for external
job caches broke some inner workings of job storage when using the
local_cache.
We need to preserve the previous behavior for the local_cache, but
keep the new behavior for other external job caches.
If "savefstr" is called in the local cache, the target data does not
get written to the local_cache, and the target-type gets listed as a
"list" type instead of "glob".
This is a regression test for fixing the local_cache behavior.
'''
self.run_salt('minion test.echo target_info_test')
ret = self.run_run_plus('jobs.list_jobs')
for item in ret['return'].values():
if item['Function'] == 'test.echo' and \
item['Arguments'][0] == 'target_info_test':
job_ret = item
tgt = job_ret['Target']
tgt_type = job_ret['Target-type']
assert tgt != 'unknown-target'
assert tgt in ['minion', 'sub_minion']
assert tgt_type == 'glob'