Debugging RPCs and handling lists as RPC output

I have an RPC where the output is a list, as follows:

rpc myrpc {
tailf:actionpoint spoint;

output {      
  list my-list {

    key "elemA";

    leaf elemA {
      type string;
    }
    leaf elemB {
      type uint8;
    }
    leaf elemC {
      type boolean;
    }
}

Let’s suppose that my python code returns the following:

result = [
    _confd.TagValue(_confd.XmlTag(ns_hash, my_list_tag),
                    _confd.Value(_confd.C_XMLBEGIN)),
    _confd.TagValue(_confd.XmlTag(ns_hash, elemA_tag),
                    _confd.Value('a1')),
    _confd.TagValue(_confd.XmlTag(ns_hash, elemB_tag),
                    _confd.Value(1)),
    _confd.TagValue(_confd.XmlTag(ns_hash, elemC_tag),
                    _confd.Value(True)),
    _confd.TagValue(_confd.XmlTag(ns_hash, my_list_tag),
                    _confd.Value(_confd.C_XMLEND)),
    _confd.TagValue(_confd.XmlTag(ns_hash, my_list_tag),
                    _confd.Value(_confd.C_XMLBEGIN)),
    _confd.TagValue(_confd.XmlTag(ns_hash, elemA_tag),
                    _confd.Value('a2')),
    _confd.TagValue(_confd.XmlTag(ns_hash, elemB_tag),
                    _confd.Value(2)),
    _confd.TagValue(_confd.XmlTag(ns_hash, elemC_tag),
                    _confd.Value(False)),
    _confd.TagValue(_confd.XmlTag(ns_hash, my_list_tag),
                    _confd.Value(_confd.C_XMLEND))]

dp.action_reply_values(uinfo, result)

Is that the correct way of returning lists? I’m prepending _confd.C_XMLBEGIN and appending _confd.C_XMLEND to each list element, as explained in a previous question. Am I missing something?

In confd CLI, I am getting this error:

> request myrpc
my-list --ERROR--
Error: bad response from action
[error][2018-05-30 15:26:32]

I had a vague memory that in /var/log/syslog I could find more details if the developerLogLevel of confd is set to “trace”, but even after editing confd.conf so that all logs are active and are active on syslog, I only get the following:

May 30 15:53:51 localhost confd[3598]: devel-c new_action request daemon id: 3 usid: 17
May 30 15:53:51 localhost confd[3598]: devel-c new_action succeeded daemon id: 3 session id: -27 worker id: 11
May 30 15:53:51 localhost confd[3598]: devel-c action action() request for callpoint spoint path
May 30 15:53:51 localhost confd[3598]: devel-c action action() succeeded for callpoint spoint path

Is there a way to get more debug messages from ConfD so as to know exactly what went wrong?

As you saw in the response from the user in that previous question, my reply there had an issue with the begin and end tags. So in your case:

result = [
    _confd.TagValue(_confd.XmlTag(ns_hash, my_list_tag),
                               _confd.Value((my_list_tag,ns_hash),_confd.C_XMLBEGIN)),
    _confd.TagValue(_confd.XmlTag(ns_hash, elemA_tag),
                               _confd.Value('a1', _confd.C_STR)),
    _confd.TagValue(_confd.XmlTag(ns_hash, elemB_tag),
                               _confd.Value(1, _confd.C_UINT8)),
    _confd.TagValue(_confd.XmlTag(ns_hash, elemC_tag),
                               _confd.Value(True, _confd.C_BOOL)),
    _confd.TagValue(_confd.XmlTag(ns_hash, my_list_tag),
                               _confd.Value((my_list_tag,ns_hash),_confd.C_XMLEND))
]
dp.action_reply_values(self.uinfo, result)

Note that it is a good habit to enter the type for the value too, even though for the string and boolean it is not required.

1 Like