Refactored get_conn_type() method to use Enum

This commit is contained in:
Marcelo Moreira de Mello 2021-09-22 23:03:45 -04:00
parent 45600d034d
commit 045785c36f
2 changed files with 11 additions and 8 deletions

View File

@ -3049,7 +3049,7 @@ class AWXReceptorJob:
_kw = {}
if self.work_type == 'ansible-runner':
_kw['node'] = self.task.instance.execution_node
use_stream_tls = True if get_conn_type(_kw['node'], receptor_ctl) == 2 else False
use_stream_tls = get_conn_type(_kw['node'], receptor_ctl).name == "STREAMTLS"
_kw['tlsclient'] = get_tls_client(use_stream_tls)
result = receptor_ctl.submit_work(worktype=self.work_type, payload=sockout.makefile('rb'), params=self.receptor_params, **_kw)

View File

@ -4,12 +4,20 @@ import time
from receptorctl.socket_interface import ReceptorControl
from enum import Enum, unique
logger = logging.getLogger('awx.main.utils.receptor')
__RECEPTOR_CONF = '/etc/receptor/receptor.conf'
@unique
class ReceptorConnectionType(Enum):
DATAGRAM = 0
STREAM = 1
STREAMTLS = 2
def get_receptor_sockfile():
with open(__RECEPTOR_CONF, 'r') as f:
data = yaml.safe_load(f)
@ -47,20 +55,15 @@ def get_receptor_ctl():
def get_conn_type(node_name, receptor_ctl):
"""
ConnType 0: Datagram
ConnType 1: Stream
ConnType 2: StreamTLS
"""
all_nodes = receptor_ctl.simple_command("status").get('Advertisements', None)
for node in all_nodes:
if node.get('NodeID') == node_name:
return node.get('ConnType')
return ReceptorConnectionType(node.get('ConnType'))
def worker_info(node_name, work_type='ansible-runner'):
receptor_ctl = get_receptor_ctl()
use_stream_tls = True if get_conn_type(node_name, receptor_ctl) == 2 else False
use_stream_tls = get_conn_type(node_name, receptor_ctl).name == "STREAMTLS"
transmit_start = time.time()
error_list = []
data = {'errors': error_list, 'transmit_timing': 0.0}