mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 15:36:04 -03:30
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
This commit is contained in:
committed by
Shane McDonald
parent
5ffffebe34
commit
d0b7d970c4
@@ -87,7 +87,7 @@ from awx.main.exceptions import AwxTaskError, PostRunError
|
|||||||
from awx.main.queue import CallbackQueueDispatcher
|
from awx.main.queue import CallbackQueueDispatcher
|
||||||
from awx.main.dispatch.publish import task
|
from awx.main.dispatch.publish import task
|
||||||
from awx.main.dispatch import get_local_queuename, reaper
|
from awx.main.dispatch import get_local_queuename, reaper
|
||||||
from awx.main.utils import (
|
from awx.main.utils.common import (
|
||||||
update_scm_url,
|
update_scm_url,
|
||||||
ignore_inventory_computed_fields,
|
ignore_inventory_computed_fields,
|
||||||
ignore_inventory_group_removal,
|
ignore_inventory_group_removal,
|
||||||
@@ -97,6 +97,7 @@ from awx.main.utils import (
|
|||||||
deepmerge,
|
deepmerge,
|
||||||
parse_yaml_or_json,
|
parse_yaml_or_json,
|
||||||
cleanup_new_process,
|
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.execution_environments import get_default_pod_spec, CONTAINER_ROOT, to_container_path
|
||||||
from awx.main.utils.ansible import read_ansible_config
|
from awx.main.utils.ansible import read_ansible_config
|
||||||
@@ -1791,6 +1792,7 @@ class RunJob(BaseTask):
|
|||||||
if 'update_' not in sync_metafields['job_tags']:
|
if 'update_' not in sync_metafields['job_tags']:
|
||||||
sync_metafields['scm_revision'] = job_revision
|
sync_metafields['scm_revision'] = job_revision
|
||||||
local_project_sync = job.project.create_project_update(_eager_fields=sync_metafields)
|
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
|
# save the associated job before calling run() so that a
|
||||||
# cancel() call on the job can cancel the project update
|
# cancel() call on the job can cancel the project update
|
||||||
job = self.update_model(job.pk, project_update=local_project_sync)
|
job = self.update_model(job.pk, project_update=local_project_sync)
|
||||||
@@ -2081,6 +2083,7 @@ class RunProjectUpdate(BaseTask):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
|
create_partition(local_inv_update.event_class._meta.db_table, start=local_inv_update.created)
|
||||||
inv_update_class().run(local_inv_update.id)
|
inv_update_class().run(local_inv_update.id)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception('{} Unhandled exception updating dependent SCM inventory sources.'.format(project_update.log_format))
|
logger.exception('{} Unhandled exception updating dependent SCM inventory sources.'.format(project_update.log_format))
|
||||||
|
|||||||
@@ -40,11 +40,12 @@ class TestDependentInventoryUpdate:
|
|||||||
scm_inventory_source.scm_last_revision = ''
|
scm_inventory_source.scm_last_revision = ''
|
||||||
proj_update = ProjectUpdate.objects.create(project=scm_inventory_source.source_project)
|
proj_update = ProjectUpdate.objects.create(project=scm_inventory_source.source_project)
|
||||||
with mock.patch.object(RunInventoryUpdate, 'run') as iu_run_mock:
|
with mock.patch.object(RunInventoryUpdate, 'run') as iu_run_mock:
|
||||||
task._update_dependent_inventories(proj_update, [scm_inventory_source])
|
with mock.patch('awx.main.tasks.create_partition'):
|
||||||
assert InventoryUpdate.objects.count() == 1
|
task._update_dependent_inventories(proj_update, [scm_inventory_source])
|
||||||
inv_update = InventoryUpdate.objects.first()
|
assert InventoryUpdate.objects.count() == 1
|
||||||
iu_run_mock.assert_called_once_with(inv_update.id)
|
inv_update = InventoryUpdate.objects.first()
|
||||||
assert inv_update.source_project_update_id == proj_update.pk
|
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):
|
def test_dependent_inventory_project_cancel(self, project, inventory):
|
||||||
"""
|
"""
|
||||||
@@ -63,8 +64,9 @@ class TestDependentInventoryUpdate:
|
|||||||
ProjectUpdate.objects.all().update(cancel_flag=True)
|
ProjectUpdate.objects.all().update(cancel_flag=True)
|
||||||
|
|
||||||
with mock.patch.object(RunInventoryUpdate, 'run') as iu_run_mock:
|
with mock.patch.object(RunInventoryUpdate, 'run') as iu_run_mock:
|
||||||
iu_run_mock.side_effect = user_cancels_project
|
with mock.patch('awx.main.tasks.create_partition'):
|
||||||
task._update_dependent_inventories(proj_update, [is1, is2])
|
iu_run_mock.side_effect = user_cancels_project
|
||||||
# Verify that it bails after 1st update, detecting a cancel
|
task._update_dependent_inventories(proj_update, [is1, is2])
|
||||||
assert is2.inventory_updates.count() == 0
|
# Verify that it bails after 1st update, detecting a cancel
|
||||||
iu_run_mock.assert_called_once()
|
assert is2.inventory_updates.count() == 0
|
||||||
|
iu_run_mock.assert_called_once()
|
||||||
|
|||||||
Reference in New Issue
Block a user