diff --git a/awx/main/tests/base.py b/awx/main/tests/base.py index 09b30b5523..281515dc41 100644 --- a/awx/main/tests/base.py +++ b/awx/main/tests/base.py @@ -66,6 +66,8 @@ class BaseTestMixin(object): self._temp_paths.append(callback_queue_path) settings.CALLBACK_QUEUE_PORT = 'ipc://%s' % callback_queue_path settings.TASK_COMMAND_PORT = 'ipc:///tmp/task_command_receiver_%d.ipc' % callback_port + # Disable socket notifications for unit tests. + settings.SOCKETIO_NOTIFICATION_PORT = None # Make temp job status directory for unit tests. job_status_dir = tempfile.mkdtemp() self._temp_paths.append(job_status_dir) diff --git a/awx/main/tests/commands.py b/awx/main/tests/commands.py index f9411f1512..3a118287e2 100644 --- a/awx/main/tests/commands.py +++ b/awx/main/tests/commands.py @@ -323,7 +323,8 @@ class CleanupJobsTest(BaseCommandMixin, BaseLiveServerTest): self.project = None self.credential = None settings.INTERNAL_API_URL = self.live_server_url - self.start_queue(settings.CALLBACK_CONSUMER_PORT, settings.CALLBACK_QUEUE_PORT) + if settings.CALLBACK_CONSUMER_PORT: + self.start_queue(settings.CALLBACK_CONSUMER_PORT, settings.CALLBACK_QUEUE_PORT) def tearDown(self): super(CleanupJobsTest, self).tearDown() diff --git a/awx/main/utils.py b/awx/main/utils.py index a9a582b03a..81b5763e55 100644 --- a/awx/main/utils.py +++ b/awx/main/utils.py @@ -19,9 +19,6 @@ from Crypto.Cipher import AES # ZeroMQ import zmq -# Django -from django.conf import settings - __all__ = ['get_object_or_400', 'get_object_or_403', 'camelcase_to_underscore', 'get_ansible_version', 'get_awx_version', 'update_scm_url', 'get_type_for_model', 'get_model_for_type'] @@ -345,9 +342,11 @@ def get_system_task_capacity(): return 50 + ((int(total_mem_value) / 1024) - 2) * 75 def emit_websocket_notification(endpoint, event, payload): - emit_context = zmq.Context() - emit_socket = emit_context.socket(zmq.PUSH) - emit_socket.connect(settings.SOCKETIO_NOTIFICATION_PORT) - payload['event'] = event - payload['endpoint'] = endpoint - emit_socket.send_json(payload); + from django.conf import settings + if getattr(settings, 'SOCKETIO_NOTIFICATION_PORT', None): + emit_context = zmq.Context() + emit_socket = emit_context.socket(zmq.PUSH) + emit_socket.connect(settings.SOCKETIO_NOTIFICATION_PORT) + payload['event'] = event + payload['endpoint'] = endpoint + emit_socket.send_json(payload);