summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2017-02-08 10:38:17 +0100
committerLinus Nordberg <linus@nordu.net>2017-02-08 10:38:17 +0100
commitc1ac7daa7589346f7308e5399452e3a7993a1b85 (patch)
tree70a43b0ef3f28fd8396823fa927038b8ece676de
parentb188fcc29c3df97978e5da4a87b946b300d79932 (diff)
Have loginfo.py tolerate 500 for a while when waiting for STH.
-rw-r--r--tools/certtools.py10
-rwxr-xr-xtools/loginfo.py4
-rwxr-xr-xtools/testcase1.py9
3 files changed, 12 insertions, 11 deletions
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)