mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 01:47:35 -02:30
Merge pull request #524 from AlanCoding/yaml_devel
Allow job_template launch to store YAML extra_vars
This commit is contained in:
@@ -18,10 +18,11 @@ The response will include the following fields:
|
|||||||
associated with the job template. If not then one should be supplied when
|
associated with the job template. If not then one should be supplied when
|
||||||
launching the job (boolean, read-only)
|
launching the job (boolean, read-only)
|
||||||
|
|
||||||
Make a POST request to this resource to launch the job_template. If any
|
Make a POST request to this resource to launch the job_template. If any
|
||||||
passwords or variables are required, they must be passed via POST data.
|
passwords or extra variables (extra_vars) are required, they must be passed
|
||||||
If `credential_needed_to_start` is `True` then the `credential` field is
|
via POST data, with extra_vars given as a YAML or JSON string and escaped
|
||||||
required as well.
|
parentheses. If `credential_needed_to_start` is `True` then the `credential`
|
||||||
|
field is required as well.
|
||||||
|
|
||||||
If successful, the response status code will be 202. If any required passwords
|
If successful, the response status code will be 202. If any required passwords
|
||||||
are not provided, a 400 status code will be returned. If the job cannot be
|
are not provided, a 400 status code will be returned. If the job cannot be
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
# Python
|
# Python
|
||||||
import hmac
|
import hmac
|
||||||
import json
|
import json
|
||||||
|
import yaml
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
@@ -305,7 +306,8 @@ class JobTemplate(UnifiedJobTemplate, JobOptions):
|
|||||||
kwargs_extra_vars = json.loads(kwargs_extra_vars)
|
kwargs_extra_vars = json.loads(kwargs_extra_vars)
|
||||||
except Exception:
|
except Exception:
|
||||||
try:
|
try:
|
||||||
yaml.safe_load(kwargs_extra_vars)
|
kwargs_extra_vars = yaml.safe_load(kwargs_extra_vars)
|
||||||
|
assert type(kwargs_extra_vars) is dict
|
||||||
except:
|
except:
|
||||||
kwargs_extra_vars = {}
|
kwargs_extra_vars = {}
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ from django.core.urlresolvers import reverse
|
|||||||
# AWX
|
# AWX
|
||||||
from awx.main.models import * # noqa
|
from awx.main.models import * # noqa
|
||||||
from .base import BaseJobTestMixin
|
from .base import BaseJobTestMixin
|
||||||
|
import yaml
|
||||||
|
|
||||||
__all__ = ['JobTemplateLaunchTest', 'JobTemplateLaunchPasswordsTest']
|
__all__ = ['JobTemplateLaunchTest', 'JobTemplateLaunchPasswordsTest']
|
||||||
|
|
||||||
@@ -70,6 +71,28 @@ class JobTemplateLaunchTest(BaseJobTestMixin, django.test.TestCase):
|
|||||||
j = Job.objects.get(pk=response['job'])
|
j = Job.objects.get(pk=response['job'])
|
||||||
self.assertTrue(j.status == 'new')
|
self.assertTrue(j.status == 'new')
|
||||||
|
|
||||||
|
def test_launch_extra_vars_json(self):
|
||||||
|
# Sending extra_vars as a JSON string, implicit credentials
|
||||||
|
with self.current_user(self.user_sue):
|
||||||
|
data = dict(extra_vars = '{\"a\":3}')
|
||||||
|
response = self.post(self.launch_url, data, expect=202)
|
||||||
|
j = Job.objects.get(pk=response['job'])
|
||||||
|
ev_dict = yaml.load(j.extra_vars)
|
||||||
|
self.assertIn('a', ev_dict)
|
||||||
|
if 'a' in ev_dict:
|
||||||
|
self.assertEqual(ev_dict['a'], 3)
|
||||||
|
|
||||||
|
def test_launch_extra_vars_yaml(self):
|
||||||
|
# Sending extra_vars as a JSON string, implicit credentials
|
||||||
|
with self.current_user(self.user_sue):
|
||||||
|
data = dict(extra_vars = 'a: 3')
|
||||||
|
response = self.post(self.launch_url, data, expect=202)
|
||||||
|
j = Job.objects.get(pk=response['job'])
|
||||||
|
ev_dict = yaml.load(j.extra_vars)
|
||||||
|
self.assertIn('a', ev_dict)
|
||||||
|
if 'a' in ev_dict:
|
||||||
|
self.assertEqual(ev_dict['a'], 3)
|
||||||
|
|
||||||
def test_credential_explicit(self):
|
def test_credential_explicit(self):
|
||||||
# Explicit, credential
|
# Explicit, credential
|
||||||
with self.current_user(self.user_sue):
|
with self.current_user(self.user_sue):
|
||||||
@@ -195,4 +218,3 @@ class JobTemplateLaunchPasswordsTest(BaseJobTestMixin, django.test.TestCase):
|
|||||||
with self.current_user(self.user_sue):
|
with self.current_user(self.user_sue):
|
||||||
response = self.post(self.launch_url, {'ssh_password': ''}, expect=400)
|
response = self.post(self.launch_url, {'ssh_password': ''}, expect=400)
|
||||||
self.assertIn('ssh_password', response['passwords_needed_to_start'])
|
self.assertIn('ssh_password', response['passwords_needed_to_start'])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user