Skip to content

Commit

Permalink
Fix clean satellites when receive new conf and use it. closes #768
Browse files Browse the repository at this point in the history
  • Loading branch information
David Durieux committed Apr 4, 2017
1 parent 364fb47 commit a9fe9b4
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 15 deletions.
19 changes: 4 additions & 15 deletions alignak/daemons/brokerdaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ def setup_new_conf(self): # pylint: disable=R0915,R0912
"""

with self.conf_lock:
self.clean_previous_run()
conf = unserialize(self.new_conf, True)
self.new_conf = None
self.cur_conf = conf
Expand Down Expand Up @@ -712,7 +713,9 @@ def clean_previous_run(self):
self.schedulers.clear()
self.pollers.clear()
self.reactionners.clear()
self.receivers.clear()
self.broks = self.broks[:]
self.arbiters.clear()
self.broks_internal_raised = self.broks_internal_raised[:]
with self.arbiter_broks_lock:
self.arbiter_broks = self.arbiter_broks[:]
Expand Down Expand Up @@ -760,21 +763,7 @@ def do_loop_turn(self):
# Begin to clean modules
self.check_and_del_zombie_modules()

# Maybe the arbiter ask us to wait for a new conf
# If true, we must restart all...
if self.cur_conf is None:
# Clean previous run from useless objects
# and close modules
self.clean_previous_run()

self.wait_for_initial_conf()
# we may have been interrupted or so; then
# just return from this loop turn
if not self.new_conf:
return
self.setup_new_conf()

# Now we check if arbiter speak to us.
# Now we check if arbiter speak to me.
# If so, we listen for it
# When it pushes conf to us, we reinit connections
self.watch_for_new_conf(0.0)
Expand Down
1 change: 1 addition & 0 deletions alignak/daemons/receiverdaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ def setup_new_conf(self):
:return: None
"""
with self.conf_lock:
self.clean_previous_run()
conf = unserialize(self.new_conf, True)
self.new_conf = None
self.cur_conf = conf
Expand Down
11 changes: 11 additions & 0 deletions alignak/daemons/schedulerdaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def setup_new_conf(self):
:return: None
"""
with self.conf_lock:
self.clean_previous_run()
new_c = self.new_conf
logger.warning("Sending us a configuration %s", new_c['push_flavor'])
conf_raw = new_c['conf']
Expand Down Expand Up @@ -368,6 +369,16 @@ def what_i_managed(self):
else:
return {}

def clean_previous_run(self):
"""Clean variables from previous configuration
:return: None
"""
# Clean all lists
self.pollers.clear()
self.reactionners.clear()
self.brokers.clear()

def main(self):
"""Main function for Scheduler, launch after the init::
Expand Down
1 change: 1 addition & 0 deletions alignak/satellite.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,7 @@ def setup_new_conf(self): # pylint: disable=R0915,R0912
:return: None
"""
with self.conf_lock:
self.clean_previous_run()
conf = self.new_conf
self.new_conf = None
self.cur_conf = conf
Expand Down
61 changes: 61 additions & 0 deletions test/test_setup_new_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ def test_conf_scheduler(self):
assert sched.modules[0].module_alias == 'Example'
assert sched.modules[0].option_3 == 'foobar'
assert 2 == len(sched.conf.hosts)
assert len(sched.pollers) == 1
assert len(sched.reactionners) == 1
assert len(sched.brokers) == 1

# send new conf, so it's the second time. This test the cleanup
self.setup_with_file('cfg/cfg_default.cfg')
for scheduler in self.arbiter.dispatcher.schedulers:
sched.new_conf = scheduler.conf_package
sched.setup_new_conf()
assert len(sched.pollers) == 1
assert len(sched.reactionners) == 1
assert len(sched.brokers) == 1

# Stop launched modules
sched.modules_manager.stop_all()

Expand Down Expand Up @@ -84,6 +97,16 @@ def test_conf_receiver(self):
assert receiv.modules[0].option_3 == 'foobar'
# check get hosts
assert len(receiv.host_assoc) == 2
assert len(receiv.schedulers) == 1

# send new conf, so it's the second time. This test the cleanup
self.setup_with_file('cfg/cfg_default.cfg')
for satellite in self.arbiter.dispatcher.satellites:
if satellite.get_my_type() == 'receiver':
receiv.new_conf = satellite.cfg
receiv.setup_new_conf()
assert len(receiv.schedulers) == 1

# Stop launched modules
receiv.modules_manager.stop_all()

Expand All @@ -109,6 +132,16 @@ def test_conf_poller(self):
assert 1 == len(poller.new_modules_conf)
assert poller.new_modules_conf[0].module_alias == 'Example'
assert poller.new_modules_conf[0].option_3 == 'foobar'
assert len(poller.schedulers) == 1

# send new conf, so it's the second time. This test the cleanup
self.setup_with_file('cfg/cfg_default.cfg')
for satellite in self.arbiter.dispatcher.satellites:
if satellite.get_my_type() == 'poller':
poller.new_conf = satellite.cfg
poller.setup_new_conf()
assert len(poller.schedulers) == 1

# Stop launched modules
poller.modules_manager.stop_all()

Expand All @@ -134,6 +167,24 @@ def test_conf_broker(self):
assert 1 == len(broker.modules)
assert broker.modules[0].module_alias == 'Example'
assert broker.modules[0].option_3 == 'foobar'
assert len(broker.schedulers) == 1
assert len(broker.arbiters) == 1
assert len(broker.pollers) == 1
assert len(broker.reactionners) == 1
assert len(broker.receivers) == 1

# send new conf, so it's the second time. This test the cleanup
self.setup_with_file('cfg/cfg_default.cfg')
for satellite in self.arbiter.dispatcher.satellites:
if satellite.get_my_type() == 'broker':
broker.new_conf = satellite.cfg
broker.setup_new_conf()
assert len(broker.schedulers) == 1
assert len(broker.arbiters) == 1
assert len(broker.pollers) == 1
assert len(broker.reactionners) == 1
assert len(broker.receivers) == 1

# Stop launched modules
broker.modules_manager.stop_all()

Expand All @@ -159,5 +210,15 @@ def test_conf_reactionner(self):
assert 1 == len(reac.new_modules_conf)
assert reac.new_modules_conf[0].module_alias == 'Example'
assert reac.new_modules_conf[0].option_3 == 'foobar'
assert len(reac.schedulers) == 1

# send new conf, so it's the second time. This test the cleanup
self.setup_with_file('cfg/cfg_default.cfg')
for satellite in self.arbiter.dispatcher.satellites:
if satellite.get_my_type() == 'reactionner':
reac.new_conf = satellite.cfg
reac.setup_new_conf()
assert len(reac.schedulers) == 1

# Stop launched modules
reac.modules_manager.stop_all()

0 comments on commit a9fe9b4

Please sign in to comment.