gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r22784 - in gnunet-planetlab/gplmt: . contrib


From: gnunet
Subject: [GNUnet-SVN] r22784 - in gnunet-planetlab/gplmt: . contrib
Date: Fri, 20 Jul 2012 11:55:51 +0200

Author: wachs
Date: 2012-07-20 11:55:51 +0200 (Fri, 20 Jul 2012)
New Revision: 22784

Added:
   gnunet-planetlab/gplmt/contrib/sftp_tasks.xml
   gnunet-planetlab/gplmt/contrib/test.file
Modified:
   gnunet-planetlab/gplmt/Notifications.py
   gnunet-planetlab/gplmt/Tasks.py
   gnunet-planetlab/gplmt/Worker.py
   gnunet-planetlab/gplmt/contrib/test.conf
Log:
- sftp get and put operations

Modified: gnunet-planetlab/gplmt/Notifications.py
===================================================================
--- gnunet-planetlab/gplmt/Notifications.py     2012-07-20 09:02:31 UTC (rev 
22783)
+++ gnunet-planetlab/gplmt/Notifications.py     2012-07-20 09:55:51 UTC (rev 
22784)
@@ -66,5 +66,7 @@
     def task_completed (self, node, task, result):
         if (result == Tasks.Taskresult.success):
             print node + " : Task '" +  task.name + "' completed successfully"
+        elif (result == Tasks.Taskresult.src_file_not_found):
+            print node + " : Task '" +  task.name + "' failed : source file 
not found"
         else:
             print node + " : Task '" +  task.name + "' completed with failure" 
            
\ No newline at end of file

Modified: gnunet-planetlab/gplmt/Tasks.py
===================================================================
--- gnunet-planetlab/gplmt/Tasks.py     2012-07-20 09:02:31 UTC (rev 22783)
+++ gnunet-planetlab/gplmt/Tasks.py     2012-07-20 09:55:51 UTC (rev 22784)
@@ -32,10 +32,13 @@
 supported_operations = ["run", "monitor", "get", "put"]
 
 class Taskresult:
-    success=0
-    timeout=1
-    return_value_did_not_match=2
-    output_did_not_match=3
+    success = 0
+    timeout = 1
+    fail = 2 
+    return_value_did_not_match = 3
+    output_did_not_match = 4
+    src_file_not_found = 5
+    
 
 class Operation:
     none=0
@@ -56,12 +59,26 @@
         self.expected_output = None
         self.stop_on_fail = False
         self.set = None
+        self.src = None
+        self.dest = None
     def log (self):
         glogger.log ("Task " + str(self.id) + ": " + self.name)
     def check (self):
-        if ((self.id == -1) or (self.name == "") or (self.type == 
Operation.none)):
+        if (Operation.none):
             return False
-
+        if (self.type == Operation.run):                   
+            if ((self.id == -1) or (self.name == "") or (self.command == "")):
+                return False
+        if (self.type == Operation.put):                   
+            if ((self.id == -1) or (self.name == "") or 
+                (self.src == None) or (self.dest == None)):
+                return False
+        if (self.type == Operation.get):                   
+            if ((self.id == -1) or (self.name == "") or 
+                (self.src == None) or (self.dest == None)):
+                return False            
+        return True
+                        
 class Taskset:
     def __init__(self):
         self.set = list()
@@ -80,9 +97,9 @@
         t.type = Operation.run
     elif (elem.tag == "monitor"):            
         t.type = Operation.monitor
-    elif (elem.text == "get"):            
+    elif (elem.tag == "get"):            
         t.type = Operation.get
-    elif (elem.text == "put"):            
+    elif (elem.tag == "put"):       
         t.type = Operation.put
     else:
         t.type = Operation.none
@@ -108,10 +125,14 @@
             if (str.upper(child.text) == "TRUE"):
                 t.stop_on_fail = True
             else:
-                t.stop_on_fail = False                
+                t.stop_on_fail = False        
+        if ((child.tag == "source") and (child.text != None)):
+            t.src = child.text
+        if ((child.tag == "destination") and (child.text != None)):
+            t.dest = child.text                
 
     if (False == t.check()):
-        print "Parsing invalid task with id " + str (t.id) + " name " + t.name
+        print "Parsed invalid task with id " + str (t.id) + " name '" + t.name 
+ "'"
         return None 
     else:
         t.log ()

Modified: gnunet-planetlab/gplmt/Worker.py
===================================================================
--- gnunet-planetlab/gplmt/Worker.py    2012-07-20 09:02:31 UTC (rev 22783)
+++ gnunet-planetlab/gplmt/Worker.py    2012-07-20 09:55:51 UTC (rev 22784)
@@ -96,7 +96,41 @@
         else: 
             g_logger.log (self.node + " : Task '"+ task.name + "' failed")
         return result
-               
+    def exec_put (self, task, transport):
+        if (False == os.path.exists (task.src)):
+            return Tasks.Taskresult.src_file_not_found
+            
+        result = Tasks.Taskresult.success
+        try:
+            sftp = paramiko.SFTPClient.from_transport (transport)
+            sftp.put(task.src, task.dest)
+            sftp.close()
+        except paramiko.SSHException as e:
+            g_logger.log (self.node + " : Task '"+ task.name + "' :" + e)
+            result = Tasks.Taskresult.fail
+            pass
+        except (OSError, IOError) as e:
+            g_logger.log (self.node + " : Task '"+ task.name + "' : " + str(e))
+            result = Tasks.Taskresult.src_file_not_found 
+            pass           
+        return result
+            
+    def exec_get (self, task, transport):
+        result = Tasks.Taskresult.success
+        try:
+            sftp = paramiko.SFTPClient.from_transport (transport)
+            sftp.get (task.src, task.dest)
+            sftp.close()
+        except paramiko.SSHException as e:
+            g_logger.log (self.node + " : Task '"+ task.name + "' :" + e)
+            result = Tasks.Taskresult.fail
+            pass
+        except (OSError, IOError) as e:
+            g_logger.log (self.node + " : Task '"+ task.name + "' : " + str(e))
+            result = Tasks.Taskresult.src_file_not_found 
+            pass           
+        return result    
+          
     def run(self):
         g_logger.log (self.node + " : Starting tasklist " + self.tasks.name)
         task = self.tasks.get()
@@ -149,11 +183,13 @@
                     result = self.exec_run (task, transport)
                     g_notifications.task_completed (self.node, task, result)
                 elif (task.type == Tasks.Operation.put):
-                    print "TO IMPLEMENT"
+                    result = self.exec_put (task, transport)
+                    g_notifications.task_completed (self.node, task, result)
                 elif (task.type == Tasks.Operation.get):
-                    print "TO IMPLEMENT"
+                    result = self.exec_get (task, transport)
+                    g_notifications.task_completed (self.node, task, result)
                 else:
-                    print "TO IMPLEMENT"                    
+                    print "FAIL"                    
             elif (task.__class__.__name__ == "Taskset"):
                 g_logger.log (self.node + " : Running task set")
             if ((task.stop_on_fail == True) and (result != 
Tasks.Taskresult.success)):

Added: gnunet-planetlab/gplmt/contrib/sftp_tasks.xml
===================================================================
--- gnunet-planetlab/gplmt/contrib/sftp_tasks.xml                               
(rev 0)
+++ gnunet-planetlab/gplmt/contrib/sftp_tasks.xml       2012-07-20 09:55:51 UTC 
(rev 22784)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<tasklist name="Simple task list" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:noNamespaceSchemaLocation="../tasklist_schema.xsd">
+       <put id="0" name="put testfile">
+               <source>/tmp/test.file</source>
+               <destination>/tmp/put.file</destination>
+       </put> 
+       <get id="1" name="get testfile">
+               <source>/tmp/put.file</source>
+               <destination>/tmp/get.file</destination>
+       </get> 
+</tasklist>

Modified: gnunet-planetlab/gplmt/contrib/test.conf
===================================================================
--- gnunet-planetlab/gplmt/contrib/test.conf    2012-07-20 09:02:31 UTC (rev 
22783)
+++ gnunet-planetlab/gplmt/contrib/test.conf    2012-07-20 09:55:51 UTC (rev 
22784)
@@ -1,7 +1,11 @@
 [gplmt]
-nodes = contrib/current.nodes
+nodes = contrib/localhost.nodes
+#nodes = contrib/current.nodes
+
 #tasks = contrib/tasks.xml
-tasks = contrib/simpletasks.xml
+#tasks = contrib/simpletasks.xml
+tasks = contrib/sftp_tasks.xml
+
 # Which notification mechanism to use: 
 # simple: print messages to stdout
 notification = simple
@@ -9,7 +13,8 @@
 
 
 [planetlab]
-slice = tumple_gnunet_deployment
+slice = mwachs
+#slice = tumple_gnunet_deployment
 
 [ssh]
 # Order of ssh authentication:

Added: gnunet-planetlab/gplmt/contrib/test.file
===================================================================



reply via email to

[Prev in Thread] Current Thread [Next in Thread]