ConfD User Community

Subscriber two phase is returning username empty

I am getting username as empty when trying to create new socket for Subscriber two phase

maapisock = socket.socket()
maapi.connect(maapisock, '127.0.0.1', _confd.CONFD_PORT)
us = maapi.get_user_session(maapisock, cdb.get_user_session(self.sock))
return us.username

where specifically are you trying to run this code excerpt?
is it subscriber callback before iterating the changes, or the iteration function itself?

are you getting the session id successfully in the nested cdb.get_user_session(...)?

The code excerpt is used to get the session user name.
It is written inside
def _get_username(self):
try:
maapisock = socket.socket()
maapi.connect(maapisock, ‘127.0.0.1’, _confd.CONFD_PORT)
us = maapi.get_user_session(maapisock, cdb.get_user_session(self.sock))
username = us.username
return username
I was able to get the session id in the nested cdb.get_user_session.

You may need to write which line specifically goes wrong and what you receive vs what you expect - what error message/code you get with debug for confd-lib enabled… Make sure you get correct ssid from cdb.get_user_session() call, and use proper subscription (not cdb!) socket…

it seems to work nicely on my side - this is the small addition to a python example in ConfD that you can try to test the get_user_session with subscriber:

diff --git a/examples.confd/cdb_subscription/iter_python/cdbl.py b/examples.confd/cdb_subscription/iter_python/cdbl.py
index ...
--- a/examples.confd/cdb_subscription/iter_python/cdbl.py
+++ b/examples.confd/cdb_subscription/iter_python/cdbl.py
@@ -202,6 +202,16 @@ def iter(kp, op, oldv, newv, cdbsock):
     return rv


+def test_user_session(subsock):
+    ussid = cdb.get_user_session(subsock)
+    print("Ussid: %d" % ussid)
+    maapisock = socket.socket()
+    maapi.connect(maapisock, '127.0.0.1', _confd.CONFD_PORT)
+    us = maapi.get_user_session(maapisock, ussid)
+    print("Username: %s" % us.username)
+    print("Usid: %d" % us.usid)
+
+
 def run():
     log.info("==>")
     # In C we use confd_init() which sets the debug-level, but for Python the
@@ -245,6 +255,7 @@ def run():
                                 log.debug("our spoint=%i triggered" % spoint)
                                 cdb.start_session(sock, cdb.RUNNING)
                                 cdb.set_namespace(sock, root_ns.ns.hash)
+                                test_user_session(subsock)
                                 cdb.diff_iterate(subsock, spoint, iter,
                                                  _confd.ITER_WANT_PREV, sock)
                                 cdb.end_session(sock)

and this is the output when i change some managed config data below subscriber, e.g.

set root node-b rf-head 123
commit

in CLI…

Subscriber dump output:

...
TRACE CDB_GET_USER_SESSION  --> CONFD_OK
Ussid: 14
TRACE Connected (maapi) to ConfD
TRACE MAAPI_GET_USER_SESSION  --> CONFD_OK
Username: admin
Usid: 14
...