github.com/weaveworks/common@v0.0.0-20230728070032-dd9e68f319d5/tools/sched (about) 1 #!/usr/bin/env python 2 import sys, string, urllib 3 import requests 4 from requests.packages.urllib3.util.retry import Retry 5 from requests.adapters import HTTPAdapter 6 import optparse 7 8 session = requests.Session() 9 adapter = HTTPAdapter( 10 max_retries=Retry( 11 connect=5, 12 status=5, 13 backoff_factor=0.1, 14 status_forcelist=[500, 502, 503, 504] 15 ) 16 ) 17 session.mount('http://', adapter) 18 session.mount('https://', adapter) 19 20 21 def test_time(target, test_name, runtime): 22 r = session.post(target + "/record/%s/%f" % (urllib.quote(test_name, safe=""), runtime)) 23 print r.text.encode('utf-8') 24 assert r.status_code == 204 25 26 def test_sched(target, test_run, shard_count, shard_id): 27 tests = {'tests': string.split(sys.stdin.read())} 28 r = session.post(target + "/schedule/%s/%d/%d" % (test_run, shard_count, shard_id), json=tests) 29 assert r.status_code == 200 30 result = r.json() 31 for test in sorted(result['tests']): 32 print test.encode('utf-8') 33 34 def usage(): 35 print "%s (--target=...) <cmd> <args..>" % sys.argv[0] 36 print " time <test name> <run time>" 37 print " sched <test run> <num shards> <shard id>" 38 39 def main(): 40 parser = optparse.OptionParser() 41 parser.add_option('--target', default="http://positive-cocoa-90213.appspot.com") 42 options, args = parser.parse_args() 43 if len(args) < 3: 44 usage() 45 sys.exit(1) 46 47 if args[0] == "time": 48 test_time(options.target, args[1], float(args[2])) 49 elif args[0] == "sched": 50 test_sched(options.target, args[1], int(args[2]), int(args[3])) 51 else: 52 usage() 53 54 if __name__ == '__main__': 55 main()