Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
---------------------------------------------------------------
commit 39d1348ba4f762e57c72ce02adcd1a59f12d3bd3
Author: Peter Hatina <phatina(a)redhat.com>
Date: Mon Sep 1 12:16:32 2014 +0200
fix compat.CIMIndicationListener indication delivery
When using PyWBEM, no indications are being passed to callbacks due to wrong prefix
present in path.
---------------------------------------------------------------
cli/lmi/shell/LMIMethod.py | 7 ++-----
cli/lmi/shell/compat/CIMIndicationListener.py | 21 +++++++++++++++++----
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/cli/lmi/shell/LMIMethod.py b/cli/lmi/shell/LMIMethod.py
index b30d265..b6f1775 100644
--- a/cli/lmi/shell/LMIMethod.py
+++ b/cli/lmi/shell/LMIMethod.py
@@ -393,14 +393,11 @@ class LMIMethod(LMIWrapperBaseObject):
s.close()
# Create handler object
- indication_prefix = ""
- if HAVE_LMIWBEM:
- indication_prefix = "CIMListener/"
cim_handler_props = {
"Name": indication_name,
- "Destination": "%s://%s:%d/%s%s" % (
+ "Destination": "%s://%s:%d/CIMListener/%s" % (
"https" if listener.uses_ssl else "http",
- destination, listener.port, indication_prefix, indication_name),
+ destination, listener.port, indication_name),
}
cim_handler, _, _ = self._conn.client.create_instance(
"CIM_IndicationHandlerCIMXML",
diff --git a/cli/lmi/shell/compat/CIMIndicationListener.py
b/cli/lmi/shell/compat/CIMIndicationListener.py
index 6b8a2d1..d2d939e 100644
--- a/cli/lmi/shell/compat/CIMIndicationListener.py
+++ b/cli/lmi/shell/compat/CIMIndicationListener.py
@@ -53,6 +53,8 @@ class CIMIndicationHandler(ThreadingMixIn, BaseHTTPRequestHandler):
listener is designed as concurrent server to properly handle each incoming
indication.
"""
+ CIMLISTENER_PREFIX = "/CIMListener"
+
def do_POST(self):
"""
Overridden method, which is called, when a indication is received. It
@@ -98,12 +100,23 @@ class CIMIndicationHandler(ThreadingMixIn, BaseHTTPRequestHandler):
ind_dict = export_methods.values()[0]
if "NewIndication" in ind_dict:
ind = ind_dict["NewIndication"]
+
path = self.path
- if path.startswith("CIMListener/"):
- # We got an indication with lmiwbem CIMListener prefix. We are
- # using pywbem now so it's necessary to strip the prefix.
- path = path[12:]
+ cimlistener_ind = path.find(self.CIMLISTENER_PREFIX)
+ if cimlistener_ind != -1:
+ # We got an indication with lmiwbem's CIMListener substring
+ # present. We are using pywbem now, so it's necessary to strip the
+ # prefix also with the substring (from the beginning). We try to
+ # mimic Pegasus::CIMListener behavior here.
+ path = path[cimlistener_ind + len(self.CIMLISTENER_PREFIX):]
+
+ if path[0] == '/':
+ # Path of the received indication may be prefixed by additional
+ # slash. Drop it then.
+ path = path[1:]
+
if path in self.server._handlers:
+ # We found the indication handler. Execute the callback.
cb = self.server._handlers[path]
cb.callback(ind, *cb.args, **cb.kwargs)