Browse Source

[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.
Michal 'vorner' Vaner 14 years ago
parent
commit
def088d4e8

+ 8 - 3
src/lib/python/isc/config/cfgmgr.py

@@ -322,12 +322,19 @@ class ConfigManager:
             data.merge(conf_part[module_name], cmd)
             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:
             # The module is virtual, so call it to get the answer
             try:
                 error = self.virtual_modules[module_name](use_part)
                 if error is None:
                     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:
                     answer = ccsession.create_answer(1, error)
             # Make sure just a validating plugin don't kill the whole manager
@@ -336,9 +343,7 @@ class ConfigManager:
                 answer = ccsession.create_answer(1, "Exception: " + str(excp))
         else:
             # Real module, send it over the wire to it
-            # send out changed info
-            update_cmd = ccsession.create_command(
-                ccsession.COMMAND_CONFIG_UPDATE, use_part)
+            # send out changed info and wait for answer
             seq = self.cc.group_sendmsg(update_cmd, module_name)
             try:
                 # replace 'our' answer with that of the module

+ 13 - 3
src/lib/python/isc/config/tests/cfgmgr_test.py

@@ -353,9 +353,8 @@ class TestConfigManager(unittest.TestCase):
 
             # Register our virtual module
             self.cm.set_virtual_module(self.spec, check_test)
-            # The fake session will throw now if it is touched, as there's no
-            # message or answer ready. Handy, we don't need any code about it
-            # to check explicitly.
+            # The fake session will throw now if it tries to read a response.
+            # Handy, we don't need to find a complicated way to check for it.
             result = self.cm._handle_set_config_module(self.spec.
                                                        get_module_name(),
                                                        {'item1': value})
@@ -363,6 +362,17 @@ class TestConfigManager(unittest.TestCase):
             # With correct data
             self.assertEqual(self.called_with['item1'], value)
             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
         single_test(5, lambda: None, [0])