From 40dea6a747d3b06087d379fdd5a936d4b7a73958 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 20 Oct 2021 18:23:35 -0400 Subject: [PATCH] Support older python subprocess Older python did not provide timeout. Keep the timeout for the modern python that skips select without a timeout, but try again without timeout to retain compatibility. --- confluent_server/confluent/certutil.py | 13 ++++++++++--- confluent_server/confluent/selfservice.py | 5 ++++- confluent_server/confluent/sshutil.py | 5 ++++- confluent_server/confluent/syncfiles.py | 8 ++++++-- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/confluent_server/confluent/certutil.py b/confluent_server/confluent/certutil.py index a6119faa..3582a53a 100644 --- a/confluent_server/confluent/certutil.py +++ b/confluent_server/confluent/certutil.py @@ -15,7 +15,10 @@ def get_openssl_conf_location(): raise Exception("Cannot find openssl config file") def get_ip_addresses(): - lines = subprocess.check_output('ip addr'.split(' '), timeout=86400) + try: + lines = subprocess.check_output('ip addr'.split(' '), timeout=86400) + except TypeError: + lines = subprocess.check_output('ip addr'.split(' ')) if not isinstance(lines, str): lines = lines.decode('utf8') for line in lines.split('\n'): @@ -101,8 +104,12 @@ def assure_tls_ca(): if e.errno != 17: raise shutil.copy2('/etc/confluent/tls/cacert.pem', fname) - hv = subprocess.check_output( - ['openssl', 'x509', '-in', '/etc/confluent/tls/cacert.pem', '-hash', '-noout'], timeout=86400) + try: + hv = subprocess.check_output( + ['openssl', 'x509', '-in', '/etc/confluent/tls/cacert.pem', '-hash', '-noout'], timeout=86400) + except TypeError: + hv = subprocess.check_output( + ['openssl', 'x509', '-in', '/etc/confluent/tls/cacert.pem', '-hash', '-noout']) if not isinstance(hv, str): hv = hv.decode('utf8') hv = hv.strip() diff --git a/confluent_server/confluent/selfservice.py b/confluent_server/confluent/selfservice.py index bc50c7a6..05616c32 100644 --- a/confluent_server/confluent/selfservice.py +++ b/confluent_server/confluent/selfservice.py @@ -217,7 +217,10 @@ def handle_request(env, start_response): if ckeymap == 'n/a': continue keymap = ckeymap - tdc = subprocess.check_output(['timedatectl'], timeout=86400).split(b'\n') + try: + tdc = subprocess.check_output(['timedatectl'], timeout=86400).split(b'\n') + except TypeError: + tdc = subprocess.check_output(['timedatectl']).split(b'\n') for ent in tdc: ent = ent.strip() if ent.startswith(b'Time zone:'): diff --git a/confluent_server/confluent/sshutil.py b/confluent_server/confluent/sshutil.py index 8faa0692..dcdfc57f 100644 --- a/confluent_server/confluent/sshutil.py +++ b/confluent_server/confluent/sshutil.py @@ -43,7 +43,10 @@ def assure_agent(): if agent_pid is None: try: agent_starting = True - sai = subprocess.check_output(['ssh-agent'], timeout=86400) + try: + sai = subprocess.check_output(['ssh-agent'], timeout=86400) + except TypeError: + sai = subprocess.check_output(['ssh-agent']) for line in sai.split(b'\n'): if b';' not in line: continue diff --git a/confluent_server/confluent/syncfiles.py b/confluent_server/confluent/syncfiles.py index 46aebafd..a02d03ed 100644 --- a/confluent_server/confluent/syncfiles.py +++ b/confluent_server/confluent/syncfiles.py @@ -142,8 +142,12 @@ def sync_list_to_node(sl, node, suffixes): stage_ent(sl.appendoncemap, ent, os.path.join(targdir, suffixes['appendonce']), True) sshutil.prep_ssh_key('/etc/confluent/ssh/automation') - output = subprocess.check_output( - ['rsync', '-rvLD', targdir + '/', 'root@{}:/'.format(node)], timeout=86400) + try: + output = subprocess.check_output( + ['rsync', '-rvLD', targdir + '/', 'root@{}:/'.format(node)], timeout=86400) + except TypeError: + output = subprocess.check_output( + ['rsync', '-rvLD', targdir + '/', 'root@{}:/'.format(node)]) except Exception as e: if 'CalledProcessError' not in repr(e): # https://github.com/eventlet/eventlet/issues/413