mirror of
https://github.com/ansible/awx.git
synced 2026-05-16 22:07:36 -02:30
initial models and endpoints added for workflows
This commit is contained in:
@@ -7,6 +7,7 @@ from awx.main.tests.factories import (
|
||||
create_job_template,
|
||||
create_notification_template,
|
||||
create_survey_spec,
|
||||
create_workflow_job_template,
|
||||
)
|
||||
|
||||
@pytest.fixture
|
||||
@@ -40,6 +41,10 @@ def job_template_with_survey_passwords_factory(job_template_factory):
|
||||
def job_with_secret_key_unit(job_with_secret_key_factory):
|
||||
return job_with_secret_key_factory(persisted=False)
|
||||
|
||||
@pytest.fixture
|
||||
def workflow_job_template_factory():
|
||||
return create_workflow_job_template
|
||||
|
||||
@pytest.fixture
|
||||
def get_ssh_version(mocker):
|
||||
return mocker.patch('awx.main.tasks.get_ssh_version', return_value='OpenSSH_6.9p1, LibreSSL 2.1.8')
|
||||
|
||||
@@ -3,6 +3,7 @@ from .tower import (
|
||||
create_job_template,
|
||||
create_notification_template,
|
||||
create_survey_spec,
|
||||
create_workflow_job_template,
|
||||
)
|
||||
|
||||
from .exc import (
|
||||
@@ -14,5 +15,6 @@ __all__ = [
|
||||
'create_job_template',
|
||||
'create_notification_template',
|
||||
'create_survey_spec',
|
||||
'create_workflow_job_template',
|
||||
'NotUnique',
|
||||
]
|
||||
|
||||
@@ -13,6 +13,7 @@ from awx.main.models import (
|
||||
Credential,
|
||||
Inventory,
|
||||
Label,
|
||||
WorkflowJobTemplate,
|
||||
)
|
||||
|
||||
# mk methods should create only a single object of a single type.
|
||||
@@ -152,3 +153,28 @@ def mk_job_template(name, job_type='run',
|
||||
if persisted:
|
||||
jt.save()
|
||||
return jt
|
||||
|
||||
def mk_workflow_job_template(name, extra_vars='', spec=None, persisted=True):
|
||||
wfjt = WorkflowJobTemplate(name=name, extra_vars=extra_vars)
|
||||
|
||||
wfjt.survey_spec = spec
|
||||
if wfjt.survey_spec is not None:
|
||||
wfjt.survey_enabled = True
|
||||
|
||||
if persisted:
|
||||
wfjt.save()
|
||||
return wfjt
|
||||
|
||||
def mk_workflow_node(workflow_job_template=None, unified_job_template=None,
|
||||
success_nodes=None, failure_nodes=None, always_nodes=None,
|
||||
job=None, persisted=True):
|
||||
workflow_node = WorkflowNode(workflow_job_template=workflow_job_template,
|
||||
unified_job_template=job_template,
|
||||
success_nodes=success_nodes,
|
||||
failure_nodes=failure_nodes,
|
||||
always_nodes=always_nodes,
|
||||
job=job)
|
||||
if persisted:
|
||||
workflow_node.save()
|
||||
return workflow_node
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ from awx.main.models import (
|
||||
Inventory,
|
||||
Job,
|
||||
Label,
|
||||
WorkflowJobTemplate,
|
||||
)
|
||||
|
||||
from .objects import (
|
||||
@@ -28,6 +29,7 @@ from .fixtures import (
|
||||
mk_project,
|
||||
mk_label,
|
||||
mk_notification_template,
|
||||
mk_workflow_job_template,
|
||||
)
|
||||
|
||||
|
||||
@@ -343,3 +345,35 @@ def create_notification_template(name, roles=None, persisted=True, **kwargs):
|
||||
users=_Mapped(users),
|
||||
superusers=_Mapped(superusers),
|
||||
teams=teams)
|
||||
|
||||
def create_workflow_job_template(name, persisted=True, **kwargs):
|
||||
Objects = generate_objects(["workflow_job_template",
|
||||
"survey",], kwargs)
|
||||
|
||||
spec = None
|
||||
jobs = None
|
||||
|
||||
extra_vars = kwargs.get('extra_vars', '')
|
||||
|
||||
if 'survey' in kwargs:
|
||||
spec = create_survey_spec(kwargs['survey'])
|
||||
|
||||
wfjt = mk_workflow_job_template(name, spec=spec, extra_vars=extra_vars,
|
||||
persisted=persisted)
|
||||
|
||||
if 'jobs' in kwargs:
|
||||
for i in kwargs['jobs']:
|
||||
if type(i) is Job:
|
||||
jobs[i.pk] = i
|
||||
else:
|
||||
# Fill in default survey answers
|
||||
job_extra_vars = {}
|
||||
for question in spec['spec']:
|
||||
job_extra_vars[question['variable']] = question['default']
|
||||
jobs[i] = mk_job(job_template=wfjt, extra_vars=job_extra_vars,
|
||||
persisted=persisted)
|
||||
|
||||
return Objects(workflow_job_template=wfjt,
|
||||
#jobs=jobs,
|
||||
survey=spec,)
|
||||
|
||||
|
||||
@@ -43,6 +43,8 @@ class TestApiV1RootView:
|
||||
'unified_job_templates',
|
||||
'unified_jobs',
|
||||
'activity_stream',
|
||||
'workflow_job_templates',
|
||||
'workflow_jobs',
|
||||
]
|
||||
view = ApiV1RootView()
|
||||
ret = view.get(mocker.MagicMock())
|
||||
|
||||
Reference in New Issue
Block a user