BIND 10 trac547, updated. 293a8a684262ffcb187a9c7ed2649eee2e9d0e30 [trac547] necessary more changes for adding "b10-stats-httpd" module [trac547] added "shutdown" command handling to "b10-stats-httpd" module

BIND 10 source code commits bind10-changes at lists.isc.org
Tue Feb 15 08:24:25 UTC 2011


The branch, trac547 has been updated
       via  293a8a684262ffcb187a9c7ed2649eee2e9d0e30 (commit)
      from  a2bf4e3f087041001b8ad32f501773ad135ca494 (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 293a8a684262ffcb187a9c7ed2649eee2e9d0e30
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Thu Feb 3 20:40:51 2011 +0900

    [trac547] necessary more changes for adding "b10-stats-httpd" module
    [trac547] added "shutdown" command handling to "b10-stats-httpd" module

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

Summary of changes:
 configure.ac                                |    1 +
 src/bin/bind10/bind10.py.in                 |    5 ++
 src/bin/bind10/tests/bind10_test.py         |    9 +++
 src/bin/stats/Makefile.am                   |   21 +++++--
 src/bin/stats/stats_httpd.py.in             |   91 +++++++++++++++++++++++++--
 src/bin/stats/tests/Makefile.am             |    2 +-
 src/bin/stats/tests/b10-stats-httpd_test.py |   28 +++++++--
 7 files changed, 141 insertions(+), 16 deletions(-)

-----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index cb9c8b8..3907864 100644
--- a/configure.ac
+++ b/configure.ac
@@ -735,6 +735,7 @@ AC_OUTPUT([doc/version.ent
            src/bin/stats/stats.py
            src/bin/stats/stats_httpd.py
            src/bin/stats/stats.spec.pre
+           src/bin/stats/stats_httpd.spec.pre
            src/bin/stats/run_b10-stats.sh
            src/bin/stats/run_b10-stats-httpd.sh
            src/bin/stats/tests/stats_test
diff --git a/src/bin/bind10/bind10.py.in b/src/bin/bind10/bind10.py.in
index 7594b77..8b80b50 100644
--- a/src/bin/bind10/bind10.py.in
+++ b/src/bin/bind10/bind10.py.in
@@ -473,6 +473,9 @@ class BoB:
     def start_stats(self, c_channel_env):
         self.start_simple("b10-stats", c_channel_env)
 
+    def start_stats_httpd(self, c_channel_env):
+        self.start_simple("b10-stats-httpd", c_channel_env)
+
     def start_cmdctl(self, c_channel_env):
         # XXX: we hardcode port 8080
         self.start_simple("b10-cmdctl", c_channel_env, 8080)
@@ -514,6 +517,7 @@ class BoB:
 
         # ... and finally start the remaining processes
         self.start_stats(c_channel_env)
+        self.start_stats_httpd(c_channel_env)
         self.start_cmdctl(c_channel_env)
     
     def startup(self):
@@ -562,6 +566,7 @@ class BoB:
         self.cc_session.group_sendmsg(cmd, "Xfrin", "Xfrin")
         self.cc_session.group_sendmsg(cmd, "Zonemgr", "Zonemgr")
         self.cc_session.group_sendmsg(cmd, "Stats", "Stats")
+        self.cc_session.group_sendmsg(cmd, "StatsHttpd", "StatsHttpd")
 
     def stop_process(self, process):
         """Stop the given process, friendly-like."""
diff --git a/src/bin/bind10/tests/bind10_test.py b/src/bin/bind10/tests/bind10_test.py
index 5b38913..9a1066a 100644
--- a/src/bin/bind10/tests/bind10_test.py
+++ b/src/bin/bind10/tests/bind10_test.py
@@ -162,6 +162,7 @@ class StartAllProcessesBob(BoB):
         self.xfrin = False
         self.zonemgr = False
         self.stats = False
+        self.stats_httpd = False
         self.cmdctl = False
 
     def read_bind10_config(self):
@@ -195,6 +196,9 @@ class StartAllProcessesBob(BoB):
     def start_stats(self, c_channel_env):
         self.stats = True
 
+    def start_stats_httpd(self, c_channel_env):
+        self.stats_httpd = True
+
     def start_cmdctl(self, c_channel_env):
         self.cmdctl = True
 
@@ -211,6 +215,7 @@ class TestStartAllProcessesBob(unittest.TestCase):
         self.assertEqual(bob.xfrin, False)
         self.assertEqual(bob.zonemgr, False)
         self.assertEqual(bob.stats, False)
+        self.assertEqual(bob.stats_httpd, False)
         self.assertEqual(bob.cmdctl, False)
 
     # Checks the processes started when starting neither auth nor resolver
@@ -236,6 +241,7 @@ class TestStartAllProcessesBob(unittest.TestCase):
         self.assertEqual(bob.xfrin, False)
         self.assertEqual(bob.zonemgr, False)
         self.assertEqual(bob.stats, True)
+        self.assertEqual(bob.stats_httpd, True)
         self.assertEqual(bob.cmdctl, True)
 
     # Checks the processes started when starting only the auth process
@@ -260,6 +266,7 @@ class TestStartAllProcessesBob(unittest.TestCase):
         self.assertEqual(bob.xfrin, True)
         self.assertEqual(bob.zonemgr, True)
         self.assertEqual(bob.stats, True)
+        self.assertEqual(bob.stats_httpd, True)
         self.assertEqual(bob.cmdctl, True)
 
     # Checks the processes started when starting only the resolver process
@@ -284,6 +291,7 @@ class TestStartAllProcessesBob(unittest.TestCase):
         self.assertEqual(bob.xfrin, False)
         self.assertEqual(bob.zonemgr, False)
         self.assertEqual(bob.stats, True)
+        self.assertEqual(bob.stats_httpd, True)
         self.assertEqual(bob.cmdctl, True)
 
     # Checks the processes started when starting both auth and resolver process
@@ -308,6 +316,7 @@ class TestStartAllProcessesBob(unittest.TestCase):
         self.assertEqual(bob.xfrin, True)
         self.assertEqual(bob.zonemgr, True)
         self.assertEqual(bob.stats, True)
+        self.assertEqual(bob.stats_httpd, True)
         self.assertEqual(bob.cmdctl, True)
 
 
diff --git a/src/bin/stats/Makefile.am b/src/bin/stats/Makefile.am
index 45a2ef0..f8e3636 100644
--- a/src/bin/stats/Makefile.am
+++ b/src/bin/stats/Makefile.am
@@ -2,26 +2,32 @@ SUBDIRS = tests
 
 pkglibexecdir = $(libexecdir)/@PACKAGE@
 
-pkglibexec_SCRIPTS = b10-stats
+pkglibexec_SCRIPTS = b10-stats b10-stats-httpd
 
 b10_statsdir = $(DESTDIR)$(pkgdatadir)
-b10_stats_DATA = stats.spec
+b10_stats_DATA = stats.spec stats_httpd.spec
 
-CLEANFILES = stats.spec b10-stats stats.pyc stats.pyo
+CLEANFILES = stats.spec b10-stats stats.pyc stats.pyo stats.spec b10-stats-httpd stats_httpd.pyc stats_httpd.pyo
 
-man_MANS = b10-stats.8
-EXTRA_DIST = $(man_MANS) b10-stats.xml
+man_MANS = b10-stats.8 b10-stats-httpd.8
+EXTRA_DIST = $(man_MANS) b10-stats.xml b10-stats-httpd.xml
 
 if ENABLE_MAN
 
 b10-stats.8: b10-stats.xml
 	xsltproc --novalid --xinclude --nonet -o $@ http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $(srcdir)/b10-stats.xml
 
+b10-stats-httpd.8: b10-stats-httpd.xml
+	xsltproc --novalid --xinclude --nonet -o $@ http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $(srcdir)/b10-stats-httpd.xml
+
 endif
 
 stats.spec: stats.spec.pre
 	$(SED) -e "s|@@LOCALSTATEDIR@@|$(localstatedir)|" stats.spec.pre >$@
 
+stats_httpd.spec: stats_httpd.spec.pre
+	$(SED) -e "s|@@LOCALSTATEDIR@@|$(localstatedir)|" stats_httpd.spec.pre >$@
+
 # TODO: does this need $$(DESTDIR) also?
 # this is done here since configure.ac AC_OUTPUT doesn't expand exec_prefix
 b10-stats: stats.py
@@ -29,3 +35,8 @@ b10-stats: stats.py
 	       -e "s|@@LOCALSTATEDIR@@|$(localstatedir)|" \
 	       -e "s|.*#@@REMOVED@@$$||"  stats.py >$@
 	chmod a+x $@
+
+b10-stats-httpd: stats_httpd.py
+	$(SED) -e "s|@@PYTHONPATH@@|@pyexecdir@|" \
+	       -e "s|@@LOCALSTATEDIR@@|$(localstatedir)|" stats_httpd.py >$@
+	chmod a+x $@
diff --git a/src/bin/stats/stats_httpd.py.in b/src/bin/stats/stats_httpd.py.in
index b43aba4..81a214b 100644
--- a/src/bin/stats/stats_httpd.py.in
+++ b/src/bin/stats/stats_httpd.py.in
@@ -15,14 +15,95 @@
 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
-__version__ = "$Revision$"
-
 import sys; sys.path.append ('@@PYTHONPATH@@')
+import os
 import time
+import errno
+import select
+from optparse import OptionParser, OptionValueError
 
-# for setproctitle
+import isc.cc
+import isc.config
 import isc.util.process
-isc.util.process.rename()
+
+# If B10_FROM_SOURCE is set in the environment, we use data files
+# from a directory relative to that, otherwise we use the ones
+# installed on the system
+if "B10_FROM_SOURCE" in os.environ:
+    SPECFILE_LOCATION = os.environ["B10_FROM_SOURCE"] + "/src/bin/stats/stats_httpd.spec"
+else:
+    PREFIX = "@prefix@"
+    DATAROOTDIR = "@datarootdir@"
+    SPECFILE_LOCATION = "@datadir@/@PACKAGE@/stats_httpd.spec".replace(
+        "${datarootdir}", DATAROOTDIR).replace("${prefix}", PREFIX)
+
+# Assign this process some longer name
+isc.util.process.rename(sys.argv[0])
+
+class Main():
+    """
+    """
+    def __init__(self):
+        try:
+            parser = OptionParser()
+            parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
+                              help="display more about what is going on")
+            (self.options, self.args) = parser.parse_args()
+        except OptionValueError:
+            sys.stderr.write("[b10-stats] Error parsing options\n")
+            sys.exit(1)
+        # start ccsession
+        self.ccs = isc.config.ModuleCCSession(SPECFILE_LOCATION, 
+                                         self.config_handler, self.command_handler)
+        self.ccs.start()
+        self.runnable = True
+
+    def config_handler(self, new_config):
+        """
+        config handler
+        """
+        return isc.config.ccsession.create_answer(0)
+
+    def command_handler(self, command, args):
+        """
+        command handler
+        """
+        if command == "shutdown":
+            self.runnable = False
+            if self.options.verbose:
+                sys.stdout.write("[b10-stats-httpd] shutiing down\n")
+            return isc.config.ccsession.create_answer(0)
+        else:
+            return isc.config.ccsession.create_answer(1, "Unknown command: " + str(command))
+
+    def main(self):
+        """
+        """
+        self.ccs_fd = self.ccs.get_socket().fileno()
+        tout = 1
+        while self.runnable:
+            try:
+                (rfd, wfd, xfd) = select.select([self.ccs_fd], [], [], tout)
+                if (rfd, wfd, xfd) == ([], [], []):
+                    pass
+                elif (rfd, wfd, xfd) == ([self.ccs_fd], [], []):
+                    self.ccs.check_command()
+                else:
+                    sys.stderr.write("[b10-stats-httpd] Unexpected Error with select();\n")
+                    break
+            except select.error as err:
+                if err.args[0] == errno.EINTR:
+                    (rlist, wlist, xlist) = ([], [], [])
+                else:
+                    sys.stderr.write("[b10-stats-httpd] Error with select(); %s\n" % err)
+                    break
+        self.ccs.close()
 
 if __name__ == "__main__":
-    time.sleep(999999)
+    try:
+        Main.main()
+    except isc.cc.session.SessionError as se:
+        sys.stderr.write("[b10-stats-httpd] Error creating module, "
+                         + "is the command channel daemon running?\n")
+    except KeyboardInterrupt as kie:
+        sys.stderr.write("[b10-stats-httpd] Interrupted, exiting\n")
diff --git a/src/bin/stats/tests/Makefile.am b/src/bin/stats/tests/Makefile.am
index 0c718d1..fa242d7 100644
--- a/src/bin/stats/tests/Makefile.am
+++ b/src/bin/stats/tests/Makefile.am
@@ -1,6 +1,6 @@
 SUBDIRS = isc testdata
 PYCOVERAGE_RUN = @PYCOVERAGE_RUN@
-PYTESTS = b10-stats_test.py
+PYTESTS = b10-stats_test.py b10-stats-httpd_test.py
 EXTRA_DIST = $(PYTESTS) fake_time.py
 CLEANFILES = fake_time.pyc
 
diff --git a/src/bin/stats/tests/b10-stats-httpd_test.py b/src/bin/stats/tests/b10-stats-httpd_test.py
index fe809ea..971a0b9 100644
--- a/src/bin/stats/tests/b10-stats-httpd_test.py
+++ b/src/bin/stats/tests/b10-stats-httpd_test.py
@@ -13,20 +13,38 @@
 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
-__version__ = "$Revision$"
-
 import unittest
 
+import isc.cc
+
+import stats_httpd
+
 class TestStats(unittest.TestCase):
 
     def setUp(self):
-        pass
+        self.m = stats_httpd.Main()
 
     def tearDown(self):
         pass
 
-    def test_dummy(self):
-        self.assertEqual(1, 1)
+    def test_config_handler(self):
+        self.assertEqual(self.m.config_handler(None),
+                         isc.config.ccsession.create_answer(0))
+
+    def test_command_handler(self):
+        self.assertTrue(self.m.runnable)
+        self.assertEqual(self.m.command_handler("shutdown", None),
+                         isc.config.ccsession.create_answer(0))
+        self.assertEqual(
+            self.m.command_handler("unknown_command", None),
+            isc.config.ccsession.create_answer(
+                1, "Unknown command: unknown_command"))
+        self.assertFalse(self.m.runnable)
+
+    #def tests_main(self):
+    #    self.assertRaises(
+    #        isc.cc.session.SessionError,
+    #        self.m.main())
 
 if __name__ == "__main__":
     unittest.main()




More information about the bind10-changes mailing list