Commit 0bfea71b authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[trac990] 3 tests for dummy dhcp6 daemon implemented.

parent 0dc70602
......@@ -747,6 +747,7 @@ AC_CONFIG_FILES([Makefile
src/bin/auth/tests/Makefile
src/bin/auth/benchmarks/Makefile
src/bin/dhcp6/Makefile
src/bin/dhcp6/tests/Makefile
src/bin/resolver/Makefile
src/bin/resolver/tests/Makefile
src/bin/sockcreator/Makefile
......
......@@ -221,6 +221,7 @@ class BoB:
self.cfg_start_auth = True
self.cfg_start_resolver = False
self.cfg_start_dhcp6 = False
self.cfg_start_dhcp4 = False
self.started_auth_family = False
self.started_resolver_family = False
self.curproc = None
......
......@@ -111,6 +111,9 @@ class TestBoB(unittest.TestCase):
self.assertEqual(bob.cfg_start_auth, True)
self.assertEqual(bob.cfg_start_resolver, False)
self.assertEqual(bob.cfg_start_dhcp4, False)
self.assertEqual(bob.cfg_start_dhcp6, False)
def test_init_alternate_socket(self):
bob = BoB("alt_socket_file")
self.assertEqual(bob.verbose, False)
......@@ -125,6 +128,8 @@ class TestBoB(unittest.TestCase):
self.assertEqual(bob.nocache, False)
self.assertEqual(bob.cfg_start_auth, True)
self.assertEqual(bob.cfg_start_resolver, False)
self.assertEqual(bob.cfg_start_dhcp4, False)
self.assertEqual(bob.cfg_start_dhcp6, False)
def test_command_handler(self):
class DummySession():
......@@ -247,6 +252,16 @@ class MockBob(BoB):
self.processes[12] = ProcessInfo('b10-cmdctl', ['/bin/false'])
self.processes[12].pid = 12
def start_dhcp6(self, c_channel_env):
self.dhcp6 = True
self.processes[13] = ProcessInfo('b10-dhcp6', ['/bin/false'])
self.processes[13]
def start_dhcp4(self, c_channel_env):
self.dhcp4 = True
self.processes[14] = ProcessInfo('b10-dhcp4', ['/bin/false'])
self.processes[14]
# We don't really use all of these stop_ methods. But it might turn out
# someone would add some stop_ method to BoB and we want that one overriden
# in case he forgets to update the tests.
......@@ -359,6 +374,24 @@ class TestStartStopProcessesBob(unittest.TestCase):
"""
self.check_started(bob, True, False, True)
def check_started_dhcp(self, bob, v4, v6):
"""
Check if proper combinations of DHCPv4 and DHCpv6 can be started
"""
v4found = 0
v6found = 0
for pid in bob.processes:
if (bob.processes[pid].name == "b10-dhcp4"):
v4found += 1
if (bob.processes[pid].name == "b10-dhcp6"):
v6found += 1
# there should be exactly one DHCPv4 daemon (if v4==True)
# there should be exactly one DHCPv6 daemon (if v6==True)
self.assertEqual(v4==True, v4found==1)
self.assertEqual(v6==True, v6found==1)
# Checks the processes started when starting neither auth nor resolver
# is specified.
def test_start_none(self):
......@@ -524,6 +557,40 @@ class TestStartStopProcessesBob(unittest.TestCase):
bob.config_handler({'start_auth': True, 'start_resolver': True})
# Checks that DHCP (v4 and v6) processes are started when expected
def test_start_dhcp(self):
# Create BoB and ensure correct initialization
bob = MockBob()
self.check_preconditions(bob)
# don't care about DNS stuff
bob.cfg_start_auth = False
bob.cfg_start_resolver = False
# v4 and v6 disabled
bob.cfg_start_dhcp6 = False
bob.cfg_start_dhcp4 = False
bob.start_all_processes()
self.check_started_dhcp(bob, False, False)
# v6 only enabled
bob.cfg_start_dhcp6 = True
bob.cfg_start_dhcp4 = False
bob.start_all_processes()
self.check_started_dhcp(bob, False, True)
# uncomment when dhcpv4 becomes implemented
# v4 only enabled
#bob.cfg_start_dhcp6 = False
#bob.cfg_start_dhcp4 = True
#self.check_started_dhcp(bob, True, False)
# both v4 and v6 enabled
#bob.cfg_start_dhcp6 = True
#bob.cfg_start_dhcp4 = True
#self.check_started_dhcp(bob, True, True)
class TestBossCmd(unittest.TestCase):
def test_ping(self):
"""
......
SUBDIRS = .
SUBDIRS = . tests
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CPPFLAGS += -I$(top_srcdir)/src/bin -I$(top_builddir)/src/bin
......
......@@ -106,7 +106,7 @@ main(int argc, char* argv[]) {
// auth_server = new AuthSrv(cache, xfrout_client);
// auth_server->setVerbose(verbose_mode);
cout << "[b10-dhcp6] Server created." << endl;
cout << "[b10-dhcp6] Initiating DHCPv6 operation." << endl;
} catch (const std::exception& ex) {
cerr << "[b10-dhcp6] Server failed: " << ex.what() << endl;
......
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC 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.
#define AUTH_SPECFILE_LOCATION "@prefix@/share/@PACKAGE@/dhcp6.spec"
PYCOVERAGE_RUN = @PYCOVERAGE_RUN@
#PYTESTS = args_test.py bind10_test.py
# NOTE: this has a generated test found in the builddir
PYTESTS = dhcp6_test.py
EXTRA_DIST = $(PYTESTS)
# test using command-line arguments, so use check-local target instead of TESTS
check-local:
for pytest in $(PYTESTS) ; do \
echo Running test: $$pytest ; \
env PYTHONPATH=$(abs_top_srcdir)/src/lib/python:$(abs_top_builddir)/src/lib/python:$(abs_top_builddir)/src/bin/bind10 \
BIND10_MSGQ_SOCKET_FILE=$(abs_top_builddir)/msgq_socket \
$(PYCOVERAGE_RUN) $(abs_builddir)/$$pytest || exit ; \
done
# 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 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 TestDhcpv6Daemon(unittest.TestCase):
def setUp(self):
# 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-dhcp6 can be started and prints out info
about starting DHCPv6 operation.
"""
pi = ProcessInfo('Test Process', [ '../b10-dhcp6' , '-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-dhcp6] Initiating DHCPv6 operation."), 1)
# kill this process
# XXX: b10-dhcp6 is too dumb to understand 'shutdown' command for now,
# so let's just kill the bastard
os.kill(pi.pid, signal.SIGTERM)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment