BIND 10 trac930, updated. 065c6004799a76d45859289d2ebae0379e9dceba [trac930] raise StatsError including errors in the stats spec file

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Aug 1 09:47:56 UTC 2011


The branch, trac930 has been updated
       via  065c6004799a76d45859289d2ebae0379e9dceba (commit)
       via  24fa3987d6e1f42d645f2c0a9c26cd8bdbc9c16b (commit)
      from  d2ee7e7bad03494e0f59fc5f82ddaf052f991be3 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 065c6004799a76d45859289d2ebae0379e9dceba
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Aug 1 18:38:35 2011 +0900

    [trac930] raise StatsError including errors in the stats spec file

commit 24fa3987d6e1f42d645f2c0a9c26cd8bdbc9c16b
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Aug 1 18:21:23 2011 +0900

    [trac930] rename the function name
     - rename the name of 'parse_spec' to 'get_spec_defaults' in the result of
       consideration of what it is doing
     - modify the description of the function as docstring
     - fix unitttests for the stats module depending on the function name

-----------------------------------------------------------------------

Summary of changes:
 src/bin/stats/stats.py.in             |   28 +++++++++++++++++-----------
 src/bin/stats/tests/b10-stats_test.py |   14 +++++++-------
 2 files changed, 24 insertions(+), 18 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/bin/stats/stats.py.in b/src/bin/stats/stats.py.in
index ca206bf..bea7016 100644
--- a/src/bin/stats/stats.py.in
+++ b/src/bin/stats/stats.py.in
@@ -68,12 +68,14 @@ def get_datetime(gmt=None):
     if not gmt: gmt = gmtime()
     return strftime("%Y-%m-%dT%H:%M:%SZ", gmt)
 
-def parse_spec(spec):
+def get_spec_defaults(spec):
     """
-    parse spec type data
+    extracts the default values of the items from spec specified in
+    arg, and returns the dict-type variable which is a set of the item
+    names and the default values
     """
     if type(spec) is not list: return {}
-    def _parse_spec(spec):
+    def _get_spec_defaults(spec):
         item_type = spec['item_type']
         if item_type == "integer":
             return int(spec.get('item_default', 0))
@@ -86,14 +88,14 @@ def parse_spec(spec):
         elif item_type == "list":
             return spec.get(
                     "item_default",
-                    [ _parse_spec(s) for s in spec["list_item_spec"] ])
+                    [ _get_spec_defaults(s) for s in spec["list_item_spec"] ])
         elif item_type == "map":
             return spec.get(
                     "item_default",
-                    dict([ (s["item_name"], _parse_spec(s)) for s in spec["map_item_spec"] ]) )
+                    dict([ (s["item_name"], _get_spec_defaults(s)) for s in spec["map_item_spec"] ]) )
         else:
             return spec.get("item_default", None)
