gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r22775 - in gnunet-planetlab/gplmt: . contrib
Date: Thu, 19 Jul 2012 17:30:01 +0200

Author: wachs
Date: 2012-07-19 17:30:01 +0200 (Thu, 19 Jul 2012)
New Revision: 22775

Modified:
   gnunet-planetlab/gplmt/Notifications.py
   gnunet-planetlab/gplmt/Tasks.py
   gnunet-planetlab/gplmt/Worker.py
   gnunet-planetlab/gplmt/contrib/simpletasks.xml
Log:
- cmd execution with timeout

Modified: gnunet-planetlab/gplmt/Notifications.py
===================================================================
--- gnunet-planetlab/gplmt/Notifications.py     2012-07-19 12:50:32 UTC (rev 
22774)
+++ gnunet-planetlab/gplmt/Notifications.py     2012-07-19 15:30:01 UTC (rev 
22775)
@@ -21,6 +21,7 @@
 # GNUnet Planetlab deployment and automation toolset 
 #
 # Notifications     
+import Tasks
 
 class Notification:
     def __init__(self, logger):
@@ -62,8 +63,8 @@
             print node + " : Tasklist '" +  tasks.name + "' completed with 
failure"
     def task_started (self, node, task):
         print node + " : Task '" +  task.name + "' started"
-    def task_completed (self, node, task, success):
-        if (success == True):
+    def task_completed (self, node, task, result):
+        if (result == Tasks.Taskresult.success):
             print node + " : Task '" +  task.name + "' completed successfully"
         else:
-            print node + " : Task '" +  task.name + "' completed with failure" 
             
\ No newline at end of file
+            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-19 12:50:32 UTC (rev 22774)
+++ gnunet-planetlab/gplmt/Tasks.py     2012-07-19 15:30:01 UTC (rev 22775)
@@ -29,6 +29,12 @@
 
 glogger = None
 
+class Taskresult:
+    success=0
+    timeout=1
+    return_value_did_not_match=2
+    output_did_not_match=3
+
 class Operation:
     none=0
     run=1
@@ -44,7 +50,7 @@
         self.arguments = ""
         self.timeout = 0
         self.expected_return_code = 0
-        self.expected_output = ""
+        self.expected_output = None
         self.stop_on_fail = False
         self.set = None
     def log (self):
@@ -91,7 +97,9 @@
             try:
                 t.expected_return_code = int(child.text)
             except ValueError:
-                print "Invalid expected return code '" +child.text+ "' for 
task id " + str (t.id) + " name " + t.name            
+                print "Invalid expected return code '" +child.text+ "' for 
task id " + str (t.id) + " name " + t.name
+        if ((child.tag == "expected_output") and (child.text != None)):
+            t.expected_output = child.text                            
         if ((child.tag == "stop_on_fail") and (child.text != None)):
             if (child.text == "yes"):
                 t.stop_on_fail = True

Modified: gnunet-planetlab/gplmt/Worker.py
===================================================================
--- gnunet-planetlab/gplmt/Worker.py    2012-07-19 12:50:32 UTC (rev 22774)
+++ gnunet-planetlab/gplmt/Worker.py    2012-07-19 15:30:01 UTC (rev 22775)
@@ -24,13 +24,11 @@
 
 import Tasks
 import threading
+import paramiko
 import socket
 import os
-try: 
-    import paramiko
-    paramiko_loaded = True 
-except ImportError: 
-    pass
+import time
+import sys
 
 # Global variables
 g_logger = None
@@ -96,34 +94,52 @@
                     channel.settimeout(1.0)
                     channel.exec_command(task.command + " " + task.arguments)
                     
-                    exit_status = channel.recv_exit_status()
-                    stdout_data = []
-                    stderr_data = []
- 
-                    while channel.recv_ready():
-                        stdout_data.append(channel.recv(1024))
-                        stdout_data = "".join(stdout_data)
- 
-                    while channel.recv_stderr_ready():
-                        stderr_data.append(channel.recv_stderr(1024))
-                        stderr_data = "".join(stderr_data)
- 
-                    fail = False;                    
-                    if (exit_status != task.expected_return_code):
-                        g_logger.log (self.node + " : Task '"+ task.name + "' 
completed, but exit code " +str(exit_status)+ " was not as expected " + 
str(task.expected_return_code))
-                        fail = True;
+                    if (task.timeout > 0):
+                        timeout = task.timeout
                     else:
