BIND 10 trac930, updated. fee53aeaaf8c953c856f12ae3388a61abc47d2f9 [trac930] add comments about abstracts of the test scripts in their headers
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Aug 2 13:35:48 UTC 2011
The branch, trac930 has been updated
via fee53aeaaf8c953c856f12ae3388a61abc47d2f9 (commit)
via 5c9bdf1345699e47018c16254778de67cc695847 (commit)
via 5002ef4bc64e1d58293d8891adbaf652e075a6cf (commit)
via f02cc6985eff417f34e4edd232b6836852de6c98 (commit)
from 065c6004799a76d45859289d2ebae0379e9dceba (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 fee53aeaaf8c953c856f12ae3388a61abc47d2f9
Author: Naoki Kambe <kambe at jprs.co.jp>
Date: Tue Aug 2 22:00:11 2011 +0900
[trac930] add comments about abstracts of the test scripts in their headers
commit 5c9bdf1345699e47018c16254778de67cc695847
Author: Naoki Kambe <kambe at jprs.co.jp>
Date: Tue Aug 2 21:44:07 2011 +0900
[trac930] modify stats.py
- add more documentations into update_modules, get_statistics_data and
update_statistics_data methods
- modify two methods: "update_modules" and "get_statistics_data" methods raise
StatsError instead of just returning None, when communication between stats
module and config manager is failed or when it can't find specified
statistics data.
- also modify the unittest depending on the changes of these behaviors.
commit 5002ef4bc64e1d58293d8891adbaf652e075a6cf
Author: Naoki Kambe <kambe at jprs.co.jp>
Date: Tue Aug 2 20:17:28 2011 +0900
[trac930] modify b10-stats_test.py
- set the constant variables in the setUp method in the TestUtilties class,
and compare values returned from the functions with these constants in
testing methods.
[trac930] remove the tearDown method which has no test case in the TestCallback
class
commit f02cc6985eff417f34e4edd232b6836852de6c98
Author: Naoki Kambe <kambe at jprs.co.jp>
Date: Tue Aug 2 19:57:58 2011 +0900
[trac930] remove tailing whitespaces.
-----------------------------------------------------------------------
Summary of changes:
src/bin/stats/b10-stats-httpd.xml | 2 +-
src/bin/stats/stats.py.in | 29 ++++++++++---
src/bin/stats/stats_httpd.py.in | 2 +-
src/bin/stats/tests/Makefile.am | 2 +-
src/bin/stats/tests/b10-stats-httpd_test.py | 17 ++++++--
src/bin/stats/tests/b10-stats_test.py | 56 +++++++++++++++++---------
src/bin/stats/tests/test_utils.py | 8 ++--
src/bin/tests/Makefile.am | 2 +-
8 files changed, 78 insertions(+), 40 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/stats/b10-stats-httpd.xml b/src/bin/stats/b10-stats-httpd.xml
index 3636d9d..c8df9b8 100644
--- a/src/bin/stats/b10-stats-httpd.xml
+++ b/src/bin/stats/b10-stats-httpd.xml
@@ -132,7 +132,7 @@
<refsect1>
<title>CONFIGURATION AND COMMANDS</title>
<para>
- The configurable setting in
+ The configurable setting in
<filename>stats-httpd.spec</filename> is:
</para>
<variablelist>
diff --git a/src/bin/stats/stats.py.in b/src/bin/stats/stats.py.in
index bea7016..9f24c67 100644
--- a/src/bin/stats/stats.py.in
+++ b/src/bin/stats/stats.py.in
@@ -197,7 +197,10 @@ class Stats:
def update_modules(self):
"""
- update information of each module
+ updates information of each module. This method gets each
+ module's information from the config manager and sets it into
+ self.modules. If its getting from the config manager fails, it
+ raises StatsError.
"""
modules = {}
seq = self.cc_session.group_sendmsg(
@@ -213,12 +216,16 @@ class Stats:
if value[mod] and type(value[mod]) is list:
spec["statistics"] = value[mod]
modules[mod] = isc.config.module_spec.ModuleSpec(spec)
+ else:
+ raise StatsError("Updating module spec fails: " + str(value))
modules[self.module_name] = self.mccs.get_module_spec()
self.modules = modules
def get_statistics_data(self, owner=None, name=None):
"""
- return statistics data which stats module has of each module
+ returns statistics data which stats module has of each
+ module. If it can't find specified statistics data, it raises
+ StatsError.
"""
self.update_statistics_data()
if owner and name:
@@ -235,10 +242,18 @@ class Stats:
pass
else:
return self.statistics_data
+ raise StatsError("No statistics data found: "
+ + "owner: " + str(owner) + ", "
+ + "name: " + str(name))
def update_statistics_data(self, owner=None, **data):
"""
- change statistics date of specified module into specified data
+ change statistics date of specified module into specified
+ data. It updates information of each module first, and it
+ updates statistics data. If specified data is invalid for
+ statistics spec of specified owner, it returns a list of error
+ messeges. If there is no error or if neither owner nor data is
+ specified in args, it returns None.
"""
self.update_modules()
statistics_data = {}
@@ -297,10 +312,10 @@ class Stats:
if errors:
raise StatsError("stats spec file is incorrect: "
+ ", ".join(errors))
- ret = self.get_statistics_data(owner, name)
- if ret is not None:
- return isc.config.create_answer(0, ret)
- else:
+ try:
+ return isc.config.create_answer(
+ 0, self.get_statistics_data(owner, name))
+ except StatsError:
return isc.config.create_answer(
1, "specified arguments are incorrect: " \
+ "owner: " + str(owner) + ", name: " + str(name))
diff --git a/src/bin/stats/stats_httpd.py.in b/src/bin/stats/stats_httpd.py.in
index 32ec6b7..f8a09e5 100644
--- a/src/bin/stats/stats_httpd.py.in
+++ b/src/bin/stats/stats_httpd.py.in
@@ -415,7 +415,7 @@ class StatsHttpd:
annotation.append(documentation)
element.append(annotation)
alltag.append(element)
-
+
complextype = xml.etree.ElementTree.Element("complexType")
complextype.append(alltag)
mod_element = xml.etree.ElementTree.Element("element", { "name" : mod })
diff --git a/src/bin/stats/tests/Makefile.am b/src/bin/stats/tests/Makefile.am
index 19f6117..368e90c 100644
--- a/src/bin/stats/tests/Makefile.am
+++ b/src/bin/stats/tests/Makefile.am
@@ -13,7 +13,7 @@ endif
# test using command-line arguments, so use check-local target instead of TESTS
check-local:
if ENABLE_PYTHON_COVERAGE
- touch $(abs_top_srcdir)/.coverage
+ touch $(abs_top_srcdir)/.coverage
rm -f .coverage
${LN_S} $(abs_top_srcdir)/.coverage .coverage
endif
diff --git a/src/bin/stats/tests/b10-stats-httpd_test.py b/src/bin/stats/tests/b10-stats-httpd_test.py
index 89dea29..e1c05da 100644
--- a/src/bin/stats/tests/b10-stats-httpd_test.py
+++ b/src/bin/stats/tests/b10-stats-httpd_test.py
@@ -13,6 +13,13 @@
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+"""
+This unittests run Msgq, Cfgmgr, Auth, Boss and Stats as mock in
+background. Because the stats httpd communicates various other modules
+in runtime. However this aim is not to actually simulate a whole
+system running.
+"""
+
import unittest
import os
import imp
@@ -30,7 +37,7 @@ import stats_httpd
import stats
from test_utils import BaseModules, ThreadingServerManager, MyStats, MyStatsHttpd, TIMEOUT_SEC
-# set test name for logger
+# set test name for logger
isc.log.init("b10-stats-httpd_test")
DUMMY_DATA = {
@@ -364,7 +371,7 @@ class TestStatsHttpd(unittest.TestCase):
for ht in self.stats_httpd.httpd:
self.assertTrue(isinstance(ht.socket, socket.socket))
self.stats_httpd.close_httpd()
-
+
# dual stack (address is ipv4)
if self.ipv6_enabled:
self.stats_httpd.http_addrs = [ ('127.0.0.1', 8000) ]
@@ -380,20 +387,20 @@ class TestStatsHttpd(unittest.TestCase):
for ht in self.stats_httpd.httpd:
self.assertTrue(isinstance(ht.socket, socket.socket))
self.stats_httpd.close_httpd()
-
+
# only-ipv4 single stack (force set ipv6 )
if not self.ipv6_enabled:
self.stats_httpd.http_addrs = [ ('::1', 8000) ]
self.assertRaises(stats_httpd.HttpServerError,
self.stats_httpd.open_httpd)
-
+
# hostname
self.stats_httpd.http_addrs = [ ('localhost', 8000) ]
self.stats_httpd.open_httpd()
for ht in self.stats_httpd.httpd:
self.assertTrue(isinstance(ht.socket, socket.socket))
self.stats_httpd.close_httpd()
-
+
self.stats_httpd.http_addrs = [ ('my.host.domain', 8000) ]
self.assertRaises(stats_httpd.HttpServerError, self.stats_httpd.open_httpd)
self.assertEqual(type(self.stats_httpd.httpd), list)
diff --git a/src/bin/stats/tests/b10-stats_test.py b/src/bin/stats/tests/b10-stats_test.py
index 7eb2555..f8830eb 100644
--- a/src/bin/stats/tests/b10-stats_test.py
+++ b/src/bin/stats/tests/b10-stats_test.py
@@ -13,6 +13,13 @@
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+"""
+This unittests run Msgq, Cfgmgr, Auth and Boss as mock in
+background. Because the stats module communicates various other
+modules in runtime. However this aim is not to actually simulate a
+whole system running.
+"""
+
import unittest
import os
import threading
@@ -24,7 +31,7 @@ import stats
import isc.cc.session
from test_utils import BaseModules, ThreadingServerManager, MyStats, send_command, TIMEOUT_SEC
-# set test name for logger
+# set test name for logger
isc.log.init("b10-stats_test")
class TestUtilties(unittest.TestCase):
@@ -56,6 +63,13 @@ class TestUtilties(unittest.TestCase):
{ 'item_name': 'test_none', 'item_type': 'none' }
]
+ def setUp(self):
+ 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'
+ stats.time = lambda : self.const_timestamp
+ stats.gmtime = lambda : self.const_timetuple
+
def test_get_spec_defaults(self):
self.assertEqual(
stats.get_spec_defaults(self.items), {
@@ -76,14 +90,12 @@ class TestUtilties(unittest.TestCase):
self.assertRaises(KeyError, stats.get_spec_defaults, [{'item_name':'Foo'}])
def test_get_timestamp(self):
- self.assertEqual(stats.get_timestamp(), 1308730448.965706)
+ self.assertEqual(stats.get_timestamp(), self.const_timestamp)
def test_get_datetime(self):
- stats.time = lambda : 1308730448.965706
- stats.gmtime = lambda : (2011, 6, 22, 8, 14, 8, 2, 173, 0)
- self.assertEqual(stats.get_datetime(), '2011-06-22T08:14:08Z')
+ self.assertEqual(stats.get_datetime(), self.const_datetime)
self.assertNotEqual(stats.get_datetime(
- (2011, 6, 22, 8, 23, 40, 2, 173, 0)), '2011-06-22T08:14:08Z')
+ (2011, 6, 22, 8, 23, 40, 2, 173, 0)), self.const_datetime)
class TestCallback(unittest.TestCase):
def setUp(self):
@@ -108,9 +120,6 @@ class TestCallback(unittest.TestCase):
args=self.dummy_args
)
- def tearDown(self):
- pass
-
def test_init(self):
self.assertEqual((self.cback1.command, self.cback1.args, self.cback1.kwargs),
(self.dummy_func, self.dummy_args, self.dummy_kwargs))
@@ -205,19 +214,19 @@ class TestStats(unittest.TestCase):
self.base.boss.server._started.wait()
self.assertEqual(
send_command(
- 'show', 'Stats',
+ 'show', 'Stats',
params={ 'owner' : 'Boss',
'name' : 'boot_time' }),
(0, '2011-06-22T08:14:08Z'))
self.assertEqual(
send_command(
- 'set', 'Stats',
+ 'set', 'Stats',
params={ 'owner' : 'Boss',
'data' : { 'boot_time' : '2012-06-22T18:24:08Z' } }),
(0, None))
self.assertEqual(
send_command(
- 'show', 'Stats',
+ 'show', 'Stats',
params={ 'owner' : 'Boss',
'name' : 'boot_time' }),
(0, '2012-06-22T18:24:08Z'))
@@ -267,7 +276,7 @@ class TestStats(unittest.TestCase):
self.assertTrue('item_description' in item)
if len(item) == 7:
self.assertTrue('item_format' in item)
-
+
self.assertEqual(
send_command('__UNKNOWN__', 'Stats'),
(1, "Unknown command: '__UNKNOWN__'"))
@@ -294,6 +303,10 @@ class TestStats(unittest.TestCase):
my_statistics_data = stats.get_spec_defaults(self.stats.modules['Boss'].get_statistics_spec())
self.assertTrue('boot_time' in my_statistics_data)
self.assertEqual(my_statistics_data['boot_time'], "1970-01-01T00:00:00Z")
+ orig_parse_answer = stats.isc.config.ccsession.parse_answer
+ stats.isc.config.ccsession.parse_answer = lambda x: (99, 'error')
+ self.assertRaises(stats.StatsError, self.stats.update_modules)
+ stats.isc.config.ccsession.parse_answer = orig_parse_answer
def test_get_statistics_data(self):
my_statistics_data = self.stats.get_statistics_data()
@@ -305,7 +318,7 @@ class TestStats(unittest.TestCase):
self.assertTrue('last_update_time' in my_statistics_data)
self.assertTrue('timestamp' in my_statistics_data)
self.assertTrue('lname' in my_statistics_data)
- self.assertIsNone(self.stats.get_statistics_data(owner='Foo'))
+ self.assertRaises(stats.StatsError, self.stats.get_statistics_data, owner='Foo')
my_statistics_data = self.stats.get_statistics_data(owner='Stats')
self.assertTrue('boot_time' in my_statistics_data)
my_statistics_data = self.stats.get_statistics_data(owner='Stats', name='report_time')
@@ -318,9 +331,12 @@ class TestStats(unittest.TestCase):
self.assertEqual(my_statistics_data, 0.0)
my_statistics_data = self.stats.get_statistics_data(owner='Stats', name='lname')
self.assertEqual(my_statistics_data, '')
- self.assertIsNone(self.stats.get_statistics_data(owner='Stats', name='Bar'))
- self.assertIsNone(self.stats.get_statistics_data(owner='Foo', name='Bar'))
- self.assertEqual(self.stats.get_statistics_data(name='Bar'), None)
+ self.assertRaises(stats.StatsError, self.stats.get_statistics_data,
+ owner='Stats', name='Bar')
+ self.assertRaises(stats.StatsError, self.stats.get_statistics_data,
+ owner='Foo', name='Bar')
+ self.assertRaises(stats.StatsError, self.stats.get_statistics_data,
+ name='Bar')
def test_update_statistics_data(self):
self.stats.update_statistics_data(owner='Stats', lname='foo at bar')
@@ -340,13 +356,13 @@ class TestStats(unittest.TestCase):
self.assertEqual(self.stats.command_status(),
isc.config.create_answer(
0, "Stats is up. (PID " + str(os.getpid()) + ")"))
-
+
def test_command_shutdown(self):
self.stats.running = True
self.assertEqual(self.stats.command_shutdown(),
isc.config.create_answer(0))
self.assertFalse(self.stats.running)
-
+
def test_command_show(self):
self.assertEqual(self.stats.command_show(owner='Foo', name=None),
isc.config.create_answer(
@@ -380,7 +396,7 @@ class TestStats(unittest.TestCase):
"statistics": [] } )
self.assertRaises(
stats.StatsError, self.stats.command_show, owner='Foo', name='bar')
-
+
def test_command_showchema(self):
(rcode, value) = isc.config.ccsession.parse_answer(
self.stats.command_showschema())
diff --git a/src/bin/stats/tests/test_utils.py b/src/bin/stats/tests/test_utils.py
index b3e20b5..a793dc6 100644
--- a/src/bin/stats/tests/test_utils.py
+++ b/src/bin/stats/tests/test_utils.py
@@ -10,7 +10,7 @@ import threading
import tempfile
import msgq
-import isc.config.cfgmgr
+import isc.config.cfgmgr
import stats
import stats_httpd
@@ -49,7 +49,7 @@ class ThreadingServerManager:
self.server._thread = threading.Thread(
name=self.server_class_name, target=self.server.run)
self.server._thread.daemon = True
-
+
def run(self):
self.server._thread.start()
self.server._started.wait()
@@ -94,7 +94,7 @@ class MockCfgmgr:
def shutdown(self):
self.cfgmgr.running = False
-
+
class MockBoss:
spec_str = """\
{
@@ -157,7 +157,7 @@ class MockBoss:
params = { "owner": "Boss",
"data": {
'boot_time': time.strftime('%Y-%m-%dT%H:%M:%SZ', self._BASETIME)
- }
+ }
}
return send_command("set", "Stats", params=params, session=self.cc_session)
return isc.config.create_answer(1, "Unknown Command")
diff --git a/src/bin/tests/Makefile.am b/src/bin/tests/Makefile.am
index b5bcea2..3d3f3dc 100644
--- a/src/bin/tests/Makefile.am
+++ b/src/bin/tests/Makefile.am
@@ -13,7 +13,7 @@ endif
# test using command-line arguments, so use check-local target instead of TESTS
check-local:
if ENABLE_PYTHON_COVERAGE
- touch $(abs_top_srcdir)/.coverage
+ touch $(abs_top_srcdir)/.coverage
rm -f .coverage
${LN_S} $(abs_top_srcdir)/.coverage .coverage
endif
More information about the bind10-changes
mailing list