Improve debug display
authorJulien Tribino <julien.tribino@inria.fr>
Fri, 21 Dec 2012 13:11:04 +0000 (14:11 +0100)
committerJulien Tribino <julien.tribino@inria.fr>
Fri, 21 Dec 2012 13:11:04 +0000 (14:11 +0100)
src/nepi/testbeds/omf/metadata.py
src/nepi/testbeds/omf/omf_api.py
src/nepi/testbeds/omf/omf_client.py

index 0f15542..fc0f246 100644 (file)
@@ -388,7 +388,7 @@ testbed_attributes = dict({
                 "name": "xmppRoot",
                 "help": "Root node of the xmpp server pubsub tree",
                 "type": Attribute.STRING,
-                "value": "OMF",
+                "value": "OMF_5.4",
                 "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
                 "validation_function": validation.is_string
             }),
index 7b54b4c..4eea26e 100644 (file)
@@ -18,7 +18,7 @@ class OmfAPI(object):
         self._port = port
         self._password = password
         self._hostnames = []
-        self._xmpp_root = xmpp_root or "OMF"
+        self._xmpp_root = xmpp_root or "OMF_5.4"
 
         self._logger = logging.getLogger("nepi.testbeds.omf")
 
@@ -60,9 +60,13 @@ class OmfAPI(object):
     def _enroll_experiment(self):
         xmpp_node = self._exp_session_id
         self._client.create(xmpp_node)
+        #print "Create experiment sesion id topics !!" 
         self._client.subscribe(xmpp_node)
+        #print "Subscribe to experiment sesion id topics !!" 
+
 
         address = "/%s/%s/%s/%s" % (self._host, self._xmpp_root, self._slice, self._user)
+        print address
         payload = self._message.newexpfunction(self._user, address)
         slice_sid = "/%s/%s" % (self._xmpp_root, self._slice)
         self._client.publish(payload, slice_sid)
index 8969f1a..fd1b930 100644 (file)
@@ -2,6 +2,7 @@ import logging
 import sleekxmpp
 from sleekxmpp.exceptions import IqError, IqTimeout
 import traceback
+import xml.etree.ElementTree as ET
 
 class OMFClient(sleekxmpp.ClientXMPP):
     def __init__(self, jid, password):
@@ -164,10 +165,45 @@ class OMFClient(sleekxmpp.ClientXMPP):
             self._logger.error('Could not unsubscribe %s from node %s\ntraceback:\n%s' \
                     % (self.boundjid.bare, node, error))
 
+    def _check_for_tag(self, treeroot, namespaces, tag):
+        for element in treeroot.iter(namespaces+tag):
+            if element.text:
+                return element
+            else : 
+                return None    
+
+    def _check_app_event(self, treeroot, namespaces):
+        message = self._check_for_tag(treeroot, namespaces, 'MESSAGE')
+        if message is not None :
+            target = self._check_for_tag(treeroot, namespaces, 'TARGET')
+            if target is not None :
+                self._logger.info(target.text + ": APP_EVENT: " + message.text)
+
+    def _check_configure(self, treeroot, namespaces, status):
+        for message in treeroot.iter(namespaces + status):
+            reason = self._check_for_tag(treeroot, namespaces, 'REASON')
+            if reason is not None and reason.text!="ENROLLED" :
+                target = self._check_for_tag(treeroot, namespaces, 'TARGET')
+                if target is not None :
+                    path = self._check_for_tag(treeroot, namespaces, 'PATH')
+                    if path is not None :
+                        self._logger.debug(target.text+ ": " +reason.text+ ": " +path.text)
+                    else :
+                        self._logger.debug(target.text+ ": " +reason.text ) 
+
     def handle_omf_message(self, iq):
+        namespaces = "{http://jabber.org/protocol/pubsub}"
         for i in iq['pubsub_event']['items']:
+            root = ET.fromstring(str(i))
+            self._check_app_event(root, namespaces)
+            self._check_configure(root, namespaces, "OK")
+            self._check_configure(root, namespaces, "ERROR")
             #self._logger.debug(i)
-            print ""
+
+           
+#<item xmlns="http://jabber.org/protocol/pubsub#event" id="WlO9GaRXpy6ayRB"><omf-message xmlns="http://jabber.org/protocol/pubsub"><OK id="omf-payload"><EXPID>default_slice-2012-12-20t12.07.02+02.00</EXPID><MESSAGE /><REASON>CONFIGURED</REASON><TARGET>omf.plexus.wlab17</TARGET><SLICEID>default_slice</SLICEID><VALUE>cvlcmode</VALUE><PATH>net/w0/essid</PATH></OK></omf-message></item>
+
+#<item xmlns="http://jabber.org/protocol/pubsub#event" id="nL1uzyXRMe86jEV"><omf-message xmlns="http://jabber.org/protocol/pubsub"><ERROR id="omf-payload"><EXPID>default_slice-2012-12-20t12.07.02+02.00</EXPID><MESSAGE /><REASON>FAILED_CONFIGURE</REASON><TARGET>omf.plexus.wlab17</TARGET><SLICEID>default_slice</SLICEID><VALUE>g</VALUE><PATH>net/w0/type</PATH></ERROR></omf-message></item>
 
             #<item xmlns="http://jabber.org/protocol/pubsub#event" id="dFbv6WRlMuKghJ0"><omf-message xmlns="http://jabber.org/protocol/pubsub"><LOGGING id="&apos;omf-payload&apos;"><LEVEL>2</LEVEL><SLICEID>default_slice</SLICEID><LOGGER>nodeHandler::NodeHandler</LOGGER><EXPID>default_slice-2012-09-28t16.22.17+02.00</EXPID><LEVEL_NAME>INFO</LEVEL_NAME><DATA>OMF Experiment Controller 5.4 (git 529a626)</DATA></LOGGING></omf-message></item>