mirror of
https://github.com/ansible/awx.git
synced 2026-03-20 18:37:39 -02:30
move job tests to new survey testing file
This commit is contained in:
@@ -2633,26 +2633,7 @@ class WorkflowJobLaunchSerializer(BaseSerializer):
|
|||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
errors = {}
|
errors = {}
|
||||||
obj = self.context.get('obj')
|
obj = self.instance
|
||||||
data = self.context.get('data')
|
|
||||||
|
|
||||||
for field in obj.resources_needed_to_start:
|
|
||||||
if not (attrs.get(field, False) and obj._ask_for_vars_dict().get(field, False)):
|
|
||||||
errors[field] = "Job Template '%s' is missing or undefined." % field
|
|
||||||
|
|
||||||
if (not obj.ask_credential_on_launch) or (not attrs.get('credential', None)):
|
|
||||||
credential = obj.credential
|
|
||||||
else:
|
|
||||||
credential = attrs.get('credential', None)
|
|
||||||
|
|
||||||
# fill passwords dict with request data passwords
|
|
||||||
if credential and credential.passwords_needed:
|
|
||||||
passwords = self.context.get('passwords')
|
|
||||||
try:
|
|
||||||
for p in credential.passwords_needed:
|
|
||||||
passwords[p] = data[p]
|
|
||||||
except KeyError:
|
|
||||||
errors['passwords_needed_to_start'] = credential.passwords_needed
|
|
||||||
|
|
||||||
extra_vars = attrs.get('extra_vars', {})
|
extra_vars = attrs.get('extra_vars', {})
|
||||||
|
|
||||||
@@ -2674,27 +2655,12 @@ class WorkflowJobLaunchSerializer(BaseSerializer):
|
|||||||
if validation_errors:
|
if validation_errors:
|
||||||
errors['variables_needed_to_start'] = validation_errors
|
errors['variables_needed_to_start'] = validation_errors
|
||||||
|
|
||||||
# Special prohibited cases for scan jobs
|
|
||||||
errors.update(obj._extra_job_type_errors(data))
|
|
||||||
|
|
||||||
if errors:
|
if errors:
|
||||||
raise serializers.ValidationError(errors)
|
raise serializers.ValidationError(errors)
|
||||||
|
|
||||||
JT_extra_vars = obj.extra_vars
|
WFJT_extra_vars = obj.extra_vars
|
||||||
JT_limit = obj.limit
|
attrs = super(WorkflowJobLaunchSerializer, self).validate(attrs)
|
||||||
JT_job_type = obj.job_type
|
obj.extra_vars = WFJT_extra_vars
|
||||||
JT_job_tags = obj.job_tags
|
|
||||||
JT_skip_tags = obj.skip_tags
|
|
||||||
JT_inventory = obj.inventory
|
|
||||||
JT_credential = obj.credential
|
|
||||||
attrs = super(JobLaunchSerializer, self).validate(attrs)
|
|
||||||
obj.extra_vars = JT_extra_vars
|
|
||||||
obj.limit = JT_limit
|
|
||||||
obj.job_type = JT_job_type
|
|
||||||
obj.skip_tags = JT_skip_tags
|
|
||||||
obj.job_tags = JT_job_tags
|
|
||||||
obj.inventory = JT_inventory
|
|
||||||
obj.credential = JT_credential
|
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
class NotificationTemplateSerializer(BaseSerializer):
|
class NotificationTemplateSerializer(BaseSerializer):
|
||||||
|
|||||||
@@ -2815,10 +2815,9 @@ class WorkflowJobTemplateLaunch(GenericAPIView):
|
|||||||
if not request.user.can_access(self.model, 'start', obj):
|
if not request.user.can_access(self.model, 'start', obj):
|
||||||
raise PermissionDenied()
|
raise PermissionDenied()
|
||||||
|
|
||||||
|
serializer = self.serializer_class(instance=obj, data=request.data)
|
||||||
# serializer = self.serializer_class(instance=obj, data=request.data, context={'obj': obj, 'data': request.data, 'passwords': passwords})
|
if not serializer.is_valid():
|
||||||
# if not serializer.is_valid():
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||||
# return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
prompted_fields, ignored_fields = obj._accept_or_ignore_job_kwargs(**request.data)
|
prompted_fields, ignored_fields = obj._accept_or_ignore_job_kwargs(**request.data)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user