From ccfec2c729117fcf95c877aad48f5a293bdfef0a Mon Sep 17 00:00:00 2001 From: David Arthur Date: Fri, 4 Oct 2019 18:16:07 -0400 Subject: [PATCH 1/2] Add retries to sftp uploads These fail often for me due to SSH connection loss --- release.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/release.py b/release.py index a9fa697f0e159..b10d02d935545 100755 --- a/release.py +++ b/release.py @@ -99,7 +99,9 @@ def print_output(output): def cmd(action, cmd, *args, **kwargs): if isinstance(cmd, basestring) and not kwargs.get("shell", False): cmd = cmd.split() + allow_failure = kwargs.pop("allow_failure", False) + num_retries = kwargs.pop("num_retries", 0) stdin_log = "" if "stdin" in kwargs and isinstance(kwargs["stdin"], basestring): @@ -116,9 +118,16 @@ def cmd(action, cmd, *args, **kwargs): except subprocess.CalledProcessError as e: print_output(e.output) + if num_retries > 0: + kwargs['num_retries'] = num_retries - 1 + kwargs['allow_failure'] = allow_failure + print("Retrying... %d remaining retries" % (num_retries - 1)) + return cmd(action, cmd, *args, **kwargs) + if allow_failure: return + print("*************************************************") print("*** First command failure occurred here. ***") print("*** Will now try to clean up working state. ***") @@ -628,7 +637,7 @@ def select_gpg_key(): sftp_cmds = """ put %s %s """ % (local_path, remote_path) - cmd("Uploading artifacts in %s to your Apache home directory" % root, "sftp -b - %s@home.apache.org" % apache_id, stdin=sftp_cmds) + cmd("Uploading artifacts in %s to your Apache home directory" % root, "sftp -b - %s@home.apache.org" % apache_id, stdin=sftp_cmds, num_retries=3) with open(os.path.expanduser("~/.gradle/gradle.properties")) as f: contents = f.read() From 2d699a6b6c5756b6cf7f7d7ca1e33431f83c8f28 Mon Sep 17 00:00:00 2001 From: David Arthur Date: Fri, 4 Oct 2019 21:45:36 -0400 Subject: [PATCH 2/2] Fix cmd --- release.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/release.py b/release.py index b10d02d935545..536ddc930866e 100755 --- a/release.py +++ b/release.py @@ -96,9 +96,9 @@ def print_output(output): for line in output.split('\n'): print(">", line) -def cmd(action, cmd, *args, **kwargs): - if isinstance(cmd, basestring) and not kwargs.get("shell", False): - cmd = cmd.split() +def cmd(action, cmd_arg, *args, **kwargs): + if isinstance(cmd_arg, basestring) and not kwargs.get("shell", False): + cmd_arg = cmd_arg.split() allow_failure = kwargs.pop("allow_failure", False) num_retries = kwargs.pop("num_retries", 0) @@ -111,9 +111,9 @@ def cmd(action, cmd, *args, **kwargs): stdin.seek(0) kwargs["stdin"] = stdin - print(action, cmd, stdin_log) + print(action, cmd_arg, stdin_log) try: - output = subprocess.check_output(cmd, *args, stderr=subprocess.STDOUT, **kwargs) + output = subprocess.check_output(cmd_arg, *args, stderr=subprocess.STDOUT, **kwargs) print_output(output) except subprocess.CalledProcessError as e: print_output(e.output) @@ -122,7 +122,7 @@ def cmd(action, cmd, *args, **kwargs): kwargs['num_retries'] = num_retries - 1 kwargs['allow_failure'] = allow_failure print("Retrying... %d remaining retries" % (num_retries - 1)) - return cmd(action, cmd, *args, **kwargs) + return cmd(action, cmd_arg, *args, **kwargs) if allow_failure: return @@ -162,7 +162,7 @@ def regexReplace(path, pattern, replacement): def user_ok(msg): ok = raw_input(msg) - return ok.lower() == 'y' + return ok.strip().lower() == 'y' def sftp_mkdir(dir): basedir, dirname = os.path.split(dir)