BIND 10 trac1914, updated. c9ba856c4cc0f98b33cbeb030fedec3b29ee0e0c [1924] Add python group_sent want_reply parameter
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Jan 30 13:58:06 UTC 2013
The branch, trac1914 has been updated
via c9ba856c4cc0f98b33cbeb030fedec3b29ee0e0c (commit)
via 10166e33f1d08985830a8bf5804af40c00328b86 (commit)
via 4f49376c5dee81bcc140f1445e762f62ee92e29f (commit)
from 3e94ba20d52e2c62243af504f95f5b3134efd0f7 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit c9ba856c4cc0f98b33cbeb030fedec3b29ee0e0c
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Wed Jan 30 14:46:43 2013 +0100
[1924] Add python group_sent want_reply parameter
So the reporting of errors can be turned on from python.
commit 10166e33f1d08985830a8bf5804af40c00328b86
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Wed Jan 30 14:23:58 2013 +0100
[1924] (minor) Style cleanups
* Spaces
* Remove commented-out code
* Use full relative path to header
commit 4f49376c5dee81bcc140f1445e762f62ee92e29f
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Wed Jan 30 14:22:21 2013 +0100
[1924] Provide proper headers
It wouldn't be needed in practice, but provide headers as close to if it
was sent by another client as reasonable and possible.
Also test we can explicitly say we don't want the answer, instead of
having just the default.
-----------------------------------------------------------------------
Summary of changes:
src/bin/msgq/msgq.py.in | 9 ++++----
src/bin/msgq/tests/msgq_test.py | 11 ++++++++--
src/lib/cc/session.cc | 5 ++---
src/lib/cc/tests/session_unittests.cc | 9 ++++----
src/lib/python/isc/cc/session.py | 10 +++++----
src/lib/python/isc/cc/tests/session_test.py | 30 ++++++++++++++++++++++++---
6 files changed, 53 insertions(+), 21 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/msgq/msgq.py.in b/src/bin/msgq/msgq.py.in
index f3b2777..ea2e2d7 100755
--- a/src/bin/msgq/msgq.py.in
+++ b/src/bin/msgq/msgq.py.in
@@ -568,10 +568,11 @@ class MsgQ:
# one should be enough, we modify the dict only.
header = routing.copy()
header["reply"] = routing["seq"]
- # The other headers can just stay the same. They are not used
- # in the recipient and we know where to send it, so we don't
- # need the "to" header. We don't know the sender's lname
- # in this part of code anyway.
+ header["from"] = 'msgq' # Dummy lname not assigned to clients
+ header["to"] = routing["from"]
+ # We keep the seq as it is. We don't need to track the message
+ # and provided the sender always uses a new one, it won't know
+ # we're cheating, since we won't send it two same either.
errmsg = self.preparemsg(header, payload)
# Send it back.
self.send_prepared_msg(sock, errmsg)
diff --git a/src/bin/msgq/tests/msgq_test.py b/src/bin/msgq/tests/msgq_test.py
index d3c430a..1748c17 100644
--- a/src/bin/msgq/tests/msgq_test.py
+++ b/src/bin/msgq/tests/msgq_test.py
@@ -179,6 +179,7 @@ class MsgQTest(unittest.TestCase):
# The routing headers and data to test with.
routing = {
'to': '*',
+ 'from': 'sender',
'group': 'group',
'instance': '*',
'seq': 42
@@ -190,6 +191,10 @@ class MsgQTest(unittest.TestCase):
# so none is generated.
self.__msgq.process_command_send(sender, routing, data)
self.assertEqual([], sent_messages)
+ # It should act the same if we explicitly say we do not want replies.
+ routing["wants_reply"] = False
+ self.__msgq.process_command_send(sender, routing, data)
+ self.assertEqual([], sent_messages)
# Ask for errors if it can't be delivered.
routing["wants_reply"] = True
self.__msgq.process_command_send(sender, routing, data)
@@ -200,7 +205,8 @@ class MsgQTest(unittest.TestCase):
'instance': '*',
'reply': 42,
'seq': 42,
- 'to': '*',
+ 'from': 'msgq',
+ 'to': 'sender',
'wants_reply': True
}, {'result': [-1, "No such recipient"]}),
self.parse_msg(sent_messages[0][1]))
@@ -235,7 +241,8 @@ class MsgQTest(unittest.TestCase):
'instance': '*',
'reply': 42,
'seq': 42,
- 'to': 'lname',
+ 'from': 'msgq',
+ 'to': 'sender',
'wants_reply': True
}, {'result': [-1, "No such recipient"]}),
self.parse_msg(sent_messages[0][1]))
diff --git a/src/lib/cc/session.cc b/src/lib/cc/session.cc
index 4455b68..57c88ab 100644
--- a/src/lib/cc/session.cc
+++ b/src/lib/cc/session.cc
@@ -479,14 +479,13 @@ Session::group_sendmsg(ConstElementPtr msg, std::string group,
arg(group);
ElementPtr env = Element::createMap();
long int nseq = ++impl_->sequence_;
-
+
env->set("type", Element::create("send"));
env->set("from", Element::create(impl_->lname_));
env->set("to", Element::create(to));
env->set("group", Element::create(group));
env->set("instance", Element::create(instance));
env->set("seq", Element::create(nseq));
- //env->set("msg", Element::create(msg->toWire()));
sendmsg(env, msg);
return (nseq);
@@ -513,7 +512,7 @@ Session::reply(ConstElementPtr envelope, ConstElementPtr newmsg) {
arg(newmsg->str());
ElementPtr env = Element::createMap();
long int nseq = ++impl_->sequence_;
-
+
env->set("type", Element::create("send"));
env->set("from", Element::create(impl_->lname_));
env->set("to", Element::create(envelope->get("from")->stringValue()));
diff --git a/src/lib/cc/tests/session_unittests.cc b/src/lib/cc/tests/session_unittests.cc
index 528dda9..3b58121 100644
--- a/src/lib/cc/tests/session_unittests.cc
+++ b/src/lib/cc/tests/session_unittests.cc
@@ -26,7 +26,7 @@
#include <cc/session.h>
#include <cc/data.h>
-#include <session_unittests_config.h>
+#include <cc/tests/session_unittests_config.h>
using namespace isc::cc;
@@ -50,7 +50,6 @@ TEST(AsioSession, establish) {
"/aaaaaaaaaa/aaaaaaaaaa/aaaaaaaaaa/aaaaaaaaaa/"
), isc::cc::SessionError
);
-
}
// This class sets up a domain socket for the session to connect to
@@ -70,7 +69,7 @@ public:
boost::bind(&TestDomainSocket::acceptHandler,
this, _1));
}
-
+
~TestDomainSocket() {
socket_.close();
unlink(BIND10_TEST_SOCKET_FILE);
@@ -89,7 +88,7 @@ public:
const unsigned int length_net = htonl(length);
const unsigned short header_length = header_wire.length();
const unsigned short header_length_net = htons(header_length);
-
+
socket_.send(asio::buffer(&length_net, sizeof(length_net)));
socket_.send(asio::buffer(&header_length_net,
sizeof(header_length_net)));
@@ -112,7 +111,7 @@ public:
asio::async_read(socket_, asio::buffer(data_buf, 0),
boost::bind(&TestDomainSocket::sendLname, this));
}
-
+
private:
asio::io_service& io_service_;
asio::local::stream_protocol::endpoint ep_;
diff --git a/src/lib/python/isc/cc/session.py b/src/lib/python/isc/cc/session.py
index 33a47bd..b6060ee 100644
--- a/src/lib/python/isc/cc/session.py
+++ b/src/lib/python/isc/cc/session.py
@@ -30,7 +30,7 @@ class SessionTimeout(Exception): pass
class Session:
MSGQ_DEFAULT_TIMEOUT = 4000
-
+
def __init__(self, socket_file=None):
self._socket = None
self._lname = None
@@ -159,7 +159,7 @@ class Session:
if len(data) == 0: # server closed connection
raise ProtocolError("Read of 0 bytes: connection closed")
return data
-
+
def _receive_len_data(self):
"""Reads self._recv_len_size bytes of data from the socket into
self._recv_len_data
@@ -203,7 +203,7 @@ class Session:
# they may never both be non-zero (we are either starting
# a full read, or continuing one of the reads
assert self._recv_size == 0 or self._recv_len_size == 0
-
+
if self._recv_size == 0:
if self._recv_len_size == 0:
# both zero, start a new full read
@@ -256,7 +256,8 @@ class Session:
"instance": instance,
})
- def group_sendmsg(self, msg, group, instance = "*", to = "*"):
+ def group_sendmsg(self, msg, group, instance = "*", to = "*",
+ want_answer=False):
seq = self._next_sequence()
self.sendmsg({
"type": "send",
@@ -265,6 +266,7 @@ class Session:
"group": group,
"instance": instance,
"seq": seq,
+ "want_answer": want_answer
}, isc.cc.message.to_wire(msg))
return seq
diff --git a/src/lib/python/isc/cc/tests/session_test.py b/src/lib/python/isc/cc/tests/session_test.py
index e8656e7..05caf0a 100644
--- a/src/lib/python/isc/cc/tests/session_test.py
+++ b/src/lib/python/isc/cc/tests/session_test.py
@@ -381,18 +381,42 @@ class testSession(unittest.TestCase):
sent = sess._socket.readsentmsg_parsed()
self.assertEqual(sent, ({"from": "test_name", "seq": 2, "to": "*",
"instance": "*", "group": "my_group",
- "type": "send"}, {"hello": "a"}))
+ "type": "send", "want_answer": False},
+ {"hello": "a"}))
self.assertEqual(sess._sequence, 2)
sess.group_sendmsg({ 'hello': 'a' }, "my_group", "my_instance")
sent = sess._socket.readsentmsg_parsed()
- self.assertEqual(sent, ({"from": "test_name", "seq": 3, "to": "*", "instance": "my_instance", "group": "my_group", "type": "send"}, {"hello": "a"}))
+ self.assertEqual(sent, ({"from": "test_name", "seq": 3, "to": "*",
+ "instance": "my_instance",
+ "group": "my_group", "type": "send",
+ "want_answer": False},
+ {"hello": "a"}))
self.assertEqual(sess._sequence, 3)
sess.group_sendmsg({ 'hello': 'a' }, "your_group", "your_instance")
sent = sess._socket.readsentmsg_parsed()
- self.assertEqual(sent, ({"from": "test_name", "seq": 4, "to": "*", "instance": "your_instance", "group": "your_group", "type": "send"}, {"hello": "a"}))
+ self.assertEqual(sent, ({"from": "test_name", "seq": 4, "to": "*",
+ "instance": "your_instance",
+ "group": "your_group", "type": "send",
+ "want_answer": False},
+ {"hello": "a"}))
self.assertEqual(sess._sequence, 4)
+ # Test the optional want_answer parameter
+ sess.group_sendmsg({'hello': 'a'}, "group", want_answer=True)
+ sent = sess._socket.readsentmsg_parsed()
+ self.assertEqual(sent, ({"from": "test_name", "seq": 5, "to": "*",
+ "instance": "*", "group": "group", "type":
+ "send", "want_answer": True},
+ {"hello": "a"}))
+ self.assertEqual(sess._sequence, 5)
+ sess.group_sendmsg({'hello': 'a'}, "group", want_answer=False)
+ sent = sess._socket.readsentmsg_parsed()
+ self.assertEqual(sent, ({"from": "test_name", "seq": 6, "to": "*",
+ "instance": "*", "group": "group", "type":
+ "send", "want_answer": False},
+ {"hello": "a"}))
+ self.assertEqual(sess._sequence, 6)
def test_group_recvmsg(self):
# must this one do anything except not return messages with
More information about the bind10-changes
mailing list