Browse Source

[trac930] modify stats.py and b10-stats_test.py

 - correct error messages in bindctl it prints together with
   arguments.

 - modify the command_show function it reports statistics data of the
   module even if name is not specified.

 - add/modify unittests depending on the changes of error messages
Naoki Kambe 13 years ago
parent
commit
611d0300fb
2 changed files with 53 additions and 20 deletions
  1. 8 9
      src/bin/stats/stats.py.in
  2. 45 11
      src/bin/stats/tests/b10-stats_test.py

+ 8 - 9
src/bin/stats/stats.py.in

@@ -267,7 +267,7 @@ class Stats:
                     self.statistics_data[owner].update(data)
                     return
             except KeyError:
-                errors.append('unknown module name')
+                errors.append("unknown module name: " + str(owner))
             return errors
 
     def command_status(self):
@@ -297,8 +297,6 @@ class Stats:
         else:
             logger.debug(DBG_STATS_MESSAGING,
                          STATS_RECEIVED_SHOW_ALL_COMMAND)
-        if owner and not name:
-            return isc.config.create_answer(1, "item name is not specified")
         errors = self.update_statistics_data(
             self.module_name,
             timestamp=get_timestamp(),
@@ -306,11 +304,12 @@ class Stats:
             )
         if errors: raise StatsError("stats spec file is incorrect")
         ret = self.get_statistics_data(owner, name)
-        if ret:
+        if ret is not None:
             return isc.config.create_answer(0, ret)
         else:
             return isc.config.create_answer(
-                1, "specified module name and/or item name are incorrect")
+                1, "specified arguments are incorrect: " \
+                    + "owner: " + str(owner) + ", name: " + str(name))
 
     def command_showschema(self, owner=None, name=None):
         """
@@ -343,7 +342,8 @@ class Stats:
             else:
                 return isc.config.create_answer(0, schema)
         return isc.config.create_answer(
-                1, "specified module name and/or item name are incorrect")
+                1, "specified arguments are incorrect: " \
+                    + "owner: " + str(owner) + ", name: " + str(name))
 
     def command_set(self, owner, data):
         """
@@ -352,9 +352,8 @@ class Stats:
         errors = self.update_statistics_data(owner, **data)
         if errors:
             return isc.config.create_answer(
-                1,
-                "specified module name and/or statistics data are incorrect: "
-                + ", ".join(errors))
+                1, "errors while setting statistics data: " \
+                    + ", ".join(errors))
         errors = self.update_statistics_data(
             self.module_name, last_update_time=get_datetime() )
         if errors:

+ 45 - 11
src/bin/stats/tests/b10-stats_test.py

@@ -331,7 +331,7 @@ class TestStats(unittest.TestCase):
         self.assertEqual(self.stats.update_statistics_data(owner='Stats', lname=0.0),
                          ['0.0 should be a string'])
         self.assertEqual(self.stats.update_statistics_data(owner='Dummy', foo='bar'),
-                         ['unknown module name'])
+                         ['unknown module name: Dummy'])
 
     def test_command_status(self):
         self.assertEqual(self.stats.command_status(),
@@ -346,13 +346,20 @@ class TestStats(unittest.TestCase):
         
     def test_command_show(self):
         self.assertEqual(self.stats.command_show(owner='Foo', name=None),
-                         isc.config.create_answer(1, "item name is not specified"))
+                         isc.config.create_answer(
+                1, "specified arguments are incorrect: owner: Foo, name: None"))
         self.assertEqual(self.stats.command_show(owner='Foo', name='_bar_'),
                          isc.config.create_answer(
-                1, "specified module name and/or item name are incorrect"))
+                1, "specified arguments are incorrect: owner: Foo, name: _bar_"))
         self.assertEqual(self.stats.command_show(owner='Foo', name='bar'),
                          isc.config.create_answer(
-                1, "specified module name and/or item name are incorrect"))
+                1, "specified arguments are incorrect: owner: Foo, name: bar"))
+        self.assertEqual(self.stats.command_show(owner='Auth'),
+                         isc.config.create_answer(
+                0, {'queries.tcp': 0, 'queries.udp': 0}))
+        self.assertEqual(self.stats.command_show(owner='Auth', name='queries.udp'),
+                         isc.config.create_answer(
+                0, 0))
         orig_get_timestamp = stats.get_timestamp
         orig_get_datetime = stats.get_datetime
         stats.get_timestamp = lambda : 1308730448.965706
@@ -452,13 +459,42 @@ class TestStats(unittest.TestCase):
 
         self.assertEqual(self.stats.command_showschema(owner='Foo'),
                          isc.config.create_answer(
-                1, "specified module name and/or item name are incorrect"))
+                1, "specified arguments are incorrect: owner: Foo, name: None"))
         self.assertEqual(self.stats.command_showschema(owner='Foo', name='bar'),
                          isc.config.create_answer(
-                1, "specified module name and/or item name are incorrect"))
+                1, "specified arguments are incorrect: owner: Foo, name: bar"))
+        self.assertEqual(self.stats.command_showschema(owner='Auth'),
+                         isc.config.create_answer(
+                0, [{
+                        "item_default": 0,
+                        "item_description": "A number of total query counts which all auth servers receive over TCP since they started initially",
+                        "item_name": "queries.tcp",
+                        "item_optional": False,
+                        "item_title": "Queries TCP",
+                        "item_type": "integer"
+                        },
+                    {
+                        "item_default": 0,
+                        "item_description": "A number of total query counts which all auth servers receive over UDP since they started initially",
+                        "item_name": "queries.udp",
+                        "item_optional": False,
+                        "item_title": "Queries UDP",
+                        "item_type": "integer"
+                        }]))
+        self.assertEqual(self.stats.command_showschema(owner='Auth', name='queries.tcp'),
+                         isc.config.create_answer(
+                0, {
+                    "item_default": 0,
+                    "item_description": "A number of total query counts which all auth servers receive over TCP since they started initially",
+                    "item_name": "queries.tcp",
+                    "item_optional": False,
+                    "item_title": "Queries TCP",
+                    "item_type": "integer"
+                    }))
+
         self.assertEqual(self.stats.command_showschema(owner='Stats', name='bar'),
                          isc.config.create_answer(
-                1, "specified module name and/or item name are incorrect"))
+                1, "specified arguments are incorrect: owner: Stats, name: bar"))
         self.assertEqual(self.stats.command_showschema(name='bar'),
                          isc.config.create_answer(
                 1, "module name is not specified"))
@@ -487,8 +523,7 @@ class TestStats(unittest.TestCase):
                                                 data={ 'lname' : '_foo_@_bar_' }),
                          isc.config.create_answer(
                 1,
-                "specified module name and/or statistics data are incorrect:"
-                + " unknown item lname"))
+                "errors while setting statistics data: unknown item lname"))
         self.stats.statistics_data['Stats'] = {}
         self.stats.mccs.specification = isc.config.module_spec.ModuleSpec(
             { "module_name": self.stats.module_name } )
@@ -496,8 +531,7 @@ class TestStats(unittest.TestCase):
                                                 data={ 'lname' : '_foo_@_bar_' }),
                          isc.config.create_answer(
                 1,
-                "specified module name and/or statistics data are incorrect:"
-                + " No statistics specification"))
+                "errors while setting statistics data: No statistics specification"))
         self.stats.statistics_data['Stats'] = {}
         self.stats.mccs.specification = isc.config.module_spec.ModuleSpec(
             { "module_name": self.stats.module_name,