Commit 6b27e075 authored by Petr Špaček's avatar Petr Špaček

finish allinone.py

It now produces the same result as each individual script, including
pickled intermediate results.
parent fd2ee7f9
Pipeline #40744 passed with stage
in 1 minute and 58 seconds
......@@ -52,6 +52,7 @@ def main():
new / total * 100,
remaining,
remaining/total * 100)
nsname2ipset.save(nsname_ipsets)
# domain2ipset.py
logging.info('looking for a working NS IP addresses for each domain')
......@@ -79,7 +80,7 @@ def main():
new / total * 100,
remaining,
remaining/total * 100)
domain2ipset.save(domain_nsset, netstats, domain_ipset)
logging.info('generating input data for genreport tool')
with open('ednscomp.input', 'w') as ednscomp_input:
......@@ -94,11 +95,17 @@ def main():
logging.info('processing genreport output in EDNS strict mode')
nsstats_strict = ednscomp2pickle.collect_server_stats(ednscomp2pickle.eval_edns_strict, ednscompresults)
ednscomp2pickle.save(nsstats_strict, 'strict')
logging.info('processing genreport output in EDNS permissive mode')
nsstats_permissive = ednscomp2pickle.collect_server_stats(ednscomp2pickle.eval_edns_permissive, ednscompresults)
ednscomp2pickle.save(nsstats_permissive, 'permissive')
summary, results_strict, results_permissive = evalzone.evaluate(nsstats_strict, nsstats_permissive, domain_nsset, nsname_ipsets, domain_ipset)
evalzone.save(results_strict, 'strict')
evalzone.save(results_permissive, 'permissive')
with open('summary', 'w') as summary_file:
summary_file.write(summary)
print(summary)
if __name__ == "__main__":
......
......@@ -82,18 +82,24 @@ def collect_server_stats(eval_edns_func, edns_infns: str) -> Dict[str, Counter[E
i += 1
return server_stats
def save(nsstats, criteria: str) -> None:
"""
param criteria: name of criteria - strict / permissive
"""
filename = 'ednsstats_{}.pickle'.format(criteria)
logging.info('saving EDNS results into {}'.format(filename))
pickle.dump(nsstats, open(filename, 'wb'))
def main(infiles):
"""
infiles - names of files with output from ISC genreport
"""
logging.info('processing input in EDNS strict mode')
nsstats_strict = collect_server_stats(eval_edns_strict, infiles)
pickle.dump(nsstats_strict, open('ednsstats_strict.pickle', 'wb'))
logging.info('saving results')
save(nsstats_strict, 'strict')
logging.info('processing input in EDNS permissive mode')
nsstats_permissive = collect_server_stats(eval_edns_permissive, infiles)
pickle.dump(nsstats_permissive, open('ednsstats_permissive.pickle', 'wb'))
logging.info('saving results')
save(nsstats_permissive, 'permissive')
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(message)s')
......
......@@ -162,17 +162,16 @@ def evaluate(ednsstats_strict, ednsstats_permissive, domain2nsset, nsname2ipset,
return summary, results_strict, results_permissive
def save(results_strict, results_permissive):
logging.info('pickling results for EDNS strict mode')
with open('results_strict.pickle', 'wb') as results_bin:
pickle.dump(results_strict, results_bin)
logging.info('pickling results for EDNS permissive mode')
with open('results_permissive.pickle', 'wb') as results_bin:
pickle.dump(results_permissive, results_bin)
def save(results, mode: str) -> None:
logging.info('pickling results for EDNS {} mode'.format(mode))
with open('results_{}.pickle'.format(mode), 'wb') as results_bin:
pickle.dump(results, results_bin)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')
summary, results_strict, results_permissive = evaluate(*load())
save(results_strict, results_permissive)
print(summary)
\ No newline at end of file
save(results_strict, 'strict')
save(results_permissive, 'permissive')
print(summary)
with open('summary', 'w') as summary_file:
summary_file.write(summary)
\ No newline at end of file
......@@ -74,8 +74,6 @@ def update_mapping(nsnames: Set[dns.name.Name],
def save(mapping: Dict[dns.name.Name, Set[str]]) -> None:
logging.info('writting %d results', len(mapping))
pickle.dump(mapping, open('nsname2ipset.pickle', 'wb'))
logging.info('%s out of %s NS names resolved to an IP address (%0.2f %%)',
len(mapping), len(nsnames), len(mapping)/len(nsnames)*100)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')
......@@ -87,6 +85,8 @@ if __name__ == "__main__":
logging.exception('exception while resolving names to IP addresses')
raise
finally: # attempt to salvage partial results
logging.info('%s out of %s NS names resolved to an IP address (%0.2f %%)',
len(mapping), len(nsnames), len(mapping)/len(nsnames)*100)
save(mapping)
# machine readable output: # of NS names resolved to an IP address
print(len(mapping))
......
Markdown is supported
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