]> git.ipfire.org Git - nitsi.git/blobdiff - test.py
Correctly handle exit codes
[nitsi.git] / test.py
diff --git a/test.py b/test.py
index 54d256df85da7767846bd00fa4aac483bb5c7e02..634bf5b174faff4de75215cadded0c3295f92631 100755 (executable)
--- a/test.py
+++ b/test.py
@@ -355,7 +355,7 @@ class connection():
         self.con.flush()
 
     def command(self, command):
-        self.write("{}\n".format(command))
+        self.write("{}; echo \"END: $?\"\n".format(command))
 
         # We need to read out the prompt for this command first
         # If we do not do this we will break the loop immediately
@@ -367,6 +367,13 @@ class connection():
             data = self.readline()
             self.log_console_line(data.decode())
 
+        # We saved our exit code in data (the last line)
+        self.log.debug(data.decode())
+        data = data.decode().replace("END: ", "")
+        self.log.debug(data)
+        self.log.debug(data.strip())
+        return data.strip()
+
 
 # A class which define and undefine a virtual network based on an xml file
 class network():
@@ -508,12 +515,15 @@ class test():
     def run_recipe(self):
         for line in self.recipe.recipe:
             return_value = self.virtual_machines[line[0]].cmd(line[2])
-            if not return_value and line[1] == "":
-                self.log.error("Failed to execute command '{}' on {}".format(line[2],line[0]))
+            self.log.debug("Return value is: {}".format(return_value))
+            if return_value != "0" and line[1] == "":
+                self.log.error("Failed to execute command '{}' on {}, return code: {}".format(line[2],line[0], return_value))
                 return False
-            elif return_value == True and line[1] == "!":
-                self.log.error("Succeded to execute command '{}' on {}".format(line[2],line[0]))
+            elif return_value == "0" and line[1] == "!":
+                self.log.error("Succeded to execute command '{}' on {}, return code: {}".format(line[2],line[0],return_value))
                 return False
+            else:
+                self.log.debug("Command '{}' on {} returned with: {}".format(line[2],line[0],return_value))
 
     def virtual_environ_stop(self):
         for name in self.virtual_environ.machine_names: