Fixing UdpTunnel unit tests for PlanetLab
[nepi.git] / src / nepi / resources / linux / udptunnel.py
index 4dae96c..01f6898 100644 (file)
@@ -34,7 +34,6 @@ class UdpTunnel(LinuxApplication):
     _help = "Constructs a tunnel between two Linux endpoints using a UDP connection "
     _backend = "linux"
 
-
     @classmethod
     def _register_attributes(cls):
         cipher = Attribute("cipher",
@@ -43,25 +42,25 @@ class UdpTunnel(LinuxApplication):
                 default = None,
                 allowed = ["PLAIN", "AES", "Blowfish", "DES", "DES3"],
                 type = Types.Enumerate, 
-                flags = Flags.ExecReadOnly)
+                flags = Flags.Design)
 
         cipher_key = Attribute("cipherKey",
                 "Specify a symmetric encryption key with which to protect "
                 "packets across the tunnel. python-crypto must be installed "
                 "on the system." ,
-                flags = Flags.ExecReadOnly)
+                flags = Flags.Design)
 
         txqueuelen = Attribute("txQueueLen",
                 "Specifies the interface's transmission queue length. "
                 "Defaults to 1000. ", 
                 type = Types.Integer, 
-                flags = Flags.ExecReadOnly)
+                flags = Flags.Design)
 
         bwlimit = Attribute("bwLimit",
                 "Specifies the interface's emulated bandwidth in bytes "
                 "per second.",
                 type = Types.Integer, 
-                flags = Flags.ExecReadOnly)
+                flags = Flags.Design)
 
         cls._register_attribute(cipher)
         cls._register_attribute(cipher_key)
@@ -161,7 +160,7 @@ class UdpTunnel(LinuxApplication):
         port = self.wait_local_port(endpoint)
         return (port, pid, ppid)
 
-    def provision(self):
+    def do_provision(self):
         # create run dir for tunnel on each node 
         self.endpoint1.node.mkdir(self.run_home(self.endpoint1))
         self.endpoint2.node.mkdir(self.run_home(self.endpoint2))
@@ -190,22 +189,17 @@ class UdpTunnel(LinuxApplication):
  
         self.set_provisioned()
 
-    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()
-                return
+            self.do_discover()
+            self.do_provision()
  
-            self.debug("----- READY ---- ")
             self.set_ready()
 
-    def start(self):
+    def do_start(self):
         if self.state == ResourceState.READY:
             command = self.get("command")
             self.info("Starting command '%s'" % command)
@@ -214,9 +208,9 @@ class UdpTunnel(LinuxApplication):
         else:
             msg = " Failed to execute command '%s'" % command
             self.error(msg, out, err)
-            self.fail()
+            raise RuntimeError, msg
 
-    def stop(self):
+    def do_stop(self):
         """ Stops application execution
         """
         if self.state == ResourceState.STARTED:
@@ -230,12 +224,11 @@ class UdpTunnel(LinuxApplication):
                 (out2, err2), proc2 = self.endpoint2.node.kill(self._pid2, 
                         self._ppid2, sudo = True) 
 
-                if err1 or err2 or proc1.poll() or proc2.poll():
+                if (proc1.poll() and err1) or (proc2.poll() and err2):
                     # check if execution errors occurred
                     msg = " Failed to STOP tunnel"
                     self.error(msg, err1, err2)
-                    self.fail()
-                    return
+                    raise RuntimeError, msg
 
             self.set_stopped()
 
@@ -271,7 +264,7 @@ class UdpTunnel(LinuxApplication):
                             self.error(msg, err1, err2)
                             self.fail()
                         else:
-                            self.set_finished()
+                            self.set_stopped()
 
                 self._last_state_check = tnow()
 
@@ -295,7 +288,7 @@ class UdpTunnel(LinuxApplication):
         result = None
         delay = 1.0
 
-        for i in xrange(4):
+        for i in xrange(20):
             (out, err), proc = endpoint.node.check_output(
                     self.run_home(endpoint), filename)