[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Parsing dirreq-stats-end extrainfo lines



commit 6f40a5e87228ea8f0af76d2aeba859025ce468b2
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat May 12 12:32:09 2012 -0700

    Parsing dirreq-stats-end extrainfo lines
    
    Parsing and test. This is the same format as bridge-stats-end so combining
    those tests.
---
 stem/descriptor/extrainfo_descriptor.py      |   32 ++++++++++++++----
 test/unit/descriptor/extrainfo_descriptor.py |   47 +++++++++++++++-----------
 2 files changed, 52 insertions(+), 27 deletions(-)

diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py
index 380d022..a8f7961 100644
--- a/stem/descriptor/extrainfo_descriptor.py
+++ b/stem/descriptor/extrainfo_descriptor.py
@@ -154,6 +154,12 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
     write_history_end (datetime.datetime) - end of the sampling interval
     write_history_interval (int) - seconds per interval
     write_history_values (list) - bytes written during each interval (*)
+  
+  Directory Mirror Attributes:
+    dirreq_stats_end (datetime.datetime) - end of the period where directory
+        mirroring stats were gathered
+    dirreq_stats_interval (int) - length in seconds of the interval where
+        directory stats were gathered
     
     dir_read_history_line (str) - bytes read for directory mirroring
     dir_read_history_end (datetime.datetime) - end of the sampling interval
@@ -164,18 +170,18 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
     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 (*)
-    
-  Bridge-only Attributes:
+  
+  Bridge Attributes:
     bridge_stats_end (datetime.datetime) - end of the period when geoip
         statistics were gathered
-    bridge_stats_end_interval (int) - length in seconds of th interval where
+    bridge_stats_interval (int) - length in seconds of the interval where
         stats were gathered
     bridge_ips (dict) - mapping of country codes to a rounded number of unique
         ips from that region
     geoip_start_time (datetime.datetime) - replaced by bridge_stats_end
     geoip_client_origins (dict) - replaced by bridge_ips
-    
-    (*) required fields, others are left as None if undefined
+  
+  (*) required fields, others are left as None if undefined
   """
   
   def __init__(self, raw_contents, validate = True, annotations = None):
@@ -215,6 +221,9 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
     self.write_history_interval = None
     self.write_history_values = []
     
+    self.dirreq_stats_end = None
+    self.dirreq_stats_interval = None
+    
     self.dir_read_history_line = None
     self.dir_read_history_end = None
     self.dir_read_history_interval = None
@@ -226,7 +235,7 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
     self.dir_write_history_values = []
     
     self.bridge_stats_end = None
-    self.bridge_stats_end_interval = None
+    self.bridge_stats_interval = None
     self.bridge_ips = None
     self.geoip_start_time = None
     self.geoip_client_origins = None
@@ -320,7 +329,7 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
         try:
           timestamp, interval, _ = _parse_timestamp_and_interval(keyword, value)
           self.bridge_stats_end = timestamp
-          self.bridge_stats_end_interval = interval
+          self.bridge_stats_interval = interval
         except ValueError, exc:
           if validate: raise exc
       elif keyword in ("geoip-client-origins", "bridge-ips"):
@@ -345,6 +354,15 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
           self.geoip_client_origins = locale_usage
         elif keyword == "bridge-ips":
           self.bridge_ips = locale_usage
+      elif keyword == "dirreq-stats-end":
+        # "dirreq-stats-end" YYYY-MM-DD HH:MM:SS (NSEC s)
+        
+        try:
+          timestamp, interval, _ = _parse_timestamp_and_interval(keyword, value)
+          self.dirreq_stats_end = timestamp
+          self.dirreq_stats_interval = interval
+        except ValueError, exc:
+          if validate: raise exc
       elif keyword in ("read-history", "write-history", "dirreq-read-history", "dirreq-write-history"):
         try:
           timestamp, interval, remainder = _parse_timestamp_and_interval(keyword, value)
diff --git a/test/unit/descriptor/extrainfo_descriptor.py b/test/unit/descriptor/extrainfo_descriptor.py
index 32732e3..b4c5fbe 100644
--- a/test/unit/descriptor/extrainfo_descriptor.py
+++ b/test/unit/descriptor/extrainfo_descriptor.py
@@ -151,29 +151,36 @@ class TestExtraInfoDescriptor(unittest.TestCase):
       desc_text = _make_descriptor({"geoip-start-time": entry})
       desc = self._expect_invalid_attr(desc_text, "geoip_start_time")
   
-  def test_bridge_stats_end(self):
+  def test_stats_end(self):
     """
-    Parses the bridge-stats-end line with valid and invalid data.
+    Parses the bridge-stats-end and dirreq-stats-end lines with valid and
+    invalid data.
     """
     
-    desc_text = _make_descriptor({"bridge-stats-end": "2012-05-03 12:07:50 (500 s)"})
-    desc = ExtraInfoDescriptor(desc_text)
-    self.assertEquals(datetime.datetime(2012, 5, 3, 12, 7, 50), desc.bridge_stats_end)
-    self.assertEquals(500, desc.bridge_stats_end_interval)
-    
-    test_entry = (
-      "",
-      "2012-05-03 12:07:60 (500 s)",
-      "2012-05-03 12:07:50 (500s)",
-      "2012-05-03 12:07:50 (500 s",
-      "2012-05-03 12:07:50 (500 )",
-      "2012-05-03 ",
-      "2012-05-03",
-    )
-    
-    for entry in test_entry:
-      desc_text = _make_descriptor({"bridge-stats-end": entry})
-      desc = self._expect_invalid_attr(desc_text, "bridge_stats_end")
+    for keyword in ('bridge-stats-end', 'dirreq-stats-end'):
+      end_attr = keyword.replace('-', '_')
+      interval_attr = end_attr[:-4] + "_interval"
+      
+      desc_text = _make_descriptor({keyword: "2012-05-03 12:07:50 (500 s)"})
+      desc = ExtraInfoDescriptor(desc_text)
+      self.assertEquals(datetime.datetime(2012, 5, 3, 12, 7, 50), getattr(desc, end_attr))
+      self.assertEquals(500, getattr(desc, interval_attr))
+      
+      test_entry = (
+        "",
+        "2012-05-03 12:07:60 (500 s)",
+        "2012-05-03 12:07:50 (500s)",
+        "2012-05-03 12:07:50 (500 s",
+        "2012-05-03 12:07:50 (500 )",
+        "2012-05-03 ",
+        "2012-05-03",
+      )
+      
+      for entry in test_entry:
+        desc_text = _make_descriptor({keyword: entry})
+        desc = self._expect_invalid_attr(desc_text)
+        self.assertEquals(None, getattr(desc, end_attr))
+        self.assertEquals(None, getattr(desc, interval_attr))
   
   def test_bridge_ips(self):
     """



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits