From 39eeae75671bb25c892798af19ad5136a9e7167f Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Fri, 31 Jan 2025 09:30:04 -0500 Subject: [PATCH 1/3] By default, do not count indirect hosts --- awx/main/migrations/0201_indirect_managed_node_audit.py | 4 ++-- awx/main/models/jobs.py | 4 ++-- awx/main/tasks/callback.py | 1 + awx/main/tests/functional/tasks/test_host_indirect.py | 9 ++++----- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/awx/main/migrations/0201_indirect_managed_node_audit.py b/awx/main/migrations/0201_indirect_managed_node_audit.py index b4ce65f052a6..74e4c8a598fe 100644 --- a/awx/main/migrations/0201_indirect_managed_node_audit.py +++ b/awx/main/migrations/0201_indirect_managed_node_audit.py @@ -11,10 +11,10 @@ class Migration(migrations.Migration): ] operations = [ - migrations.AddField( + migrations.AlterField( model_name='job', name='event_queries_processed', - field=models.BooleanField(default=False, help_text='Events of this job have been queried for indirect host information'), + field=models.BooleanField(default=True, help_text='Events of this job have been queried for indirect host information, or do not need processing.'), ), migrations.CreateModel( name='EventQuery', diff --git a/awx/main/models/jobs.py b/awx/main/models/jobs.py index 50257fc6075f..c6b8b0988301 100644 --- a/awx/main/models/jobs.py +++ b/awx/main/models/jobs.py @@ -608,8 +608,8 @@ class Meta: help_text=_("If ran as part of sliced jobs, the total number of slices. If 1, job is not part of a sliced job."), ) event_queries_processed = models.BooleanField( - default=False, - help_text=_("Events of this job have been queried for indirect host information"), + default=True, + help_text=_("Events of this job have been queried for indirect host information, or do not need processing."), ) def _get_parent_field_name(self): diff --git a/awx/main/tasks/callback.py b/awx/main/tasks/callback.py index f07899dd6ca0..c6d89d0b796e 100644 --- a/awx/main/tasks/callback.py +++ b/awx/main/tasks/callback.py @@ -277,6 +277,7 @@ def status_handler(self, status_data, runner_config): def artifacts_handler(self, artifact_dir): success, query_file_contents = try_load_query_file(artifact_dir) if success: + self.delay_update(event_queries_processed=False) collections_info = collect_queries(query_file_contents) for collection, data in collections_info.items(): version = data['version'] diff --git a/awx/main/tests/functional/tasks/test_host_indirect.py b/awx/main/tests/functional/tasks/test_host_indirect.py index 6ac8e409944e..8bbec4dcf41c 100644 --- a/awx/main/tests/functional/tasks/test_host_indirect.py +++ b/awx/main/tests/functional/tasks/test_host_indirect.py @@ -25,7 +25,8 @@ def bare_job(job_factory): job = job_factory() job.installed_collections = {'demo.query': {'version': '1.0.1'}, 'demo2.query': {'version': '1.0.1'}} - job.save(update_fields=['installed_collections']) + job.event_queries_processed = False + job.save(update_fields=['installed_collections', 'event_queries_processed']) return job @@ -72,11 +73,9 @@ def new_audit_record(bare_job, organization): @pytest.mark.django_db -def test_build_with_no_results(job_factory): +def test_build_with_no_results(bare_job): # never filled in events, should do nothing - job = job_factory() - assert job.event_queries_processed is False - assert build_indirect_host_data(job, {}) == [] + assert build_indirect_host_data(bare_job, {}) == [] @pytest.mark.django_db From 16d49aca62ffbc66ce51a65db880b02cc38110d8 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Fri, 31 Jan 2025 09:50:45 -0500 Subject: [PATCH 2/3] Fix copy paste goof --- awx/main/migrations/0201_indirect_managed_node_audit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/main/migrations/0201_indirect_managed_node_audit.py b/awx/main/migrations/0201_indirect_managed_node_audit.py index 74e4c8a598fe..c6d92566937a 100644 --- a/awx/main/migrations/0201_indirect_managed_node_audit.py +++ b/awx/main/migrations/0201_indirect_managed_node_audit.py @@ -11,7 +11,7 @@ class Migration(migrations.Migration): ] operations = [ - migrations.AlterField( + migrations.AddField( model_name='job', name='event_queries_processed', field=models.BooleanField(default=True, help_text='Events of this job have been queried for indirect host information, or do not need processing.'), From f7a40e3eb7b5c20b958acfabd55b024cdf757ace Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Fri, 31 Jan 2025 10:08:52 -0500 Subject: [PATCH 3/3] Fix linter issue from base branch --- awx/main/tests/functional/tasks/test_host_indirect.py | 1 - 1 file changed, 1 deletion(-) diff --git a/awx/main/tests/functional/tasks/test_host_indirect.py b/awx/main/tests/functional/tasks/test_host_indirect.py index 8bbec4dcf41c..cca85c38f164 100644 --- a/awx/main/tests/functional/tasks/test_host_indirect.py +++ b/awx/main/tests/functional/tasks/test_host_indirect.py @@ -13,7 +13,6 @@ ) from awx.main.models.event_query import EventQuery from awx.main.models.indirect_managed_node_audit import IndirectManagedNodeAudit -from awx.main.tests.functional.conftest import organization """These are unit tests, similar to test_indirect_host_counting in the live tests"""