mirror of
https://github.com/ansible/awx.git
synced 2026-01-16 20:30:46 -03:30
AC-553 Added test, fixed extra_vars for passing to jobs.
This commit is contained in:
parent
cb052dc775
commit
b8ad8184ef
@ -1754,9 +1754,17 @@ class Job(CommonModelNameNotUnique):
|
||||
|
||||
@property
|
||||
def extra_vars_dict(self):
|
||||
'''Return extra_vars key=value pairs as a dictionary.'''
|
||||
d = {}
|
||||
'''Return extra_vars as a dictionary.'''
|
||||
extra_vars = self.extra_vars.encode('utf-8')
|
||||
try:
|
||||
return json.loads(extra_vars.strip() or '{}')
|
||||
except ValueError:
|
||||
pass
|
||||
try:
|
||||
return yaml.safe_load(extra_vars)
|
||||
except yaml.YAMLError:
|
||||
pass
|
||||
d = {}
|
||||
for kv in [x.decode('utf-8') for x in shlex.split(extra_vars, posix=True)]:
|
||||
if '=' in kv:
|
||||
k, v = kv.split('=', 1)
|
||||
|
||||
@ -368,8 +368,8 @@ class RunJob(BaseTask):
|
||||
args.extend(['-l', job.limit])
|
||||
if job.verbosity:
|
||||
args.append('-%s' % ('v' * min(3, job.verbosity)))
|
||||
if job.extra_vars:
|
||||
args.extend(['-e', job.extra_vars])
|
||||
if job.extra_vars_dict:
|
||||
args.extend(['-e', json.dumps(job.extra_vars_dict)])
|
||||
if job.job_tags:
|
||||
args.extend(['-t', job.job_tags])
|
||||
args.append(job.playbook) # relative path to project.local_path
|
||||
|
||||
@ -649,20 +649,35 @@ class RunJobTest(BaseCeleryTest):
|
||||
|
||||
def test_extra_job_options(self):
|
||||
self.create_test_project(TEST_PLAYBOOK)
|
||||
# Test with extra_vars containing misc whitespace.
|
||||
job_template = self.create_test_job_template(forks=3, verbosity=2,
|
||||
extra_vars='foo=1')
|
||||
extra_vars=u'{\n\t"abc": 1234\n}')
|
||||
job = self.create_test_job(job_template=job_template)
|
||||
self.assertEqual(job.status, 'new')
|
||||
self.assertFalse(job.passwords_needed_to_start)
|
||||
self.assertTrue(job.start())
|
||||
self.assertEqual(job.status, 'pending')
|
||||
job = Job.objects.get(pk=job.pk)
|
||||
# Job may fail if current user doesn't have password-less sudo
|
||||
# privileges, but we're mainly checking the command line arguments.
|
||||
self.check_job_result(job, ('successful', 'failed'))
|
||||
self.check_job_result(job, 'successful')
|
||||
self.assertTrue('--forks=3' in self.run_job_args)
|
||||
self.assertTrue('-vv' in self.run_job_args)
|
||||
self.assertTrue('-e' in self.run_job_args)
|
||||
# Test with extra_vars as key=value (old format).
|
||||
job_template2 = self.create_test_job_template(extra_vars='foo=1')
|
||||
job2 = self.create_test_job(job_template=job_template2)
|
||||
self.assertEqual(job2.status, 'new')
|
||||
self.assertTrue(job2.start())
|
||||
self.assertEqual(job2.status, 'pending')
|
||||
job2 = Job.objects.get(pk=job2.pk)
|
||||
self.check_job_result(job2, 'successful')
|
||||
# Test with extra_vars as YAML (should be converted to JSON in args).
|
||||
job_template3 = self.create_test_job_template(extra_vars='abc: 1234')
|
||||
job3 = self.create_test_job(job_template=job_template3)
|
||||
self.assertEqual(job3.status, 'new')
|
||||
self.assertTrue(job3.start())
|
||||
self.assertEqual(job3.status, 'pending')
|
||||
job3 = Job.objects.get(pk=job3.pk)
|
||||
self.check_job_result(job3, 'successful')
|
||||
|
||||
def test_lots_of_extra_vars(self):
|
||||
self.create_test_project(TEST_PLAYBOOK)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user