-    return dict([ (s['item_name'], _parse_spec(s)) for s in spec ])
+    return dict([ (s['item_name'], _get_spec_defaults(s)) for s in spec ])
 
 class Callback():
     """
@@ -137,7 +139,7 @@ class Stats:
             name = "command_" + cmd["command_name"]
             try:
                 callback = getattr(self, name)
-                kwargs = parse_spec(cmd["command_args"])
+                kwargs = get_spec_defaults(cmd["command_args"])
                 self.callbacks[name] = Callback(command=callback, kwargs=kwargs)
             except AttributeError:
                 raise StatsError(STATS_UNKNOWN_COMMAND_IN_SPEC, cmd["command_name"])
@@ -163,7 +165,8 @@ class Stats:
             boot_time=get_datetime(_BASETIME)
             )
         if errors:
-            raise StatsError("stats spec file is incorrect")
+            raise StatsError("stats spec file is incorrect: "
+                             + ", ".join(errors))
 
         while self.running:
             self.mccs.check_command(False)
@@ -240,7 +243,7 @@ class Stats:
         self.update_modules()
         statistics_data = {}
         for (name, module) in self.modules.items():
-            value = parse_spec(module.get_statistics_spec())
+            value = get_spec_defaults(module.get_statistics_spec())
             if module.validate_statistics(True, value):
                 statistics_data[name] = value
         for (name, value) in self.statistics_data.items():
@@ -291,7 +294,9 @@ class Stats:
             timestamp=get_timestamp(),
             report_time=get_datetime()
             )
-        if errors: raise StatsError("stats spec file is incorrect")
+        if errors:
+            raise StatsError("stats spec file is incorrect: "
+                             + ", ".join(errors))
         ret = self.get_statistics_data(owner, name)
         if ret is not None:
             return isc.config.create_answer(0, ret)
@@ -350,7 +355,8 @@ class Stats:
         errors = self.update_statistics_data(
             self.module_name, last_update_time=get_datetime() )
         if errors:
-            raise StatsError("stats spec file is incorrect")
+            raise StatsError("stats spec file is incorrect: "
+                             + ", ".join(errors))
         return isc.config.create_answer(0)
 
 if __name__ == "__main__":
diff --git a/src/bin/stats/tests/b10-stats_test.py b/src/bin/stats/tests/b10-stats_test.py
index 4c6bde0..7eb2555 100644
--- a/src/bin/stats/tests/b10-stats_test.py
+++ b/src/bin/stats/tests/b10-stats_test.py
@@ -56,9 +56,9 @@ class TestUtilties(unittest.TestCase):
         { 'item_name': 'test_none',  'item_type': 'none'    }
         ]
 
-    def test_parse_spec(self):
+    def test_get_spec_defaults(self):
         self.assertEqual(
-            stats.parse_spec(self.items), {
+            stats.get_spec_defaults(self.items), {
                 'test_int1'  : 12345              ,
                 'test_real1' : 12345.6789         ,
                 'test_bool1' : True               ,
@@ -72,8 +72,8 @@ class TestUtilties(unittest.TestCase):
                 'test_list2' : [0,0,0],
                 'test_map2'  : { 'A' : 0, 'B' : 0, 'C' : 0 },
                 'test_none'  : None })
-        self.assertEqual(stats.parse_spec(None), {})
-        self.assertRaises(KeyError, stats.parse_spec, [{'item_name':'Foo'}])
+        self.assertEqual(stats.get_spec_defaults(None), {})
+        self.assertRaises(KeyError, stats.get_spec_defaults, [{'item_name':'Foo'}])
 
     def test_get_timestamp(self):
         self.assertEqual(stats.get_timestamp(), 1308730448.965706)
@@ -191,7 +191,7 @@ class TestStats(unittest.TestCase):
 
     def test_start_with_err(self):
         statsd = stats.Stats()
-        statsd.update_statistics_data = lambda x,**y: [1]
+        statsd.update_statistics_data = lambda x,**y: ['an error']
         self.assertRaises(stats.StatsError, statsd.start)
 
     def test_config_handler(self):
@@ -280,7 +280,7 @@ class TestStats(unittest.TestCase):
         self.assertTrue('Stats' in self.stats.modules)
         self.assertTrue('Boss' in self.stats.modules)
         self.assertFalse('Dummy' in self.stats.modules)
-        my_statistics_data = stats.parse_spec(self.stats.modules['Stats'].get_statistics_spec())
+        my_statistics_data = stats.get_spec_defaults(self.stats.modules['Stats'].get_statistics_spec())
         self.assertTrue('report_time' in my_statistics_data)
         self.assertTrue('boot_time' in my_statistics_data)
         self.assertTrue('last_update_time' in my_statistics_data)
@@ -291,7 +291,7 @@ class TestStats(unittest.TestCase):
         self.assertEqual(my_statistics_data['last_update_time'], "1970-01-01T00:00:00Z")
         self.assertEqual(my_statistics_data['timestamp'], 0.0)
         self.assertEqual(my_statistics_data['lname'], "")
-        my_statistics_data = stats.parse_spec(self.stats.modules['Boss'].get_statistics_spec())
+        my_statistics_data = stats.get_spec_defaults(self.stats.modules['Boss'].get_statistics_spec())
         self.assertTrue('boot_time' in my_statistics_data)
         self.assertEqual(my_statistics_data['boot_time'], "1970-01-01T00:00:00Z")
 




More information about the bind10-changes mailing list