Skip to content
Snippets Groups Projects
Commit 7cdc15f4 authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Allow to launch a workflow job

New resource argument can be passed to launch_job_template.
It is optional and is set to "job" by default.
Shall be set to "workflow_job" to run a workflow template.

Note that passing the workflow name didn't work during my test.
The id had to be used instead.

JIRA INFRA-867 #action In Progress
parent cc6cf0c9
No related branches found
No related tags found
No related merge requests found
...@@ -91,6 +91,9 @@ CSENTRY_ENVIRONMENT = "staging" ...@@ -91,6 +91,9 @@ CSENTRY_ENVIRONMENT = "staging"
AWX_URL = "https://torn.tn.esss.lu.se" AWX_URL = "https://torn.tn.esss.lu.se"
# AWX job templates # AWX job templates
AWX_CORE_SERVICES_UPDATE = "ics-ans-core @ DHCP test" AWX_CORE_SERVICES_UPDATE = "ics-ans-core @ DHCP test"
# Shall be set to job or workflow_job
# Assumed to be job if the variable is not defined
AWX_CORE_SERVICES_UPDATE_RESOURCE = "job"
AWX_CREATE_VM = "deploy-vm-in-proxmox" AWX_CREATE_VM = "deploy-vm-in-proxmox"
AWX_CREATE_VIOC = "ics-ans-deploy-vioc" AWX_CREATE_VIOC = "ics-ans-deploy-vioc"
AWX_ZTP_CONFIGURATION = "ics-ans-ztp" AWX_ZTP_CONFIGURATION = "ics-ans-ztp"
......
...@@ -160,7 +160,14 @@ def trigger_ztp_configuration(host): ...@@ -160,7 +160,14 @@ def trigger_ztp_configuration(host):
return task return task
def launch_job_template(job_template, **kwargs): def launch_job_template(job_template, resource="job", **kwargs):
"""Launch an AWX job or workflow job
:param job_template: name or id of the job template
:param resource: job|workflow_job
:param **kwargs: keyword arguments passed to launch the job
:returns: A dictionary with information from resource.monitor
"""
rq_job = get_current_job() rq_job = get_current_job()
if job_template in ( if job_template in (
current_app.config["AWX_CREATE_VIOC"], current_app.config["AWX_CREATE_VIOC"],
...@@ -172,8 +179,8 @@ def launch_job_template(job_template, **kwargs): ...@@ -172,8 +179,8 @@ def launch_job_template(job_template, **kwargs):
current_app.logger.info("AWX job is disabled. Not sending any request.") current_app.logger.info("AWX job is disabled. Not sending any request.")
return "AWX job not triggered" return "AWX job not triggered"
# Launch the AWX job # Launch the AWX job
resource = tower_cli.get_resource("job") resource = tower_cli.get_resource(resource)
result = resource.launch(job_template=job_template, **kwargs) result = resource.launch(job_template, **kwargs)
# Save the AWX job id in the task # Save the AWX job id in the task
task = models.Task.query.get(rq_job.id) task = models.Task.query.get(rq_job.id)
task.awx_job_id = result["id"] task.awx_job_id = result["id"]
......
...@@ -240,12 +240,17 @@ def trigger_core_services_update(): ...@@ -240,12 +240,17 @@ def trigger_core_services_update():
Make sure that we don't have more than one in queue. Make sure that we don't have more than one in queue.
""" """
job_template = current_app.config["AWX_CORE_SERVICES_UPDATE"] job_template = current_app.config["AWX_CORE_SERVICES_UPDATE"]
resource = current_app.config.get("AWX_CORE_SERVICES_UPDATE_RESOURCE", "job")
if current_user.is_task_waiting("trigger_core_services_update"): if current_user.is_task_waiting("trigger_core_services_update"):
current_app.logger.info( current_app.logger.info(
'Already one "trigger_core_services_update" task waiting. No need to trigger a new one.' 'Already one "trigger_core_services_update" task waiting. No need to trigger a new one.'
) )
return None return None
kwargs = {"func": "launch_job_template", "job_template": job_template} kwargs = {
"func": "launch_job_template",
"job_template": job_template,
"resource": resource,
}
started = current_user.get_task_started("trigger_core_services_update") started = current_user.get_task_started("trigger_core_services_update")
if started: if started:
# There is already one running task. Trigger a new one when it's done. # There is already one running task. Trigger a new one when it's done.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment