X-Git-Url: http://git.ipfire.org/?p=nitsi.git;a=blobdiff_plain;f=test.py;h=2e2f13ae50cd39c98a1d8903072ba05fe708b9bb;hp=54d256df85da7767846bd00fa4aac483bb5c7e02;hb=07bf49a3262c5128cc737add62c808bc1cd3d9c8;hpb=946371163cc06e6399000cf225e58d50d25583f5 diff --git a/test.py b/test.py index 54d256d..2e2f13a 100755 --- 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(): @@ -401,10 +408,15 @@ class RecipeExeption(Exception): # Should read the test, check if the syntax are valid # and return tuples with the ( host, command ) structure class recipe(): - def __init__(self, path): + def __init__(self, path, circle=[]): self.log = log(4) self.recipe_file = path + self.path = os.path.dirname(self.recipe_file) + self.log.debug("Path of recipe is: {}".format(self.recipe_file)) self._recipe = None + self.circle = circle + self.log.debug(circle) + self.log.debug(self.circle) if not os.path.isfile(self.recipe_file): self.log.error("No such file: {}".format(self.recipe_file)) @@ -430,22 +442,38 @@ class recipe(): if len(raw_line) < 2: self.log.error("Error parsing the recipe in line {}".format(i)) raise RecipeExeption - cmd = raw_line[1] + cmd = raw_line[1].strip() raw_line = raw_line[0].strip().split(" ") if len(raw_line) == 0: self.log.error("Failed to parse the recipe in line {}".format(i)) raise RecipeExeption - elif len(raw_line) == 1: - if raw_line[0] == "": + + if raw_line[0].strip() == "": self.log.error("Failed to parse the recipe in line {}".format(i)) raise RecipeExeption - machine = raw_line[0] + + machine = raw_line[0].strip() + + if len(raw_line) == 2: + extra = raw_line[1].strip() + else: extra = "" - elif len(raw_line) == 2: - machine = raw_line[0] - extra = raw_line[1] - self._recipe.append((machine.strip(), extra.strip(), cmd.strip())) + # We could get a machine here or a include statement + if machine == "include": + path = cmd.strip() + path = os.path.normpath(self.path + "/" + path) + path = path + "/recipe" + if path in self.circle: + self.log.error("Detect import loop!") + raise RecipeExeption + self.circle.append(path) + recipe_to_include = recipe(path, circle=self.circle) + + if machine == "include": + self._recipe.extend(recipe_to_include.recipe) + else: + self._recipe.append((machine.strip(), extra.strip(), cmd.strip())) i = i + 1 @@ -508,12 +536,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: