Browse Source

Merge branch 'master' of ssh://bind10.isc.org/var/bind10/git/bind10

Jelte Jansen 14 years ago
parent
commit
4929dc5658

+ 10 - 0
ChangeLog

@@ -1,3 +1,13 @@
+  213.  [bug]       naokikambe
+	Solved incorrect datetime of "bind10.boot_time" and also added a new
+	command "sendstats" for Bob. This command is to send statistics data to
+	the stats daemon immediately. The solved problem is that statistics
+	data doesn't surely reach to the daemon because Bob sent statistics
+	data to the daemon while it is starting. So the daemon invokes the
+	command for Bob after it starts up. This command is also useful for
+	resending statistics data via bindctl manually.
+	(Trac #521, git 1c269cbdc76f5dc2baeb43387c4d7ccc6dc863d2)
+
   212.  [bug]		naokikambe
   212.  [bug]		naokikambe
 	Fixed that the ModuleCCSession object may group_unsubscribe in the
 	Fixed that the ModuleCCSession object may group_unsubscribe in the
 	closed CC session in being deleted.
 	closed CC session in being deleted.

+ 10 - 12
src/bin/bind10/bind10.py.in

@@ -297,7 +297,7 @@ class BoB:
 
 
     def command_handler(self, command, args):
     def command_handler(self, command, args):
         if self.verbose:
         if self.verbose:
-            sys.stdout.write("[bind10] Boss got command: " + command + "\n")
+            sys.stdout.write("[bind10] Boss got command: " + str(command) + "\n")
         answer = isc.config.ccsession.create_answer(1, "command not implemented")
         answer = isc.config.ccsession.create_answer(1, "command not implemented")
         if type(command) != str:
         if type(command) != str:
             answer = isc.config.ccsession.create_answer(1, "bad command")
             answer = isc.config.ccsession.create_answer(1, "bad command")
@@ -305,6 +305,15 @@ class BoB:
             if command == "shutdown":
             if command == "shutdown":
                 self.runnable = False
                 self.runnable = False
                 answer = isc.config.ccsession.create_answer(0)
                 answer = isc.config.ccsession.create_answer(0)
+            elif command == "sendstats":
+                # send statistics data to the stats daemon immediately
+                cmd = isc.config.ccsession.create_command(
+                    'set', { "stats_data": {
+                            'bind10.boot_time': time.strftime('%Y-%m-%dT%H:%M:%SZ', _BASETIME)
+                            }})
+                seq = self.cc_session.group_sendmsg(cmd, 'Stats')
+                self.cc_session.group_recvmsg(True, seq)
+                answer = isc.config.ccsession.create_answer(0)
             elif command == "ping":
             elif command == "ping":
                 answer = isc.config.ccsession.create_answer(0, "pong")
                 answer = isc.config.ccsession.create_answer(0, "pong")
             elif command == "show_processes":
             elif command == "show_processes":
@@ -977,17 +986,6 @@ def main():
     sys.stdout.write("[bind10] BIND 10 started\n")
     sys.stdout.write("[bind10] BIND 10 started\n")
     dump_pid(options.pid_file)
     dump_pid(options.pid_file)
 
 
-    # send "bind10.boot_time" to b10-stats
-    time.sleep(1) # wait a second
-    if options.verbose:
-        sys.stdout.write("[bind10] send \"bind10.boot_time\" to b10-stats\n")
-    cmd = isc.config.ccsession.create_command('set', 
-            { "stats_data": {
-              'bind10.boot_time': time.strftime('%Y-%m-%dT%H:%M:%SZ', _BASETIME)
-              }
-            })
-    boss_of_bind.cc_session.group_sendmsg(cmd, 'Stats')
-
     # In our main loop, we check for dead processes or messages 
     # In our main loop, we check for dead processes or messages 
     # on the c-channel.
     # on the c-channel.
     wakeup_fd = wakeup_pipe[0]
     wakeup_fd = wakeup_pipe[0]

+ 5 - 0
src/bin/bind10/bob.spec

@@ -23,6 +23,11 @@
         "command_args": []
         "command_args": []
       },
       },
       {
       {
+        "command_name": "sendstats",
+        "command_description": "Send data to a statistics module at once",
+        "command_args": []
+      },
+      {
         "command_name": "ping",
         "command_name": "ping",
         "command_description": "Ping the boss process",
         "command_description": "Ping the boss process",
         "command_args": []
         "command_args": []

+ 39 - 1
src/bin/bind10/tests/bind10_test.py.in

@@ -13,7 +13,7 @@
 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 
-from bind10 import ProcessInfo, BoB, parse_args, dump_pid, unlink_pid_file
+from bind10 import ProcessInfo, BoB, parse_args, dump_pid, unlink_pid_file, _BASETIME
 
 
 # XXX: environment tests are currently disabled, due to the preprocessor
 # XXX: environment tests are currently disabled, due to the preprocessor
 #      setup that we have now complicating the environment
 #      setup that we have now complicating the environment
@@ -24,6 +24,9 @@ import os
 import signal
 import signal
 import socket
 import socket
 from isc.net.addr import IPAddr
 from isc.net.addr import IPAddr
+import time
+import isc
+
 from isc.testutils.parse_args import TestOptParser, OptsError
 from isc.testutils.parse_args import TestOptParser, OptsError
 
 
 class TestProcessInfo(unittest.TestCase):
 class TestProcessInfo(unittest.TestCase):
@@ -123,6 +126,41 @@ class TestBoB(unittest.TestCase):
         self.assertEqual(bob.cfg_start_auth, True)
         self.assertEqual(bob.cfg_start_auth, True)
         self.assertEqual(bob.cfg_start_resolver, False)
         self.assertEqual(bob.cfg_start_resolver, False)
 
 
+    def test_command_handler(self):
+        class DummySession():
+            def group_sendmsg(self, msg, group):
+                (self.msg, self.group) = (msg, group)
+            def group_recvmsg(self, nonblock, seq): pass
+        bob = BoB()
+        bob.verbose = True
+        bob.cc_session = DummySession()
+        # a bad command
+        self.assertEqual(bob.command_handler(-1, None),
+                         isc.config.ccsession.create_answer(1, "bad command"))
+        # "shutdown" command
+        self.assertEqual(bob.command_handler("shutdown", None),
+                         isc.config.ccsession.create_answer(0))
+        self.assertFalse(bob.runnable)
+        # "sendstats" command
+        self.assertEqual(bob.command_handler("sendstats", None),
+                         isc.config.ccsession.create_answer(0))
+        self.assertEqual(bob.cc_session.group, "Stats")
+        self.assertEqual(bob.cc_session.msg,
+                         isc.config.ccsession.create_command(
+                'set', { "stats_data": {
+                        'bind10.boot_time': time.strftime('%Y-%m-%dT%H:%M:%SZ', _BASETIME)
+                        }}))
+        # "ping" command
+        self.assertEqual(bob.command_handler("ping", None),
+                         isc.config.ccsession.create_answer(0, "pong"))
+        # "show_processes" command
+        self.assertEqual(bob.command_handler("show_processes", None),
+                         isc.config.ccsession.create_answer(0,
+                                                            bob.get_processes()))
+        # an unknown command
+        self.assertEqual(bob.command_handler("__UNKNOWN__", None),
+                         isc.config.ccsession.create_answer(1, "Unknown command"))
+
 # Class for testing the BoB without actually starting processes.
 # Class for testing the BoB without actually starting processes.
 # This is used for testing the start/stop components routines and
 # This is used for testing the start/stop components routines and
 # the BoB commands.
 # the BoB commands.

+ 17 - 2
src/bin/stats/b10-stats.8

@@ -1,7 +1,7 @@
 '\" t
 '\" t
 .\"     Title: b10-stats
 .\"     Title: b10-stats
 .\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
 .\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
+.\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
 .\"      Date: Oct 15, 2010
 .\"      Date: Oct 15, 2010
 .\"    Manual: BIND10
 .\"    Manual: BIND10
 .\"    Source: BIND10
 .\"    Source: BIND10
@@ -9,6 +9,15 @@
 .\"
 .\"
 .TH "B10\-STATS" "8" "Oct 15, 2010" "BIND10" "BIND10"
 .TH "B10\-STATS" "8" "Oct 15, 2010" "BIND10" "BIND10"
 .\" -----------------------------------------------------------------
 .\" -----------------------------------------------------------------
+.\" * Define some portability stuff
+.\" -----------------------------------------------------------------
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.\" http://bugs.debian.org/507673
+.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.ie \n(.g .ds Aq \(aq
+.el       .ds Aq '
+.\" -----------------------------------------------------------------
 .\" * set default formatting
 .\" * set default formatting
 .\" -----------------------------------------------------------------
 .\" -----------------------------------------------------------------
 .\" disable hyphenation
 .\" disable hyphenation
@@ -35,6 +44,11 @@ with other modules like
 \fBbind10\fR,
 \fBbind10\fR,
 \fBb10\-auth\fR
 \fBb10\-auth\fR
 and so on\&. It waits for coming data from other modules, then other modules send data to stats module periodically\&. Other modules send stats data to stats module independently from implementation of stats module, so the frequency of sending data may not be constant\&. Stats module collects data and aggregates it\&.
 and so on\&. It waits for coming data from other modules, then other modules send data to stats module periodically\&. Other modules send stats data to stats module independently from implementation of stats module, so the frequency of sending data may not be constant\&. Stats module collects data and aggregates it\&.
+\fBb10\-stats\fR
+invokes "sendstats" command for
+\fBbind10\fR
+after its initial starting because it\*(Aqs sure to collect statistics data from
+\fBbind10\fR\&.
 .SH "OPTIONS"
 .SH "OPTIONS"
 .PP
 .PP
 The arguments are as follows:
 The arguments are as follows:
@@ -49,7 +63,8 @@ switches to verbose mode\&. It sends verbose messages to STDOUT\&.
 .PP
 .PP
 /usr/local/share/bind10\-devel/stats\&.spec
 /usr/local/share/bind10\-devel/stats\&.spec
 \(em This is a spec file for
 \(em This is a spec file for
-\fBb10\-stats\fR\&. It contains definitions of statistics items of BIND 10 and commands received vi bindctl\&.
+\fBb10\-stats\fR\&. It contains definitions of statistics items of BIND 10 and commands received via
+bindctl(1)\&.
 .SH "SEE ALSO"
 .SH "SEE ALSO"
 .PP
 .PP
 
 

+ 4 - 2
src/bin/stats/b10-stats.xml

@@ -2,7 +2,7 @@
                "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
                "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
 	       [<!ENTITY mdash "&#8212;">]>
 	       [<!ENTITY mdash "&#8212;">]>
 <!--
 <!--
- - Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
+ - Copyright (C) 2010,2011  Internet Systems Consortium, Inc. ("ISC")
  -
  -
  - Permission to use, copy, modify, and/or distribute this software for any
  - Permission to use, copy, modify, and/or distribute this software for any
  - purpose with or without fee is hereby granted, provided that the above
  - purpose with or without fee is hereby granted, provided that the above
@@ -64,7 +64,9 @@
       send stats data to stats module independently from
       send stats data to stats module independently from
       implementation of stats module, so the frequency of sending data
       implementation of stats module, so the frequency of sending data
       may not be constant. Stats module collects data and aggregates
       may not be constant. Stats module collects data and aggregates
-      it.
+      it. <command>b10-stats</command> invokes "sendstats" command
+      for <command>bind10</command> after its initial starting because it's
+      sure to collect statistics data from <command>bind10</command>.
     </para>
     </para>
   </refsect1>
   </refsect1>
 
 

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

@@ -1,6 +1,6 @@
 #!@PYTHON@
 #!@PYTHON@
 
 
-# Copyright (C) 2010  Internet Systems Consortium.
+# Copyright (C) 2010, 2011  Internet Systems Consortium.
 #
 #
 # Permission to use, copy, modify, and distribute this software for any
 # Permission to use, copy, modify, and distribute this software for any
 # purpose with or without fee is hereby granted, provided that the above
 # purpose with or without fee is hereby granted, provided that the above
@@ -15,8 +15,6 @@
 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 
-__version__ = "$Revision$"
-
 import sys; sys.path.append ('@@PYTHONPATH@@')
 import sys; sys.path.append ('@@PYTHONPATH@@')
 import os
 import os
 import signal
 import signal
@@ -220,7 +218,13 @@ class CCSessionListener(Listener):
         self.stats_data['stats.start_time'] = get_datetime()
         self.stats_data['stats.start_time'] = get_datetime()
         self.stats_data['stats.last_update_time'] = get_datetime()
         self.stats_data['stats.last_update_time'] = get_datetime()
         self.stats_data['stats.lname'] = self.session.lname
         self.stats_data['stats.lname'] = self.session.lname
-        return self.cc_session.start()
+        self.cc_session.start()
+        # request Bob to send statistics data
+        if self.verbose:
+            sys.stdout.write("[b10-stats] request Bob to send statistics data\n")
+        cmd = isc.config.ccsession.create_command("sendstats", None)
+        seq = self.session.group_sendmsg(cmd, 'Boss')
+        self.session.group_recvmsg(True, seq)
 
 
     def stop(self):
     def stop(self):
         """
         """

+ 8 - 3
src/bin/stats/tests/b10-stats_test.py

@@ -1,4 +1,4 @@
-# Copyright (C) 2010  Internet Systems Consortium.
+# Copyright (C) 2010,2011  Internet Systems Consortium.
 #
 #
 # Permission to use, copy, modify, and distribute this software for any
 # Permission to use, copy, modify, and distribute this software for any
 # purpose with or without fee is hereby granted, provided that the above
 # purpose with or without fee is hereby granted, provided that the above
@@ -13,8 +13,6 @@
 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 
-__version__ = "$Revision$"
-
 #
 #
 # Tests for the stats module
 # Tests for the stats module
 #
 #
@@ -504,6 +502,13 @@ class TestStats(unittest.TestCase):
         self.assertEqual(result_ok(),
         self.assertEqual(result_ok(),
                          self.session.get_message("Stats", None))
                          self.session.get_message("Stats", None))
 
 
+    def test_for_boss(self):
+        last_queue = self.session.old_message_queue.pop()
+        self.assertEqual(
+            last_queue.msg, {'command': ['sendstats']})
+        self.assertEqual(
+            last_queue.env['group'], 'Boss')
+
 class TestStats2(unittest.TestCase):
 class TestStats2(unittest.TestCase):
 
 
     def setUp(self):
     def setUp(self):