mirror of
https://github.com/ansible/awx.git
synced 2026-04-09 20:19:21 -02:30
prohibit config callback with no inventory
This commit is contained in:
@@ -3063,6 +3063,11 @@ class JobTemplateSerializer(JobTemplateMixin, UnifiedJobTemplateSerializer, JobO
|
|||||||
inventory = get_field_from_model_or_attrs('inventory')
|
inventory = get_field_from_model_or_attrs('inventory')
|
||||||
project = get_field_from_model_or_attrs('project')
|
project = get_field_from_model_or_attrs('project')
|
||||||
|
|
||||||
|
if get_field_from_model_or_attrs('host_config_key') and not inventory:
|
||||||
|
raise serializers.ValidationError({'host_config_key': _(
|
||||||
|
"Cannot enable provisioning callback without an inventory set."
|
||||||
|
)})
|
||||||
|
|
||||||
prompting_error_message = _("Must either set a default value or ask to prompt on launch.")
|
prompting_error_message = _("Must either set a default value or ask to prompt on launch.")
|
||||||
if project is None:
|
if project is None:
|
||||||
raise serializers.ValidationError({'project': _("Job types 'run' and 'check' must have assigned a project.")})
|
raise serializers.ValidationError({'project': _("Job types 'run' and 'check' must have assigned a project.")})
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ from awx.main.migrations import _save_password_keys as save_password_keys
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
|
|
||||||
|
# DRF
|
||||||
|
from rest_framework.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@@ -615,3 +618,16 @@ def test_job_template_unset_custom_virtualenv(get, patch, organization_factory,
|
|||||||
url = reverse('api:job_template_detail', kwargs={'pk': jt.id})
|
url = reverse('api:job_template_detail', kwargs={'pk': jt.id})
|
||||||
resp = patch(url, {'custom_virtualenv': value}, user=objs.superusers.admin, expect=200)
|
resp = patch(url, {'custom_virtualenv': value}, user=objs.superusers.admin, expect=200)
|
||||||
assert resp.data['custom_virtualenv'] is None
|
assert resp.data['custom_virtualenv'] is None
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_callback_disallowed_null_inventory(project):
|
||||||
|
jt = JobTemplate.objects.create(
|
||||||
|
name='test-jt', inventory=None,
|
||||||
|
ask_inventory_on_launch=True,
|
||||||
|
project=project, playbook='helloworld.yml')
|
||||||
|
serializer = JobTemplateSerializer(jt)
|
||||||
|
assert serializer.instance == jt
|
||||||
|
with pytest.raises(ValidationError) as exc:
|
||||||
|
serializer.validate({'host_config_key': 'asdfbasecfeee'})
|
||||||
|
assert 'Cannot enable provisioning callback without an inventory set' in str(exc)
|
||||||
|
|||||||
Reference in New Issue
Block a user