Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object registration in python succeeds, but handlers are never invoked #84

Open
kot-begemot-uk opened this issue Jun 15, 2018 · 3 comments
Assignees
Labels

Comments

@kot-begemot-uk
Copy link

kot-begemot-uk commented Jun 15, 2018

I am trying to register a handler in python for a new model.

The model augments if/interfaces/interface:

augment "/if:interfaces/if:interface" {
    when "if:type = 'ianaift:l2vlan'";

It is added successfully to the models, everything is recompiled and cps.type() reports the correct information on it.

cps.type("dhcp-agent/if/interfaces/interface")
{'name': 'dhcp-agent/if/interfaces/interface', 'embedded': 'True', 'attribute_type': 'container', 'data_type': 'bin', 'key': '300.44.2883617.2883612.2883613', 'id': '19661025', 'description': ''}

I am testing the object registration for this path using the following simple python snippet:

#!/usr/bin/env python
'''DHCP Agent CPS Registration'''
import cps
import cps_utils
PATH = 'dhcp-agent/if/interfaces/interface'

def test_get(arg):
    print "test get invoked with args {}".format(arg)
    return True

class DHCPRegistration(object):
    '''CPS Registration handler for DHCP'''
     def __init__(self):
        self.handle = cps.obj_init()
        self.callback = {"get".encode('ascii'):test_get, "transaction".encode('ascii'):self.transaction}
        cps.obj_register(self.handle, PATH, self.callback)

    def get(self, arg):
        '''Get Handler'''
        print "get invoked with args {}".format(arg)

    def transaction(self, arg):
        '''Transaction Handler'''
        print "transaction invoked with args {}".format(arg)
  1. cps.obj_register returns True which according to the code in the cps api means registration is OK
  2. Neither the bound methods (in the object) or the simple function test_get are invoked for any transactions coming via CPS.
  3. CPS returns transaction successful for transactions targeted at dhcp-agent/if/interfaces/interface (f.e. set). The method is not invoked and the data is lost along the way
  4. Prior to registering an handler obj_stats() returns None. After registering an object it reports the same information for any path so the available debug info is not particularly informative.
@rakeshdatta
Copy link
Collaborator

I did an exercise myself in 2.3.1 to see what’s going on.. Everything seems to be all right. Can u plz follow the steps below and see if you’re good. Let me know.

  • Clone opx-build.
  • Clone opx-base-model.
  • cd opx-base-model; git checkout v2.3.1
  • Create the dell-test.yang (attached) file in opx-base-model/yang-models.
  • add this new yang file in the opx-base-model/Makefile.am (attached).
  • increase the version to “+rakesh” in the debian/changelog and configure.ac (attached) [use any string you want instead of “+rakesh”].
  • build the opx-base-model (“DIST=jessie OPX_RELEASE=2.3.1 opx-build/scripts/opx_run opx_build opx-base-model”) from the top level dir where the opx repos reside.
  • scp “pool/jessie-amd64/opx-base-model/libopx-base-model1_3.112.0+rakesh_amd64.deb” to the OPX 2.3.1 box and install it
  • Get into the root mode.
  • Check if you see the *.so corresponding to this new yang file, in the ‘/usr/lib/x86_64-linux-gnu/ ’ directory. If not, reboot the box and re-check.
  • Try ‘cps_get_oid.py -qua target test/if/interfaces/interface’. You should get an error since there is no callback registered.
  • Try ‘cps_set_oid.py -oper set test/if/interfaces/interface’. You should get an error since there is no callback registered.
  • Copy the server code (test-server.py attached) into the box, that registers the cps callbacks, and start it in background: ‘sudo python test-server.py &’
  • Try ‘cps_get_oid.py -qua target test/if/interfaces/interface’. You should see the ‘GET_CB invoked’ debug message.
  • Try ‘cps_set_oid.py -oper set test/if/interfaces/interface’. You should see the ‘TRANS_CB invoked’ debug message.

There are multiple reasons your code may not be working:

  • You have used the object path instead of key in the cps.obj_register()
  • You are not letting the server app keep running continuously.
  • Etc.
rdatta@netlogin-eqx-01:/neteng/rdatta/github-issues/84_cps_obj_reg$ cat test_server.py
#!/usr/bin/env python

import cps
import cps_utils
import time

PATH = "test/if/interfaces/interface"


def get_cb(method, params):
        print "GET_CB is invoked"

        return TRUE



def trans_cb(method, params):
        print "TRANS_CB invoked"

        return TRUE


if __name__ == '__main__':
        dict_cb = {}
        dict_cb['get'] = get_cb
        dict_cb['transaction'] = trans_cb

        handle = cps.obj_init()

        cps.obj_register(handle, cps.key_from_name("target", PATH) , dict_cb)

        while True:
                time.sleep(1)

rdatta@netlogin-eqx-01:/neteng/rdatta/github-issues/84_cps_obj_reg/opx-base-model$ git diff
diff --git a/configure.ac b/configure.ac
index 18ae828..9e5b32c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,7 +1,7 @@
 #                                               -*- Autoconf -*-
 # Process this file with autoconf to produce a configure script.
 AC_PREREQ([2.69])
-AC_INIT([opx-base-model], [3.112.0], [[email protected]])
+AC_INIT([opx-base-model], [3.112.0+rakesh], [[email protected]])
 AM_INIT_AUTOMAKE([foreign subdir-objects])
 AC_CONFIG_SRCDIR([yang-models])
 AC_CONFIG_HEADERS([config.h])
diff --git a/debian/changelog b/debian/changelog
index 073113c..0d22131 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+opx-base-model (3.112.0+rakesh) unstable; urgency=medium
+
+  * Update: Test
+
+ -- Dell EMC <[email protected]>  Mon, 23 Jul 2018 16:00:00 -0800
+
 opx-base-model (3.112.0) unstable; urgency=medium

   * Update: Adding ip-mtu to interface state attribute
rdatta@netlogin-eqx-01:/neteng/rdatta/github-issues/84_cps_obj_reg/opx-base-model$ git status
HEAD detached at v2.3.1
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   Makefile.am
        new file:   yang-models/dell-test.yang

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   configure.ac
        modified:   debian/changelog

rdatta@netlogin-eqx-01:/neteng/rdatta/github-issues/84_cps_obj_reg/opx-base-model$ git diff --staged
diff --git a/Makefile.am b/Makefile.am
index 3b61e74..5ca6fd0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -27,6 +27,7 @@ YANG_PARSED_FILES = \
     $(top_srcdir)/yang-models/dell-base-packet.yang \
     $(top_srcdir)/yang-models/dell-base-interface-common.yang \
     $(top_srcdir)/yang-models/dell-base-ip.yang \
+    $(top_srcdir)/yang-models/dell-test.yang \
     $(top_srcdir)/yang-models/dell-base-qos.yang \
     $(top_srcdir)/yang-models/dell-base-l2-mac.yang \
     $(top_srcdir)/yang-models/dell-base-if-phy.yang \
@@ -94,6 +95,7 @@ YANG_GENERATED_SRCS = \
     @YANG_OUTPUT@/dell-base-packet.cpp \
     @YANG_OUTPUT@/dell-base-interface-common.cpp \
     @YANG_OUTPUT@/dell-base-ip.cpp \
+    @YANG_OUTPUT@/dell-test.cpp \
     @YANG_OUTPUT@/dell-base-qos.cpp \
     @YANG_OUTPUT@/dell-base-l2-mac.cpp \
     @YANG_OUTPUT@/dell-base-if-phy.cpp \
@@ -157,6 +159,7 @@ YANG_GENERATED_HDRS = \
     @YANG_OUTPUT@/dell-base-packet.h \
     @YANG_OUTPUT@/dell-base-interface-common.h \
     @YANG_OUTPUT@/dell-base-ip.h \
+    @YANG_OUTPUT@/dell-test.h \
     @YANG_OUTPUT@/dell-base-qos.h \
     @YANG_OUTPUT@/dell-base-l2-mac.h \
     @YANG_OUTPUT@/dell-base-if-phy.h \
@@ -224,6 +227,7 @@ lib_LTLIBRARIES = \
     libcpsclass_dell-base-packet.la \
     libcpsclass_dell-base-interface-common.la \
     libcpsclass_dell-base-ip.la \
+    libcpsclass_dell-test.la \
     libcpsclass_dell-base-qos.la \
     libcpsclass_dell-base-l2-mac.la \
     libcpsclass_dell-base-if-phy.la \
@@ -345,6 +349,9 @@ libcpsclass_dell_base_interface_common_la_LIBADD = -lopx_cps_class_map -lopx_cps
 libcpsclass_dell_base_ip_la_SOURCES = @YANG_OUTPUT@/dell-base-ip.cpp
 libcpsclass_dell_base_ip_la_LIBADD = -lopx_cps_class_map -lopx_cps_api_common

+libcpsclass_dell_test_la_SOURCES = @YANG_OUTPUT@/dell-test.cpp
+libcpsclass_dell_test_la_LIBADD = -lopx_cps_class_map -lopx_cps_api_common
+
 libcpsclass_dell_base_qos_la_SOURCES = @YANG_OUTPUT@/dell-base-qos.cpp
 libcpsclass_dell_base_qos_la_LIBADD = -lopx_cps_class_map -lopx_cps_api_common

diff --git a/yang-models/dell-test.yang b/yang-models/dell-test.yang
new file mode 100644
index 0000000..bdfdb2e
--- /dev/null
+++ b/yang-models/dell-test.yang
@@ -0,0 +1,34 @@
+module dell-test {
+    namespace "http://www.dellemc.com/networking/os10/dell-test";
+
+    prefix "test";
+
+    import ietf-interfaces {
+        prefix "if";
+    }
+
+    import dell-base-common {
+        prefix "base-cmn";
+    }
+
+    organization "Dell EMC";
+
+    contact "http://www.dell.com/support";
+
+    description "This is a test module";
+
+    revision 2018-07-20 {
+        description
+            "This is a test module";
+        reference
+            "Network Platform Abstraction";
+    }
+
+    augment "/if:interfaces/if:interface" {
+        leaf test-node {
+            type base-cmn:vlan-id;
+            description "test id";
+        }
+    }
+}
+
(END)

@kot-begemot-uk
Copy link
Author

I think this needs reopening.
While all examples are correct and the callback gets invoked, that does not actually perform an augment.
They are invoked ONLY if the node test/if/interfaces/interface is accessed directly.
If you access the augmented node (should be if/interfaces/interface, but for whatever reason it's dhcp-agent/if/interfaces/interface/dhcp-server), the callback is not invoked. So in fact, the augment does not work as intended.

@jeff-yin jeff-yin reopened this Sep 10, 2018
@jeff-yin
Copy link
Member

@rakeshdatta will follow up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants