From 35ae13f4989bc499a54f09156e7bbbe9acad9f01 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Thu, 4 May 2017 11:08:05 -0400 Subject: [PATCH] fully link up source_project_update to inventory update --- awx/api/serializers.py | 5 ++++- awx/main/tasks.py | 10 +++++----- awx/main/tests/functional/test_tasks.py | 6 ++++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index aa158bff32..34fd5c0bfb 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -1629,7 +1629,7 @@ class InventoryUpdateSerializer(UnifiedJobSerializer, InventorySourceOptionsSeri class Meta: model = InventoryUpdate - fields = ('*', 'inventory_source', 'license_error') + fields = ('*', 'inventory_source', 'license_error', 'source_project_update') def get_related(self, obj): res = super(InventoryUpdateSerializer, self).get_related(obj) @@ -1638,6 +1638,9 @@ class InventoryUpdateSerializer(UnifiedJobSerializer, InventorySourceOptionsSeri cancel = self.reverse('api:inventory_update_cancel', kwargs={'pk': obj.pk}), notifications = self.reverse('api:inventory_update_notifications_list', kwargs={'pk': obj.pk}), )) + if obj.source_project_update_id: + res['source_project_update'] = self.reverse('api:project_update_detail', + kwargs={'pk': obj.source_project_update.pk}) return res diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 6bbab22d9f..3104527b96 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -1128,7 +1128,7 @@ class RunJob(BaseTask): job_request_id = '' if self.request.id is None else self.request.id local_project_sync = job.project.create_project_update( launch_type="sync", - _eager_params=dict( + _eager_fields=dict( job_type='run', status='running', celery_task_id=job_request_id)) @@ -1367,11 +1367,11 @@ class RunProjectUpdate(BaseTask): 'another update is already active.'.format(inv.name)) continue local_inv_update = inv_src.create_inventory_update( - source_project_update_id=project_update.id, launch_type='scm', _eager_fields=dict( status='running', - celery_task_id=str(project_request_id))) + celery_task_id=str(project_request_id), + source_project_update=project_update)) inv_update_task = local_inv_update._get_task_class() try: task_instance = inv_update_task() @@ -1443,7 +1443,7 @@ class RunProjectUpdate(BaseTask): # Update any inventories that depend on this project if len(dependent_inventory_sources) > 0: if status == 'successful' and instance.launch_type != 'sync': - self._update_dependent_inventories(p, dependent_inventory_sources) + self._update_dependent_inventories(instance, dependent_inventory_sources) class RunInventoryUpdate(BaseTask): @@ -1810,7 +1810,7 @@ class RunInventoryUpdate(BaseTask): request_id = '' if self.request.id is None else self.request.id local_project_sync = source_project.create_project_update( launch_type="sync", - _eager_params=dict( + _eager_fields=dict( job_type='run', status='running', celery_task_id=request_id)) diff --git a/awx/main/tests/functional/test_tasks.py b/awx/main/tests/functional/test_tasks.py index fb3e3d253c..ee80e85a7a 100644 --- a/awx/main/tests/functional/test_tasks.py +++ b/awx/main/tests/functional/test_tasks.py @@ -24,7 +24,7 @@ class TestDependentInventoryUpdate: proj_update = ProjectUpdate.objects.create(project=scm_inventory_source.source_project) with mock.patch.object(RunProjectUpdate, '_update_dependent_inventories') as inv_update_mck: task.post_run_hook(proj_update, 'successful') - inv_update_mck.assert_called_once_with(scm_inventory_source.source_project, mock.ANY) + inv_update_mck.assert_called_once_with(proj_update, mock.ANY) def test_no_unwanted_dependent_inventory_updates(self, project, scm_revision_file): task = RunProjectUpdate() @@ -36,8 +36,10 @@ class TestDependentInventoryUpdate: def test_dependent_inventory_updates(self, scm_inventory_source): task = RunProjectUpdate() + 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(scm_inventory_source.source_project, [scm_inventory_source]) + 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