Skip to content

Commit

Permalink
fix: audit record name should not be the hostname (#15864)
Browse files Browse the repository at this point in the history
* fix: audit record name should not be the hostname

* fix: update tests
  • Loading branch information
pb82 authored Feb 27, 2025
1 parent 43b7216 commit 7b8b37d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion awx/main/tasks/host_indirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
facts = data.get('facts')
name = data.get('name')

if hashable_facts in results:
audit_record = results[hashable_facts]
else:
Expand All @@ -90,7 +92,7 @@ def build_indirect_host_data(job: Job, job_event_queries: dict[str, dict[str, st
facts=facts,
job=job,
organization=job.organization,
name=event.host_name,
name=name,
)
results[hashable_facts] = audit_record

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
demo.query.example:
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}}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def run_module():

result['direct_host_name'] = module.params['host_name']
result['nested_host_name'] = {'host_name': module.params['host_name']}
result['name'] = 'vm-foo'

# non-cononical facts
result['device_type'] = 'Fake Host'
Expand Down
5 changes: 3 additions & 2 deletions awx/main/tests/functional/tasks/test_host_indirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""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
Expand All @@ -30,7 +30,7 @@ def bare_job(job_factory):


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
Expand Down Expand Up @@ -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.facts == {'another_host_name': 'foo_host'}
assert host_audit.organization == job_with_counted_event.organization
assert host_audit.name == 'vm-foo'


@pytest.mark.django_db
Expand Down
2 changes: 1 addition & 1 deletion awx/main/tests/live/tests/test_indirect_host_counting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# 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}}

# Run the task logic directly with local data
Expand Down

0 comments on commit 7b8b37d

Please sign in to comment.