commit 0737bada04f71434e9169bc964257dffce8f90c3 Author: Damian Johnson atagar@torproject.org Date: Wed May 9 10:01:32 2012 -0700
Parsing extrainfo dirreq-read/write-history lines
Handling the dirreq-read-history and dirreq-write-history. These are almost identical to the read-history and write-history lines so tieing it into that parser. This is the last field I need to parse the metrics descriptor I'm using for an example in the integ tests. --- stem/descriptor/extrainfo_descriptor.py | 38 +++++++++++++++++++++++- test/integ/descriptor/extrainfo_descriptor.py | 23 ++++++++++++-- 2 files changed, 55 insertions(+), 6 deletions(-)
diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py index 1def09c..aa02bc9 100644 --- a/stem/descriptor/extrainfo_descriptor.py +++ b/stem/descriptor/extrainfo_descriptor.py @@ -155,6 +155,16 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor): write_history_interval (int) - seconds per interval write_history_values (list) - bytes written during each interval (*)
+ dir_read_history_line (str) - bytes read for directory mirroring + dir_read_history_end (datetime.datetime) - end of the sampling interval + dir_read_history_interval (int) - seconds per interval + dir_read_history_values (list) - bytes read during each interval (*) + + dir_write_history_line (str) - bytes written for directory mirroring + dir_write_history_end (datetime.datetime) - end of the sampling interval + dir_write_history_interval (int) - seconds per interval + dir_write_history_values (list) - bytes read during each interval (*) + (*) required fields, others are left as None if undefined """
@@ -195,6 +205,16 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor): self.write_history_interval = None self.write_history_values = []
+ self.dir_read_history_line = None + self.dir_read_history_end = None + self.dir_read_history_interval = None + self.dir_read_history_values = [] + + self.dir_write_history_line = None + self.dir_write_history_end = None + self.dir_write_history_interval = None + self.dir_write_history_values = [] + self._unrecognized_lines = []
entries, first_keyword, last_keyword, _ = \ @@ -263,7 +283,7 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor): except ValueError: if validate: raise ValueError("Published line's time wasn't parseable: %s" % line) - elif keyword in ("read-history", "write-history"): + elif keyword in ("read-history", "write-history", "dirreq-read-history", "dirreq-write-history"): try: timestamp, interval, remainder = _parse_timestamp_and_interval(keyword, value)
@@ -280,11 +300,25 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor): self.read_history_end = timestamp self.read_history_interval = interval self.read_history_values = history_values - else: + elif keyword == "write-history": self.write_history_line = value self.write_history_end = timestamp self.write_history_interval = interval self.write_history_values = history_values + elif keyword == "dirreq-read-history": + self.dir_read_history_line = value + self.dir_read_history_end = timestamp + self.dir_read_history_interval = interval + self.dir_read_history_values = history_values + elif keyword == "dirreq-write-history": + self.dir_write_history_line = value + self.dir_write_history_end = timestamp + self.dir_write_history_interval = interval + self.dir_write_history_values = history_values + else: + # not gonna happen unless we change the main loop's conditional + # without fixing this one + raise ValueError("BUG: unrecognized keyword '%s'" % keyword) except ValueError, exc: if not validate: continue else: raise exc diff --git a/test/integ/descriptor/extrainfo_descriptor.py b/test/integ/descriptor/extrainfo_descriptor.py index 51af571..7a041d0 100644 --- a/test/integ/descriptor/extrainfo_descriptor.py +++ b/test/integ/descriptor/extrainfo_descriptor.py @@ -38,12 +38,15 @@ k0d2aofcVbHr4fPQOSST0LXDrhFl5Fqo5um296zpJGvRUeO6S44U/EfJAGShtqWw self.assertEquals(900, desc.read_history_interval) self.assertEquals(datetime.datetime(2012, 5, 5, 17, 2, 45), desc.write_history_end) self.assertEquals(900, desc.write_history_interval) + self.assertEquals(datetime.datetime(2012, 5, 5, 17, 2, 45), desc.dir_read_history_end) + self.assertEquals(900, desc.dir_read_history_interval) + self.assertEquals(datetime.datetime(2012, 5, 5, 17, 2, 45), desc.dir_write_history_end) + self.assertEquals(900, desc.dir_write_history_interval) self.assertEquals(expected_signature, desc.signature) + self.assertEquals([], desc.get_unrecognized_lines())
- # TODO: still missing dirreq-read-history and dirreq-write-history - #self.assertEquals([], desc.get_unrecognized_lines()) - - # The read-history and write-history lines are pretty long so just checking + # The read-history, write-history, dirreq-read-history, and + # dirreq-write-history lines are pretty long so just checking # the initial contents for the line and parsed values.
read_start = "2012-05-05 17:02:45 (900 s) 3309568,9216,41984" @@ -57,6 +60,18 @@ k0d2aofcVbHr4fPQOSST0LXDrhFl5Fqo5um296zpJGvRUeO6S44U/EfJAGShtqWw
write_values_start = [1082368, 19456, 50176, 272384, 485376] self.assertEquals(write_values_start, desc.write_history_values[:5]) + + dir_read_start = "2012-05-05 17:02:45 (900 s) 0,0,0,0,33792,27648,48128" + self.assertTrue(desc.dir_read_history_line.startswith(dir_read_start)) + + dir_read_values_start = [0, 0, 0, 0, 33792, 27648, 48128] + self.assertEquals(dir_read_values_start, desc.dir_read_history_values[:7]) + + dir_write_start = "2012-05-05 17:02:45 (900 s) 0,0,0,227328,349184" + self.assertTrue(desc.dir_write_history_line.startswith(dir_write_start)) + + dir_write_values_start = [0, 0, 0, 227328, 349184, 382976, 738304] + self.assertEquals(dir_write_values_start, desc.dir_write_history_values[:7])
def test_cached_descriptor(self): """