Commit 6d4db045 authored by Alexandre's avatar Alexandre
Browse files

Move code into function

parent d9f93376
......@@ -1309,6 +1309,68 @@ def parse_opts_monitoring(me, opts):
return (url, name)
def run_default(name, connection, opts):
ok = True
if opts.multistreams:
connection.init_multi()
for i in range (0, opts.tests):
if opts.tests > 1 and (opts.verbose or opts.display_results):
print("\nTest %i" % i)
if opts.ifile is not None:
name, opts.rtype = get_next_domain(input)
request = create_request(name, qtype=opts.rtype, use_edns=opts.edns,
want_dnssec=opts.dnssec, no_ecs=opts.no_ecs, dot=opts.dot)
request.i = i
if not opts.dot:
request.head = opts.head
request.post = opts.post
if not opts.pipelining:
try:
connection.do_test(request, synchronous = not opts.multistreams)
except (OpenSSL.SSL.Error, CustomException) as e:
ok = False
error(e)
break
if not opts.multistreams:
if not print_result(connection, request):
ok = False
if opts.tests > 1 and i == 0:
start2 = time.time()
if opts.delay is not None:
time.sleep(opts.delay)
else: # We do pipelining
connection.pipelining_add_request(request)
if opts.multistreams:
connection.perform_multi()
if opts.sync:
connection.read_results()
if opts.dot and opts.pipelining:
print("")
done = 0
current = connection.pipelining_init_pending(opts.max_in_flight)
while done < opts.tests:
if time.time() > start + MAX_DURATION: # if we send thousands of requests
# MAX_DURATION will be reached
# need to increase MAX_DURATION based
# on the number of queries
# or to define a relation such as
# f(tests) = MAX_DURATION
print("Elapsed time too long, %i requests never got a reply" % (opts.tests-done))
ok = False
break
id = connection.read_result(connection, connection.pending)
if id is None: # Probably a timeout
time.sleep(SLEEP_TIMEOUT)
continue
done += 1
over, rank, request = connection.pending[id]
if not over:
error("Internal error, request %i should be over" % id)
if current < len(connection.all_requests):
connection.pipelining_fill_pending(current)
current += 1
return ok
# Main program
me = os.path.basename(sys.argv[0])
......@@ -1385,65 +1447,7 @@ for ip in ip_set:
if opts.ifile is not None:
input = open(opts.ifile)
if not opts.check:
if opts.multistreams:
conn.init_multi()
for i in range (0, opts.tests):
if opts.tests > 1 and (opts.verbose or opts.display_results):
print("\nTest %i" % i)
if opts.ifile is not None:
name, rtype = get_next_domain(input)
else:
name, rtype = name, opts.rtype
request = create_request(name, qtype=rtype, use_edns=opts.edns, want_dnssec=opts.dnssec, no_ecs=opts.no_ecs, dot=opts.dot)
request.i = i
if not opts.dot:
request.head = opts.head
request.post = opts.post
if not opts.pipelining:
try:
conn.do_test(request, synchronous = not opts.multistreams)
except (OpenSSL.SSL.Error, CustomException) as e:
ok = False
error(e)
break
if not opts.multistreams:
if not print_result(conn, request):
ok = False
if opts.tests > 1 and i == 0:
start2 = time.time()
if opts.delay is not None:
time.sleep(opts.delay)
else: # We do pipelining
conn.pipelining_add_request(request)
if opts.multistreams:
conn.perform_multi()
if opts.sync:
conn.read_results()
if opts.dot and opts.pipelining:
print("")
done = 0
current = conn.pipelining_init_pending(opts.max_in_flight)
while done < opts.tests:
if time.time() > start + MAX_DURATION: # if we send thousands of requests
# MAX_DURATION will be reached
# need to increase MAX_DURATION based
# on the number of queries
# or to define a relation such as
# f(tests) = MAX_DURATION
print("Elapsed time too long, %i requests never got a reply" % (opts.tests-done))
ok = False
break
id = conn.read_result(conn, conn.pending)
if id is None: # Probably a timeout
time.sleep(SLEEP_TIMEOUT)
continue
done += 1
over, rank, request = conn.pending[id]
if not over:
error("Internal error, request %i should be over" % id)
if current < len(conn.all_requests):
conn.pipelining_fill_pending(current)
current += 1
ok = run_default(name, conn, opts)
else:
ok = run_check(conn) and ok # need to run run_check first
stop = time.time()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment