def __init__(self, deck_hash=None, deckFile=None, decks_directory=config.decks_directory, no_collector=False): self.id = deck_hash self.requiresTor = False self.no_collector = no_collector self.bouncer = '' self.netTestLoaders = [] self.inputs = [] self.oonibclient = OONIBClient(self.bouncer) self.decksDirectory = os.path.abspath(decks_directory) self.deckHash = deck_hash if deckFile: self.loadDeck(deckFile)
def upload(report_file, collector=None, bouncer=None): oonib_report_log = OONIBReportLog() log.msg("Attempting to upload %s" % report_file) with open(config.report_log_file) as f: report_log = yaml.safe_load(f) report = parser.ReportLoader(report_file) if bouncer and not collector: oonib_client = OONIBClient(bouncer) net_tests = [{ 'test-helpers': [], 'input-hashes': report.header['input_hashes'], 'name': report.header['test_name'], 'version': report.header['test_version'], }] result = yield oonib_client.lookupTestCollector( net_tests ) collector = str(result['net-tests'][0]['collector']) if collector is None: try: collector = report_log[report_file]['collector'] if collector is None: raise KeyError except KeyError: raise Exception( "No collector or bouncer specified" " and collector not in report log." ) oonib_reporter = OONIBReporter(report.header, collector) log.msg("Creating report for %s with %s" % (report_file, collector)) report_id = yield oonib_reporter.createReport() report.header['report_id'] = report_id yield oonib_report_log.created(report_file, collector, report_id) for entry in report: yield oonib_reporter.writeReportEntry(entry) log.msg("Closing report.") yield oonib_reporter.finish() yield oonib_report_log.closed(report_file)
def setUp(self): super(TestOONIBClient, self).setUp() host = '127.0.0.1' port = 8889 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.connect((host, port)) s.shutdown(2) data_dir = '/tmp/testooni' config.advanced.data_dir = data_dir if os.path.exists(data_dir): shutil.rmtree(data_dir) os.mkdir(data_dir) os.mkdir(os.path.join(data_dir, 'inputs')) os.mkdir(os.path.join(data_dir, 'decks')) except Exception: self.skipTest( "OONIB must be listening on port 8888 to run this test (tor_hidden_service: false)" ) self.oonibclient = OONIBClient('http://' + host + ':' + str(port))