-                        g_logger.log (self.node + " : Task '"+ task.name + "' 
completed, exit code " +str(exit_status)+ " was as expected " + 
str(task.expected_return_code))
-                    if ((task.expected_output not in stdout_data) and
-                        (task.expected_output not in stderr_data)):
-                        fail = True; 
+                        timeout = 10
+                    exec_time = 0
+                    result = Tasks.Taskresult.success
+                    while ((not channel.exit_status_ready()) and (exec_time < 
timeout)):
+                        time.sleep(1)
+                        exec_time += 1
+                    if (exec_time < timeout):
+                        stdout = channel.makefile("rb")
+                        stderr = channel.makefile_stderr("rb")
+                    
+                        stdout_data = stdout.readlines()
+                        stderr_data = stderr.readlines()
+                        exit_status = channel.recv_exit_status()
+                    else:
+                        g_logger.log (self.node + " : Task '"+ task.name + "' 
had timeout after " +str (exec_time)+ " seconds")
+                        result = Tasks.Taskresult.timeout
                         
-                    if (fail == True):
+                    if (result == Tasks.Taskresult.success):                   
 
+                        if (exit_status != task.expected_return_code):
+                            g_logger.log (self.node + " : Task '"+ task.name + 
"' completed, but exit code " +str(exit_status)+ " was not as expected " + 
str(task.expected_return_code))
+                            result = 
Tasks.Taskresult.return_value_did_not_match
+                        else:
+                            g_logger.log (self.node + " : Task '"+ task.name + 
"' completed, exit code " +str(exit_status)+ " was as expected " + 
str(task.expected_return_code))
+                        
+                        if ((fail == False) and (task.expected_output != 
None)):
+                            output_contained = False
+                            for l in stdout_data:
+                                if (task.expected_output in l):
+                                    output_contained = True
+                            for l in stderr_data:
+                                if (task.expected_output in l):
+                                    output_contained = True                
+                            if (output_contained == True):
+                                g_logger.log (self.node + " : Task '"+ 
task.name + "' expected output '"+task.expected_output+"' was found")
+                            else:
+                                g_logger.log (self.node + " : Task '"+ 
task.name + "' expected output '"+task.expected_output+"' was not found")
+                                result = Tasks.Taskresult.output_did_not_match
+                                
+                    if (result == Tasks.Taskresult.success):
+                        g_logger.log (self.node + " : Task '"+ task.name + "' 
successful")
+                    else: 
                         g_logger.log (self.node + " : Task '"+ task.name + "' 
failed")
-                    else: 
-                        g_logger.log (self.node + " : Task '"+ task.name + "' 
successful")
-                        
-                    g_notifications.task_completed (self.node, task, not fail)
+                    g_notifications.task_completed (self.node, task, result)   
                     
                 elif (task.type == Tasks.Operation.put):
                     print "TO IMPLEMENT"
                 elif (task.type == Tasks.Operation.get):
@@ -136,14 +152,16 @@
                 g_notifications.task_started (self.node, task)
             elif (task.__class__.__name__ == "Taskset"):
                 g_logger.log (self.node + " : Running task set")
-            if ((task.stop_on_fail == True) and (fail == True)):
+            if ((task.stop_on_fail == True) and (result != 
Tasks.Taskresult.success)):
                 g_logger.log (self.node + " : Task failed and therefore 
execution is stopped")
                 transport.close()
+                success = False
                 break
             task = self.tasks.get()
         
         ssh.close()
         g_notifications.node_disconnected (self.node, True)
+        print 
         g_notifications.tasklist_completed (self.node, self.tasks, success)
         g_logger.log (self.node + " : All tasks done for " + self.node)
         

Modified: gnunet-planetlab/gplmt/contrib/simpletasks.xml
===================================================================
--- gnunet-planetlab/gplmt/contrib/simpletasks.xml      2012-07-19 12:50:32 UTC 
(rev 22774)
+++ gnunet-planetlab/gplmt/contrib/simpletasks.xml      2012-07-19 15:30:01 UTC 
(rev 22775)
@@ -6,18 +6,19 @@
         <type>run</type> 
         <command>date</command> 
         <arguments></arguments> 
-        <expected_return_code>1</expected_return_code>
-        <expected_output></expected_output>
+        <expected_return_code>0</expected_return_code>
+        <expected_output>2012</expected_output>
         <stop_on_fail>yes</stop_on_fail>
     </task> 
       <task name="simple tasks">
         <id>0</id>
         <name>get date</name>
         <type>run</type> 
-        <command>date</command> 
+        <command>sleep 3</command> 
         <arguments></arguments> 
-        <expected_return_code>1</expected_return_code>
+        <timeout>10</timeout> 
+        <expected_return_code>0</expected_return_code>
         <expected_output></expected_output>
-        <stop_on_fail>0</stop_on_fail>
+        <stop_on_fail>yes</stop_on_fail>
     </task> 
 </tasklist>




reply via email to

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