From 65d01d508b7a45ab5eae4cf0934861c50c24f12c Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Wed, 15 Nov 2017 13:12:06 -0500 Subject: [PATCH 1/2] Fix an issue with handler tasks after celery upgrade There's a bug in celery 4.X when using bound tasks as error handlers. We don't actually need it to be bound especially since the request object is now available in the function signature --- awx/main/tasks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/awx/main/tasks.py b/awx/main/tasks.py index a0963c73ce..4e62f52298 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -357,9 +357,9 @@ def handle_work_success(self, result, task_actual): run_job_complete.delay(instance.id) -@shared_task(bind=True, queue='tower', base=LogErrorsTask) -def handle_work_error(self, task_id, subtasks=None): - logger.debug('Executing error task id %s, subtasks: %s' % (str(self.request.id), str(subtasks))) +@shared_task(queue='tower', base=LogErrorsTask) +def handle_work_error(request, exc, traceback, task_id, subtasks=None): + logger.debug('Executing error task id %s, subtasks: %s' % (request.id, str(subtasks))) first_instance = None first_instance_type = '' if subtasks is not None: From 03eca250d99e87ce963798ac18017a80ebd21c30 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Wed, 15 Nov 2017 13:12:54 -0500 Subject: [PATCH 2/2] Fix an openshift issue writing the inventory file Openshift was throwing an error here, though I'm not sure why it makes a whole lot of difference to call fdopen() vs open(). This was introduced when this method was unified under the new ansible-inventory system. This fixes it for all cases. mkstemp(), while not necessary, is a useful addition to keep from leaking inventory details unnecessarily. --- awx/main/tasks.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 4e62f52298..a32c9dca5d 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -678,11 +678,12 @@ class BaseTask(LogErrorsTask): return False def build_inventory(self, instance, **kwargs): - path = os.path.join(kwargs['private_data_dir'], 'inventory') - with open(path, 'w') as f: - json_data = json.dumps(instance.inventory.get_script_data(hostvars=True)) - f.write('#! /usr/bin/env python\n# -*- coding: utf-8 -*-\nprint %r\n' % json_data) - os.chmod(path, stat.S_IRUSR | stat.S_IXUSR) + json_data = json.dumps(instance.inventory.get_script_data(hostvars=True)) + handle, path = tempfile.mkstemp(dir=kwargs.get('private_data_dir', None)) + f = os.fdopen(handle, 'w') + f.write('#! /usr/bin/env python\n# -*- coding: utf-8 -*-\nprint %r\n' % json_data) + f.close() + os.chmod(path, stat.S_IRUSR | stat.S_IXUSR | stat.S_IWUSR) return path def build_args(self, instance, **kwargs):