mirror of
https://github.com/ansible/awx.git
synced 2026-01-13 02:50:02 -03:30
Merge pull request #4277 from jainnikhil30/devel
add inventory name and id to meta vars Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
This commit is contained in:
commit
ca83b62c21
@ -1397,6 +1397,13 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
||||
r['{}_user_email'.format(name)] = created_by.email
|
||||
r['{}_user_first_name'.format(name)] = created_by.first_name
|
||||
r['{}_user_last_name'.format(name)] = created_by.last_name
|
||||
|
||||
inventory = getattr_dne(self, 'inventory')
|
||||
if inventory:
|
||||
for name in ('awx', 'tower'):
|
||||
r['{}_inventory_id'.format(name)] = inventory.pk
|
||||
r['{}_inventory_name'.format(name)] = inventory.name
|
||||
|
||||
return r
|
||||
|
||||
def get_queue_name(self):
|
||||
|
||||
@ -9,7 +9,8 @@ from awx.main.models import (
|
||||
Job,
|
||||
User,
|
||||
Project,
|
||||
JobTemplate
|
||||
JobTemplate,
|
||||
Inventory
|
||||
)
|
||||
|
||||
|
||||
@ -81,11 +82,13 @@ class TestMetaVars:
|
||||
|
||||
def test_job_metavars(self):
|
||||
maker = User(username='joe', pk=47, id=47)
|
||||
inv = Inventory(name='example-inv', id=45)
|
||||
assert Job(
|
||||
name='fake-job',
|
||||
pk=42, id=42,
|
||||
launch_type='manual',
|
||||
created_by=maker
|
||||
created_by=maker,
|
||||
inventory=inv
|
||||
).awx_meta_vars() == {
|
||||
'tower_job_id': 42,
|
||||
'awx_job_id': 42,
|
||||
@ -100,7 +103,11 @@ class TestMetaVars:
|
||||
'awx_user_last_name': '',
|
||||
'tower_user_last_name': '',
|
||||
'awx_user_id': 47,
|
||||
'tower_user_id': 47
|
||||
'tower_user_id': 47,
|
||||
'tower_inventory_id': 45,
|
||||
'awx_inventory_id': 45,
|
||||
'tower_inventory_name': 'example-inv',
|
||||
'awx_inventory_name': 'example-inv'
|
||||
}
|
||||
|
||||
def test_project_update_metavars(self):
|
||||
|
||||
@ -256,6 +256,7 @@ class TestExtraVarSanitation(TestJobExecution):
|
||||
|
||||
def test_vars_unsafe_by_default(self, job, private_data_dir):
|
||||
job.created_by = User(pk=123, username='angry-spud')
|
||||
job.inventory = Inventory(pk=123, name='example-inv')
|
||||
|
||||
task = tasks.RunJob()
|
||||
task.build_extra_vars_file(job, private_data_dir)
|
||||
@ -268,13 +269,14 @@ class TestExtraVarSanitation(TestJobExecution):
|
||||
'awx_user_name', 'tower_job_launch_type',
|
||||
'awx_project_revision',
|
||||
'tower_project_revision', 'tower_user_name',
|
||||
'awx_job_launch_type']:
|
||||
'awx_job_launch_type',
|
||||
'awx_inventory_name', 'tower_inventory_name']:
|
||||
assert hasattr(extra_vars[unsafe], '__UNSAFE__')
|
||||
|
||||
# ensure that non-strings are marked as safe
|
||||
for safe in ['awx_job_template_id', 'awx_job_id', 'awx_user_id',
|
||||
'tower_user_id', 'tower_job_template_id',
|
||||
'tower_job_id']:
|
||||
'tower_job_id', 'awx_inventory_id', 'tower_inventory_id']:
|
||||
assert not hasattr(extra_vars[safe], '__UNSAFE__')
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user