Commit 38778d44 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[trac565] Test config_handler calls start and stop

parent 696cec5b
......@@ -198,9 +198,42 @@ class StartAllProcessesBob(BoB):
def start_cmdctl(self, c_channel_env):
self.cmdctl = True
# Check that the start_all_processes method starts the right combination
# of processes.
class TestStartAllProcessesBob(unittest.TestCase):
def stop_msgq(self, c_channel_env):
self.msgq = False
def stop_cfgmgr(self, c_channel_env):
self.cfgmgr = False
def stop_ccsession(self, c_channel_env):
self.ccsession = False
def stop_auth(self, c_channel_env):
self.auth = False
def stop_resolver(self, c_channel_env):
self.resolver = False
def stop_xfrout(self, c_channel_env):
self.xfrout = False
def stop_xfrin(self, c_channel_env):
self.xfrin = False
def stop_zonemgr(self, c_channel_env):
self.zonemgr = False
def stop_stats(self, c_channel_env):
self.stats = False
def stop_cmdctl(self, c_channel_env):
self.cmdctl = False
class TestStartStopProcessesBob(unittest.TestCase):
"""
Check that the start_all_processes method starts the right combination
of processes and that the right processes are started and stopped
according to changes in configuration.
"""
def check_preconditions(self, bob):
self.assertEqual(bob.msgq, False)
self.assertEqual(bob.cfgmgr, False)
......@@ -213,6 +246,68 @@ class TestStartAllProcessesBob(unittest.TestCase):
self.assertEqual(bob.stats, False)
self.assertEqual(bob.cmdctl, False)
def check_started_none(self, bob):
"""
Check that the situation is according to configuration where no servers
should be started. Some processes still need to be running.
"""
self.assertEqual(bob.msgq, True)
self.assertEqual(bob.cfgmgr, True)
self.assertEqual(bob.ccsession, True)
self.assertEqual(bob.auth, False)
self.assertEqual(bob.resolver, False)
self.assertEqual(bob.xfrout, False)
self.assertEqual(bob.xfrin, False)
self.assertEqual(bob.zonemgr, False)
self.assertEqual(bob.stats, True)
self.assertEqual(bob.cmdctl, True)
def check_started_both(self, bob):
"""
Check the situation is according to configuration where both servers
(auth and resolver) are enabled.
"""
self.assertEqual(bob.msgq, True)
self.assertEqual(bob.cfgmgr, True)
self.assertEqual(bob.ccsession, True)
self.assertEqual(bob.auth, True)
self.assertEqual(bob.resolver, True)
self.assertEqual(bob.xfrout, True)
self.assertEqual(bob.xfrin, True)
self.assertEqual(bob.zonemgr, True)
self.assertEqual(bob.stats, True)
self.assertEqual(bob.cmdctl, True)
def check_started_auth(self, bob):
"""
Check the set of processes needed to run auth only is started.
"""
self.assertEqual(bob.msgq, True)
self.assertEqual(bob.cfgmgr, True)
self.assertEqual(bob.ccsession, True)
self.assertEqual(bob.auth, True)
self.assertEqual(bob.resolver, False)
self.assertEqual(bob.xfrout, True)
self.assertEqual(bob.xfrin, True)
self.assertEqual(bob.zonemgr, True)
self.assertEqual(bob.stats, True)
self.assertEqual(bob.cmdctl, True)
def check_started_resolver(self, bob):
"""
Check the set of processes needed to run resolver only is started.
"""
self.assertEqual(bob.msgq, True)
self.assertEqual(bob.cfgmgr, True)
self.assertEqual(bob.ccsession, True)
self.assertEqual(bob.auth, False)
self.assertEqual(bob.resolver, True)
self.assertEqual(bob.xfrout, False)
self.assertEqual(bob.xfrin, False)
self.assertEqual(bob.zonemgr, False)
self.assertEqual(bob.stats, True)
self.assertEqual(bob.cmdctl, True)
# Checks the processes started when starting neither auth nor resolver
# is specified.
def test_start_none(self):
......@@ -226,17 +321,7 @@ class TestStartAllProcessesBob(unittest.TestCase):
bob.cfg_start_resolver = False
bob.start_all_processes(c_channel_env)
self.assertEqual(bob.msgq, True)
self.assertEqual(bob.cfgmgr, True)
self.assertEqual(bob.ccsession, True)
self.assertEqual(bob.auth, False)
self.assertEqual(bob.resolver, False)
self.assertEqual(bob.xfrout, False)
self.assertEqual(bob.xfrin, False)
self.assertEqual(bob.zonemgr, False)
self.assertEqual(bob.stats, True)
self.assertEqual(bob.cmdctl, True)
self.check_started_none(bob)
# Checks the processes started when starting only the auth process
def test_start_auth(self):
......@@ -251,16 +336,7 @@ class TestStartAllProcessesBob(unittest.TestCase):
bob.start_all_processes(c_channel_env)
self.assertEqual(bob.msgq, True)
self.assertEqual(bob.cfgmgr, True)
self.assertEqual(bob.ccsession, True)
self.assertEqual(bob.auth, True)
self.assertEqual(bob.resolver, False)
self.assertEqual(bob.xfrout, True)
self.assertEqual(bob.xfrin, True)
self.assertEqual(bob.zonemgr, True)
self.assertEqual(bob.stats, True)
self.assertEqual(bob.cmdctl, True)
self.check_started_auth(bob)
# Checks the processes started when starting only the resolver process
def test_start_resolver(self):
......@@ -275,16 +351,7 @@ class TestStartAllProcessesBob(unittest.TestCase):
bob.start_all_processes(c_channel_env)
self.assertEqual(bob.msgq, True)
self.assertEqual(bob.cfgmgr, True)
self.assertEqual(bob.ccsession, True)
self.assertEqual(bob.auth, False)
self.assertEqual(bob.resolver, True)
self.assertEqual(bob.xfrout, False)
self.assertEqual(bob.xfrin, False)
self.assertEqual(bob.zonemgr, False)
self.assertEqual(bob.stats, True)
self.assertEqual(bob.cmdctl, True)
self.check_started_resolver(bob)
# Checks the processes started when starting both auth and resolver process
def test_start_both(self):
......@@ -299,17 +366,74 @@ class TestStartAllProcessesBob(unittest.TestCase):
bob.start_all_processes(c_channel_env)
self.assertEqual(bob.msgq, True)
self.assertEqual(bob.cfgmgr, True)
self.assertEqual(bob.ccsession, True)
self.assertEqual(bob.auth, True)
self.assertEqual(bob.resolver, True)
self.assertEqual(bob.xfrout, True)
self.assertEqual(bob.xfrin, True)
self.assertEqual(bob.zonemgr, True)
self.assertEqual(bob.stats, True)
self.assertEqual(bob.cmdctl, True)
self.check_started_both(bob)
def test_config_start(self):
"""
Test that the configuration starts and stops processes according
to configuration changes.
"""
# Created Bob and ensure initialization correct
bob = StartAllProcessesBob()
self.check_preconditions(bob)
# Start processes (nothing much should be started, as in
# test_start_none)
c_channel_env = {}
bob.cfg_start_auth = False
bob.cfg_start_resolver = False
bob.start_all_processes(c_channel_env)
self.check_started_none(bob)
# Enable both at once
bob.config_handler({'start_auth': True, 'start_resolver': True})
self.check_started_both(bob)
# Not touched by empty change
bob.config_handler({})
self.check_started_both(bob)
# Not touched by change to the same configuration
bob.config_handler({'start_auth': True, 'start_resolver': True})
self.check_started_both(bob)
# Turn them both off again
bob.config_handler({'start_auth': False, 'start_resolver': False})
self.check_started_none(bob)
# Not touched by empty change
bob.config_handler({})
self.check_started_none(bob)
# Not touched by change to the same configuration
bob.config_handler({'start_auth': False, 'start_resolver': False})
self.check_started_none(bob)
# Start and stop auth separately
bob.config_handler({'start_auth': True})
self.check_started_auth(bob)
bob.config_handler({'start_auth': False})
self.check_started_none(bob)
# Start and stop resolver separately
bob.config_handler({'start_resolver': True})
self.check_started_resolver(bob)
bob.config_handler({'start_resolver': False})
self.check_started_none(bob)
# Alternate
bob.config_handler({'start_auth': True})
self.check_started_auth(bob)
bob.config_handler({'start_auth': False, 'start_resolver': True})
self.check_started_resolver(bob)
bob.config_handler({'start_auth': True, 'start_resolver': False})
self.check_started_auth(bob)
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