|
@@ -23,7 +23,6 @@ to real environment.
|
|
|
|
|
|
import unittest
|
|
|
import os
|
|
|
-import threading
|
|
|
import io
|
|
|
import time
|
|
|
import imp
|
|
@@ -31,10 +30,7 @@ import sys
|
|
|
|
|
|
import stats
|
|
|
import isc.log
|
|
|
-import isc.cc.session
|
|
|
-from test_utils import BaseModules, ThreadingServerManager, MyStats, \
|
|
|
- SimpleStats, SignalHandler, MyModuleCCSession, send_command
|
|
|
-from isc.testutils.ccsession_mock import MockModuleCCSession
|
|
|
+from test_utils import MyStats
|
|
|
|
|
|
class TestUtilties(unittest.TestCase):
|
|
|
items = [
|
|
@@ -91,9 +87,15 @@ class TestUtilties(unittest.TestCase):
|
|
|
self.const_timestamp = 1308730448.965706
|
|
|
self.const_timetuple = (2011, 6, 22, 8, 14, 8, 2, 173, 0)
|
|
|
self.const_datetime = '2011-06-22T08:14:08Z'
|
|
|
+ self.__orig_time = stats.time
|
|
|
+ self.__orig_gmtime = stats.gmtime
|
|
|
stats.time = lambda : self.const_timestamp
|
|
|
stats.gmtime = lambda : self.const_timetuple
|
|
|
|
|
|
+ def tearDown(self):
|
|
|
+ stats.time = self.__orig_time
|
|
|
+ stats.gmtime = self.__orig_gmtime
|
|
|
+
|
|
|
def test_get_spec_defaults(self):
|
|
|
self.assertEqual(
|
|
|
stats.get_spec_defaults(self.items), {
|
|
@@ -243,8 +245,6 @@ class TestCallback(unittest.TestCase):
|
|
|
class TestStats(unittest.TestCase):
|
|
|
def setUp(self):
|
|
|
# set the signal handler for deadlock
|
|
|
- self.sig_handler = SignalHandler(self.fail)
|
|
|
- self.base = BaseModules()
|
|
|
self.const_timestamp = 1308730448.965706
|
|
|
self.const_datetime = '2011-06-22T08:14:08Z'
|
|
|
self.const_default_datetime = '1970-01-01T00:00:00Z'
|
|
@@ -253,15 +253,12 @@ class TestStats(unittest.TestCase):
|
|
|
self.__orig_get_datetime = stats.get_datetime
|
|
|
|
|
|
def tearDown(self):
|
|
|
- self.base.shutdown()
|
|
|
- # reset the signal handler
|
|
|
- self.sig_handler.reset()
|
|
|
# restore the stored original function in case we replaced them
|
|
|
stats.get_timestamp = self.__orig_timestamp
|
|
|
stats.get_datetime = self.__orig_get_datetime
|
|
|
|
|
|
def test_init(self):
|
|
|
- self.stats = stats.Stats()
|
|
|
+ self.stats = MyStats()
|
|
|
self.assertEqual(self.stats.module_name, 'Stats')
|
|
|
self.assertFalse(self.stats.running)
|
|
|
self.assertTrue('command_show' in self.stats.callbacks)
|
|
@@ -291,7 +288,7 @@ class TestStats(unittest.TestCase):
|
|
|
"""
|
|
|
orig_spec_location = stats.SPECFILE_LOCATION
|
|
|
stats.SPECFILE_LOCATION = io.StringIO(spec_str)
|
|
|
- self.assertRaises(stats.StatsError, stats.Stats)
|
|
|
+ self.assertRaises(stats.StatsError, MyStats)
|
|
|
stats.SPECFILE_LOCATION = orig_spec_location
|
|
|
|
|
|
def __send_command(self, stats, command_name, params=None):
|
|
@@ -310,13 +307,13 @@ class TestStats(unittest.TestCase):
|
|
|
raise CheckException # terminate the loop
|
|
|
|
|
|
# start without err
|
|
|
- stats = SimpleStats()
|
|
|
- self.assertFalse(stats.running)
|
|
|
- stats._check_command = lambda: __check_start(stats)
|
|
|
+ self.stats = MyStats()
|
|
|
+ self.assertFalse(self.stats.running)
|
|
|
+ self.stats._check_command = lambda: __check_start(self.stats)
|
|
|
# We are going to confirm start() will set running to True, avoiding
|
|
|
# to fall into a loop with the exception trick.
|
|
|
- self.assertRaises(CheckException, stats.start)
|
|
|
- self.assertEqual(self.__send_command(stats, "status"),
|
|
|
+ self.assertRaises(CheckException, self.stats.start)
|
|
|
+ self.assertEqual(self.__send_command(self.stats, "status"),
|
|
|
(0, "Stats is up. (PID " + str(os.getpid()) + ")"))
|
|
|
|
|
|
def test_shutdown(self):
|
|
@@ -328,15 +325,15 @@ class TestStats(unittest.TestCase):
|
|
|
# override get_interval() so it won't go poll statistics
|
|
|
tested_stats.get_interval = lambda : 0
|
|
|
|
|
|
- stats = SimpleStats()
|
|
|
- stats._check_command = lambda: __check_shutdown(stats)
|
|
|
- stats.start()
|
|
|
- self.assertTrue(stats.mccs.stopped)
|
|
|
+ self.stats = MyStats()
|
|
|
+ self.stats._check_command = lambda: __check_shutdown(self.stats)
|
|
|
+ self.stats.start()
|
|
|
+ self.assertTrue(self.stats.mccs.stopped)
|
|
|
|
|
|
def test_handlers(self):
|
|
|
"""Test command_handler"""
|
|
|
|
|
|
- __stats = SimpleStats()
|
|
|
+ __stats = MyStats()
|
|
|
|
|
|
# 'show' command. We're going to check the expected methods are
|
|
|
# called in the expected order, and check the resulting response.
|
|
@@ -433,7 +430,7 @@ class TestStats(unittest.TestCase):
|
|
|
}]}
|
|
|
return answer_value
|
|
|
|
|
|
- self.stats = SimpleStats()
|
|
|
+ self.stats = MyStats()
|
|
|
self.stats.cc_session.rpc_call = __check_rpc_call
|
|
|
|
|
|
self.stats.update_modules()
|
|
@@ -480,7 +477,7 @@ class TestStats(unittest.TestCase):
|
|
|
where we set the expected data in statistics_data.
|
|
|
|
|
|
"""
|
|
|
- self.stats = SimpleStats()
|
|
|
+ self.stats = MyStats()
|
|
|
def __faked_update_modules():
|
|
|
self.stats.statistics_data = { \
|
|
|
'Stats': {
|
|
@@ -539,7 +536,7 @@ class TestStats(unittest.TestCase):
|
|
|
|
|
|
def test_update_statistics_data(self):
|
|
|
"""test for list-type statistics"""
|
|
|
- self.stats = SimpleStats()
|
|
|
+ self.stats = MyStats()
|
|
|
_test_exp1 = {
|
|
|
'zonename': 'test1.example',
|
|
|
'queries.tcp': 5,
|
|
@@ -616,7 +613,7 @@ class TestStats(unittest.TestCase):
|
|
|
|
|
|
def test_update_statistics_data_pt2(self):
|
|
|
"""test for named_set-type statistics"""
|
|
|
- self.stats = SimpleStats()
|
|
|
+ self.stats = MyStats()
|
|
|
_test_exp1 = \
|
|
|
{ 'test10.example': { 'queries.tcp': 5, 'queries.udp': 4 } }
|
|
|
_test_exp2 = \
|
|
@@ -686,7 +683,7 @@ class TestStats(unittest.TestCase):
|
|
|
'Foo', 'foo1', _test_exp6), ['unknown module name: Foo'])
|
|
|
|
|
|
def test_update_statistics_data_withmid(self):
|
|
|
- self.stats = SimpleStats()
|
|
|
+ self.stats = MyStats()
|
|
|
|
|
|
# This test relies on existing statistics data at the Stats object.
|
|
|
# This version of test prepares the data using the do_polling() method;
|
|
@@ -701,7 +698,7 @@ class TestStats(unittest.TestCase):
|
|
|
# We use the knowledge of what kind of messages are sent via
|
|
|
# do_polling, and return the following faked answer directly.
|
|
|
create_answer = isc.config.ccsession.create_answer # shortcut
|
|
|
- self.stats._answers = [\
|
|
|
+ self.stats._answers = [
|
|
|
# Answer for "show_processes"
|
|
|
(create_answer(0, [[1034, 'b10-auth-1', 'Auth'],
|
|
|
[1035, 'b10-auth-2', 'Auth']]), None),
|
|
@@ -754,7 +751,6 @@ class TestStats(unittest.TestCase):
|
|
|
self.assertEqual(self.stats.statistics_data_bymid['Auth']['bar2@foo'],
|
|
|
{'queries.tcp': bar2_tcp})
|
|
|
# kill running Auth but the statistics data doesn't change
|
|
|
- self.base.auth2.server.shutdown()
|
|
|
self.stats.update_statistics_data()
|
|
|
self.assertTrue('Auth' in self.stats.statistics_data)
|
|
|
self.assertTrue('queries.tcp' in self.stats.statistics_data['Auth'])
|
|
@@ -765,7 +761,6 @@ class TestStats(unittest.TestCase):
|
|
|
sum_qudp)
|
|
|
self.assertTrue('Auth' in self.stats.statistics_data_bymid)
|
|
|
# restore statistics data of killed auth
|
|
|
- # self.base.b10_init.server.pid_list = [ killed ] + self.base.b10_init.server.pid_list[:]
|
|
|
self.stats.update_statistics_data('Auth',
|
|
|
"bar1@foo",
|
|
|
{'queries.tcp': bar1_tcp})
|
|
@@ -794,7 +789,7 @@ class TestStats(unittest.TestCase):
|
|
|
def test_config(self):
|
|
|
orig_get_timestamp = stats.get_timestamp
|
|
|
stats.get_timestamp = lambda : self.const_timestamp
|
|
|
- stat = SimpleStats()
|
|
|
+ stat = MyStats()
|
|
|
|
|
|
# test updating poll-interval
|
|
|
self.assertEqual(stat.config['poll-interval'], 60)
|
|
@@ -840,7 +835,7 @@ class TestStats(unittest.TestCase):
|
|
|
(0, {'Init': {'boot_time': self.const_datetime}}))
|
|
|
|
|
|
def test_commands(self):
|
|
|
- self.stats = stats.Stats()
|
|
|
+ self.stats = MyStats()
|
|
|
|
|
|
# status
|
|
|
self.assertEqual(self.stats.command_status(),
|
|
@@ -853,39 +848,57 @@ class TestStats(unittest.TestCase):
|
|
|
isc.config.create_answer(0))
|
|
|
self.assertFalse(self.stats.running)
|
|
|
|
|
|
- @unittest.skipIf(sys.version_info >= (3, 3), "Unsupported in Python 3.3 or higher")
|
|
|
- def test_command_show(self):
|
|
|
- # two auth instances invoked
|
|
|
- list_auth = [ self.base.auth.server,
|
|
|
- self.base.auth2.server ]
|
|
|
- sum_qtcp = 0
|
|
|
- sum_qudp = 0
|
|
|
- sum_qtcp_perzone1 = 0
|
|
|
- sum_qudp_perzone1 = 0
|
|
|
- sum_qtcp_perzone2 = 4 * len(list_auth)
|
|
|
- sum_qudp_perzone2 = 3 * len(list_auth)
|
|
|
- sum_qtcp_nds_perzone10 = 0
|
|
|
- sum_qudp_nds_perzone10 = 0
|
|
|
- sum_qtcp_nds_perzone20 = 4 * len(list_auth)
|
|
|
- sum_qudp_nds_perzone20 = 3 * len(list_auth)
|
|
|
- self.stats = stats.Stats()
|
|
|
+ def test_command_show_error(self):
|
|
|
+ self.stats = MyStats()
|
|
|
self.assertEqual(self.stats.command_show(owner='Foo', name=None),
|
|
|
isc.config.create_answer(
|
|
|
- 1, "specified arguments are incorrect: owner: Foo, name: None"))
|
|
|
+ 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 arguments are incorrect: owner: Foo, name: _bar_"))
|
|
|
+ 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 arguments are incorrect: owner: Foo, name: bar"))
|
|
|
+ 1,
|
|
|
+ "specified arguments are incorrect: owner: Foo, name: bar"))
|
|
|
|
|
|
- for a in list_auth:
|
|
|
- sum_qtcp += a.queries_tcp
|
|
|
- sum_qudp += a.queries_udp
|
|
|
- sum_qtcp_perzone1 += a.queries_per_zone[0]['queries.tcp']
|
|
|
- sum_qudp_perzone1 += a.queries_per_zone[0]['queries.udp']
|
|
|
- sum_qtcp_nds_perzone10 += a.nds_queries_per_zone['test10.example']['queries.tcp']
|
|
|
- sum_qudp_nds_perzone10 += a.nds_queries_per_zone['test10.example']['queries.udp']
|
|
|
+ def test_command_show_auth(self):
|
|
|
+ self.stats = MyStats()
|
|
|
+ self.stats.update_modules = lambda: None
|
|
|
+
|
|
|
+ # Test data borrowed from test_update_statistics_data_withmid
|
|
|
+ create_answer = isc.config.ccsession.create_answer # shortcut
|
|
|
+ self.stats._answers = [
|
|
|
+ (create_answer(0, [[1034, 'b10-auth-1', 'Auth'],
|
|
|
+ [1035, 'b10-auth-2', 'Auth']]), None),
|
|
|
+ (create_answer(0, self.stats._auth_sdata), {'from': 'auth1'}),
|
|
|
+ (create_answer(0, self.stats._auth_sdata), {'from': 'auth2'}),
|
|
|
+ (create_answer(0, self.stats._auth_sdata), {'from': 'auth3'})
|
|
|
+ ]
|
|
|
+
|
|
|
+ num_instances = 2
|
|
|
+ sum_qtcp = 0
|
|
|
+ sum_qudp = 0
|
|
|
+ sum_qtcp_perzone1 = 0
|
|
|
+ sum_qudp_perzone1 = 0
|
|
|
+ sum_qtcp_perzone2 = 4 * num_instances
|
|
|
+ sum_qudp_perzone2 = 3 * num_instances
|
|
|
+ sum_qtcp_nds_perzone10 = 0
|
|
|
+ sum_qudp_nds_perzone10 = 0
|
|
|
+ sum_qtcp_nds_perzone20 = 4 * num_instances
|
|
|
+ sum_qudp_nds_perzone20 = 3 * num_instances
|
|
|
+
|
|
|
+ self.maxDiff = None
|
|
|
+ for a in (0, num_instances):
|
|
|
+ sum_qtcp += self.stats._queries_tcp
|
|
|
+ sum_qudp += self.stats._queries_udp
|
|
|
+ sum_qtcp_perzone1 += self.stats._queries_per_zone[0]['queries.tcp']
|
|
|
+ sum_qudp_perzone1 += self.stats._queries_per_zone[0]['queries.udp']
|
|
|
+ sum_qtcp_nds_perzone10 += \
|
|
|
+ self.stats._nds_queries_per_zone['test10.example']['queries.tcp']
|
|
|
+ sum_qudp_nds_perzone10 += \
|
|
|
+ self.stats._nds_queries_per_zone['test10.example']['queries.udp']
|
|
|
|
|
|
self.assertEqual(self.stats.command_show(owner='Auth'),
|
|
|
isc.config.create_answer(
|
|
@@ -926,26 +939,33 @@ class TestStats(unittest.TestCase):
|
|
|
'test20.example': {
|
|
|
'queries.udp': sum_qudp_nds_perzone20,
|
|
|
'queries.tcp': sum_qtcp_nds_perzone20 }}}}))
|
|
|
+
|
|
|
+ def test_command_show_stats(self):
|
|
|
+ self.stats = MyStats()
|
|
|
orig_get_datetime = stats.get_datetime
|
|
|
orig_get_timestamp = stats.get_timestamp
|
|
|
stats.get_datetime = lambda x=None: self.const_datetime
|
|
|
stats.get_timestamp = lambda : self.const_timestamp
|
|
|
- self.assertEqual(self.stats.command_show(owner='Stats', name='report_time'),
|
|
|
+ self.assertEqual(self.stats.command_show(owner='Stats',
|
|
|
+ name='report_time'),
|
|
|
isc.config.create_answer(
|
|
|
0, {'Stats': {'report_time':self.const_datetime}}))
|
|
|
- self.assertEqual(self.stats.command_show(owner='Stats', name='timestamp'),
|
|
|
+ self.assertEqual(self.stats.command_show(owner='Stats',
|
|
|
+ name='timestamp'),
|
|
|
isc.config.create_answer(
|
|
|
0, {'Stats': {'timestamp':self.const_timestamp}}))
|
|
|
stats.get_datetime = orig_get_datetime
|
|
|
stats.get_timestamp = orig_get_timestamp
|
|
|
- self.stats.modules[self.stats.module_name] = isc.config.module_spec.ModuleSpec(
|
|
|
- { "module_name": self.stats.module_name,
|
|
|
- "statistics": [] } )
|
|
|
+ self.stats.do_polling = lambda : None
|
|
|
+ self.stats.modules[self.stats.module_name] = \
|
|
|
+ isc.config.module_spec.ModuleSpec(
|
|
|
+ { "module_name": self.stats.module_name, "statistics": [] } )
|
|
|
self.assertRaises(
|
|
|
- stats.StatsError, self.stats.command_show, owner=self.stats.module_name, name='bar')
|
|
|
+ stats.StatsError, self.stats.command_show,
|
|
|
+ owner=self.stats.module_name, name='bar')
|
|
|
|
|
|
def test_command_showchema(self):
|
|
|
- self.stats = stats.Stats()
|
|
|
+ self.stats = MyStats()
|
|
|
(rcode, value) = isc.config.ccsession.parse_answer(
|
|
|
self.stats.command_showschema())
|
|
|
self.assertEqual(rcode, 0)
|
|
@@ -1261,96 +1281,125 @@ class TestStats(unittest.TestCase):
|
|
|
isc.config.create_answer(
|
|
|
1, "module name is not specified"))
|
|
|
|
|
|
- @unittest.skipIf(sys.version_info >= (3, 3), "Unsupported in Python 3.3 or higher")
|
|
|
- def test_polling(self):
|
|
|
- stats_server = ThreadingServerManager(MyStats)
|
|
|
- stat = stats_server.server
|
|
|
- stats_server.run()
|
|
|
- self.assertEqual(
|
|
|
- send_command('show', 'Stats'),
|
|
|
- (0, stat.statistics_data))
|
|
|
- # check statistics data of 'Init'
|
|
|
- b10_init = self.base.b10_init.server
|
|
|
- self.assertEqual(
|
|
|
- stat.statistics_data_bymid['Init'][b10_init.cc_session.lname],
|
|
|
- {'boot_time': self.const_datetime})
|
|
|
- self.assertEqual(
|
|
|
- len(stat.statistics_data_bymid['Init']), 1)
|
|
|
+ def test_polling_init(self):
|
|
|
+ """check statistics data of 'Init'."""
|
|
|
+
|
|
|
+ stat = MyStats()
|
|
|
+ stat.update_modules = lambda: None
|
|
|
+ create_answer = isc.config.ccsession.create_answer # shortcut
|
|
|
+
|
|
|
+ stat._answers = [
|
|
|
+ # Answer for "show_processes"
|
|
|
+ (create_answer(0, []), None),
|
|
|
+ # Answers for "getstats" for Init (type of boot_time is invalid)
|
|
|
+ (create_answer(0, {'boot_time': self.const_datetime}),
|
|
|
+ {'from': 'init'}),
|
|
|
+ ]
|
|
|
+
|
|
|
+ stat.do_polling()
|
|
|
self.assertEqual(
|
|
|
- stat.statistics_data['Init'],
|
|
|
+ stat.statistics_data_bymid['Init']['init'],
|
|
|
{'boot_time': self.const_datetime})
|
|
|
- # check statistics data of each 'Auth' instances
|
|
|
- list_auth = ['', '2']
|
|
|
- for i in list_auth:
|
|
|
- auth = getattr(self.base,"auth"+i).server
|
|
|
- for s in stat.statistics_data_bymid['Auth'].values():
|
|
|
- self.assertEqual(
|
|
|
- s, {'queries.perzone': auth.queries_per_zone,
|
|
|
- 'nds_queries.perzone': auth.nds_queries_per_zone,
|
|
|
- 'queries.tcp': auth.queries_tcp,
|
|
|
- 'queries.udp': auth.queries_udp})
|
|
|
- n = len(stat.statistics_data_bymid['Auth'])
|
|
|
- self.assertEqual(n, len(list_auth))
|
|
|
- # check consolidation of statistics data of the auth
|
|
|
- # instances
|
|
|
+
|
|
|
+ def test_polling_consolidate(self):
|
|
|
+ """check statistics data of multiple instances of same module."""
|
|
|
+ stat = MyStats()
|
|
|
+ stat.update_modules = lambda: None
|
|
|
+ create_answer = isc.config.ccsession.create_answer # shortcut
|
|
|
+
|
|
|
+ # Test data borrowed from test_update_statistics_data_withmid
|
|
|
+ stat._answers = [
|
|
|
+ (create_answer(0, [[1034, 'b10-auth-1', 'Auth'],
|
|
|
+ [1035, 'b10-auth-2', 'Auth']]), None),
|
|
|
+ (create_answer(0, stat._auth_sdata), {'from': 'auth1'}),
|
|
|
+ (create_answer(0, stat._auth_sdata), {'from': 'auth2'}),
|
|
|
+ (create_answer(0, stat._auth_sdata), {'from': 'auth3'})
|
|
|
+ ]
|
|
|
+
|
|
|
+ stat.do_polling()
|
|
|
+
|
|
|
+ # check statistics data of each 'Auth' instances. expected data
|
|
|
+ # for 'nds_queries.perzone' is special as it needs data merge.
|
|
|
+ self.assertEqual(2, len(stat.statistics_data_bymid['Auth'].values()))
|
|
|
+ for s in stat.statistics_data_bymid['Auth'].values():
|
|
|
self.assertEqual(
|
|
|
- stat.statistics_data['Auth'],
|
|
|
- {'queries.perzone': [
|
|
|
- {'zonename':
|
|
|
- auth.queries_per_zone[0]['zonename'],
|
|
|
- 'queries.tcp':
|
|
|
- auth.queries_per_zone[0]['queries.tcp']*n,
|
|
|
- 'queries.udp':
|
|
|
- auth.queries_per_zone[0]['queries.udp']*n},
|
|
|
- {'zonename': "test2.example",
|
|
|
- 'queries.tcp': 4*n,
|
|
|
- 'queries.udp': 3*n },
|
|
|
- ],
|
|
|
- 'nds_queries.perzone': {
|
|
|
- 'test10.example': {
|
|
|
- 'queries.tcp':
|
|
|
- auth.nds_queries_per_zone['test10.example']['queries.tcp']*n,
|
|
|
- 'queries.udp':
|
|
|
- auth.nds_queries_per_zone['test10.example']['queries.udp']*n},
|
|
|
- 'test20.example': {
|
|
|
- 'queries.tcp':
|
|
|
- 4*n,
|
|
|
- 'queries.udp':
|
|
|
- 3*n},
|
|
|
- },
|
|
|
- 'queries.tcp': auth.queries_tcp*n,
|
|
|
- 'queries.udp': auth.queries_udp*n})
|
|
|
- # check statistics data of 'Stats'
|
|
|
+ s, {'queries.perzone': stat._auth_sdata['queries.perzone'],
|
|
|
+ 'nds_queries.perzone': stat._nds_queries_per_zone,
|
|
|
+ 'queries.tcp': stat._auth_sdata['queries.tcp'],
|
|
|
+ 'queries.udp': stat._auth_sdata['queries.udp']})
|
|
|
+
|
|
|
+ # check consolidation of statistics data of the auth instances.
|
|
|
+ # it's union of the reported data and the spec default.
|
|
|
+ n = len(stat.statistics_data_bymid['Auth'].values())
|
|
|
+ self.maxDiff = None
|
|
|
self.assertEqual(
|
|
|
- len(stat.statistics_data['Stats']), 5)
|
|
|
- self.assertTrue('boot_time' in
|
|
|
- stat.statistics_data['Stats'])
|
|
|
- self.assertTrue('last_update_time' in
|
|
|
- stat.statistics_data['Stats'])
|
|
|
- self.assertTrue('report_time' in
|
|
|
- stat.statistics_data['Stats'])
|
|
|
- self.assertTrue('timestamp' in
|
|
|
- stat.statistics_data['Stats'])
|
|
|
- self.assertEqual(
|
|
|
- stat.statistics_data['Stats']['lname'],
|
|
|
- stat.mccs._session.lname)
|
|
|
- stats_server.shutdown()
|
|
|
+ stat.statistics_data['Auth'],
|
|
|
+ {'queries.perzone': [
|
|
|
+ {'zonename': 'test1.example',
|
|
|
+ 'queries.tcp': 5 * n,
|
|
|
+ 'queries.udp': 4 * n},
|
|
|
+ {'zonename': 'test2.example',
|
|
|
+ 'queries.tcp': 4 * n,
|
|
|
+ 'queries.udp': 3 * n},
|
|
|
+ ],
|
|
|
+ 'nds_queries.perzone': {
|
|
|
+ 'test10.example': {
|
|
|
+ 'queries.tcp': 5 * n,
|
|
|
+ 'queries.udp': 4 * n
|
|
|
+ },
|
|
|
+ 'test20.example': {
|
|
|
+ 'queries.tcp': 4 * n,
|
|
|
+ 'queries.udp': 3 * n
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'queries.tcp': 3 * n,
|
|
|
+ 'queries.udp': 2 * n})
|
|
|
+
|
|
|
+ def test_polling_stats(self):
|
|
|
+ """Check statistics data of 'Stats'
|
|
|
+
|
|
|
+ This is actually irrelevant to do_polling(), but provided to
|
|
|
+ compatibility of older tests.
|
|
|
+
|
|
|
+ """
|
|
|
+ stat = MyStats()
|
|
|
+ self.assertEqual(len(stat.statistics_data['Stats']), 5)
|
|
|
+ self.assertTrue('boot_time' in stat.statistics_data['Stats'])
|
|
|
+ self.assertTrue('last_update_time' in stat.statistics_data['Stats'])
|
|
|
+ self.assertTrue('report_time' in stat.statistics_data['Stats'])
|
|
|
+ self.assertTrue('timestamp' in stat.statistics_data['Stats'])
|
|
|
+ self.assertEqual(stat.statistics_data['Stats']['lname'],
|
|
|
+ stat.mccs._session.lname)
|
|
|
|
|
|
def test_polling2(self):
|
|
|
- # set invalid statistics
|
|
|
- b10_init = self.base.b10_init.server
|
|
|
- b10_init.statistics_data = {'boot_time':1}
|
|
|
- stats_server = ThreadingServerManager(MyStats)
|
|
|
- stat = stats_server.server
|
|
|
- stats_server.run()
|
|
|
- self.assertEqual(
|
|
|
- send_command('status', 'Stats'),
|
|
|
- (0, "Stats is up. (PID " + str(os.getpid()) + ")"))
|
|
|
+ """Test do_polling() doesn't incorporate broken statistics data.
|
|
|
+
|
|
|
+ Actually, this is not a test for do_polling() itself. It's bad, but
|
|
|
+ fixing that is a subject of different ticket.
|
|
|
+
|
|
|
+ """
|
|
|
+ stat = MyStats()
|
|
|
# check default statistics data of 'Init'
|
|
|
self.assertEqual(
|
|
|
- stat.statistics_data['Init'],
|
|
|
- {'boot_time': self.const_default_datetime})
|
|
|
- stats_server.shutdown()
|
|
|
+ stat.statistics_data['Init'],
|
|
|
+ {'boot_time': self.const_default_datetime})
|
|
|
+
|
|
|
+ # set invalid statistics
|
|
|
+ create_answer = isc.config.ccsession.create_answer # shortcut
|
|
|
+ stat._answers = [
|
|
|
+ # Answer for "show_processes"
|
|
|
+ (create_answer(0, []), None),
|
|
|
+ # Answers for "getstats" for Init (type of boot_time is invalid)
|
|
|
+ (create_answer(0, {'boot_time': 1}), {'from': 'init'}),
|
|
|
+ ]
|
|
|
+ stat.update_modules = lambda: None
|
|
|
+
|
|
|
+ # do_polling() should ignore the invalid answer;
|
|
|
+ # default data shouldn't be replaced.
|
|
|
+ stat.do_polling()
|
|
|
+ self.assertEqual(
|
|
|
+ stat.statistics_data['Init'],
|
|
|
+ {'boot_time': self.const_default_datetime})
|
|
|
|
|
|
class TestOSEnv(unittest.TestCase):
|
|
|
def test_osenv(self):
|