[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [ooni-probe/master] Include the deck_id in the returned value
commit bcb93b889d55a22347f2d1f2d01a63c707fb7ef1
Author: Arturo Filastò <arturo@xxxxxxxxxxx>
Date: Thu Jan 12 12:54:17 2017 +0000
Include the deck_id in the returned value
---
ooni/deck/deck.py | 8 +++++---
ooni/measurements.py | 13 ++++++++-----
ooni/ui/web/server.py | 8 +++++++-
ooni/utils/__init__.py | 6 ++++--
4 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/ooni/deck/deck.py b/ooni/deck/deck.py
index fbbb8c3d..c57ccb63 100644
--- a/ooni/deck/deck.py
+++ b/ooni/deck/deck.py
@@ -234,7 +234,7 @@ class NGDeck(object):
# XXX-REFACTOR we do this so late to avoid the collision between the
# same id and hence generating the same filename.
test_details = net_test_loader.getTestDetails()
- task.id = generate_filename(test_details)
+ task.id = generate_filename(test_details, deck_id=self.id)
measurement_id = None
report_filename = task.output_path
@@ -330,7 +330,8 @@ class DeckTask(object):
self.ooni = {
'bouncer_client': None,
- 'test_details': {}
+ 'test_details': {},
+ 'test_name': None
}
self.output_path = None
@@ -353,8 +354,9 @@ class DeckTask(object):
if required_key not in task_data:
raise MissingTaskDataKey(required_key)
+ self.ooni['test_name'] = task_data.pop('test_name')
# This raises e.NetTestNotFound, we let it go onto the caller
- nettest_path = nettest_to_path(task_data.pop("test_name"),
+ nettest_path = nettest_to_path(self.ooni['test_name'],
self._arbitrary_paths)
annotations = self._pop_option('annotations', task_data, {})
diff --git a/ooni/measurements.py b/ooni/measurements.py
index 9197ee75..68b5c555 100644
--- a/ooni/measurements.py
+++ b/ooni/measurements.py
@@ -106,8 +106,11 @@ def get_measurement(measurement_id, compute_size=False):
if compute_size is True:
size = directory_usage(measurement.path)
- test_start_time, country_code, asn, test_name = \
- measurement_id.split("-")[:4]
+ measurement_metadata = measurement_id.split("-")
+ test_start_time, country_code, asn, test_name = measurement_metadata[:4]
+ deck_id = "none"
+ if len(measurement_metadata) > 4:
+ deck_id = '-'.join(measurement_metadata[4:])
return {
"test_name": test_name,
"country_code": country_code,
@@ -119,8 +122,7 @@ def get_measurement(measurement_id, compute_size=False):
"running": running,
"stale": stale,
"size": size,
- # XXX we need the deck ID in here
- "deck_id": "none"
+ "deck_id": deck_id
}
@@ -156,8 +158,9 @@ def list_measurements(compute_size=False, order=None):
for measurement_id in measurement_path.listdir():
try:
measurements.append(get_measurement(measurement_id, compute_size))
- except:
+ except Exception as exc:
log.err("Failed to get metadata for measurement {0}".format(measurement_id))
+ log.exception(exc)
if order is None:
return measurements
diff --git a/ooni/ui/web/server.py b/ooni/ui/web/server.py
index c8f191c7..e009cb74 100644
--- a/ooni/ui/web/server.py
+++ b/ooni/ui/web/server.py
@@ -370,6 +370,12 @@ class WebUIAPI(object):
def api_deck_list(self, request):
deck_list = {'decks': []}
for deck_id, deck in self.director.deck_store.list():
+ nettests = []
+ for task in deck.tasks:
+ if task.type == 'ooni':
+ assert task.ooni['test_name'] is not None
+ nettests.append(task.ooni['test_name'])
+
deck_list['decks'].append({
'id': deck_id,
'name': deck.name,
@@ -378,7 +384,7 @@ class WebUIAPI(object):
deck_id, from_schedule=False),
'running_scheduled': self.director.isDeckRunning(
deck_id, from_schedule=True),
- 'nettests': [], #XXX
+ 'nettests': nettests,
'description': deck.description,
'schedule': deck.schedule,
'enabled': self.director.deck_store.is_enabled(deck_id)
diff --git a/ooni/utils/__init__.py b/ooni/utils/__init__.py
index 6abd04fd..34b9fbba 100644
--- a/ooni/utils/__init__.py
+++ b/ooni/utils/__init__.py
@@ -1,7 +1,6 @@
import shutil
import string
import random
-import signal
import errno
import gzip
import os
@@ -103,7 +102,7 @@ def randomDate(start, end):
LONG_DATE = "%Y-%m-%d %H:%M:%S"
SHORT_DATE = "%Y%m%dT%H%M%SZ"
-def generate_filename(test_details, prefix=None, extension=None):
+def generate_filename(test_details, prefix=None, extension=None, deck_id=None):
"""
Returns a filename for every test execution.
@@ -116,6 +115,9 @@ def generate_filename(test_details, prefix=None, extension=None):
kwargs["prefix"] = prefix
filename_format += "{prefix}-"
filename_format += "{timestamp}-{probe_cc}-{probe_asn}-{test_name}"
+ if deck_id is not None:
+ kwargs["deck_id"] = deck_id
+ filename_format += "-{deck_id}"
if extension is not None:
kwargs["extension"] = extension
filename_format += ".{extension}"
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits