mirror of
https://github.com/ansible/awx.git
synced 2026-05-14 04:47:44 -02:30
Fix issue where unified_job method overrode the SurveyMixin methods
This commit is contained in:
@@ -292,12 +292,6 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, Notificatio
|
|||||||
'''
|
'''
|
||||||
raise NotImplementedError # Implement in subclass.
|
raise NotImplementedError # Implement in subclass.
|
||||||
|
|
||||||
def _update_unified_job_kwargs(self, **kwargs):
|
|
||||||
'''
|
|
||||||
Hook for subclasses to update kwargs.
|
|
||||||
'''
|
|
||||||
return kwargs # Override if needed in subclass.
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def notification_templates(self):
|
def notification_templates(self):
|
||||||
'''
|
'''
|
||||||
@@ -346,7 +340,10 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, Notificatio
|
|||||||
m2m_fields[field_name] = getattr(self, field_name)
|
m2m_fields[field_name] = getattr(self, field_name)
|
||||||
else:
|
else:
|
||||||
create_kwargs[field_name] = getattr(self, field_name)
|
create_kwargs[field_name] = getattr(self, field_name)
|
||||||
new_kwargs = self._update_unified_job_kwargs(**create_kwargs)
|
if hasattr(self, '_update_unified_job_kwargs'):
|
||||||
|
new_kwargs = self._update_unified_job_kwargs(**create_kwargs)
|
||||||
|
else:
|
||||||
|
new_kwargs = create_kwargs
|
||||||
unified_job = unified_job_class(**new_kwargs)
|
unified_job = unified_job_class(**new_kwargs)
|
||||||
# For JobTemplate-based jobs with surveys, add passwords to list for perma-redaction
|
# For JobTemplate-based jobs with surveys, add passwords to list for perma-redaction
|
||||||
if hasattr(self, 'survey_spec') and getattr(self, 'survey_enabled', False):
|
if hasattr(self, 'survey_spec') and getattr(self, 'survey_enabled', False):
|
||||||
|
|||||||
@@ -345,7 +345,7 @@ class WorkflowJobTemplate(UnifiedJobTemplate, WorkflowJobOptions, SurveyJobTempl
|
|||||||
|
|
||||||
def can_start_without_user_input(self):
|
def can_start_without_user_input(self):
|
||||||
'''Return whether WFJT can be launched without survey passwords.'''
|
'''Return whether WFJT can be launched without survey passwords.'''
|
||||||
return bool(self.variables_needed_to_start)
|
return not bool(self.variables_needed_to_start)
|
||||||
|
|
||||||
def get_warnings(self):
|
def get_warnings(self):
|
||||||
warning_data = {}
|
warning_data = {}
|
||||||
|
|||||||
@@ -75,9 +75,29 @@ class TestWorkflowSurveys:
|
|||||||
"Assure that the survey default over-rides a JT variable"
|
"Assure that the survey default over-rides a JT variable"
|
||||||
spec = survey_spec_factory('var1')
|
spec = survey_spec_factory('var1')
|
||||||
spec['spec'][0]['default'] = 3
|
spec['spec'][0]['default'] = 3
|
||||||
|
spec['spec'][0]['required'] = False
|
||||||
wfjt = WorkflowJobTemplate(
|
wfjt = WorkflowJobTemplate(
|
||||||
name="test-wfjt",
|
name="test-wfjt",
|
||||||
survey_spec=spec,
|
survey_spec=spec,
|
||||||
|
survey_enabled=True,
|
||||||
extra_vars="var1: 5"
|
extra_vars="var1: 5"
|
||||||
)
|
)
|
||||||
assert json.loads(wfjt._update_unified_job_kwargs()['extra_vars'])['var1'] == 3
|
updated_extra_vars = wfjt._update_unified_job_kwargs()
|
||||||
|
assert 'extra_vars' in updated_extra_vars
|
||||||
|
assert json.loads(updated_extra_vars['extra_vars'])['var1'] == 3
|
||||||
|
assert wfjt.can_start_without_user_input()
|
||||||
|
|
||||||
|
def test_variables_needed_to_start(self, survey_spec_factory):
|
||||||
|
"Assure that variables_needed_to_start output contains mandatory vars"
|
||||||
|
spec = survey_spec_factory(['question1', 'question2', 'question3'])
|
||||||
|
spec['spec'][0]['required'] = False
|
||||||
|
spec['spec'][1]['required'] = True
|
||||||
|
spec['spec'][2]['required'] = False
|
||||||
|
wfjt = WorkflowJobTemplate(
|
||||||
|
name="test-wfjt",
|
||||||
|
survey_spec=spec,
|
||||||
|
survey_enabled=True,
|
||||||
|
extra_vars="question2: hiworld"
|
||||||
|
)
|
||||||
|
assert wfjt.variables_needed_to_start == ['question2']
|
||||||
|
assert not wfjt.can_start_without_user_input()
|
||||||
|
|||||||
Reference in New Issue
Block a user