Update the traces and add some tests and examples
[nepi.git] / src / nepi / resources / omf / node.py
index 6658f62..6ac01de 100644 (file)
@@ -18,6 +18,7 @@
 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
 #         Julien Tribino <julien.tribino@inria.fr>
 
+from nepi.util.timefuncs import tnow
 from nepi.execution.resource import ResourceManager, clsinit_copy, \
         ResourceState, reschedule_delay
 from nepi.execution.attribute import Attribute, Flags 
@@ -26,6 +27,9 @@ from nepi.resources.omf.omf_api_factory import OMFAPIFactory
 
 import time
 
+reschedule_check = "0.2s"
+confirmation_counter = 3000
+
 @clsinit_copy
 class OMFNode(OMFResource):
     """
@@ -65,6 +69,11 @@ class OMFNode(OMFResource):
 
         self._omf_api = None 
 
+        # For performance tests
+        self.perf = True
+        self.begin_deploy_time = None
+
+
     @property
     def exp_id(self):
         return self.ec.exp_id
@@ -94,9 +103,13 @@ class OMFNode(OMFResource):
     def do_deploy(self):
         """ Deploy the RM. It means : Send Xmpp Message Using OMF protocol 
             to enroll the node into the experiment.
-            It becomes DEPLOYED after sending messages to enroll the node
 
         """ 
+      ## For performance test
+        if self.perf:
+            self.begin_deploy_time = tnow()
+            self.perf = False
+
         if not self.get('xmppServer'):
             msg = "XmppServer is not initialzed. XMPP Connections impossible"
             self.error(msg)
@@ -130,7 +143,8 @@ class OMFNode(OMFResource):
         super(OMFNode, self).do_deploy()
 
     def do_release(self):
-        """ Clean the RM at the end of the experiment
+        """ Clean the RM at the end of the experiment by unenrolling
+        the node from the topic
 
         """
         from nepi.resources.omf.application import OMFApplication
@@ -141,6 +155,14 @@ class OMFNode(OMFResource):
                     self.ec.schedule(reschedule_delay, self.release)
                     return 
 
+        from nepi.resources.omf.interface import OMFWifiInterface
+        rm_list = self.get_connected(OMFWifiInterface.get_rtype())
+        if rm_list:
+            for rm in rm_list:
+                if rm.state < ResourceState.RELEASED:
+                    self.ec.schedule(reschedule_delay, self.release)
+                    return 
+
         if self._omf_api:
             if self.get('version') == "5":
                 self._omf_api.release(self.get('hostname'))