From c1ac7daa7589346f7308e5399452e3a7993a1b85 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Wed, 8 Feb 2017 10:38:17 +0100 Subject: Have loginfo.py tolerate 500 for a while when waiting for STH. --- tools/certtools.py | 10 ++++++++++ tools/loginfo.py | 4 ++-- tools/testcase1.py | 9 --------- 3 files changed, 12 insertions(+), 11 deletions(-) (limited to 'tools') diff --git a/tools/certtools.py b/tools/certtools.py index f5482cb..7a5f9fc 100644 --- a/tools/certtools.py +++ b/tools/certtools.py @@ -18,6 +18,7 @@ import shutil import requests import warnings import logging +from time import sleep from certkeys import publickeys @@ -131,6 +132,15 @@ def get_sth(baseurl): result.raise_for_status() return result.json() +def get_sth_retry(baseurl, tries=1): + for i in range(tries): + try: + return get_sth(baseurl) + except requests.exceptions.HTTPError, e: + if e.response.status_code == 500: + sleep(1) + raise e + def get_proof_by_hash(baseurl, hash, tree_size): params = {"hash":base64.b64encode(hash), "tree_size":tree_size} diff --git a/tools/loginfo.py b/tools/loginfo.py index c742b33..1356806 100755 --- a/tools/loginfo.py +++ b/tools/loginfo.py @@ -7,7 +7,7 @@ import sys import argparse import readconfig -from certtools import create_ssl_context, get_sth +from certtools import create_ssl_context, get_sth_retry def main(): parser = argparse.ArgumentParser(description='') @@ -29,7 +29,7 @@ def main(): paths = localconfig["paths"] create_ssl_context(cafile=paths["https_cacertfile"]) - sth = get_sth(args.baseurl) + sth = get_sth_retry(args.baseurl, tries=10) if args.raw: print sth diff --git a/tools/testcase1.py b/tools/testcase1.py index 233415a..fb081e5 100755 --- a/tools/testcase1.py +++ b/tools/testcase1.py @@ -150,15 +150,6 @@ def get_and_check_entry(timestamp, chain, leaf_index, baseurl): len(submittedcertchain), len(submittedcertchain)) -def get_sth_retry(baseurl, tries=1): - for i in range(tries): - try: - return get_sth(baseurl) - except requests.exceptions.HTTPError, e: - if e.response.status_code == 500: - sleep(1) - raise e - def correct_tree_size(expected): for baseurl in baseurls: sth = get_sth_retry(baseurl, tries=10) -- cgit v1.1