From 12158bdcbaa2c14267bb61e2b011398308d72a7d Mon Sep 17 00:00:00 2001 From: chris meyers Date: Thu, 19 Mar 2020 08:57:05 -0400 Subject: [PATCH 1/5] remove dead code --- awx/main/dispatch/__init__.py | 23 ----------------------- awx/main/dispatch/control.py | 4 ---- 2 files changed, 27 deletions(-) diff --git a/awx/main/dispatch/__init__.py b/awx/main/dispatch/__init__.py index 841f9344ae..bff1329a7d 100644 --- a/awx/main/dispatch/__init__.py +++ b/awx/main/dispatch/__init__.py @@ -9,10 +9,6 @@ from django.conf import settings NOT_READY = ([], [], []) -if 'run_callback_receiver' in sys.argv: - logger = logging.getLogger('awx.main.commands.run_callback_receiver') -else: - logger = logging.getLogger('awx.main.dispatch') def get_local_queuename(): @@ -36,25 +32,6 @@ class PubSub(object): with self.conn.cursor() as cur: cur.execute('SELECT pg_notify(%s, %s);', (channel, payload)) - def get_event(self, select_timeout=0): - # poll the connection, then return one event, if we have one. Else - # return None. - select.select([self.conn], [], [], select_timeout) - self.conn.poll() - if self.conn.notifies: - return self.conn.notifies.pop(0) - - def get_events(self, select_timeout=0): - # Poll the connection and return all events, if there are any. Else - # return None. - select.select([self.conn], [], [], select_timeout) # redundant? - self.conn.poll() - events = [] - while self.conn.notifies: - events.append(self.conn.notifies.pop(0)) - if events: - return events - def events(self, select_timeout=5, yield_timeouts=False): while True: if select.select([self.conn], [], [], select_timeout) == NOT_READY: diff --git a/awx/main/dispatch/control.py b/awx/main/dispatch/control.py index 4565df17f5..a7c8ce78de 100644 --- a/awx/main/dispatch/control.py +++ b/awx/main/dispatch/control.py @@ -21,10 +21,6 @@ class Control(object): self.service = service self.queuename = host or get_local_queuename() - def publish(self, msg, conn, **kwargs): - # TODO: delete this method?? - raise RuntimeError("Publish called?!") - def status(self, *args, **kwargs): return self.control_with_reply('status', *args, **kwargs) From 7f2e1d46bcbc5f10d85c07571292783ff0378ac5 Mon Sep 17 00:00:00 2001 From: chris meyers Date: Thu, 19 Mar 2020 08:59:15 -0400 Subject: [PATCH 2/5] replace janky unique channel name w/ uuid * postgres notify/listen channel names have size limitations as well as character limitations. Respect those limitations while at the same time generate a unique channel name. --- awx/main/dispatch/control.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/awx/main/dispatch/control.py b/awx/main/dispatch/control.py index a7c8ce78de..ea3cd75ee6 100644 --- a/awx/main/dispatch/control.py +++ b/awx/main/dispatch/control.py @@ -1,5 +1,5 @@ import logging -import string +import uuid import random import json @@ -29,8 +29,7 @@ class Control(object): @classmethod def generate_reply_queue_name(cls): - letters = string.ascii_lowercase - return 'reply_to_{}'.format(''.join(random.choice(letters) for i in range(8))) + return f"reply_to_{str(uuid.uuid4()).replace('-','_')}" def control_with_reply(self, command, timeout=5): logger.warn('checking {} {} for {}'.format(self.service, command, self.queuename)) From c7de3b05285d9a43d4a02e557a5dc679aa40a460 Mon Sep 17 00:00:00 2001 From: chris meyers Date: Thu, 19 Mar 2020 09:01:03 -0400 Subject: [PATCH 3/5] fix spelling --- awx/main/dispatch/publish.py | 2 +- awx/main/tests/functional/test_dispatch.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/awx/main/dispatch/publish.py b/awx/main/dispatch/publish.py index 020e7407cd..f7fd7cf4fb 100644 --- a/awx/main/dispatch/publish.py +++ b/awx/main/dispatch/publish.py @@ -74,7 +74,7 @@ class task: getattr(cls.queue, 'im_func', cls.queue) ) if not queue: - msg = f'{cls.name}: Queue value required and may not me None' + msg = f'{cls.name}: Queue value required and may not be None' logger.error(msg) raise ValueError(msg) obj = { diff --git a/awx/main/tests/functional/test_dispatch.py b/awx/main/tests/functional/test_dispatch.py index c13a031af3..aa3c42ce26 100644 --- a/awx/main/tests/functional/test_dispatch.py +++ b/awx/main/tests/functional/test_dispatch.py @@ -349,7 +349,7 @@ class TestTaskPublisher: def test_apply_async_queue_required(self): with pytest.raises(ValueError) as e: message, queue = add.apply_async([2, 2]) - assert "awx.main.tests.functional.test_dispatch.add: Queue value required and may not me None" == e.value.args[0] + assert "awx.main.tests.functional.test_dispatch.add: Queue value required and may not be None" == e.value.args[0] def test_queue_defined_in_task_decorator(self): message, queue = multiply.apply_async([2, 2]) From 0a1070834dda93f43b65efb26f495daced4f7f66 Mon Sep 17 00:00:00 2001 From: chris meyers Date: Thu, 19 Mar 2020 09:04:47 -0400 Subject: [PATCH 4/5] only update the ip address field on the instance * The heartbeat of an instance is determined to be the last modified time of the Instance object. Therefore, we want to be careful to only update very specific fields of the Instance object. --- awx/main/managers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/main/managers.py b/awx/main/managers.py index ea65b36234..9f1537fd6f 100644 --- a/awx/main/managers.py +++ b/awx/main/managers.py @@ -126,7 +126,7 @@ class InstanceManager(models.Manager): instance = instance.get() if instance.ip_address != ip_address: instance.ip_address = ip_address - instance.save() + instance.save(update_fields=['ip_address']) return (True, instance) else: return (False, instance) From 5e481341bc8407354beba1b031abc263767c6bce Mon Sep 17 00:00:00 2001 From: chris meyers Date: Thu, 19 Mar 2020 09:59:57 -0400 Subject: [PATCH 5/5] flake8 --- awx/main/dispatch/__init__.py | 2 -- awx/main/dispatch/control.py | 1 - 2 files changed, 3 deletions(-) diff --git a/awx/main/dispatch/__init__.py b/awx/main/dispatch/__init__.py index bff1329a7d..025710ba22 100644 --- a/awx/main/dispatch/__init__.py +++ b/awx/main/dispatch/__init__.py @@ -1,7 +1,5 @@ import psycopg2 import select -import sys -import logging from contextlib import contextmanager diff --git a/awx/main/dispatch/control.py b/awx/main/dispatch/control.py index ea3cd75ee6..186acee5cf 100644 --- a/awx/main/dispatch/control.py +++ b/awx/main/dispatch/control.py @@ -1,6 +1,5 @@ import logging import uuid -import random import json from awx.main.dispatch import get_local_queuename