Fixing RM.DEPLOY being executed after/during RM.RELEASE by adding a release_lock...
[nepi.git] / src / nepi / resources / planetlab / openvswitch / tunnel.py
index 72c6728..8ae7393 100644 (file)
@@ -19,7 +19,8 @@
 #            Alexandros Kouvakas <alexandros.kouvakas@gmail.com>
 
 from nepi.execution.attribute import Attribute, Flags, Types
-from nepi.execution.resource import ResourceManager, clsinit_copy, ResourceState 
+from nepi.execution.resource import ResourceManager, clsinit_copy, \
+        ResourceState
 from nepi.resources.linux.application import LinuxApplication
 from nepi.resources.planetlab.node import PlanetlabNode            
 from nepi.resources.planetlab.openvswitch.ovs import OVSWitch   
@@ -29,11 +30,10 @@ import os
 import time
 import socket
 
-
 reschedule_delay = "0.5s"
 
 @clsinit_copy                 
-class Tunnel(LinuxApplication):
+class OVSTunnel(LinuxApplication):
     """
     .. class:: Class Args :
       
@@ -46,7 +46,7 @@ class Tunnel(LinuxApplication):
 
     """
     
-    _rtype = "Tunnel"
+    _rtype = "OVSTunnel"
     _authorized_connections = ["OVSPort", "PlanetlabTap"]    
 
     @classmethod
@@ -93,7 +93,7 @@ class Tunnel(LinuxApplication):
         :type guid: int
     
         """
-        super(Tunnel, self).__init__(ec, guid)
+        super(OVSTunnel, self).__init__(ec, guid)
         self._home = "tunnel-%s" % self.guid
         self.port_info_tunl = []
         self._nodes = []
@@ -243,9 +243,9 @@ class Tunnel(LinuxApplication):
         msg = "Failed to connect endpoints"
 
         if proc.poll():
-            self.fail()
             self.error(msg, out, err)
             raise RuntimeError, msg
+
         msg = "Connection on host %s configured" \
             % self.node.get("hostname")
         self.info(msg)
@@ -260,7 +260,6 @@ class Tunnel(LinuxApplication):
             (out, err), proc = self.node.check_errors(self.run_home(self.node))
             # Out is what was written in the stderr file
             if err:
-                self.fail()
                 msg = " Failed to start command '%s' " % command
                 self.error(msg, out, err)
                 raise RuntimeError, msg
@@ -295,7 +294,6 @@ class Tunnel(LinuxApplication):
         msg = "Failed to connect endpoints"
 
         if proc.poll():
-            self.fail()
             self.error(msg, out, err)
             raise RuntimeError, msg
         else:
@@ -336,7 +334,6 @@ class Tunnel(LinuxApplication):
         msg = "Failed to connect endpoints"
 
         if proc.poll():
-            self.fail()
             self.error(msg, out, err)
             raise RuntimeError, msg
         else:
@@ -344,7 +341,7 @@ class Tunnel(LinuxApplication):
             self.info(msg)
             return                                                      
 
-    def provision(self):
+    def do_provision(self):
         """ Provision the tunnel
         """
         # Create folders
@@ -363,46 +360,19 @@ class Tunnel(LinuxApplication):
             (self._pid, self._ppid) = self.udp_connect(self.endpoint2, self.endpoint1)
             switch_connect = self.sw_host_connect(self.endpoint1, self.endpoint2)
 
-        self.debug("------- READY -------")
-        self._provision_time = tnow()
-        self._state = ResourceState.PROVISIONED
-
-    def discover(self):
-        """ Discover the tunnel
+        super(OVSTunnel, self).do_provision()
 
-        """    
-        pass
-
-    def deploy(self):
+    def do_deploy(self):
         if (not self.endpoint1 or self.endpoint1.state < ResourceState.READY) or \
             (not self.endpoint2 or self.endpoint2.state < ResourceState.READY):
             self.ec.schedule(reschedule_delay, self.deploy)
         else:
-            try:
-                self.discover()
-                self.provision()
-            except:
-                self.fail()
-                raise
-            self.debug("----- READY ---- ")
-            self._ready_time = tnow()
-            self._state = ResourceState.READY
+            self.do_discover()
+            self.do_provision()
 
-    def start(self):
-        """ Start the RM. It means nothing special for 
-            ovsport for now.
-        """
-        pass
-        
-       
-    def stop(self):
-        """ Stop the RM. It means nothing special for 
-            ovsport for now.        
-        """
-        pass
-
-    def release(self):
+            super(OVSTunnel, self).do_deploy()
+    def do_release(self):
         """ Release the udp_tunnel on endpoint2.
             On endpoint1 means nothing special.        
         """
@@ -417,14 +387,6 @@ class Tunnel(LinuxApplication):
                     # check if execution errors occurred
                     msg = " Failed to delete TAP device"
                     self.error(msg, err, err)
-                    self.fail()
-            
-        self._state = ResourceState.RELEASED
-
-
-
-
-
-
 
+        super(OVSTunnel, self).do_release()