Browse Source

[2768] Make sure the rpcCall asks for answer

Add tests for the fact and fix it. Also, add log from the rpcCall
itself, so it can be seen in logs.
Michal 'vorner' Vaner 12 years ago
parent
commit
83966d1e3e

+ 5 - 3
src/lib/config/ccsession.cc

@@ -32,7 +32,7 @@
 #include <boost/foreach.hpp>
 #include <boost/foreach.hpp>
 
 
 #include <cc/data.h>
 #include <cc/data.h>
-#include <module_spec.h>
+#include <config/module_spec.h>
 #include <cc/session.h>
 #include <cc/session.h>
 #include <exceptions/exceptions.h>
 #include <exceptions/exceptions.h>
 
 
@@ -863,9 +863,11 @@ ModuleCCSession::rpcCall(const std::string &command, const std::string &group,
                          const ConstElementPtr &params)
                          const ConstElementPtr &params)
 {
 {
     const ConstElementPtr &command_el(createCommand(command, params));
     const ConstElementPtr &command_el(createCommand(command, params));
-    const int seq = session_.group_sendmsg(command_el, group, instance, to);
+    const int seq = groupSendMsg(command_el, group, instance, to, true);
     ConstElementPtr env, answer;
     ConstElementPtr env, answer;
-    session_.group_recvmsg(env, answer, false, seq);
+    LOG_DEBUG(config_logger, DBGLVL_TRACE_DETAIL, CONFIG_RPC_SEQ).arg(command).
+        arg(group).arg(seq);
+    groupRecvMsg(env, answer, true, seq);
     int rcode;
     int rcode;
     const ConstElementPtr &result(parseAnswer(rcode, answer));
     const ConstElementPtr &result(parseAnswer(rcode, answer));
     if (rcode == isc::cc::CC_REPLY_NO_RECPT) {
     if (rcode == isc::cc::CC_REPLY_NO_RECPT) {

+ 4 - 2
src/lib/config/ccsession.h

@@ -363,13 +363,15 @@ public:
      * \param group see isc::cc::Session::group_sendmsg()
      * \param group see isc::cc::Session::group_sendmsg()
      * \param instance see isc::cc::Session::group_sendmsg()
      * \param instance see isc::cc::Session::group_sendmsg()
      * \param to see isc::cc::Session::group_sendmsg()
      * \param to see isc::cc::Session::group_sendmsg()
+     * \param want_answer see isc::cc::Session::group_sendmsg()
      * \return see isc::cc::Session::group_sendmsg()
      * \return see isc::cc::Session::group_sendmsg()
      */
      */
     int groupSendMsg(isc::data::ConstElementPtr msg,
     int groupSendMsg(isc::data::ConstElementPtr msg,
                      std::string group,
                      std::string group,
                      std::string instance = "*",
                      std::string instance = "*",
-                     std::string to = "*") {
-        return (session_.group_sendmsg(msg, group, instance, to));
+                     std::string to = "*",
+                     bool want_answer = false) {
+        return (session_.group_sendmsg(msg, group, instance, to, want_answer));
     };
     };
 
 
     /**
     /**

+ 4 - 0
src/lib/config/config_messages.mes

@@ -94,3 +94,7 @@ manager.
 % CONFIG_OPEN_FAIL error opening %1: %2
 % CONFIG_OPEN_FAIL error opening %1: %2
 There was an error opening the given file. The reason for the failure
 There was an error opening the given file. The reason for the failure
 is included in the message.
 is included in the message.
+
+% CONFIG_RPC_SEQ RPC call %1 to %2 with seq %3
+Debug message, saying there's a RPC call of given command to given module. It
+has internal sequence number as listed in the message.

+ 1 - 1
src/lib/config/tests/ccsession_unittests.cc

@@ -71,7 +71,7 @@ protected:
                                           "  \"command\": [\"test\", {"
                                           "  \"command\": [\"test\", {"
                                           "    \"param1\": \"Param 1\","
                                           "    \"param1\": \"Param 1\","
                                           "    \"param2\": \"Param 2\""
                                           "    \"param2\": \"Param 2\""
-                                          "}]}, -1]"));
+                                          "}]}, -1, true]"));
         // The 0th one is from the initialization, to ConfigManager.
         // The 0th one is from the initialization, to ConfigManager.
         // our is the 1st.
         // our is the 1st.
         EXPECT_TRUE(request->equals(*session.getMsgQueue()->get(1))) <<
         EXPECT_TRUE(request->equals(*session.getMsgQueue()->get(1))) <<

+ 6 - 3
src/lib/config/tests/fake_session.cc

@@ -183,12 +183,12 @@ FakeSession::unsubscribe(std::string group, std::string instance) {
 
 
 int
 int
 FakeSession::group_sendmsg(ConstElementPtr msg, std::string group,
 FakeSession::group_sendmsg(ConstElementPtr msg, std::string group,
-                           std::string to, std::string, bool)
+                           std::string to, std::string, bool want_answer)
 {
 {
     if (throw_on_send_) {
     if (throw_on_send_) {
         isc_throw(Exception, "Throw on send is set in FakeSession");
         isc_throw(Exception, "Throw on send is set in FakeSession");
     }
     }
-    addMessage(msg, group, to);
+    addMessage(msg, group, to, -1, want_answer);
     return (1);
     return (1);
 }
 }
 
 
@@ -231,13 +231,16 @@ FakeSession::getFirstMessage(std::string& group, std::string& to) const {
 
 
 void
 void
 FakeSession::addMessage(ConstElementPtr msg, const std::string& group,
 FakeSession::addMessage(ConstElementPtr msg, const std::string& group,
-                        const std::string& to, int seq)
+                        const std::string& to, int seq, bool want_answer)
 {
 {
     ElementPtr m_el = Element::createList();
     ElementPtr m_el = Element::createList();
     m_el->add(Element::create(group));
     m_el->add(Element::create(group));
     m_el->add(Element::create(to));
     m_el->add(Element::create(to));
     m_el->add(msg);
     m_el->add(msg);
     m_el->add(Element::create(seq));
     m_el->add(Element::create(seq));
+    if (want_answer) {
+        m_el->add(Element::create(want_answer));
+    }
     if (!msg_queue_) {
     if (!msg_queue_) {
         msg_queue_ = Element::createList();
         msg_queue_ = Element::createList();
     }
     }

+ 2 - 1
src/lib/config/tests/fake_session.h

@@ -75,7 +75,8 @@ public:
     isc::data::ConstElementPtr getFirstMessage(std::string& group,
     isc::data::ConstElementPtr getFirstMessage(std::string& group,
                                                std::string& to) const;
                                                std::string& to) const;
     void addMessage(isc::data::ConstElementPtr, const std::string& group,
     void addMessage(isc::data::ConstElementPtr, const std::string& group,
-                    const std::string& to, int seq = -1);
+                    const std::string& to, int seq = -1,
+                    bool want_answer = false);
     bool haveSubscription(const std::string& group,
     bool haveSubscription(const std::string& group,
                           const std::string& instance);
                           const std::string& instance);
     bool haveSubscription(const isc::data::ConstElementPtr group,
     bool haveSubscription(const isc::data::ConstElementPtr group,