Browse Source

[519] Add unit test for the change to boss process. Catch the timeout exception when boss receiving the answer from stats.

zhanglikun 13 years ago
parent
commit
568a8cc472

+ 4 - 1
src/bin/bind10/bind10_src.py.in

@@ -329,7 +329,10 @@ class BoB:
                     'set', self._get_stats_data())
                 seq = self.cc_session.group_sendmsg(cmd, 'Stats')
                 # Consume the answer, in case it becomes a orphan message.
-                self.cc_session.group_recvmsg(False, seq) 
+                try:
+                    self.cc_session.group_recvmsg(False, seq)
+                except isc.cc.session.SessionTimeout:
+                    pass
                 answer = isc.config.ccsession.create_answer(0)
             elif command == "ping":
                 answer = isc.config.ccsession.create_answer(0, "pong")

+ 6 - 0
src/bin/bind10/tests/bind10_test.py.in

@@ -147,6 +147,12 @@ class TestBoB(unittest.TestCase):
         self.assertEqual(bob.command_handler("shutdown", None),
                          isc.config.ccsession.create_answer(0))
         self.assertFalse(bob.runnable)
+        # "getstats" command
+        self.assertEqual(bob.command_handler("getstats", None),
+                         isc.config.ccsession.create_answer(0,
+                            { "stats_data": {
+                                'bind10.boot_time': time.strftime('%Y-%m-%dT%H:%M:%SZ', _BASETIME)
+                            }}))
         # "sendstats" command
         self.assertEqual(bob.command_handler("sendstats", None),
                          isc.config.ccsession.create_answer(0))

+ 3 - 1
src/bin/stats/stats.py.in

@@ -215,7 +215,9 @@ class CCSessionListener(Listener):
 
     def _update_stats_data(self, args):
         # 'args' must be dictionary type
-        self.stats_data.update(args['stats_data'])
+        if isinstance(args, dict) and isinstance(args.get('stats_data'), dict):
+            self.stats_data.update(args['stats_data'])
+
         # overwrite "stats.LastUpdateTime"
         self.stats_data['stats.last_update_time'] = get_datetime()