Example #1
0
    def __init__(self, name, test_definition):
        self.name = name
        test_definition = deep_merge(default_config, test_definition)
        # quick shortcuts
        self.test_env = test_definition['environment']
        self.test_meta = test_definition['meta']
        self.test_commands = test_definition.get('test_commands', [])
        # take care of commands ...
        self.test_commands = _build_exec_array(self.test_commands)
        self.test_meta['test_before'] = \
            _build_exec_array(self.test_meta.get('test_before', None))
        self.test_meta['test_after'] = \
            _build_exec_array(self.test_meta.get('test_after', None))

        # okay.
        # let's keep all file references relative to the configuration
        # file. easy to remember.
        configfilepath = realpath(dirname(self.test_meta.get('_configfile',
                                                             './dummy')))
        # self.TEMPLATE / .TEMPLATE_NAME
        tmp = self.test_meta['docker_compose_template']
        if not isabs(tmp):
            tmp = realpath(join(configfilepath, tmp))
        self.template = tmp
        self.template_name = basename(self.template)
        # self.BASEDIR
        tmp = self.test_meta.get('test_basedir', configfilepath)
        if not isabs(tmp):
            tmp = realpath(join(configfilepath, tmp))
        self.base_dir = tmp
        # self.SANITIZED_NAME, .TEST_DIR
        self.sanitized_name = resub("[^a-zA-Z0-9_]", "-", self.name)
        self.test_dir = dbg_tr_get_testdir(self.base_dir, self.sanitized_name)
        # extend SELF.TEST_ENV with TEST_DIR
        self.test_env['test_dir'] = self.test_dir
        # create SELF.COMMANDLINE
        self.commandline = copy.copy(default_commandline_start)
        for param in self.test_meta['docker_compose_params']:
            self.commandline.append(param)
        for key, val in self.test_env.items():
            self.commandline.append("-e")
            self.commandline.append("%s=%s" % (key, val))
        self.commandline.append("--rm")
        self.commandline.extend(copy.copy(default_commandline_end))
        self.commandline.append(self.test_meta['test_service'])
        # create .STATE, .RESULT, .EXCEPTION, .REASON
        self.state = self.NOTRUN
        self.results = []
        self.exception = None
        self.reason = None
        # log setup
        # NO LOGGING BEFORE HERE
        log_filename = join(self.base_dir, basename(self.test_dir)) + ".log"
        self.log = get_logger("t-%s" % self.name, filename=log_filename)
        # some debug output
        self.log.info("base commandline '%s'" % " ".join(self.commandline))
        self.log.debug("test directory '%s'" % self.test_dir)
        self.log.debug("template path '%s'" % self.template)
        for key, val in self.test_env.items():
            self.log.debug("env %s=%s" % (key, val))
Example #2
0
 def __init__(self,
              name,
              compose_file,
              **kwargs):
     self.name = "{}".format(name if name else basename(compose_file))
     self.sanitized_name = "intmaniac{}".format(
         resub("[^a-z0-9]", "",
               self.name.lower() + basename(compose_file).lower())
     )
     self.template = compose_file
     self.compose_wrapper = Compose(compose_file, self.sanitized_name,
                                    run_kwargs={'throw': True})
     # extract "top level" parameters
     self.test_env = kwargs.pop('environment', {})
     self.test_image = kwargs.pop('image')
     self.test_linked_services = kwargs.pop('links')
     self.test_commands = _build_exec_array(kwargs.pop('commands', []))
     # save the rest
     self.meta = kwargs
     # state information
     self.test_state = self.NOTRUN
     self.test_results = []
     self.exception = None
     self.reason = None
     # run information - this can only be set after the env is running
     self.cleanup_test_containers = []
     self.run_containers = None
     # log setup
     self.log = get_logger("t-%s" % self.name)
     # some debug output
     self.log.debug("using template '%s'" % self.template)
     for key, val in self.test_env.items():
         self.log.debug("env %s=%s" % (key, val))
Example #3
0
def _prepare_environment(arguments):
    global config, logger, derived_basedir
    parser = ArgumentParser()
    parser.add_argument("-c", "--config-file",
                        help="specify configuration file",
                        default="./intmaniac.yaml")
    parser.add_argument("-e", "--env",
                        help="dynamically add a value to the environment",
                        default=[],
                        action="append")
    parser.add_argument("-v", "--verbose",
                        help="increase verbosity level, use multiple times",
                        default=0,
                        action="count")
    parser.add_argument("-t", "--temp-output-dir",
                        help="test dir location, default: $pwd/intmaniac")
    config = parser.parse_args(arguments)
    tools.init_logging(config)
    derived_basedir = tools.setup_up_test_directory(config)
    logger = tools.get_logger(__name__,
                              filename=join(derived_basedir, "root.log"))
