BIND 10 trac519, updated. a53c7d7c450de09ceb04b47cb59450225827bd51 [519] 1. Make stats module get boss's start time from the answer of command 'getstats'. 2. Make boss and stats receive msgq message(the call to group_recvmsg) in block mode.

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Aug 10 09:52:19 UTC 2011


The branch, trac519 has been updated
       via  a53c7d7c450de09ceb04b47cb59450225827bd51 (commit)
      from  1aa26c98d1b827a80bad8abd7f8bb25c26db72b7 (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 a53c7d7c450de09ceb04b47cb59450225827bd51
Author: zhanglikun <zhanglikun at cnnic.cn>
Date:   Wed Aug 10 17:51:36 2011 +0800

    [519] 1. Make stats module get boss's start time from the answer of command 'getstats'. 2. Make boss and stats receive msgq message(the call to group_recvmsg) in block mode.

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

Summary of changes:
 src/bin/bind10/bind10_src.py.in       |   14 ++++++++++----
 src/bin/stats/stats.py.in             |   24 ++++++++++++++++--------
 src/bin/stats/tests/b10-stats_test.py |    3 ++-
 src/bin/stats/tests/isc/cc/session.py |   10 +++++++++-
 4 files changed, 37 insertions(+), 14 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/bin/bind10/bind10_src.py.in b/src/bin/bind10/bind10_src.py.in
index b497f7c..5da78bf 100755
--- a/src/bin/bind10/bind10_src.py.in
+++ b/src/bin/bind10/bind10_src.py.in
@@ -307,6 +307,11 @@ class BoB:
             process_list.append([pid, self.processes[pid].name])
         return process_list
 
+    def _get_stats_data(self):
+        return { "stats_data": {
+                    'bind10.boot_time': time.strftime('%Y-%m-%dT%H:%M:%SZ', _BASETIME)
+               }}
+
     def command_handler(self, command, args):
         logger.debug(DBG_COMMANDS, BIND10_RECEIVED_COMMAND, command)
         answer = isc.config.ccsession.create_answer(1, "command not implemented")
@@ -316,14 +321,15 @@ class BoB:
             if command == "shutdown":
                 self.runnable = False
                 answer = isc.config.ccsession.create_answer(0)
+            elif command == "getstats":
+                answer = isc.config.ccsession.create_answer(0, self._get_stats_data())
             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)
-                            }})
+                    'set', self._get_stats_data())
                 seq = self.cc_session.group_sendmsg(cmd, 'Stats')
-                self.cc_session.group_recvmsg(True, seq)
+                # Consume the answer, in case it becomes a orphan message.
+                self.cc_session.group_recvmsg(False, seq) 
                 answer = isc.config.ccsession.create_answer(0)
             elif command == "ping":
                 answer = isc.config.ccsession.create_answer(0, "pong")
diff --git a/src/bin/stats/stats.py.in b/src/bin/stats/stats.py.in
index ce3d9f4..022900a 100644
--- a/src/bin/stats/stats.py.in
+++ b/src/bin/stats/stats.py.in
@@ -213,6 +213,12 @@ class CCSessionListener(Listener):
             except AttributeError as ae:
                 logger.error(STATS_UNKNOWN_COMMAND_IN_SPEC, cmd["command_name"])
 
+    def _update_stats_data(self, args):
+        # 'args' must be dictionary type
+        self.stats_data.update(args['stats_data'])
+        # overwrite "stats.LastUpdateTime"
+        self.stats_data['stats.last_update_time'] = get_datetime()
+
     def start(self):
         """
         start the cc chanel
@@ -225,9 +231,16 @@ class CCSessionListener(Listener):
         self.cc_session.start()
         # request Bob to send statistics data
         logger.debug(DBG_STATS_MESSAGING, STATS_SEND_REQUEST_BOSS)
-        cmd = isc.config.ccsession.create_command("sendstats", None)
+        cmd = isc.config.ccsession.create_command("getstats", None)
         seq = self.session.group_sendmsg(cmd, 'Boss')
-        self.session.group_recvmsg(True, seq)
+        try:
+            answer, env = self.session.group_recvmsg(False, seq)
+            if answer:
+                rcode, arg = isc.config.ccsession.parse_answer(answer)
+                if rcode == 0:
+                    self._update_stats_data(arg)
+        except isc.cc.session.SessionTimeout:
+            pass
 
     def stop(self):
         """
@@ -276,12 +289,7 @@ class CCSessionListener(Listener):
         """
         handle set command
         """
-        # 'args' must be dictionary type
-        self.stats_data.update(args['stats_data'])
-
-        # overwrite "stats.LastUpdateTime"
-        self.stats_data['stats.last_update_time'] = get_datetime()
-
+        self._update_stats_data(args)
         return create_answer(0)
 
     def command_remove(self, args, stats_item_name=''):
diff --git a/src/bin/stats/tests/b10-stats_test.py b/src/bin/stats/tests/b10-stats_test.py
index a42c81d..2fb4ab5 100644
--- a/src/bin/stats/tests/b10-stats_test.py
+++ b/src/bin/stats/tests/b10-stats_test.py
@@ -59,6 +59,7 @@ class TestStats(unittest.TestCase):
         # check starting
         self.assertFalse(self.subject.running)
         self.subject.start()
+        self.assertEqual(len(self.session.old_message_queue), 1)
         self.assertTrue(self.subject.running)
         self.assertEqual(len(self.session.message_queue), 0)
         self.assertEqual(self.module_name, 'Stats')
@@ -509,7 +510,7 @@ class TestStats(unittest.TestCase):
     def test_for_boss(self):
         last_queue = self.session.old_message_queue.pop()
         self.assertEqual(
-            last_queue.msg, {'command': ['sendstats']})
+            last_queue.msg, {'command': ['getstats']})
         self.assertEqual(
             last_queue.env['group'], 'Boss')
 
diff --git a/src/bin/stats/tests/isc/cc/session.py b/src/bin/stats/tests/isc/cc/session.py
index e16d6a9..e18a695 100644
--- a/src/bin/stats/tests/isc/cc/session.py
+++ b/src/bin/stats/tests/isc/cc/session.py
@@ -115,8 +115,16 @@ class Session:
 
     def group_recvmsg(self, nonblock=True, seq=0):
         que = self.dequeue()
+        if que.msg != None:
+            cmd = que.msg.get("command")
+            if cmd and cmd[0] == 'getstats':
+                # Create answer for command 'getstats'
+                retdata =  { "stats_data": {
+                            'bind10.boot_time' : "1970-01-01T00:00:00Z"
+                           }}
+                return {'result': [0, retdata]}, que.env
         return que.msg, que.env
-        
+
     def group_reply(self, routing, msg):
         return self.enqueue(msg=msg, env={
                 "type": "send",




More information about the bind10-changes mailing list