Modify the OMT test and add the exp_id in the xmpp Api
authorJulien Tribino <julien.tribino@inria.fr>
Fri, 26 Jul 2013 14:11:12 +0000 (16:11 +0200)
committerJulien Tribino <julien.tribino@inria.fr>
Fri, 26 Jul 2013 14:11:12 +0000 (16:11 +0200)
src/nepi/resources/omf/application.py
src/nepi/resources/omf/channel.py
src/nepi/resources/omf/interface.py
src/nepi/resources/omf/node.py
src/nepi/resources/omf/omf_api.py
test/resources/omf/vlc.py

index ba2fddd..3b80df1 100644 (file)
@@ -90,6 +90,18 @@ class OMFApplication(ResourceManager):
 
         self._omf_api = None
 
+    @property
+    def exp_id(self):
+        if self.ec.exp_id.startswith('exp-'):
+            return None
+        return self.ec.exp_id
+
+    @property
+    def node(self):
+        rm_list = self.get_connected(OMFNode.rtype())
+        if rm_list: return rm_list[0]
+        return None
+
     def valid_connection(self, guid):
         """Check if the connection with the guid in parameter is possible. Only meaningful connections are allowed.
 
@@ -114,14 +126,22 @@ class OMFApplication(ResourceManager):
             self.debug(msg)
             return True
 
+
+
     def deploy(self):
         """Deploy the RM. It means nothing special for an application for now (later it will be upload sources, ...)
            It becomes DEPLOYED after getting the xmpp client.
         """
         if not self._omf_api :
             self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'), 
-                self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
-        
+                self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'), exp_id = self.exp_id)
+
+        if not self._omf_api :
+            self._state = ResourceState.FAILED
+            msg = "Credentials are not initialzed. XMPP Connections impossible"
+            self.error(msg)
+            return
+
         super(OMFApplication, self).deploy()
 
     def start(self):
@@ -129,27 +149,35 @@ class OMFApplication(ResourceManager):
            It becomes STARTED before the messages are sent (for coordination)
 
         """
-        super(OMFApplication, self).start()
-        if self.get('appid') and self.get('path') and self.get('args') and self.get('env') :
-            msg = " " + self.rtype() + " ( Guid : " + str(self._guid) +") : " + \
-                self.get('appid') + " : " + self.get('path') + " : " + \
-                self.get('args') + " : " + self.get('env')
-            self.info(msg)
-            rm_list = self.get_connected(OMFNode.rtype())
-            try:
-                for rm_node in rm_list:
-                    if rm_node.get('hostname') :
-                        self._omf_api.execute(rm_node.get('hostname'),self.get('appid'), \
-                            self.get('args'), self.get('path'), self.get('env'))
-            except AttributeError:
-                self._state = ResourceState.FAILED
-                msg = "Credentials are not initialzed. XMPP Connections impossible"
-                self.error(msg)
-                raise
-        else :
+        if not (self.get('appid') and self.get('path')) :
             self._state = ResourceState.FAILED
             msg = "Application's information are not initialized"
             self.error(msg)
+            return
+
+        if not self.get('args'):
+            self.set('args', " ")
+        if not self.get('env'):
+            self.set('env', " ")
+
+        # Some information to check the information in parameter
+        msg = " " + self.rtype() + " ( Guid : " + str(self._guid) +") : " + \
+            self.get('appid') + " : " + self.get('path') + " : " + \
+            self.get('args') + " : " + self.get('env')
+        self.info(msg)
+
+        try:
+            self._omf_api.execute(self.node.get('hostname'),self.get('appid'), \
+                self.get('args'), self.get('path'), self.get('env'))
+        except AttributeError:
+            self._state = ResourceState.FAILED
+            msg = "Credentials are not initialzed. XMPP Connections impossible"
+            self.error(msg)
+            raise
+
+
+        super(OMFApplication, self).start()
+
 
     def stop(self):
         """Stop the RM. It means : Send Xmpp Message Using OMF protocol to kill the application
@@ -157,14 +185,13 @@ class OMFApplication(ResourceManager):
 
         """
         try:
-            rm_list = self.get_connected("OMFNode")
-            for rm_node in rm_list :
-                self._omf_api.exit(rm_node.get('hostname'),self.get('appid'))
+            self._omf_api.exit(self.node.get('hostname'),self.get('appid'))
         except AttributeError:
             self._state = ResourceState.FAILED
             msg = "Credentials were not initialzed. XMPP Connections impossible"
             self.error(msg)
-            raise
+            #raise
+
         super(OMFApplication, self).stop()
         self._state = ResourceState.FINISHED
         
@@ -175,5 +202,7 @@ class OMFApplication(ResourceManager):
         """
         if self._omf_api :
             OMFAPIFactory.release_api(self.get('xmppSlice'), 
-                self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
+                self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'), exp_id = self.exp_id)
+
+        super(OMFApplication, self).release()
 
index 8d8a5db..deb2dfa 100644 (file)
@@ -76,6 +76,12 @@ class OMFChannel(ResourceManager):
 
         self._omf_api = None
 
+    @property
+    def exp_id(self):
+        if self.ec.exp_id.startswith('exp-'):
+            return None
+        return self.ec.exp_id
+
     def valid_connection(self, guid):
         """Check if the connection with the guid in parameter is possible. Only meaningful connections are allowed.
 