Example #4
0
 def __init__(self,
              name,
              compose_file,
              **kwargs):
     self.name = "{}".format(name if name else basename(compose_file))
     self.sanitized_name = "intmaniac{}".format(
         resub("[^a-z0-9]", "",
               self.name.lower() + basename(compose_file).lower())
     )
     self.template = compose_file
     self.compose_wrapper = Compose(compose_file, self.sanitized_name,
                                    run_kwargs={'throw': True})
     # extract "top level" parameters
     self.test_env = kwargs.pop('environment', {})
     self.test_image = kwargs.pop('image')
     self.test_linked_services = kwargs.pop('links')
     self.test_commands = _build_exec_array(kwargs.pop('commands', []))
     # meta_information
     self.pull = kwargs.pop('pull', True)
     self.pre = kwargs.pop('pre', None)
     self.post = kwargs.pop('post', None)
     self.allow_failure = kwargs.pop('allow_failure', False)
     self.volumes = self.format_volume_mapping(kwargs.pop('volumes', []))
     # save the rest (run-arguments for docker.container.create())
     self.meta = kwargs
     # state information
     self.test_state = self.NOTRUN
     self.test_results = []
     self.exception = None
     self.reason = None
     # run information - this can only be set after the env is running
     self.cleanup_test_containers = []
     self.run_containers = None
     # log setup
     self.log = get_logger("t-%s" % self.name)
     # some debug output
     self.log.debug("using template '%s'" % self.template)
     for key, val in self.test_env.items():
         self.log.debug("env %s=%s" % (key, val))
Example #5
0
def create_container(image, command=None, environment={}, **kwargs):
    """
    Creates a new test container instance with the command given. Must be
    called for each command, because we can't change the command once
    it's set.
    :param image: The docker image to use
    :param command: The command to execute with the container, can be <None>
    :param environment: The environment to use in the container
    :param kwargs: keyword-arguments passed to docker.client.containers.create()
    :return: a container-object
    """
    logger = tools.get_logger(__name__ + ".create_container")
    dc = get_client()
    container = dc.containers.create(image,
                                     command=command,
                                     environment=environment,
                                     **kwargs)
    container_id = container.id
    logger.debug(
        "Container id {} created (image: {}, command: {}, env: {})".format(
            container_id[:8], image,
            command if isinstance(command, str) else str(command),
            str(environment)))
    return container
def create_container(image, command=None, environment={}):
    """
    Creates a new test container instance with the command given. Must be
    called for each command, because we can't change the command once
    it's set.
    :param image: The docker image to use
    :param command: The command to execute with the container, can be <None>
    :param environment: The environment to use in the container
    :return: The container id string
    """
    logger = tools.get_logger(__name__+".create_container")
    dc = get_client()
    tmp = dc.create_container(image,
                              command=command,
                              environment=environment)
    container_id = tmp['Id']
    logger.debug("Container id {} created (image: {}, command: {}, env: {})"
                 .format(
                         container_id[:8], image,
                         command if isinstance(command, str) else str(command),
                         str(environment)
                        )
    )
    return container_id
Example #7
0
def _init_logging(config):
    global logger
    tools.init_logging(config)
    logger = tools.get_logger(__name__)
from intmaniac import output
from intmaniac.testrun import Testrun
from intmaniac.tools import fail, deep_merge, get_logger

import yaml
from yaml.parser import ParserError
from yaml.scanner import ScannerError

import tempfile
from functools import partial
from re import search as research
from os import write as fdwrite, close as fdclose
from os.path import dirname, join, isabs, isfile


logger = get_logger(__name__)


def parse(argconfig):
    """
    Opens the configuration file, de-serializes the contents, checks the
    version number, and gives the configuration to the actual parser function.
    Will return whatever the parser function returns, which should be a list
    of Testrun objects.
    :param path_to_file: The path to the configuration file
    :return: A list of Testrun objects (hopefully :)
    """
    fileconfig = _load_config_file(argconfig)
    if 'version' not in fileconfig:
        fail("Need 'config' key in configuration file, must be '2'.")
    else:
Example #9
0
from intmaniac import output
from intmaniac.testrun import Testrun
from intmaniac.tools import fail, deep_merge, get_logger

import yaml
from yaml.parser import ParserError
from yaml.scanner import ScannerError

import tempfile
from functools import partial
from re import search as research
from os import write as fdwrite, close as fdclose
from os.path import dirname, join, isabs, isfile

logger = get_logger(__name__)


def parse(argconfig):
    """
    Opens the configuration file, de-serializes the contents, checks the
    version number, and gives the configuration to the actual parser function.
    Will return whatever the parser function returns, which should be a list
    of Testrun objects.
    :param path_to_file: The path to the configuration file
    :return: A list of Testrun objects (hopefully :)
    """
    fileconfig = _load_config_file(argconfig)
    if 'version' not in fileconfig:
        fail("Need 'config' key in configuration file, must be '2'.")
    else:
        conf_version = str(fileconfig['version'])