diff options
author | Magnus Ahltorp <map@kth.se> | 2017-02-06 15:08:42 +0100 |
---|---|---|
committer | Magnus Ahltorp <map@kth.se> | 2017-02-06 15:08:42 +0100 |
commit | 8c1e3ac28cbb902b540f776886a6556c40d3f601 (patch) | |
tree | 2e629effbfc5000c656b0fbe0389af56dbcfafff /tools | |
parent | 8a1f3a5f5b1458aceb7567add95e7637e9c2e5fc (diff) |
Wait for merge in tests
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/mergestatus.py | 46 | ||||
-rwxr-xr-x | tools/testcase1.py | 43 |
2 files changed, 75 insertions, 14 deletions
diff --git a/tools/mergestatus.py b/tools/mergestatus.py new file mode 100755 index 0000000..80d755e --- /dev/null +++ b/tools/mergestatus.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (c) 2017, NORDUnet A/S. +# See LICENSE for licensing information. +# +import sys +import json +import urllib2 +import time +import requests +import base64 +from base64 import b64encode +from mergetools import parse_args, get_nfetched, hexencode, hexdecode, \ + get_logorder, get_sth +from certtools import create_ssl_context, get_public_key_from_file, \ + timing_point, create_sth_signature, write_file, check_sth_signature, \ + build_merkle_tree + +def main(): + args, config, localconfig = parse_args() + paths = localconfig["paths"] + mergenodes = config.get("mergenodes", []) + mergedb = paths["mergedb"] + sthfile = mergedb + "/sth" + currentsizefile = mergedb + "/fetched" + + sth = json.loads(open(sthfile, "r").read()) + currentsize = json.loads(open(currentsizefile, "r").read()) + + print >>sys.stderr, currentsize["index"]+1, + + for mergenode in mergenodes: + if mergenode["name"] == config["primarymergenode"]: + continue + verifiedfile = mergedb + "/verified." + mergenode["name"] + try: + tree = json.loads(open(verifiedfile, "r").read()) + print >>sys.stderr, tree["tree_size"], + except (IOError, ValueError): + pass + print >>sys.stderr, sth["tree_size"], + print + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tools/testcase1.py b/tools/testcase1.py index 5192074..12079c8 100755 --- a/tools/testcase1.py +++ b/tools/testcase1.py @@ -148,13 +148,28 @@ def get_and_check_entry(timestamp, chain, leaf_index, baseurl): len(submittedcertchain), len(submittedcertchain)) -def merge(): - rv = subprocess.call([toolsdir + "/merge", "--config", testdir + "/catlfish-test.cfg", - "--localconfig", testdir + "/catlfish-test-local-merge.cfg"]) - sleep(5) # FIXME: Just wait for dist instead. - return rv - -mergeresult = merge() +def correct_tree_size(expected): + for baseurl in baseurls: + sth = get_sth(baseurl) + tree_size = sth["tree_size"] + if tree_size != expected: + return False + return True + +def merge(expected=None, wait=0): + for i in range(10): + rv = subprocess.call([toolsdir + "/merge", "--config", testdir + "/catlfish-test.cfg", + "--localconfig", testdir + "/catlfish-test-local-merge.cfg"]) + if rv: + return rv + if i < wait: + sleep(1) + continue + if correct_tree_size(expected): + return 0 + return 0 + +mergeresult = merge(expected=0, wait=3) assert_equal(mergeresult, 0, "merge", quiet=True, fatal=True) for baseurl in baseurls: @@ -164,7 +179,7 @@ testgroup("cert1") result1 = do_add_chain(cc1, baseurls[0]) -mergeresult = merge() +mergeresult = merge(expected=1) assert_equal(mergeresult, 0, "merge", quiet=True, fatal=True) size_sth = {} @@ -177,7 +192,7 @@ result2 = do_add_chain(cc1, baseurls[0]) assert_equal(result2["timestamp"], result1["timestamp"], "timestamp") -mergeresult = merge() +mergeresult = merge(expected=1, wait=3) assert_equal(mergeresult, 0, "merge", quiet=True, fatal=True) for baseurl in baseurls: @@ -195,7 +210,7 @@ testgroup("cert2") result3 = do_add_chain(cc2, baseurls[0]) -mergeresult = merge() +mergeresult = merge(expected=2) assert_equal(mergeresult, 0, "merge", quiet=True, fatal=True) for baseurl in baseurls: @@ -209,7 +224,7 @@ testgroup("cert3") result4 = do_add_chain(cc3, baseurls[0]) -mergeresult = merge() +mergeresult = merge(expected=3) assert_equal(mergeresult, 0, "merge", quiet=True, fatal=True) for baseurl in baseurls: @@ -224,7 +239,7 @@ testgroup("cert4") result5 = do_add_chain(cc4, baseurls[0]) -mergeresult = merge() +mergeresult = merge(expected=4) assert_equal(mergeresult, 0, "merge", quiet=True, fatal=True) for baseurl in baseurls: @@ -240,7 +255,7 @@ testgroup("cert5") result6 = do_add_chain(cc5, baseurls[0]) -mergeresult = merge() +mergeresult = merge(expected=5) assert_equal(mergeresult, 0, "merge", quiet=True, fatal=True) for baseurl in baseurls: @@ -253,7 +268,7 @@ get_and_validate_proof(result4["timestamp"], cc3, 2, 3, baseurls[0]) get_and_validate_proof(result5["timestamp"], cc4, 3, 3, baseurls[0]) get_and_validate_proof(result6["timestamp"], cc5, 4, 1, baseurls[0]) -mergeresult = merge() +mergeresult = merge(expected=5, wait=3) assert_equal(mergeresult, 0, "merge", quiet=True, fatal=True) for first_size in range(1, 5): |