From d0b7d970c49e0428aa270ec8cf11ee70ce776380 Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Wed, 23 Jun 2021 13:46:38 -0400 Subject: [PATCH] Create partition for 2 job types that bypass TM (#5138) * Create partition for 2 job types that bypass TM * Mock create_partition in unit tests --- awx/main/tasks.py | 5 ++++- awx/main/tests/functional/test_tasks.py | 22 ++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/awx/main/tasks.py b/awx/main/tasks.py index ba8a61e9dd..ba509563f2 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -87,7 +87,7 @@ from awx.main.exceptions import AwxTaskError, PostRunError from awx.main.queue import CallbackQueueDispatcher from awx.main.dispatch.publish import task from awx.main.dispatch import get_local_queuename, reaper -from awx.main.utils import ( +from awx.main.utils.common import ( update_scm_url, ignore_inventory_computed_fields, ignore_inventory_group_removal, @@ -97,6 +97,7 @@ from awx.main.utils import ( deepmerge, parse_yaml_or_json, cleanup_new_process, + create_partition, ) from awx.main.utils.execution_environments import get_default_pod_spec, CONTAINER_ROOT, to_container_path from awx.main.utils.ansible import read_ansible_config @@ -1791,6 +1792,7 @@ class RunJob(BaseTask): if 'update_' not in sync_metafields['job_tags']: sync_metafields['scm_revision'] = job_revision local_project_sync = job.project.create_project_update(_eager_fields=sync_metafields) + create_partition(local_project_sync.event_class._meta.db_table, start=local_project_sync.created) # save the associated job before calling run() so that a # cancel() call on the job can cancel the project update job = self.update_model(job.pk, project_update=local_project_sync) @@ -2081,6 +2083,7 @@ class RunProjectUpdate(BaseTask): ) ) try: + create_partition(local_inv_update.event_class._meta.db_table, start=local_inv_update.created) inv_update_class().run(local_inv_update.id) except Exception: logger.exception('{} Unhandled exception updating dependent SCM inventory sources.'.format(project_update.log_format)) diff --git a/awx/main/tests/functional/test_tasks.py b/awx/main/tests/functional/test_tasks.py index 70223a09b7..00b31596c0 100644 --- a/awx/main/tests/functional/test_tasks.py +++ b/awx/main/tests/functional/test_tasks.py @@ -40,11 +40,12 @@ class TestDependentInventoryUpdate: scm_inventory_source.scm_last_revision = '' proj_update = ProjectUpdate.objects.create(project=scm_inventory_source.source_project) with mock.patch.object(RunInventoryUpdate, 'run') as iu_run_mock: - task._update_dependent_inventories(proj_update, [scm_inventory_source]) - assert InventoryUpdate.objects.count() == 1 - inv_update = InventoryUpdate.objects.first() - iu_run_mock.assert_called_once_with(inv_update.id) - assert inv_update.source_project_update_id == proj_update.pk + with mock.patch('awx.main.tasks.create_partition'): + task._update_dependent_inventories(proj_update, [scm_inventory_source]) + assert InventoryUpdate.objects.count() == 1 + inv_update = InventoryUpdate.objects.first() + iu_run_mock.assert_called_once_with(inv_update.id) + assert inv_update.source_project_update_id == proj_update.pk def test_dependent_inventory_project_cancel(self, project, inventory): """ @@ -63,8 +64,9 @@ class TestDependentInventoryUpdate: ProjectUpdate.objects.all().update(cancel_flag=True) with mock.patch.object(RunInventoryUpdate, 'run') as iu_run_mock: - iu_run_mock.side_effect = user_cancels_project - task._update_dependent_inventories(proj_update, [is1, is2]) - # Verify that it bails after 1st update, detecting a cancel - assert is2.inventory_updates.count() == 0 - iu_run_mock.assert_called_once() + with mock.patch('awx.main.tasks.create_partition'): + iu_run_mock.side_effect = user_cancels_project + task._update_dependent_inventories(proj_update, [is1, is2]) + # Verify that it bails after 1st update, detecting a cancel + assert is2.inventory_updates.count() == 0 + iu_run_mock.assert_called_once()