mirror of
https://github.com/ansible/awx.git
synced 2026-03-13 23:17:32 -02:30
Fix an issue where we weren't properly dealing with extra data passed as
survey answers when launching a job template
This commit is contained in:
@@ -445,16 +445,17 @@ class Job(UnifiedJob, JobOptions):
|
||||
return dependencies
|
||||
|
||||
def handle_extra_data(self, extra_data):
|
||||
if extra_data == "":
|
||||
return
|
||||
try:
|
||||
evars = json.loads(self.extra_vars)
|
||||
except Exception, e:
|
||||
return
|
||||
if evars is None:
|
||||
print("Extra data: " + str(extra_data))
|
||||
if type(extra_data) == dict:
|
||||
evars = extra_data
|
||||
else:
|
||||
evars.update(extra_data)
|
||||
if extra_data == "":
|
||||
return
|
||||
try:
|
||||
evars = json.loads(self.extra_vars)
|
||||
except Exception, e:
|
||||
logger.warn("Exception deserializing extra vars: " + str(e))
|
||||
print("Evars: " + str(evars))
|
||||
self.update_fields(extra_vars=json.dumps(evars))
|
||||
|
||||
def copy(self):
|
||||
|
||||
@@ -695,12 +695,14 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
||||
self.job_explanation = u'Missing needed fields: %s.' % missing_fields
|
||||
self.save(update_fields=['job_explanation'])
|
||||
return False
|
||||
extra_data = dict([(field, kwargs[field]) for field in kwargs
|
||||
if field not in needed])
|
||||
self.handle_extra_data(extra_data)
|
||||
task_class().apply_async((self.pk,), opts, link_error=error_callback)
|
||||
return True
|
||||
|
||||
def signal_start(self, **kwargs):
|
||||
"""Notify the task runner system to begin work on this task."""
|
||||
|
||||
# Sanity check: If we are running unit tests, then run synchronously.
|
||||
if getattr(settings, 'CELERY_UNIT_TEST', False):
|
||||
return self.start(None, **kwargs)
|
||||
|
||||
@@ -961,6 +961,10 @@ class JobTemplateTest(BaseJobTestMixin, django.test.TestCase):
|
||||
launch_url = reverse('api:job_template_launch', args=(new_jt_id,))
|
||||
response = self.get(launch_url)
|
||||
self.assertTrue('favorite_color' in response['variables_needed_to_start'])
|
||||
response = self.post(launch_url, dict(favorite_color="green"), expect=202)
|
||||
job = Job.objects.get(pk=response["job"])
|
||||
job_extra = json.loads(job.extra_vars)
|
||||
self.assertTrue("favorite_color" in job_extra)
|
||||
|
||||
with self.current_user(self.user_sue):
|
||||
response = self.post(url, json.loads(TEST_SIMPLE_NONREQUIRED_SURVEY), expect=200)
|
||||
|
||||
Reference in New Issue
Block a user