[svn] commit: r2506 - in /trunk: ./ src/bin/xfrin/ src/lib/cc/ src/lib/config/ src/lib/config/tests/ src/lib/datasrc/ src/lib/dns/ src/lib/dns/rdata/generic/ src/lib/dns/tests/ src/lib/python/isc/config/ src/lib/python/isc/config/tests/
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Jul 14 07:58:59 UTC 2010
Author: jelte
Date: Wed Jul 14 07:58:59 2010
New Revision: 2506
Log:
merged ticket #278 (modules that listen to other modules answer to command for those)
Modified:
trunk/ (props changed)
trunk/src/bin/xfrin/ (props changed)
trunk/src/lib/cc/ (props changed)
trunk/src/lib/config/ccsession.cc
trunk/src/lib/config/tests/ccsession_unittests.cc
trunk/src/lib/datasrc/ (props changed)
trunk/src/lib/dns/ (props changed)
trunk/src/lib/dns/rdata/generic/rrsig_46.cc (props changed)
trunk/src/lib/dns/tests/ (props changed)
trunk/src/lib/python/isc/config/ccsession.py
trunk/src/lib/python/isc/config/tests/ccsession_test.py
Modified: trunk/src/lib/config/ccsession.cc
==============================================================================
--- trunk/src/lib/config/ccsession.cc (original)
+++ trunk/src/lib/config/ccsession.cc Wed Jul 14 07:58:59 2010
@@ -300,8 +300,8 @@
ElementPtr answer;
try {
std::string cmd_str = parseCommand(arg, data);
+ std::string target_module = routing->get("group")->stringValue();
if (cmd_str == "config_update") {
- std::string target_module = routing->get("group")->stringValue();
if (target_module == module_name_) {
answer = handleConfigUpdate(arg);
} else {
@@ -312,16 +312,22 @@
return 0;
}
} else {
- if (command_handler_) {
- answer = command_handler_(cmd_str, arg);
- } else {
- answer = createAnswer(1, "Command given but no command handler for module");
+ if (target_module == module_name_) {
+ if (command_handler_) {
+ answer = command_handler_(cmd_str, arg);
+ } else {
+ answer = createAnswer(1, "Command given but no command handler for module");
+ }
}
}
} catch (CCSessionError re) {
+ // TODO: Once we have logging and timeouts, we should not
+ // answer here (potential interference)
answer = createAnswer(1, re.what());
}
- session_.reply(routing, answer);
+ if (!isNull(answer)) {
+ session_.reply(routing, answer);
+ }
}
return 0;
Modified: trunk/src/lib/config/tests/ccsession_unittests.cc
==============================================================================
--- trunk/src/lib/config/tests/ccsession_unittests.cc (original)
+++ trunk/src/lib/config/tests/ccsession_unittests.cc Wed Jul 14 07:58:59 2010
@@ -383,4 +383,40 @@
session.getMessages()->add(createAnswer());
mccs.addRemoteConfig(ccspecfile("spec2.spec"));
}
-}
+
+TEST_F(CCSessionTest, ignoreRemoteConfigCommands) {
+ // client will ask for config
+ session.getMessages()->add(createAnswer(0, el("{ }")));
+
+ EXPECT_EQ(false, session.haveSubscription("Spec2", "*"));
+ ModuleCCSession mccs(ccspecfile("spec2.spec"), session, my_config_handler, my_command_handler);
+ EXPECT_EQ(true, session.haveSubscription("Spec2", "*"));
+
+ EXPECT_EQ(2, session.getMsgQueue()->size());
+ ElementPtr msg;
+ std::string group, to;
+ // drop the module_spec and config commands
+ session.getFirstMessage(group, to);
+ session.getFirstMessage(group, to);
+
+ session.getMessages()->add(createAnswer(0, el("{ }")));
+ mccs.addRemoteConfig(ccspecfile("spec1.spec"));
+ EXPECT_EQ(1, session.getMsgQueue()->size());
+ msg = session.getFirstMessage(group, to);
+
+ // Check if commands for the module are handled
+ session.addMessage(el("{ \"command\": [ \"good_command\" ] }"), "Spec2", "*");
+ int result = mccs.checkCommand();
+ EXPECT_EQ(1, session.getMsgQueue()->size());
+ msg = session.getFirstMessage(group, to);
+ EXPECT_EQ("{ \"result\": [ 0 ] }", msg->str());
+ EXPECT_EQ(0, result);
+
+ // Check if commands for the other module are ignored
+ session.addMessage(el("{ \"command\": [ \"good_command\" ] }"), "Spec1", "*");
+ EXPECT_EQ(1, session.getMsgQueue()->size());
+ result = mccs.checkCommand();
+ EXPECT_EQ(0, session.getMsgQueue()->size());
+}
+
+}
Modified: trunk/src/lib/python/isc/config/ccsession.py
==============================================================================
--- trunk/src/lib/python/isc/config/ccsession.py (original)
+++ trunk/src/lib/python/isc/config/ccsession.py Wed Jul 14 07:58:59 2010
@@ -183,10 +183,10 @@
if msg and not 'result' in msg:
answer = None
try:
+ module_name = env['group']
cmd, arg = isc.config.ccsession.parse_command(msg)
if cmd == COMMAND_CONFIG_UPDATE:
new_config = arg
- module_name = env['group']
# If the target channel was not this module
# it might be in the remote_module_configs
if module_name != self._module_name:
@@ -213,10 +213,12 @@
isc.cc.data.merge(newc, new_config)
self.set_local_config(newc)
else:
- if self._command_handler:
- answer = self._command_handler(cmd, arg)
- else:
- answer = create_answer(2, self._module_name + " has no command handler")
+ # ignore commands for 'remote' modules
+ if module_name == self._module_name:
+ if self._command_handler:
+ answer = self._command_handler(cmd, arg)
+ else:
+ answer = create_answer(2, self._module_name + " has no command handler")
except Exception as exc:
answer = create_answer(1, str(exc))
if answer:
Modified: trunk/src/lib/python/isc/config/tests/ccsession_test.py
==============================================================================
--- trunk/src/lib/python/isc/config/tests/ccsession_test.py (original)
+++ trunk/src/lib/python/isc/config/tests/ccsession_test.py Wed Jul 14 07:58:59 2010
@@ -377,7 +377,34 @@
mccs = None
self.assertFalse("Spec2" in fake_session.subscriptions)
-
+ def test_ignore_command_remote_module(self):
+ # Create a Spec1 module and subscribe to remote config for Spec2
+ fake_session = FakeModuleCCSession()
+ mccs = self.create_session("spec1.spec", None, None, fake_session)
+ mccs.set_command_handler(self.my_command_handler_ok)
+ rmodname = mccs.add_remote_config(self.spec_file("spec2.spec"))
+
+ # remove the 'get config' from the queue
+ self.assertEqual(len(fake_session.message_queue), 1)
+ fake_session.get_message("ConfigManager")
+
+ # check if the command for the module itself is received
+ cmd = isc.config.ccsession.create_command("just_some_command", { 'foo': 'a' })
+ fake_session.group_sendmsg(cmd, 'Spec1')
+ self.assertEqual(len(fake_session.message_queue), 1)
+ mccs.check_command()
+ self.assertEqual(len(fake_session.message_queue), 1)
+ self.assertEqual({'result': [ 0 ]},
+ fake_session.get_message('Spec1', None))
+
+ # check if the command for the other module is ignored
+ cmd = isc.config.ccsession.create_command("just_some_command", { 'foo': 'a' })
+ fake_session.group_sendmsg(cmd, 'Spec2')
+ self.assertEqual(len(fake_session.message_queue), 1)
+ mccs.check_command()
+ self.assertEqual(len(fake_session.message_queue), 0)
+
+
class fakeUIConn():
def __init__(self):
self.get_answers = {}
More information about the bind10-changes
mailing list