Skip to content

Commit

Permalink
Merge pull request #4723 from rebeccahhh/devel
Browse files Browse the repository at this point in the history
expose schedule name for scheduled workflow node job

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
  • Loading branch information
softwarefactory-project-zuul[bot] authored Sep 16, 2019
2 parents a6c0793 + fbf182d commit 3139bc9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
8 changes: 6 additions & 2 deletions awx/main/models/unified_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
camelcase_to_underscore, get_model_for_type,
encrypt_dict, decrypt_field, _inventory_updates,
copy_model_by_class, copy_m2m_relationships,
get_type_for_model, parse_yaml_or_json, getattr_dne
get_type_for_model, parse_yaml_or_json, getattr_dne,
polymorphic, schedule_task_manager
)
from awx.main.utils import polymorphic, schedule_task_manager
from awx.main.constants import ACTIVE_STATES, CAN_CANCEL
from awx.main.redact import UriCleaner, REPLACE_STR
from awx.main.consumers import emit_channel_notification
Expand Down Expand Up @@ -1386,9 +1386,13 @@ def awx_meta_vars(self):

wj = self.get_workflow_job()
if wj:
schedule = getattr_dne(wj, 'schedule')
for name in ('awx', 'tower'):
r['{}_workflow_job_id'.format(name)] = wj.pk
r['{}_workflow_job_name'.format(name)] = wj.name
if schedule:
r['{}_parent_job_schedule_id'.format(name)] = schedule.pk
r['{}_parent_job_schedule_name'.format(name)] = schedule.name

if not created_by:
schedule = getattr_dne(self, 'schedule')
Expand Down
33 changes: 33 additions & 0 deletions awx/main/tests/functional/models/test_unified_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,39 @@ def test_scheduled_job_metavars(self, job_template, admin_user):
assert data['awx_schedule_id'] == schedule.pk
assert 'awx_user_name' not in data

def test_scheduled_workflow_job_node_metavars(self, workflow_job_template):
schedule = Schedule.objects.create(
name='job-schedule',
rrule='DTSTART:20171129T155939z\nFREQ=MONTHLY',
unified_job_template=workflow_job_template
)

workflow_job = WorkflowJob.objects.create(
name='workflow-job',
workflow_job_template=workflow_job_template,
schedule=schedule
)

job = Job.objects.create(
launch_type='workflow'
)
workflow_job.workflow_nodes.create(job=job)
assert job.awx_meta_vars() == {
'awx_job_id': job.id,
'tower_job_id': job.id,
'awx_job_launch_type': 'workflow',
'tower_job_launch_type': 'workflow',
'awx_workflow_job_name': 'workflow-job',
'tower_workflow_job_name': 'workflow-job',
'awx_workflow_job_id': workflow_job.id,
'tower_workflow_job_id': workflow_job.id,
'awx_parent_job_schedule_id': schedule.id,
'tower_parent_job_schedule_id': schedule.id,
'awx_parent_job_schedule_name': 'job-schedule',
'tower_parent_job_schedule_name': 'job-schedule',

}


@pytest.mark.django_db
def test_event_processing_not_finished():
Expand Down

0 comments on commit 3139bc9

Please sign in to comment.