X-Git-Url: http://git.ipfire.org/?p=nitsi.git;a=blobdiff_plain;f=test.py;h=0507d04570a0eabe390c5551f29c46c0f78103c3;hp=3f6f54079b3f4a59afc5af5249f8d7dbacbb37d0;hb=41ab240e1d13ac813c967581352c2ebcb52aebe6;hpb=48d5fb0a72170dec8bf6bfa84f46c5e2a83210a3 diff --git a/test.py b/test.py index 3f6f540..0507d04 100755 --- a/test.py +++ b/test.py @@ -376,12 +376,19 @@ class network(): +class RecipeExeption(Exception): + pass + + + # Should read the test, check if the syntax are valid # and return tuples with the ( host, command ) structure class recipe(): def __init__(self, path): self.log = log(4) self.recipe_file = path + self._recipe = None + if not os.path.isfile(self.recipe_file): self.log.error("No such file: {}".format(self.recipe_file)) @@ -391,8 +398,38 @@ class recipe(): except FileNotFoundError as error: self.log.error("No such file: {}".format(vm_xml_file)) + @property + def recipe(self): + if not self._recipe: + self.parse() + + return self._recipe + + def parse(self): + self._recipe = [] + i = 1 for line in self.raw_recipe: - print(line) + raw_line = line.split(":") + if len(raw_line) < 2: + self.log.error("Error parsing the recipe in line {}".format(i)) + raise RecipeExeption + cmd = raw_line[1] + 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] == "": + self.log.error("Failed to parse the recipe in line {}".format(i)) + raise RecipeExeption + machine = raw_line[0] + extra = "" + elif len(raw_line) == 2: + machine = raw_line[0] + extra = raw_line[1] + + self._recipe.append((machine.strip(), extra.strip(), cmd.strip())) + i = i + 1 class test():