@@ -103,6 +109,7 @@ class OMFChannel(ResourceManager):
         :return: self._nodes_guid
 
         """
+        res = []
         for elt in conn_set:
             rm_iface = self.ec.get_resource(elt)
             for conn in rm_iface.connections:
@@ -112,8 +119,8 @@ class OMFChannel(ResourceManager):
                         return "reschedule"
                     couple = [rm_node.get('hostname'), rm_iface.get('alias')]
                     #print couple
-                    self._nodes_guid.append(couple)
-        return self._nodes_guid
+                    res.append(couple)
+        return res
 
     def discover(self):
         """ Discover the availables channels
@@ -134,29 +141,36 @@ class OMFChannel(ResourceManager):
         """
         if not self._omf_api :
             self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'), 
-                self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
-
-
-        if self.get('channel'):
-            set_nodes = self._get_target(self._connections) 
-            if set_nodes == "reschedule" :
-                self.ec.schedule(reschedule_delay, self.deploy)
-                return
-            print set_nodes
-            try:
-                for couple in set_nodes:
-                    #print "Couple node/alias : " + couple[0] + "  ,  " + couple[1]
-                    attrval = self.get('channel')
-                    attrname = "net/%s/%s" % (couple[1], 'channel')
-                    self._omf_api.configure(couple[0], attrname, attrval)
-            except AttributeError:
-                self._state = ResourceState.FAILED
-                msg = "Credentials are not initialzed. XMPP Connections impossible"
-                self.debug(msg)
-                raise
-        else :
+                self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'), exp_id = self.exp_id)
+
+        if not self._omf_api :
+            self._state = ResourceState.FAILED
+            msg = "Credentials are not initialzed. XMPP Connections impossible"
+            self.error(msg)
+            return
+
+        if not self.get('channel'):
+            self._state = ResourceState.FAILED
             msg = "Channel's value is not initialized"
             self.error(msg)
+            raise
+
+        self._nodes_guid = self._get_target(self._connections) 
+        if self._nodes_guid == "reschedule" :
+            self.ec.schedule("2s", self.deploy)
+            return False
+
+        try:
+            for couple in self._nodes_guid:
+                #print "Couple node/alias : " + couple[0] + "  ,  " + couple[1]
+                attrval = self.get('channel')
+                attrname = "net/%s/%s" % (couple[1], 'channel')
+                self._omf_api.configure(couple[0], attrname, attrval)
+        except AttributeError:
+            self._state = ResourceState.FAILED
+            msg = "Credentials are not initialzed. XMPP Connections impossible"
+            self.error(msg)
+            raise
 
         super(OMFChannel, self).deploy()
 
@@ -181,5 +195,7 @@ class OMFChannel(ResourceManager):
         """
         if self._omf_api :
             OMFAPIFactory.release_api(self.get('xmppSlice'), 
-                self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
+                self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'), exp_id = self.exp_id)
+
+        super(OMFChannel, self).release()
 
index 5d2c7fb..d064c66 100644 (file)
@@ -87,6 +87,12 @@ class OMFWifiInterface(ResourceManager):
         self._omf_api = None
         self._alias = self.get('alias')
 
+    @property
+    def exp_id(self):
+        if self.ec.exp_id.startswith('exp-'):
+            return None
+        return self.ec.exp_id
+
     def valid_connection(self, guid):
         """ Check if the connection with the guid in parameter is possible. Only meaningful connections are allowed.
 
@@ -106,41 +112,57 @@ class OMFWifiInterface(ResourceManager):
         self.debug(msg)
         return False
 
+    @property
+    def node(self):
+        rm_list = self.get_connected(OMFNode.rtype())
+        if rm_list: return rm_list[0]
+        return None
+
     def deploy(self):
         """Deploy the RM. It means : Get the xmpp client and send messages using OMF 5.4 protocol to configure the interface
            It becomes DEPLOYED after sending messages to configure the interface
         """
         if not self._omf_api :
             self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'), 
-                self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
-
-        if self.get('mode') and self.get('type') and self.get('essid') and self.get('ip'):
-            self.debug(" " + self.rtype() + " ( Guid : " + str(self._guid) +") : " + \
-                self.get('mode') + " : " + self.get('type') + " : " + \
-                self.get('essid') + " : " + self.get('ip'))
-            rm_list = self.get_connected(OMFNode.rtype()) 
-            for rm_node in rm_list:
-                if rm_node.state < ResourceState.READY:
-                    self.ec.schedule(reschedule_delay, self.deploy)
-                    return 
-                if rm_node.get('hostname') :
-                    try :
-                        for attrname in ["mode", "type", "essid", "ip"]:
-                            attrval = self.get(attrname)
-                            attrname = "net/%s/%s" % (self._alias, attrname)
-                            #print "Send the configure message"
-                            self._omf_api.configure(rm_node.get('hostname'), attrname, attrval)
-                    except AttributeError:
-                        self._state = ResourceState.FAILED
-                        msg = "Credentials are not initialzed. XMPP Connections impossible"
-                        self.debug(msg)
-                        raise
-                else :
-                    msg = "The channel is connected with an undefined node"
-                    self.error(msg)
-        else :
+                self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'), exp_id = self.exp_id)
+
+        if not self._omf_api :
+            self._state = ResourceState.FAILED
+            msg = "Credentials are not initialzed. XMPP Connections impossible"
+            self.error(msg)
+            return
+
+        if not (self.get('mode') and self.get('type') and self.get('essid') and self.get('ip')):
+            self._state = ResourceState.FAILED
             msg = "Interface's variable are not initialized"
             self.error(msg)
+            return False
+
+        if not self.node.get('hostname') :
+            msg = "The channel is connected with an undefined node"
+            self.error(msg)
+            return False
+
+        # Just for information
+        self.debug(" " + self.rtype() + " ( Guid : " + str(self._guid) +") : " + \
+            self.get('mode') + " : " + self.get('type') + " : " + \
+            self.get('essid') + " : " + self.get('ip'))
+    
+        # Check if the node is already deployed
+        if self.node.state < ResourceState.READY:
+            self.ec.schedule(reschedule_delay, self.deploy)
+            return
+
+        try :
+            for attrname in ["mode", "type", "essid", "ip"]:
+                attrval = self.get(attrname)
+                attrname = "net/%s/%s" % (self._alias, attrname)
+                self._omf_api.configure(self.node.get('hostname'), attrname, attrval)
+        except AttributeError:
+            self._state = ResourceState.FAILED
+            msg = "Credentials are not initialzed. XMPP Connections impossible"
+            self.debug(msg)
+            #raise
 
         super(OMFWifiInterface, self).deploy()
 
@@ -165,5 +187,7 @@ class OMFWifiInterface(ResourceManager):
         """
         if self._omf_api :
             OMFAPIFactory.release_api(self.get('xmppSlice'), 
-                self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
+                self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'), exp_id = self.exp_id)
+
+        super(OMFWifiInterface, self).release()
 
index fad525b..612fa38 100644 (file)
@@ -101,6 +101,12 @@ class OMFNode(ResourceManager):
 
         self._omf_api = None 
 
+    @property
+    def exp_id(self):
+        if self.ec.exp_id.startswith('exp-'):
+            return None
+        return self.ec.exp_id
+
     def valid_connection(self, guid):
         """Check if the connection with the guid in parameter is possible. Only meaningful connections are allowed.
 
@@ -125,16 +131,27 @@ class OMFNode(ResourceManager):
         """ 
         if not self._omf_api :
             self._omf_api = OMFAPIFactory.get_api(self.get('xmppSlice'), 
-               self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
+                self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'), exp_id = self.exp_id)
 
-        if self.get('hostname') :
-            try:
-                self._omf_api.enroll_host(self.get('hostname'))
-            except AttributeError:
-                self._state = ResourceState.FAILED
-                msg = "Credentials are not initialzed. XMPP Connections impossible"
-                self.debug(msg)
-                raise AttributeError, msg
+        if not self._omf_api :
+            self._state = ResourceState.FAILED
+            msg = "Credentials are not initialzed. XMPP Connections impossible"
+            self.error(msg)
+            return
+
+        if not self.get('hostname') :
+            self._state = ResourceState.FAILED
+            msg = "Hostname's value is not initialized"
+            self.error(msg)
+            return False
+
+        try:
+            self._omf_api.enroll_host(self.get('hostname'))
+        except AttributeError:
+            self._state = ResourceState.FAILED
+            msg = "Credentials are not initialzed. XMPP Connections impossible"
+            self.debug(msg)
+            #raise AttributeError, msg
 
         super(OMFNode, self).deploy()
 
@@ -172,5 +189,7 @@ class OMFNode(ResourceManager):
         if self._omf_api :
             self._omf_api.release(self.get('hostname'))
             OMFAPIFactory.release_api(self.get('xmppSlice'), 
-                self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'))
+                self.get('xmppHost'), self.get('xmppPort'), self.get('xmppPassword'), exp_id = self.exp_id)
+
+        super(OMFNode, self).release()
 
index 7d96cfb..b4b01c5 100644 (file)
@@ -51,7 +51,7 @@ class OMFAPI(Logger):
        This class is the implementation of an OMF 5.4 API. Since the version 5.4.1, the Topic Architecture start with OMF_5.4 instead of OMF used for OMF5.3
 
     """
-    def __init__(self, slice, host, port, password, xmpp_root = None):
+    def __init__(self, slice, host, port, password, xmpp_root = None, exp_id = None):
         """
     
         :param slice: Xmpp Slice
@@ -67,11 +67,11 @@ class OMFAPI(Logger):
 
         """
         super(OMFAPI, self).__init__("OMFAPI")
-        
         date = tsformat()
         tz = -time.altzone if time.daylight != 0 else -time.timezone
         date += "%+06.2f" % (tz / 3600) # timezone difference is in seconds
-        self._user = "%s-%s" % (slice, date)
+        self._exp_id = exp_id or date
+        self._user = "%s-%s" % (slice, self._exp_id)
         self._slice = slice
         self._host = host
         self._port = port
@@ -304,7 +304,7 @@ class OMFAPIFactory(object):
     _apis = dict()
 
     @classmethod 
-    def get_api(cls, slice, host, port, password):
+    def get_api(cls, slice, host, port, password, exp_id = None):
         """ Get an OMF Api
 
         :param slice: Xmpp Slice Name
@@ -318,7 +318,7 @@ class OMFAPIFactory(object):
 
         """
         if slice and host and port and password:
-            key = cls._make_key(slice, host, port, password)
+            key = cls._make_key(slice, host, port, password, exp_id)
             cls.lock.acquire()
             if key in cls._apis:
                 #print "Api Counter : " + str(cls._apis[key]['cnt'])
@@ -326,13 +326,13 @@ class OMFAPIFactory(object):
                 cls.lock.release()
                 return cls._apis[key]['api']
             else :
-                omf_api = cls.create_api(slice, host, port, password)
+                omf_api = cls.create_api(slice, host, port, password, exp_id)
                 cls.lock.release()
                 return omf_api
         return None
 
     @classmethod 
-    def create_api(cls, slice, host, port, password):
+    def create_api(cls, slice, host, port, password, exp_id):
         """ Create an OMF API if this one doesn't exist yet with this credentials
 
         :param slice: Xmpp Slice Name
@@ -345,15 +345,15 @@ class OMFAPIFactory(object):
         :type password: str
 
         """
-        omf_api = OMFAPI(slice, host, port, password)
-        key = cls._make_key(slice, host, port, password)
+        omf_api = OMFAPI(slice, host, port, password, exp_id = exp_id)
+        key = cls._make_key(slice, host, port, password, exp_id)
         cls._apis[key] = {}
         cls._apis[key]['api'] = omf_api
         cls._apis[key]['cnt'] = 1
         return omf_api
 
     @classmethod 
-    def release_api(cls, slice, host, port, password):
+    def release_api(cls, slice, host, port, password, exp_id = None):
         """ Release an OMF API with this credentials
 
         :param slice: Xmpp Slice Name
@@ -367,7 +367,7 @@ class OMFAPIFactory(object):
 
         """
         if slice and host and port and password:
-            key = cls._make_key(slice, host, port, password)
+            key = cls._make_key(slice, host, port, password, exp_id)
             if key in cls._apis:
                 cls._apis[key]['cnt'] -= 1
                 #print "Api Counter : " + str(cls._apis[key]['cnt'])
index 0193898..a86af14 100755 (executable)
@@ -28,8 +28,6 @@ from nepi.resources.omf.interface import OMFWifiInterface
 from nepi.resources.omf.channel import OMFChannel
 from nepi.resources.omf.omf_api import OMFAPIFactory
 
-from nepi.util.timefuncs import tdiffsec
-
 from nepi.util.timefuncs import *
 
 import time
@@ -45,10 +43,6 @@ class DummyRM(ResourceManager):
 class OMFResourceFactoryTestCase(unittest.TestCase):
 
     def test_creation_phase(self):
-        ResourceFactory.register_type(OMFNode)
-        ResourceFactory.register_type(OMFWifiInterface)
-        ResourceFactory.register_type(OMFChannel)
-        ResourceFactory.register_type(OMFApplication)
 
         self.assertEquals(OMFNode.rtype(), "OMFNode")
         self.assertEquals(len(OMFNode._attributes), 11)
@@ -62,17 +56,11 @@ class OMFResourceFactoryTestCase(unittest.TestCase):
         self.assertEquals(OMFApplication.rtype(), "OMFApplication")
         self.assertEquals(len(OMFApplication._attributes), 8)
 
-        self.assertEquals(len(ResourceFactory.resource_types()), 4)
-
 
-class OMFVLCTestCase(unittest.TestCase):
+class OMFEachTestCase(unittest.TestCase):
 
     def setUp(self):
-        self.ec = DummyEC()
-        ResourceFactory.register_type(OMFNode)
-        ResourceFactory.register_type(OMFWifiInterface)
-        ResourceFactory.register_type(OMFChannel)
-        ResourceFactory.register_type(OMFApplication)
+        self.ec = DummyEC(exp_id = "99999")
 
         self.node1 = self.ec.register_resource("OMFNode")
         self.ec.set(self.node1, 'hostname', 'omf.plexus.wlab17')
@@ -80,8 +68,6 @@ class OMFVLCTestCase(unittest.TestCase):
         self.ec.set(self.node1, 'xmppHost', "xmpp-plexus.onelab.eu")
         self.ec.set(self.node1, 'xmppPort', "5222")
         self.ec.set(self.node1, 'xmppPassword', "1234")
-
-        self.node2 = self.ec.register_resource("OMFNode")
         
         self.iface1 = self.ec.register_resource("OMFWifiInterface")
         self.ec.set(self.iface1, 'alias', "w0")
@@ -93,8 +79,6 @@ class OMFVLCTestCase(unittest.TestCase):
         self.ec.set(self.iface1, 'xmppHost', "xmpp-plexus.onelab.eu")
         self.ec.set(self.iface1, 'xmppPort', "5222")
         self.ec.set(self.iface1, 'xmppPassword', "1234")
-
-        self.iface2 = self.ec.register_resource("OMFWifiInterface")
         
         self.channel = self.ec.register_resource("OMFChannel")
         self.ec.set(self.channel, 'channel', "6")
@@ -114,28 +98,10 @@ class OMFVLCTestCase(unittest.TestCase):
         self.ec.set(self.app1, 'xmppPassword', "1234")
 
         self.app2 = self.ec.register_resource("OMFApplication")
-        self.ec.set(self.app2, 'xmppSlice', "nepi")
-        self.ec.set(self.app2, 'xmppHost', "xmpp-plexus.onelab.eu")
-        self.ec.set(self.app2, 'xmppPort', "5222")
-        self.ec.set(self.app2, 'xmppPassword', "1234")
 
         self.app3 = self.ec.register_resource("OMFApplication")
-        self.ec.set(self.app3, 'appid', 'Kill#2')
-        self.ec.set(self.app3, 'path', "/usr/bin/killall")
-        self.ec.set(self.app3, 'args', "vlc")
-        self.ec.set(self.app3, 'env', " ")
-
         self.app4 = self.ec.register_resource("OMFApplication")
-
         self.app5 = self.ec.register_resource("OMFApplication")
-        self.ec.set(self.app5, 'appid', 'Kill#2')
-        self.ec.set(self.app5, 'path', "/usr/bin/killall")
-        self.ec.set(self.app5, 'args', "vlc")
-        self.ec.set(self.app5, 'env', " ")
-        self.ec.set(self.app5, 'xmppSlice', "nepi")
-        self.ec.set(self.app5, 'xmppHost', "xmpp-plexus.onelab.eu")
-        self.ec.set(self.app5, 'xmppPort', "5222")
-        self.ec.set(self.app5, 'xmppPassword', "1234")
 
         self.ec.register_connection(self.app1, self.node1)
         self.ec.register_connection(self.app2, self.node1)
@@ -144,8 +110,6 @@ class OMFVLCTestCase(unittest.TestCase):
         self.ec.register_connection(self.app5, self.node1)
         self.ec.register_connection(self.node1, self.iface1)
         self.ec.register_connection(self.iface1, self.channel)
-        self.ec.register_connection(self.node2, self.iface2)
-        self.ec.register_connection(self.iface2, self.channel)
 
         self.ec.register_condition(self.app2, ResourceAction.START, self.app1, ResourceState.STARTED , "3s")
         self.ec.register_condition(self.app3, ResourceAction.START, self.app2, ResourceState.STARTED , "2s")
@@ -153,8 +117,7 @@ class OMFVLCTestCase(unittest.TestCase):
         self.ec.register_condition(self.app5, ResourceAction.START, [self.app3, self.app2], ResourceState.STARTED , "2s")
         self.ec.register_condition(self.app5, ResourceAction.START, self.app1, ResourceState.STARTED , "25s")
 
-        self.ec.register_condition([self.app1, self.app2, self.app3,self.app4, self.app5], 
-                ResourceAction.STOP, self.app5, ResourceState.STARTED , "1s")
+        self.ec.register_condition([self.app1, self.app2, self.app3,self.app4, self.app5], ResourceAction.STOP, self.app5, ResourceState.STARTED , "1s")
 
     def tearDown(self):
         self.ec.shutdown()
@@ -197,7 +160,7 @@ class OMFVLCTestCase(unittest.TestCase):
     def test_connection(self):
         self.assertEquals(len(self.ec.get_resource(self.node1).connections), 6)
         self.assertEquals(len(self.ec.get_resource(self.iface1).connections), 2)
-        self.assertEquals(len(self.ec.get_resource(self.channel).connections), 2)
+        self.assertEquals(len(self.ec.get_resource(self.channel).connections), 1)
         self.assertEquals(len(self.ec.get_resource(self.app1).connections), 1)
         self.assertEquals(len(self.ec.get_resource(self.app2).connections), 1)
 
@@ -208,29 +171,239 @@ class OMFVLCTestCase(unittest.TestCase):
         self.assertEquals(len(self.ec.get_resource(self.app4).conditions[ResourceAction.STOP]), 1)
         self.assertEquals(len(self.ec.get_resource(self.app5).conditions[ResourceAction.START]), 2)
 
+
+
+class OMFVLCTestCaseComplete(unittest.TestCase):
+
     def test_deploy(self):
+        ec = DummyEC(exp_id = "5421" )
+
+        self.node1 = ec.register_resource("OMFNode")
+        ec.set(self.node1, 'hostname', 'omf.plexus.wlab17')
+        ec.set(self.node1, 'xmppSlice', "nepi")
+        ec.set(self.node1, 'xmppHost', "xmpp-plexus.onelab.eu")
+        ec.set(self.node1, 'xmppPort', "5222")
+        ec.set(self.node1, 'xmppPassword', "1234")
+        
+        self.iface1 = ec.register_resource("OMFWifiInterface")
+        ec.set(self.iface1, 'alias', "w0")
+        ec.set(self.iface1, 'mode', "adhoc")
+        ec.set(self.iface1, 'type', "g")
+        ec.set(self.iface1, 'essid', "vlcexp")
+        ec.set(self.iface1, 'ip', "10.0.0.17")
+        ec.set(self.iface1, 'xmppSlice', "nepi")
+        ec.set(self.iface1, 'xmppHost', "xmpp-plexus.onelab.eu")
+        ec.set(self.iface1, 'xmppPort', "5222")
+        ec.set(self.iface1, 'xmppPassword', "1234")
         
-        self.ec.deploy()
-
-        self.ec.wait_finished([self.app1, self.app2, self.app3,self.app4, self.app5])
-
-        print " HOLA ", self.ec.get_resource(self.app2).start_time, self.ec.get_resource(self.app1).start_time
-
-        self.assertEquals(round(tdiffsec(self.ec.get_resource(self.app2).start_time, 
-            self.ec.get_resource(self.app1).start_time),1), 3.0)
-        self.assertEquals(round(tdiffsec(self.ec.get_resource(self.app3).start_time, 
-            self.ec.get_resource(self.app2).start_time),1), 2.0)
-        self.assertEquals(round(tdiffsec(self.ec.get_resource(self.app4).start_time, 
-            self.ec.get_resource(self.app3).start_time),1), 3.0)
-        self.assertEquals(round(tdiffsec(self.ec.get_resource(self.app5).start_time, 
-            self.ec.get_resource(self.app3).start_time),1), 20.0)
-        self.assertEquals(round(tdiffsec(self.ec.get_resource(self.app5).start_time, 
-            self.ec.get_resource(self.app1).start_time),1), 25.0)
-        # Precision is at 1/10. So this one returns an error 7.03 != 7.0
-        #self.assertEquals(tdiffsec(self.ec.get_resource(self.app5).start_time, self.ec.get_resource(self.app1).start_time), 7)
-        #In order to release everythings
+        self.channel = ec.register_resource("OMFChannel")
+        ec.set(self.channel, 'channel', "6")
+        ec.set(self.channel, 'xmppSlice', "nepi")
+        ec.set(self.channel, 'xmppHost', "xmpp-plexus.onelab.eu")
+        ec.set(self.channel, 'xmppPort', "5222")
+        ec.set(self.channel, 'xmppPassword', "1234")
+        
+        self.app1 = ec.register_resource("OMFApplication")
+        ec.set(self.app1, 'appid', 'Vlc#1')
+        ec.set(self.app1, 'path', "/opt/vlc-1.1.13/cvlc")
+        ec.set(self.app1, 'args', "/opt/10-by-p0d.avi --sout '#rtp{dst=10.0.0.37,port=1234,mux=ts}'")
+        ec.set(self.app1, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
+        ec.set(self.app1, 'xmppSlice', "nepi")
+        ec.set(self.app1, 'xmppHost', "xmpp-plexus.onelab.eu")
+        ec.set(self.app1, 'xmppPort', "5222")
+        ec.set(self.app1, 'xmppPassword', "1234")
+
+        self.app2 = ec.register_resource("OMFApplication")
+        ec.set(self.app2, 'appid', 'Test#1')
+        ec.set(self.app2, 'path', "/usr/bin/test")
+        ec.set(self.app2, 'args', "-1")
+        ec.set(self.app2, 'env', " ")
+        ec.set(self.app2, 'xmppSlice', "nepi")
+        ec.set(self.app2, 'xmppHost', "xmpp-plexus.onelab.eu")
+        ec.set(self.app2, 'xmppPort', "5222")
+        ec.set(self.app2, 'xmppPassword', "1234")
+
+        self.app3 = ec.register_resource("OMFApplication")
+        ec.set(self.app3, 'appid', 'Test#2')
+        ec.set(self.app3, 'path', "/usr/bin/test")
+        ec.set(self.app3, 'args', "-2")
+        ec.set(self.app3, 'env', " ")
+        ec.set(self.app3, 'xmppSlice', "nepi")
+        ec.set(self.app3, 'xmppHost', "xmpp-plexus.onelab.eu")
+        ec.set(self.app3, 'xmppPort', "5222")
+        ec.set(self.app3, 'xmppPassword', "1234")
+
+        self.app4 = ec.register_resource("OMFApplication")
+        ec.set(self.app4, 'appid', 'Test#3')
+        ec.set(self.app4, 'path', "/usr/bin/test")
+        ec.set(self.app4, 'args', "-3")
+        ec.set(self.app4, 'env', " ")
+        ec.set(self.app4, 'xmppSlice', "nepi")
+        ec.set(self.app4, 'xmppHost', "xmpp-plexus.onelab.eu")
+        ec.set(self.app4, 'xmppPort', "5222")
+        ec.set(self.app4, 'xmppPassword', "1234")
+
+        self.app5 = ec.register_resource("OMFApplication")
+        ec.set(self.app5, 'appid', 'Kill#2')
+        ec.set(self.app5, 'path', "/usr/bin/killall")
+        ec.set(self.app5, 'args', "vlc")
+        ec.set(self.app5, 'env', " ")
+        ec.set(self.app5, 'xmppSlice', "nepi")
+        ec.set(self.app5, 'xmppHost', "xmpp-plexus.onelab.eu")
+        ec.set(self.app5, 'xmppPort', "5222")
+        ec.set(self.app5, 'xmppPassword', "1234")
+
+        ec.register_connection(self.app1, self.node1)
+        ec.register_connection(self.app2, self.node1)
+        ec.register_connection(self.app3, self.node1)
+        ec.register_connection(self.app4, self.node1)
+        ec.register_connection(self.app5, self.node1)
+        ec.register_connection(self.node1, self.iface1)
+        ec.register_connection(self.iface1, self.channel)
+
+        ec.register_condition(self.app2, ResourceAction.START, self.app1, ResourceState.STARTED , "3s")
+        ec.register_condition(self.app3, ResourceAction.START, self.app2, ResourceState.STARTED , "2s")
+        ec.register_condition(self.app4, ResourceAction.START, self.app3, ResourceState.STARTED , "3s")
+        ec.register_condition(self.app5, ResourceAction.START, [self.app3, self.app2], ResourceState.STARTED , "2s")
+        ec.register_condition(self.app5, ResourceAction.START, self.app1, ResourceState.STARTED , "25s")
+
+        ec.register_condition([self.app1, self.app2, self.app3,self.app4, self.app5], ResourceAction.STOP, self.app5, ResourceState.STARTED , "1s")
+
+        ec.deploy()
+
+        ec.wait_finished([self.app1, self.app2, self.app3,self.app4, self.app5])
+
+        time.sleep(2)
+
+        self.assertEquals(round(tdiffsec(ec.get_resource(self.app2).start_time, ec.get_resource(self.app1).start_time),0), 3.0)
+        self.assertEquals(round(tdiffsec(ec.get_resource(self.app3).start_time, ec.get_resource(self.app2).start_time),0), 2.0)
+        self.assertEquals(round(tdiffsec(ec.get_resource(self.app4).start_time, ec.get_resource(self.app3).start_time),0), 3.0)
+        self.assertEquals(round(tdiffsec(ec.get_resource(self.app5).start_time, ec.get_resource(self.app3).start_time),0), 20.0)
+        self.assertEquals(round(tdiffsec(ec.get_resource(self.app5).start_time, ec.get_resource(self.app1).start_time),0), 25.0)
+
+        self.assertEquals(ec.get_resource(self.node1).state, ResourceState.STARTED)
+        self.assertEquals(ec.get_resource(self.iface1).state, ResourceState.STARTED)
+        self.assertEquals(ec.get_resource(self.channel).state, ResourceState.STARTED)
+        self.assertEquals(ec.get_resource(self.app1).state, ResourceState.FINISHED)
+        self.assertEquals(ec.get_resource(self.app2).state, ResourceState.FINISHED)
+        self.assertEquals(ec.get_resource(self.app3).state, ResourceState.FINISHED)
+        self.assertEquals(ec.get_resource(self.app4).state, ResourceState.FINISHED)
+        self.assertEquals(ec.get_resource(self.app5).state, ResourceState.FINISHED)
+
+        ec.shutdown()
+        time.sleep(2)
+
+        self.assertEquals(ec.get_resource(self.node1).state, ResourceState.RELEASED)
+        self.assertEquals(ec.get_resource(self.iface1).state, ResourceState.RELEASED)
+        self.assertEquals(ec.get_resource(self.channel).state, ResourceState.RELEASED)
+        self.assertEquals(ec.get_resource(self.app1).state, ResourceState.RELEASED)
+        self.assertEquals(ec.get_resource(self.app2).state, ResourceState.RELEASED)
+        self.assertEquals(ec.get_resource(self.app3).state, ResourceState.RELEASED)
+        self.assertEquals(ec.get_resource(self.app4).state, ResourceState.RELEASED)
+        self.assertEquals(ec.get_resource(self.app5).state, ResourceState.RELEASED)
+
+
+
+class OMFVLCTestCaseNoComplete(unittest.TestCase):
+    def test_deploy(self):
+
+        ec = DummyEC(exp_id = "1245" )
+
+        self.node1 = ec.register_resource("OMFNode")
+        ec.set(self.node1, 'hostname', 'omf.plexus.wlab17')
+        ec.set(self.node1, 'xmppSlice', "nepi")
+        ec.set(self.node1, 'xmppHost', "xmpp-plexus.onelab.eu")
+        ec.set(self.node1, 'xmppPort', "5222")
+        ec.set(self.node1, 'xmppPassword', "1234")
+
+        self.node2 = ec.register_resource("OMFNode")
+        
+        self.iface1 = ec.register_resource("OMFWifiInterface")
+        ec.set(self.iface1, 'alias', "w0")
+        ec.set(self.iface1, 'mode', "adhoc")
+        ec.set(self.iface1, 'type', "g")
+        ec.set(self.iface1, 'essid', "vlcexp")
+        ec.set(self.iface1, 'ip', "10.0.0.17")
+        ec.set(self.iface1, 'xmppSlice', "nepi")
+        ec.set(self.iface1, 'xmppHost', "xmpp-plexus.onelab.eu")
+        ec.set(self.iface1, 'xmppPort', "5222")
+        ec.set(self.iface1, 'xmppPassword', "1234")
+
+        self.iface2 = ec.register_resource("OMFWifiInterface")
+        
+        self.channel = ec.register_resource("OMFChannel")
+        ec.set(self.channel, 'channel', "6")
+        ec.set(self.channel, 'xmppSlice', "nepi")
+        ec.set(self.channel, 'xmppHost', "xmpp-plexus.onelab.eu")
+        ec.set(self.channel, 'xmppPort', "5222")
+        ec.set(self.channel, 'xmppPassword', "1234")
+        
+        self.app1 = ec.register_resource("OMFApplication")
+        ec.set(self.app1, 'appid', 'Vlc#1')
+        ec.set(self.app1, 'path', "/opt/vlc-1.1.13/cvlc")
+        ec.set(self.app1, 'args', "/opt/10-by-p0d.avi --sout '#rtp{dst=10.0.0.37,port=1234,mux=ts}'")
+        ec.set(self.app1, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
+        ec.set(self.app1, 'xmppSlice', "nepi")
+        ec.set(self.app1, 'xmppHost', "xmpp-plexus.onelab.eu")
+        ec.set(self.app1, 'xmppPort', "5222")
+        ec.set(self.app1, 'xmppPassword', "1234")
+
+        self.app2 = ec.register_resource("OMFApplication")
+        ec.set(self.app2, 'xmppSlice', "nepi")
+        ec.set(self.app2, 'xmppHost', "xmpp-plexus.onelab.eu")
+        ec.set(self.app2, 'xmppPort', "5222")
+        ec.set(self.app2, 'xmppPassword', "1234")
+
+        self.app3 = ec.register_resource("OMFApplication")
+        ec.set(self.app3, 'appid', 'Kill#2')
+        ec.set(self.app3, 'path', "/usr/bin/killall")
+        ec.set(self.app3, 'args', "vlc")
+        ec.set(self.app3, 'env', " ")
+
+        self.app4 = ec.register_resource("OMFApplication")
+
+        ec.register_connection(self.app1, self.node1)
+        ec.register_connection(self.app2, self.node1)
+        ec.register_connection(self.app3, self.node1)
+        ec.register_connection(self.app4, self.node1)
+        ec.register_connection(self.node1, self.iface1)
+        ec.register_connection(self.iface1, self.channel)
+        ec.register_connection(self.node2, self.iface2)
+        ec.register_connection(self.iface2, self.channel)
+
+        ec.register_condition(self.app2, ResourceAction.START, self.app1, ResourceState.STARTED , "2s")
+        ec.register_condition(self.app3, ResourceAction.START, self.app2, ResourceState.STARTED , "2s")
+        ec.register_condition(self.app4, ResourceAction.START, [self.app3, self.app2], ResourceState.STARTED , "2s")
+
+        ec.register_condition([self.app1, self.app2, self.app3], ResourceAction.STOP, self.app1, ResourceState.STARTED , "8s")
+
+        ec.deploy()
+
+        ec.wait_finished([self.app1, self.app2, self.app3,self.app4])
+
+        self.assertEquals(ec.get_resource(self.node1).state, ResourceState.STARTED)
+        self.assertEquals(ec.get_resource(self.node2).state, ResourceState.FAILED)
+        self.assertEquals(ec.get_resource(self.iface1).state, ResourceState.STARTED)
+        self.assertEquals(ec.get_resource(self.iface2).state, ResourceState.FAILED)
+        self.assertEquals(ec.get_resource(self.channel).state, ResourceState.STARTED)
+        self.assertEquals(ec.get_resource(self.app1).state, ResourceState.FINISHED)
+        self.assertEquals(ec.get_resource(self.app2).state, ResourceState.FAILED)
+        self.assertEquals(ec.get_resource(self.app3).state, ResourceState.FAILED)
+        self.assertEquals(ec.get_resource(self.app4).state, ResourceState.FAILED)
+
         time.sleep(1)
 
+        ec.shutdown()
+
+        self.assertEquals(ec.get_resource(self.node1).state, ResourceState.RELEASED)
+        self.assertEquals(ec.get_resource(self.node2).state, ResourceState.RELEASED)
+        self.assertEquals(ec.get_resource(self.iface1).state, ResourceState.RELEASED)
+        self.assertEquals(ec.get_resource(self.iface2).state, ResourceState.RELEASED)
+        self.assertEquals(ec.get_resource(self.channel).state, ResourceState.RELEASED)
+        self.assertEquals(ec.get_resource(self.app1).state, ResourceState.RELEASED)
+        self.assertEquals(ec.get_resource(self.app2).state, ResourceState.RELEASED)
+        self.assertEquals(ec.get_resource(self.app3).state, ResourceState.RELEASED)
+        self.assertEquals(ec.get_resource(self.app4).state, ResourceState.RELEASED)
 
 if __name__ == '__main__':
     unittest.main()