from nitsi.logger import init_logging
import logging
+from nitsi.recipe import RecipeExeption
+
+from nitsi.test import TestException
+
logger = logging.getLogger("nitsi")
logger.setLevel(logging.DEBUG)
# create console handler with a higher log level
fh.setLevel(logging.DEBUG)
logger.addHandler(fh)
logger.debug("We now logging everything to {}/general.log".format(log_dir))
+ try:
+ currenttest = test(args.dir, log_dir)
+ currenttest.read_settings()
+ currenttest.virtual_environ_setup()
+ currenttest.load_recipe()
+ except RecipeExeption as e:
+ logger.exception(e)
+ exit(2)
- currenttest = test(args.dir, log_dir)
- currenttest.read_settings()
- currenttest.virtual_environ_setup()
- currenttest.load_recipe()
try:
currenttest.virtual_environ_start()
currenttest.run_recipe()
+ except TestException as e:
+ logger.exception(e)
+ exit(1)
except BaseException as e:
- print(e)
+ logger.exception(e)
+ exit(3)
finally:
- currenttest.virtual_environ_stop()
\ No newline at end of file
+ currenttest.virtual_environ_stop()
+
+ exit(0)
\ No newline at end of file
class RecipeExeption(Exception):
- pass
+ def __init__(self, message):
+ self.message = message
if not os.path.isfile(self.recipe_file):
self.log.error("{} is not a file".format(self.recipe_file))
- raise RecipeExeption
+ raise RecipeExeption("{} is not a file".format(self.recipe_file)())
try:
with open(self.recipe_file) as fobj:
self.raw_recipe = fobj.readlines()
except FileNotFoundError as error:
self.log.error("No such file: {}".format(vm_xml_file))
+ raise error
@property
def recipe(self):
raw_line = line.split(":", 1)
if len(raw_line) < 2:
self.log.error("Error parsing the recipe in line {}".format(i))
- raise RecipeExeption
+ raise RecipeExeption("Error parsing the recipe in line {}".format(i))
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
+ raise RecipeExeption("Failed to parse the recipe in line {}".format(i))
if raw_line[0].strip() == "":
self.log.error("Failed to parse the recipe in line {}".format(i))
- raise RecipeExeption
+ raise RecipeExeption("Failed to parse the recipe in line {}".format(i))
machine = raw_line[0].strip()
path = path + "/recipe"
if path in self.circle:
self.log.error("Detect import loop!")
- raise RecipeExeption
+ raise RecipeExeption("Detect import loop!")
self.circle.append(path)
recipe_to_include = recipe(path, circle=self.circle)
logger = logging.getLogger("nitsi.test")
+
+class TestException(Exception):
+ def __init__(self, message):
+ self.message = message
+
class test():
def __init__(self, path, log_path):
try:
return_value = self.virtual_machines[line[0]].cmd(line[2])
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
+ raise TestException("Failed to execute command '{}' on {}, return code: {}".format(line[2],line[0], return_value))
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
+ raise TestException("Succeded to execute command '{}' on {}, return code: {}".format(line[2],line[0],return_value))
else:
self.log.debug("Command '{}' on {} returned with: {}".format(line[2],line[0],return_value))