1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

store yaml output, test to cover bug, and docs update

This commit is contained in:
AlanCoding 2015-12-04 11:20:05 -05:00
parent 414a5e2be0
commit 319394442a
3 changed files with 31 additions and 6 deletions

View File

@ -18,10 +18,11 @@ The response will include the following fields:
associated with the job template. If not then one should be supplied when
launching the job (boolean, read-only)
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.
If `credential_needed_to_start` is `True` then the `credential` field is
required as well.
Make a POST request to this resource to launch the job_template. If any
passwords or extra variables (extra_vars) are required, they must be passed
via POST data, with extra_vars given as a YAML or JSON string and escaped
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
are not provided, a 400 status code will be returned. If the job cannot be

View File

@ -4,6 +4,7 @@
# Python
import hmac
import json
import yaml
import logging
# Django
@ -304,7 +305,8 @@ class JobTemplate(UnifiedJobTemplate, JobOptions):
kwargs_extra_vars = json.loads(kwargs_extra_vars)
except Exception:
try:
yaml.safe_load(kwargs_extra_vars)
kwargs_extra_vars = yaml.safe_load(kwargs_extra_vars)
assert type(kwargs_extra_vars) is dict
except:
kwargs_extra_vars = {}
else:

View File

@ -11,6 +11,7 @@ from django.core.urlresolvers import reverse
# AWX
from awx.main.models import * # noqa
from .base import BaseJobTestMixin
import yaml
__all__ = ['JobTemplateLaunchTest', 'JobTemplateLaunchPasswordsTest']
@ -70,6 +71,28 @@ class JobTemplateLaunchTest(BaseJobTestMixin, django.test.TestCase):
j = Job.objects.get(pk=response['job'])
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):
# Explicit, credential
with self.current_user(self.user_sue):
@ -195,4 +218,3 @@ class JobTemplateLaunchPasswordsTest(BaseJobTestMixin, django.test.TestCase):
with self.current_user(self.user_sue):
response = self.post(self.launch_url, {'ssh_password': ''}, expect=400)
self.assertIn('ssh_password', response['passwords_needed_to_start'])