diff --git a/awx/api/views.py b/awx/api/views.py index c95cebcb9e..3fb9826519 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -10,9 +10,8 @@ import time import socket import sys import logging -from base64 import b64encode, b64decode +from base64 import b64encode from collections import OrderedDict -from HTMLParser import HTMLParser # Django from django.conf import settings diff --git a/awx/lib/sitecustomize.py b/awx/lib/sitecustomize.py index cf6cab211e..02ac2eba55 100644 --- a/awx/lib/sitecustomize.py +++ b/awx/lib/sitecustomize.py @@ -7,7 +7,7 @@ import sys def argv_ready(argv): if argv and os.path.basename(argv[0]) in {'ansible', 'ansible-playbook'}: - import tower_display_callback + import tower_display_callback # noqa class argv_placeholder(object): diff --git a/awx/lib/tower_display_callback/__init__.py b/awx/lib/tower_display_callback/__init__.py index 313a1d50c6..d984956c7f 100644 --- a/awx/lib/tower_display_callback/__init__.py +++ b/awx/lib/tower_display_callback/__init__.py @@ -18,8 +18,8 @@ from __future__ import (absolute_import, division, print_function) # Tower Display Callback -from . import cleanup # to register control persistent cleanup. -from . import display # to wrap ansible.display.Display methods. +from . import cleanup # noqa (registers control persistent cleanup) +from . import display # noqa (wraps ansible.display.Display methods) from .module import TowerDefaultCallbackModule, TowerMinimalCallbackModule __all__ = ['TowerDefaultCallbackModule', 'TowerMinimalCallbackModule'] diff --git a/awx/lib/tower_display_callback/cleanup.py b/awx/lib/tower_display_callback/cleanup.py index 1bc276f742..7a0387cddf 100644 --- a/awx/lib/tower_display_callback/cleanup.py +++ b/awx/lib/tower_display_callback/cleanup.py @@ -69,4 +69,4 @@ def terminate_ssh_control_masters(): proc.terminate() procs_gone, procs_alive = psutil.wait_procs(ssh_cm_procs, timeout=5) for proc in procs_alive: - proc.kill() \ No newline at end of file + proc.kill() diff --git a/awx/lib/tower_display_callback/display.py b/awx/lib/tower_display_callback/display.py index ec32fec334..5b1265201e 100644 --- a/awx/lib/tower_display_callback/display.py +++ b/awx/lib/tower_display_callback/display.py @@ -18,10 +18,7 @@ from __future__ import (absolute_import, division, print_function) # Python -import cgi -import contextlib import functools -import json import sys import uuid @@ -36,6 +33,7 @@ __all__ = [] def with_context(**context): global event_context + def wrap(f): @functools.wraps(f) def wrapper(*args, **kwargs): @@ -57,6 +55,7 @@ for attr in dir(Display): def with_verbosity(f): global event_context + @functools.wraps(f) def wrapper(*args, **kwargs): host = args[2] if len(args) >= 3 else kwargs.get('host', None) @@ -72,6 +71,7 @@ Display.verbose = with_verbosity(Display.verbose) def display_with_context(f): + @functools.wraps(f) def wrapper(*args, **kwargs): log_only = args[5] if len(args) >= 6 else kwargs.get('log_only', False) diff --git a/awx/lib/tower_display_callback/events.py b/awx/lib/tower_display_callback/events.py index fa664e5856..ad7eb6418e 100644 --- a/awx/lib/tower_display_callback/events.py +++ b/awx/lib/tower_display_callback/events.py @@ -19,7 +19,6 @@ from __future__ import (absolute_import, division, print_function) # Python import base64 -import cgi import contextlib import datetime import json diff --git a/awx/lib/tower_display_callback/module.py b/awx/lib/tower_display_callback/module.py index 7be4835aa7..e5b4e21713 100644 --- a/awx/lib/tower_display_callback/module.py +++ b/awx/lib/tower_display_callback/module.py @@ -20,7 +20,6 @@ from __future__ import (absolute_import, division, print_function) # Python import contextlib import copy -import os import re import sys import uuid @@ -209,8 +208,10 @@ class BaseCallbackModule(CallbackBase): default=default, ) with self.capture_event_data('playbook_on_vars_prompt', **event_data): - super(BaseCallbackModule, self).v2_playbook_on_vars_prompt(varname, - private, prompt, encrypt, confirm, salt_size, salt, default) + super(BaseCallbackModule, self).v2_playbook_on_vars_prompt( + varname, private, prompt, encrypt, confirm, salt_size, salt, + default, + ) def v2_playbook_on_include(self, included_file): event_data = dict( diff --git a/awx/main/management/commands/run_callback_receiver.py b/awx/main/management/commands/run_callback_receiver.py index e99a34aa4f..6381660948 100644 --- a/awx/main/management/commands/run_callback_receiver.py +++ b/awx/main/management/commands/run_callback_receiver.py @@ -3,7 +3,6 @@ # Python import logging -import json from kombu import Connection, Exchange, Queue from kombu.mixins import ConsumerMixin diff --git a/awx/main/models/ad_hoc_commands.py b/awx/main/models/ad_hoc_commands.py index fc56802160..c81531d22c 100644 --- a/awx/main/models/ad_hoc_commands.py +++ b/awx/main/models/ad_hoc_commands.py @@ -10,7 +10,6 @@ from urlparse import urljoin # Django from django.conf import settings -from django.core.cache import cache from django.db import models from django.utils.dateparse import parse_datetime from django.utils.text import Truncator diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 503509890b..cd785ef96a 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -991,9 +991,11 @@ class RunJob(BaseTask): Wrap stdout file object to capture events. ''' stdout_handle = super(RunJob, self).get_stdout_handle(instance) + def job_event_callback(event_data): event_data.setdefault('job_id', instance.id) JobEvent.create_from_data(**event_data) + return OutputEventFilter(stdout_handle, job_event_callback) def get_ssh_key_path(self, instance, **kwargs): @@ -1716,9 +1718,11 @@ class RunAdHocCommand(BaseTask): Wrap stdout file object to capture events. ''' stdout_handle = super(RunAdHocCommand, self).get_stdout_handle(instance) + def ad_hoc_command_event_callback(event_data): event_data.setdefault('ad_hoc_command_id', instance.id) AdHocCommandEvent.create_from_data(**event_data) + return OutputEventFilter(stdout_handle, ad_hoc_command_event_callback) def get_ssh_key_path(self, instance, **kwargs): diff --git a/awx/plugins/callback/minimal.py b/awx/plugins/callback/minimal.py index e34ebdd78a..fcbaa76d55 100644 --- a/awx/plugins/callback/minimal.py +++ b/awx/plugins/callback/minimal.py @@ -27,4 +27,4 @@ if awx_lib_path not in sys.path: sys.path.insert(0, awx_lib_path) # Tower Display Callback -from tower_display_callback import TowerMinimalCallbackModule as CallbackModule +from tower_display_callback import TowerMinimalCallbackModule as CallbackModule # noqa diff --git a/awx/plugins/callback/tower_display.py b/awx/plugins/callback/tower_display.py index 36f6a29537..725232dfe4 100644 --- a/awx/plugins/callback/tower_display.py +++ b/awx/plugins/callback/tower_display.py @@ -27,4 +27,4 @@ if awx_lib_path not in sys.path: sys.path.insert(0, awx_lib_path) # Tower Display Callback -from tower_display_callback import TowerDefaultCallbackModule as CallbackModule +from tower_display_callback import TowerDefaultCallbackModule as CallbackModule # noqa