BIND 10 trac1503, updated. 9cffd7d9f5dc6c9c2909f9569c2f4c78aa71bdbd [1503] Basic Python test for b10-dhcp4 added.
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon May 21 16:45:59 UTC 2012
The branch, trac1503 has been updated
via 9cffd7d9f5dc6c9c2909f9569c2f4c78aa71bdbd (commit)
from 2be06486e504e522f9ef39586fe7fb5947c33872 (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 9cffd7d9f5dc6c9c2909f9569c2f4c78aa71bdbd
Author: Tomek Mrugalski <tomasz at isc.org>
Date: Mon May 21 19:45:46 2012 +0300
[1503] Basic Python test for b10-dhcp4 added.
-----------------------------------------------------------------------
Summary of changes:
src/bin/dhcp4/tests/Makefile.am | 12 ++++++++++++
.../dhcp6_test.py => dhcp4/tests/dhcp4_test.py} | 15 +++++++--------
2 files changed, 19 insertions(+), 8 deletions(-)
copy src/bin/{dhcp6/tests/dhcp6_test.py => dhcp4/tests/dhcp4_test.py} (82%)
-----------------------------------------------------------------------
diff --git a/src/bin/dhcp4/tests/Makefile.am b/src/bin/dhcp4/tests/Makefile.am
index b956aee..c46b9ab 100644
--- a/src/bin/dhcp4/tests/Makefile.am
+++ b/src/bin/dhcp4/tests/Makefile.am
@@ -1,5 +1,8 @@
PYCOVERAGE_RUN = @PYCOVERAGE_RUN@
+PYTESTS = dhcp4_test.py
+EXTRA_DIST = $(PYTESTS)
+
# If necessary (rare cases), explicitly specify paths to dynamic libraries
# required by loadable python modules.
LIBRARY_PATH_PLACEHOLDER =
@@ -7,6 +10,15 @@ if SET_ENV_LIBRARY_PATH
LIBRARY_PATH_PLACEHOLDER += $(ENV_LIBRARY_PATH)=$(abs_top_builddir)/src/lib/cryptolink/.libs:$(abs_top_builddir)/src/lib/dns/.libs:$(abs_top_builddir)/src/lib/dns/python/.libs:$(abs_top_builddir)/src/lib/cc/.libs:$(abs_top_builddir)/src/lib/config/.libs:$(abs_top_builddir)/src/lib/log/.libs:$(abs_top_builddir)/src/lib/util/.libs:$(abs_top_builddir)/src/lib/exceptions/.libs:$(abs_top_builddir)/src/lib/util/io/.libs:$(abs_top_builddir)/src/lib/datasrc/.libs:$$$(ENV_LIBRARY_PATH)
endif
+# test using command-line arguments, so use check-local target instead of TESTS
+check-local:
+ for pytest in $(PYTESTS) ; do \
+ echo Running test: $$pytest ; \
+ PYTHONPATH=$(COMMON_PYTHON_PATH):$(abs_top_srcdir)/src/bin:$(abs_top_builddir)/src/bin/bind10:$(abs_top_builddir)/src/lib/util/io/.libs \
+ $(LIBRARY_PATH_PLACEHOLDER) \
+ $(PYCOVERAGE_RUN) $(abs_srcdir)/$$pytest || exit ; \
+ done
+
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CPPFLAGS += -I$(top_builddir)/src/bin # for generated spec_config.h header
AM_CPPFLAGS += -I$(top_srcdir)/src/bin
diff --git a/src/bin/dhcp4/tests/dhcp4_test.py b/src/bin/dhcp4/tests/dhcp4_test.py
new file mode 100644
index 0000000..4071f7e
--- /dev/null
+++ b/src/bin/dhcp4/tests/dhcp4_test.py
@@ -0,0 +1,73 @@
+# Copyright (C) 2011 Internet Systems Consortium.
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
+# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+from bind10_src import ProcessInfo, parse_args, dump_pid, unlink_pid_file, _BASETIME
+
+import unittest
+import sys
+import os
+import signal
+import socket
+from isc.net.addr import IPAddr
+import time
+import isc
+
+class TestDhcpv4Daemon(unittest.TestCase):
+ def setUp(self):
+ print("Note: Purpose of some of the tests is to check if DHCPv4 server can be started,")
+ print(" not that is can bind sockets correctly. Please ignore binding errors.")
+ # redirect stdout to a pipe so we can check that our
+ # process spawning is doing the right thing with stdout
+ self.old_stdout = os.dup(sys.stdout.fileno())
+ self.pipes = os.pipe()
+ os.dup2(self.pipes[1], sys.stdout.fileno())
+ os.close(self.pipes[1])
+ # note that we use dup2() to restore the original stdout
+ # to the main program ASAP in each test... this prevents
+ # hangs reading from the child process (as the pipe is only
+ # open in the child), and also insures nice pretty output
+
+ def tearDown(self):
+ # clean up our stdout munging
+ os.dup2(self.old_stdout, sys.stdout.fileno())
+ os.close(self.pipes[0])
+
+ def test_alive(self):
+ """
+ Simple test. Checks that b10-dhcp4 can be started and prints out info
+ about starting DHCPv4 operation.
+ """
+ pi = ProcessInfo('Test Process', [ '../b10-dhcp4' , '-v' ])
+ pi.spawn()
+ time.sleep(1)
+ os.dup2(self.old_stdout, sys.stdout.fileno())
+ self.assertNotEqual(pi.process, None)
+ self.assertTrue(type(pi.pid) is int)
+ output = os.read(self.pipes[0], 4096)
+ self.assertEqual( str(output).count("[b10-dhcp4] Initiating DHCPv4 server operation."), 1)
+
+ # kill this process
+ # XXX: b10-dhcp6 is too dumb to understand 'shutdown' command for now,
+ # so let's just kill the bastard
+
+ # TODO: Ignore errors for now. This test will be more thorough once ticket #1503
+ # (passing port number to b10-dhcp6 daemon) is implemented.
+ try:
+ os.kill(pi.pid, signal.SIGTERM)
+ except OSError:
+ print("Ignoring failed kill attempt. Process is dead already.")
+
+if __name__ == '__main__':
+ unittest.main()
More information about the bind10-changes
mailing list