Commit def088d4 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[trac810] Provide a notification on virtual config

The notification is used even when the config is not checked by remote
config. So we send it out in case of virtual module as well, but don't
wait for the answer.
parent 4578fa11
...@@ -322,12 +322,19 @@ class ConfigManager: ...@@ -322,12 +322,19 @@ class ConfigManager:
data.merge(conf_part[module_name], cmd) data.merge(conf_part[module_name], cmd)
use_part = conf_part[module_name] use_part = conf_part[module_name]
# The command to send
update_cmd = ccsession.create_command(ccsession.COMMAND_CONFIG_UPDATE,
use_part)
if module_name in self.virtual_modules: if module_name in self.virtual_modules:
# The module is virtual, so call it to get the answer # The module is virtual, so call it to get the answer
try: try:
error = self.virtual_modules[module_name](use_part) error = self.virtual_modules[module_name](use_part)
if error is None: if error is None:
answer = ccsession.create_answer(0) answer = ccsession.create_answer(0)
# OK, it is successful, send the notify, but don't wait
# for answer
seq = self.cc.group_sendmsg(update_cmd, module_name)
else: else:
answer = ccsession.create_answer(1, error) answer = ccsession.create_answer(1, error)
# Make sure just a validating plugin don't kill the whole manager # Make sure just a validating plugin don't kill the whole manager
...@@ -336,9 +343,7 @@ class ConfigManager: ...@@ -336,9 +343,7 @@ class ConfigManager:
answer = ccsession.create_answer(1, "Exception: " + str(excp)) answer = ccsession.create_answer(1, "Exception: " + str(excp))
else: else:
# Real module, send it over the wire to it # Real module, send it over the wire to it
# send out changed info # send out changed info and wait for answer
update_cmd = ccsession.create_command(
ccsession.COMMAND_CONFIG_UPDATE, use_part)
seq = self.cc.group_sendmsg(update_cmd, module_name) seq = self.cc.group_sendmsg(update_cmd, module_name)
try: try:
# replace 'our' answer with that of the module # replace 'our' answer with that of the module
......
...@@ -353,9 +353,8 @@ class TestConfigManager(unittest.TestCase): ...@@ -353,9 +353,8 @@ class TestConfigManager(unittest.TestCase):
# Register our virtual module # Register our virtual module
self.cm.set_virtual_module(self.spec, check_test) self.cm.set_virtual_module(self.spec, check_test)
# The fake session will throw now if it is touched, as there's no # The fake session will throw now if it tries to read a response.
# message or answer ready. Handy, we don't need any code about it # Handy, we don't need to find a complicated way to check for it.
# to check explicitly.
result = self.cm._handle_set_config_module(self.spec. result = self.cm._handle_set_config_module(self.spec.
get_module_name(), get_module_name(),
{'item1': value}) {'item1': value})
...@@ -363,6 +362,17 @@ class TestConfigManager(unittest.TestCase): ...@@ -363,6 +362,17 @@ class TestConfigManager(unittest.TestCase):
# With correct data # With correct data
self.assertEqual(self.called_with['item1'], value) self.assertEqual(self.called_with['item1'], value)
self.assertEqual(result, {'result': expectedResult}) self.assertEqual(result, {'result': expectedResult})
if expectedResult[0] == 0:
# Check it provided the correct notification
self.assertEqual(len(self.fake_session.message_queue), 1)
self.assertEqual({'command': [ 'config_update',
{'item1': value}]},
self.fake_session.get_message('Spec2', None))
# and the queue should now be empty again
self.assertEqual(len(self.fake_session.message_queue), 0)
else:
# It shouldn't send anything on error
self.assertEqual(len(self.fake_session.message_queue), 0)
# Success # Success
single_test(5, lambda: None, [0]) single_test(5, lambda: None, [0])
......
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