mirror of
https://github.com/ansible/awx.git
synced 2026-03-21 02:47:35 -02:30
* fix: audit record name should not be the hostname * fix: update tests
This commit is contained in:
@@ -82,6 +82,8 @@ def build_indirect_host_data(job: Job, job_event_queries: dict[str, dict[str, st
|
|||||||
|
|
||||||
# Obtain the record based on the hashable canonical_facts now determined
|
# Obtain the record based on the hashable canonical_facts now determined
|
||||||
facts = data.get('facts')
|
facts = data.get('facts')
|
||||||
|
name = data.get('name')
|
||||||
|
|
||||||
if hashable_facts in results:
|
if hashable_facts in results:
|
||||||
audit_record = results[hashable_facts]
|
audit_record = results[hashable_facts]
|
||||||
else:
|
else:
|
||||||
@@ -90,7 +92,7 @@ def build_indirect_host_data(job: Job, job_event_queries: dict[str, dict[str, st
|
|||||||
facts=facts,
|
facts=facts,
|
||||||
job=job,
|
job=job,
|
||||||
organization=job.organization,
|
organization=job.organization,
|
||||||
name=event.host_name,
|
name=name,
|
||||||
)
|
)
|
||||||
results[hashable_facts] = audit_record
|
results[hashable_facts] = audit_record
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
---
|
---
|
||||||
demo.query.example:
|
demo.query.example:
|
||||||
query: >-
|
query: >-
|
||||||
{canonical_facts: {host_name: .direct_host_name}, facts: {device_type: .device_type}}
|
{name: .name, canonical_facts: {host_name: .direct_host_name}, facts: {device_type: .device_type}}
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ def run_module():
|
|||||||
|
|
||||||
result['direct_host_name'] = module.params['host_name']
|
result['direct_host_name'] = module.params['host_name']
|
||||||
result['nested_host_name'] = {'host_name': module.params['host_name']}
|
result['nested_host_name'] = {'host_name': module.params['host_name']}
|
||||||
|
result['name'] = 'vm-foo'
|
||||||
|
|
||||||
# non-cononical facts
|
# non-cononical facts
|
||||||
result['device_type'] = 'Fake Host'
|
result['device_type'] = 'Fake Host'
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ from awx.main.models.indirect_managed_node_audit import IndirectManagedNodeAudit
|
|||||||
"""These are unit tests, similar to test_indirect_host_counting in the live tests"""
|
"""These are unit tests, similar to test_indirect_host_counting in the live tests"""
|
||||||
|
|
||||||
|
|
||||||
TEST_JQ = "{canonical_facts: {host_name: .direct_host_name}, facts: {another_host_name: .direct_host_name}}"
|
TEST_JQ = "{name: .name, canonical_facts: {host_name: .direct_host_name}, facts: {another_host_name: .direct_host_name}}"
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@@ -30,7 +30,7 @@ def bare_job(job_factory):
|
|||||||
|
|
||||||
|
|
||||||
def create_registered_event(job, task_name='demo.query.example'):
|
def create_registered_event(job, task_name='demo.query.example'):
|
||||||
return job.job_events.create(event_data={'resolved_action': task_name, 'res': {'direct_host_name': 'foo_host'}})
|
return job.job_events.create(event_data={'resolved_action': task_name, 'res': {'direct_host_name': 'foo_host', 'name': 'vm-foo'}})
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@@ -107,6 +107,7 @@ def test_save_indirect_host_entries(job_with_counted_event, event_query):
|
|||||||
assert host_audit.canonical_facts == {'host_name': 'foo_host'}
|
assert host_audit.canonical_facts == {'host_name': 'foo_host'}
|
||||||
assert host_audit.facts == {'another_host_name': 'foo_host'}
|
assert host_audit.facts == {'another_host_name': 'foo_host'}
|
||||||
assert host_audit.organization == job_with_counted_event.organization
|
assert host_audit.organization == job_with_counted_event.organization
|
||||||
|
assert host_audit.name == 'vm-foo'
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ def test_indirect_host_counting(live_tmp_folder, run_job_from_playbook):
|
|||||||
|
|
||||||
# Data matches to awx/main/tests/data/projects/host_query/extensions/audit/event_query.yml
|
# Data matches to awx/main/tests/data/projects/host_query/extensions/audit/event_query.yml
|
||||||
# this just does things in-line to be a more localized test for the immediate testing
|
# this just does things in-line to be a more localized test for the immediate testing
|
||||||
module_jq_str = '{canonical_facts: {host_name: .direct_host_name}, facts: {device_type: .device_type}}'
|
module_jq_str = '{name: .name, canonical_facts: {host_name: .direct_host_name}, facts: {device_type: .device_type}}'
|
||||||
event_query = {'demo.query.example': {'query': module_jq_str}}
|
event_query = {'demo.query.example': {'query': module_jq_str}}
|
||||||
|
|
||||||
# Run the task logic directly with local data
|
# Run the task logic directly with local data
|
||||||
|
|||||||
Reference in New Issue
Block a user