예제 #1
0
파일: runner.py 프로젝트: FengYang/avocado
    def run(self, args):
        """
        List available test modules.

        :param args: Command line args received from the list subparser.
        """
        view = output.View(app_args=args, use_paginator=True)
        base_test_dir = data_dir.get_test_dir()
        test_files = os.listdir(base_test_dir)
        test_dirs = []
        blength = 0
        for t in test_files:
            inspector = path.PathInspector(path=t)
            if inspector.is_python():
                clength = len((t.split('.')[0]))
                if clength > blength:
                    blength = clength
                test_dirs.append((t.split('.')[0], os.path.join(base_test_dir, t)))
        format_string = "    %-" + str(blength) + "s %s"
        view.notify(event='message', msg='Tests dir: %s' % base_test_dir)
        if len(test_dirs) > 0:
            view.notify(event='message', msg=format_string % ('Alias', 'Path'))
            for test_dir in test_dirs:
                view.notify(event='minor', msg=format_string % test_dir)
        else:
            view.notify(event='error', msg='No tests were found on current tests dir')
예제 #2
0
    def run(self, args):
        LOG_UI.info("Config files read (in order, '*' means the file exists "
                    "and had been read):")
        for cfg_path in settings.all_config_paths:
            if cfg_path in settings.config_paths:
                LOG_UI.debug('    * %s', cfg_path)
            else:
                LOG_UI.debug('      %s', cfg_path)
        LOG_UI.debug("")
        if not args.datadir:
            blength = 0
            for section in settings.config.sections():
                for value in settings.config.items(section):
                    clength = len('%s.%s' % (section, value[0]))
                    if clength > blength:
                        blength = clength

            format_str = "    %-" + str(blength) + "s %s"

            LOG_UI.debug(format_str, 'Section.Key', 'Value')
            for section in settings.config.sections():
                for value in settings.config.items(section):
                    config_key = ".".join((section, value[0]))
                    LOG_UI.debug(format_str, config_key, value[1])
        else:
            LOG_UI.debug("Avocado replaces config dirs that can't be accessed")
            LOG_UI.debug("with sensible defaults. Please edit your local config")
            LOG_UI.debug("file to customize values")
            LOG_UI.debug('')
            LOG_UI.info('Avocado Data Directories:')
            LOG_UI.debug('    base     %s', data_dir.get_base_dir())
            LOG_UI.debug('    tests    %s', data_dir.get_test_dir())
            LOG_UI.debug('    data     %s', data_dir.get_data_dir())
            LOG_UI.debug('    logs     %s', data_dir.get_logs_dir())
            LOG_UI.debug('    cache    %s', ", ".join(data_dir.get_cache_dirs()))
예제 #3
0
파일: config.py 프로젝트: smruti77/avocado
    def handle_default():
        LOG_UI.info("Config files read (in order, '*' means the file exists "
                    "and had been read):")

        # Getting from settings because is already sorted
        config = settings.as_dict()
        for cfg_path in settings.all_config_paths:
            if cfg_path in settings.config_paths:
                LOG_UI.debug('    * %s', cfg_path)
            else:
                LOG_UI.debug('      %s', cfg_path)
        LOG_UI.debug("")
        if not config.get('config.datadir'):
            blength = 0
            for namespace, value in config.items():
                clength = len(namespace)
                if clength > blength:
                    blength = clength

            format_str = "    %-" + str(blength) + "s %s"

            LOG_UI.debug(format_str, 'Section.Key', 'Value')
            for namespace, value in config.items():
                LOG_UI.debug(format_str, namespace, value)
        else:
            LOG_UI.debug("Avocado replaces config dirs that can't be accessed")
            LOG_UI.debug("with sensible defaults. Please edit your local config")
            LOG_UI.debug("file to customize values")
            LOG_UI.debug('')
            LOG_UI.info('Avocado Data Directories:')
            LOG_UI.debug('    base     %s', data_dir.get_base_dir())
            LOG_UI.debug('    tests    %s', data_dir.get_test_dir())
            LOG_UI.debug('    data     %s', data_dir.get_data_dir())
            LOG_UI.debug('    logs     %s', data_dir.get_logs_dir())
            LOG_UI.debug('    cache    %s', ", ".join(data_dir.get_cache_dirs()))
예제 #4
0
파일: result.py 프로젝트: PyLearner/avocado
 def _copy_tests(self):
     """
     Gather test directories and copy them recursively to
     $remote_test_dir + $test_absolute_path.
     :note: Default tests execution is translated into absolute paths too
     """
     # TODO: Use `avocado.loader.TestLoader` instead
     self.remote.makedir(self.remote_test_dir)
     if self.args.remote_no_copy:  # Leave everything as is
         return
     paths = set()
     for i in xrange(len(self.urls)):
         url = self.urls[i]
         if not os.path.exists(url):  # use test_dir path + py
             url = os.path.join(data_dir.get_test_dir(), '%s.py' % url)
         url = os.path.abspath(url)  # always use abspath; avoid clashes
         # modify url to remote_path + abspath
         paths.add(os.path.dirname(url))
         self.urls[i] = self.remote_test_dir + url
     previous = ' NOT ABSOLUTE PATH'
     for path in sorted(paths):
         if os.path.commonprefix((path, previous)) == previous:
             continue  # already copied
         rpath = self.remote_test_dir + path
         self.remote.makedir(rpath)
         self.remote.send_files(path, os.path.dirname(rpath))
         previous = path
예제 #5
0
    def run(self, config):
        LOG_UI.info("Config files read (in order, '*' means the file exists "
                    "and had been read):")
        for cfg_path in settings.all_config_paths:
            if cfg_path in settings.config_paths:
                LOG_UI.debug('    * %s', cfg_path)
            else:
                LOG_UI.debug('      %s', cfg_path)
        LOG_UI.debug("")
        if not config.get("datadir"):
            blength = 0
            for section in settings.config.sections():
                for value in settings.config.items(section):
                    clength = len('%s.%s' % (section, value[0]))
                    if clength > blength:
                        blength = clength

            format_str = "    %-" + str(blength) + "s %s"

            LOG_UI.debug(format_str, 'Section.Key', 'Value')
            for section in settings.config.sections():
                for value in settings.config.items(section):
                    config_key = ".".join((section, value[0]))
                    LOG_UI.debug(format_str, config_key, value[1])
        else:
            LOG_UI.debug("Avocado replaces config dirs that can't be accessed")
            LOG_UI.debug("with sensible defaults. Please edit your local config")
            LOG_UI.debug("file to customize values")
            LOG_UI.debug('')
            LOG_UI.info('Avocado Data Directories:')
            LOG_UI.debug('    base     %s', data_dir.get_base_dir())
            LOG_UI.debug('    tests    %s', data_dir.get_test_dir())
            LOG_UI.debug('    data     %s', data_dir.get_data_dir())
            LOG_UI.debug('    logs     %s', data_dir.get_logs_dir())
            LOG_UI.debug('    cache    %s', ", ".join(data_dir.get_cache_dirs()))
예제 #6
0
파일: job.py 프로젝트: eduardok/avocado
    def __init__(self, args=None):
        """
        Creates an instance of Job class.

        :param args: an instance of :class:`argparse.Namespace`.
        """

        self.args = args
        if args is not None:
            self.unique_id = args.unique_id or str(uuid.uuid4())
        else:
            self.unique_id = str(uuid.uuid4())
        self.debugdir = data_dir.get_job_logs_dir(self.args)
        self.debuglog = os.path.join(self.debugdir, "debug.log")
        if self.args is not None:
            self.loglevel = args.log_level or logging.DEBUG
            self.multiplex_file = args.multiplex_file
        else:
            self.loglevel = logging.DEBUG
            self.multiplex_file = None
        self.test_dir = data_dir.get_test_dir()
        self.test_index = 1
        self.status = "RUNNING"

        self.output_manager = output.OutputManager()
예제 #7
0
파일: loader.py 프로젝트: cheliu/avocado
    def discover_test(self, params, queue):
        """
        Try to discover and resolve a test.

        :param params: dictionary with test parameters.
        :type params: dict
        :param queue: a queue for communicating with the test runner.
        :type queue: an instance of :class:`multiprocessing.Queue`
        :return: a test factory (a pair of test class and test parameters)
        """
        test_name = params.get('id')
        test_path = os.path.abspath(test_name)
        if os.path.exists(test_path):
            path_analyzer = path.PathInspector(test_path)
            if path_analyzer.is_python():
                test_class, test_parameters = self._make_test(test_name,
                                                              test_path,
                                                              params, queue)
            elif os.access(test_path, os.X_OK):
                test_class, test_parameters = self._make_simple_test(test_path,
                                                                     params)
        else:
            # Try to resolve test ID (keep compatibility)
            rel_path = '%s.py' % test_name
            test_path = os.path.join(data_dir.get_test_dir(), rel_path)
            if os.path.exists(test_path):
                test_class, test_parameters = self._make_test(rel_path,
                                                              test_path,
                                                              params, queue)
            else:
                test_class, test_parameters = self._make_missing_test(
                    test_name, params)
        return test_class, test_parameters
예제 #8
0
    def run(self, args):
        LOG_UI.info('Config files read (in order):')
        for cfg_path in settings.config_paths:
            LOG_UI.debug('    %s' % cfg_path)
        if settings.config_paths_failed:
            LOG_UI.error('\nConfig files that failed to read:')
            for cfg_path in settings.config_paths_failed:
                LOG_UI.error('    %s' % cfg_path)
        LOG_UI.debug("")
        if not args.datadir:
            blength = 0
            for section in settings.config.sections():
                for value in settings.config.items(section):
                    clength = len('%s.%s' % (section, value[0]))
                    if clength > blength:
                        blength = clength

            format_str = "    %-" + str(blength) + "s %s"

            LOG_UI.debug(format_str, 'Section.Key', 'Value')
            for section in settings.config.sections():
                for value in settings.config.items(section):
                    config_key = ".".join((section, value[0]))
                    LOG_UI.debug(format_str, config_key, value[1])
        else:
            LOG_UI.debug("Avocado replaces config dirs that can't be accessed")
            LOG_UI.debug("with sensible defaults. Please edit your local config")
            LOG_UI.debug("file to customize values")
            LOG_UI.debug('')
            LOG_UI.info('Avocado Data Directories:')
            LOG_UI.debug('    base     ' + data_dir.get_base_dir())
            LOG_UI.debug('    tests    ' + data_dir.get_test_dir())
            LOG_UI.debug('    data     ' + data_dir.get_data_dir())
            LOG_UI.debug('    logs     ' + data_dir.get_logs_dir())
            LOG_UI.debug('    cache    ' + ", ".join(data_dir.get_cache_dirs()))
예제 #9
0
파일: job.py 프로젝트: eduardok/avocado
    def __init__(self, args=None):
        """
        Creates an instance of Job class.

        :param args: an instance of :class:`argparse.Namespace`.
        """

        self.args = args
        if args is not None:
            self.unique_id = args.unique_id or str(uuid.uuid4())
        else:
            self.unique_id = str(uuid.uuid4())
        self.debugdir = data_dir.get_job_logs_dir(self.args)
        self.debuglog = os.path.join(self.debugdir, "debug.log")
        if self.args is not None:
            self.loglevel = args.log_level or logging.DEBUG
            self.multiplex_file = args.multiplex_file
        else:
            self.loglevel = logging.DEBUG
            self.multiplex_file = None
        self.test_dir = data_dir.get_test_dir()
        self.test_index = 1
        self.status = "RUNNING"

        self.output_manager = output.OutputManager()
예제 #10
0
    def run(self, args):
        log = logging.getLogger("avocado.app")
        log.info('Config files read (in order):')
        for cfg_path in settings.config_paths:
            log.debug('    %s' % cfg_path)
        if settings.config_paths_failed:
            log.error('\nConfig files that failed to read:')
            for cfg_path in settings.config_paths_failed:
                log.error('    %s' % cfg_path)
        log.debug("")
        if not args.datadir:
            blength = 0
            for section in settings.config.sections():
                for value in settings.config.items(section):
                    clength = len('%s.%s' % (section, value[0]))
                    if clength > blength:
                        blength = clength

            format_str = "    %-" + str(blength) + "s %s"

            log.debug(format_str, 'Section.Key', 'Value')
            for section in settings.config.sections():
                for value in settings.config.items(section):
                    config_key = ".".join((section, value[0]))
                    log.debug(format_str, config_key, value[1])
        else:
            log.debug("Avocado replaces config dirs that can't be accessed")
            log.debug("with sensible defaults. Please edit your local config")
            log.debug("file to customize values")
            log.debug('')
            log.info('Avocado Data Directories:')
            log.debug('    base     ' + data_dir.get_base_dir())
            log.debug('    tests    ' + data_dir.get_test_dir())
            log.debug('    data     ' + data_dir.get_data_dir())
            log.debug('    logs     ' + data_dir.get_logs_dir())
예제 #11
0
파일: datadir.py 프로젝트: FengYang/avocado
 def run(self, args):
     view = output.View()
     view.notify(event="message", msg='Avocado Data Directories:')
     view.notify(event="message", msg='    base dir        ' + data_dir.get_base_dir())
     view.notify(event="message", msg='    tests dir       ' + data_dir.get_test_dir())
     view.notify(event="message", msg='    data dir        ' + data_dir.get_data_dir())
     view.notify(event="message", msg='    logs dir        ' + data_dir.get_logs_dir())
     view.notify(event="message", msg='    tmp dir         ' + data_dir.get_tmp_dir())
예제 #12
0
 def _log_avocado_datadir(self):
     LOG_JOB.info('Avocado Data Directories:')
     LOG_JOB.info('')
     LOG_JOB.info('base     %s', self.config.get('datadir.paths.base_dir'))
     LOG_JOB.info('tests    %s', data_dir.get_test_dir())
     LOG_JOB.info('data     %s', self.config.get('datadir.paths.data_dir'))
     LOG_JOB.info('logs     %s', self.logdir)
     LOG_JOB.info('')
예제 #13
0
 def _log_avocado_datadir(self):
     LOG_JOB.info("Avocado Data Directories:")
     LOG_JOB.info("")
     LOG_JOB.info("base     %s", self.config.get("datadir.paths.base_dir"))
     LOG_JOB.info("tests    %s", data_dir.get_test_dir())
     LOG_JOB.info("data     %s", self.config.get("datadir.paths.data_dir"))
     LOG_JOB.info("logs     %s", self.logdir)
     LOG_JOB.info("")
예제 #14
0
파일: loader.py 프로젝트: cliping/avocado
 def _make_nonexisting_file_tests(self, test_path, make_broken,
                                  subtests_filter, test_name):
     # Try to resolve test ID (keep compatibility)
     test_path = os.path.join(data_dir.get_test_dir(), test_name)
     if os.path.exists(test_path):
         return self._make_python_file_tests(test_path, make_broken,
                                             subtests_filter, test_name)
     else:
         if not subtests_filter and ':' in test_name:
             test_name, subtests_filter = test_name.split(':', 1)
             test_path = os.path.join(data_dir.get_test_dir(), test_name)
             if os.path.exists(test_path):
                 subtests_filter = re.compile(subtests_filter)
                 return self._make_python_file_tests(
                     test_path, make_broken, subtests_filter, test_name)
         return make_broken(
             NotATest, test_name, "File not found "
             "('%s'; '%s')" % (test_name, test_path))
예제 #15
0
파일: loader.py 프로젝트: mxie91/avocado
    def _discover(self, reference, which_tests=DiscoverMode.DEFAULT):
        """
        Recursively walk in a directory and find tests params.
        The tests are returned in alphabetic order.

        :param reference: the directory path to inspect.
        :param which_tests: Limit tests to be displayed
        :type which_tests: :class:`DiscoverMode`
        :return: list of matching tests
        """
        if reference is None:
            if which_tests == DiscoverMode.DEFAULT:
                return []  # Return empty set when not listing details
            else:
                reference = data_dir.get_test_dir()
        ignore_suffix = (".data", ".pyc", ".pyo", "__init__.py", "__main__.py")

        # Look for filename:test_method pattern
        reference, subtests_filter = reference_split(reference)
        if subtests_filter is not None:
            subtests_filter = re.compile(subtests_filter)

        if not os.path.isdir(reference):  # Single file
            return self._make_tests(
                reference, which_tests == DiscoverMode.ALL, subtests_filter
            )

        tests = []

        def add_test_from_exception(exception):
            """If the exc.filename is valid test it's added to tests"""
            tests.extend(
                self._make_tests(exception.filename, which_tests == DiscoverMode.ALL)
            )

        def skip_non_test(exception):  # pylint: disable=W0613
            """Always return None"""
            return None

        if which_tests == DiscoverMode.ALL:
            onerror = add_test_from_exception
        else:  # DEFAULT, AVAILABLE => skip missing tests
            onerror = skip_non_test

        for dirpath, dirs, filenames in os.walk(reference, onerror=onerror):
            dirs.sort()
            for file_name in sorted(filenames):
                if file_name.startswith(".") or file_name.endswith(ignore_suffix):
                    continue

                pth = os.path.join(dirpath, file_name)
                tests.extend(
                    self._make_tests(
                        pth, which_tests == DiscoverMode.ALL, subtests_filter
                    )
                )
        return tests
예제 #16
0
파일: datadir.py 프로젝트: eduardok/avocado
 def list_data_dirs(self, args):
     bcolors = output.colors
     pipe = output.get_paginator()
     pipe.write(bcolors.header_str('Avocado Data Directories:'))
     pipe.write('\n    base dir:        ' + data_dir.get_base_dir())
     pipe.write('\n    tests dir:       ' + data_dir.get_test_dir())
     pipe.write('\n    data dir:        ' + data_dir.get_data_dir())
     pipe.write('\n    logs dir:        ' + data_dir.get_logs_dir())
     pipe.write('\n    tmp dir:         ' + data_dir.get_tmp_dir())
예제 #17
0
파일: vm.py 프로젝트: FengYang/avocado
 def _copy_tests(self):
     self.vm.remote.makedir(self.remote_test_dir)
     uniq_urls = list(set(self.urls))
     for url in uniq_urls:
         parent_dir = url.split(os.path.sep)[0]
         if os.path.isdir(parent_dir):
             test_path = os.path.abspath(parent_dir)
         else:
             test_path = os.path.join(data_dir.get_test_dir(), "%s*" % url)
         self.vm.remote.send_files(test_path, self.remote_test_dir)
예제 #18
0
파일: vm.py 프로젝트: eduardok/avocado
    def __init__(self, stream, args):
        """
        Creates an instance of VMTestResult.

        :param stream: an instance of :class:`avocado.core.output.OutputManager`.
        :param args: an instance of :class:`argparse.Namespace`.
        """
        TestResult.__init__(self, stream, args)
        self.test_dir = data_dir.get_test_dir()
        self.remote_test_dir = '~/avocado/tests'
예제 #19
0
파일: job.py 프로젝트: FreeTommyLi/avocado
    def __init__(self, args=None, standalone=False):
        """
        Creates an instance of Job class.

        :param args: an instance of :class:`argparse.Namespace`.
        :param standalone: do not create any content and present the job log
                           on the output.
        """
        self.args = args
        self.standalone = standalone
        if args is not None:
            self.unique_id = args.unique_job_id or job_id.create_unique_job_id(
            )
        else:
            self.unique_id = job_id.create_unique_job_id()
        self.view = output.View(app_args=self.args)
        self.logdir = None
        if self.args is not None:
            raw_log_level = args.job_log_level
            mapping = {
                'info': logging.INFO,
                'debug': logging.DEBUG,
                'warning': logging.WARNING,
                'error': logging.ERROR,
                'critical': logging.CRITICAL
            }
            if raw_log_level is not None and raw_log_level in mapping:
                self.loglevel = mapping[raw_log_level]
            else:
                self.loglevel = logging.DEBUG
            if multiplexer.MULTIPLEX_CAPABLE:
                self.multiplex_files = args.multiplex_files
            self.show_job_log = args.show_job_log
            self.silent = args.silent
        else:
            self.loglevel = logging.DEBUG
            self.multiplex_files = None
            self.show_job_log = False
            self.silent = False

        if standalone:
            self.show_job_log = True
            if self.args is not None:
                setattr(self.args, 'show_job_log', True)

        if self.show_job_log:
            if not self.silent:
                test_logger = logging.getLogger('avocado.test')
                output.add_console_handler(test_logger)
                test_logger.setLevel(self.loglevel)
        self.test_dir = data_dir.get_test_dir()
        self.test_index = 1
        self.status = "RUNNING"
        self.result_proxy = result.TestResultProxy()
        self.sysinfo = None
예제 #20
0
파일: runner.py 프로젝트: eduardok/avocado
    def list_tests(self, args):
        """
        List available test modules.

        :param args: Command line args received from the list subparser.
        """
        bcolors = output.colors
        pipe = output.get_paginator()
        test_dirs = os.listdir(data_dir.get_test_dir())
        pipe.write(bcolors.header_str('Tests available:'))
        pipe.write("\n")
        for test_dir in test_dirs:
            pipe.write("    %s\n" % test_dir)
예제 #21
0
파일: config.py 프로젝트: svirt/avocado
    def run(self, args):
        view = output.View(use_paginator=(args.paginator == 'on'))
        try:
            view.notify(event="message", msg='Config files read (in order):')
            for cfg_path in settings.config_paths:
                view.notify(event="message", msg='    %s' % cfg_path)
            if settings.config_paths_failed:
                view.notify(event="minor", msg='')
                view.notify(event="error",
                            msg='Config files that failed to read:')
                for cfg_path in settings.config_paths_failed:
                    view.notify(event="error", msg='    %s' % cfg_path)
            view.notify(event="minor", msg='')
            if not args.datadir:
                blength = 0
                for section in settings.config.sections():
                    for value in settings.config.items(section):
                        clength = len('%s.%s' % (section, value[0]))
                        if clength > blength:
                            blength = clength

                format_str = "    %-" + str(blength) + "s %s"

                view.notify(event="minor",
                            msg=format_str % ('Section.Key', 'Value'))
                for section in settings.config.sections():
                    for value in settings.config.items(section):
                        config_key = ".".join((section, value[0]))
                        view.notify(event="minor",
                                    msg=format_str % (config_key, value[1]))
            else:
                view.notify(
                    event="minor",
                    msg="Avocado replaces config dirs that can't be accessed")
                view.notify(
                    event="minor",
                    msg="with sensible defaults. Please edit your local config"
                )
                view.notify(event="minor", msg="file to customize values")
                view.notify(event="message", msg='')
                view.notify(event="message", msg='Avocado Data Directories:')
                view.notify(event="minor",
                            msg='    base     ' + data_dir.get_base_dir())
                view.notify(event="minor",
                            msg='    tests    ' + data_dir.get_test_dir())
                view.notify(event="minor",
                            msg='    data     ' + data_dir.get_data_dir())
                view.notify(event="minor",
                            msg='    logs     ' + data_dir.get_logs_dir())
        finally:
            view.cleanup()
예제 #22
0
파일: job.py 프로젝트: ypu/avocado
    def __init__(self, args=None):
        """
        Creates an instance of Job class.

        :param args: an instance of :class:`argparse.Namespace`.
        """
        if args is None:
            args = argparse.Namespace()
        self.args = args
        self.standalone = getattr(self.args, 'standalone', False)
        unique_id = getattr(self.args, 'unique_job_id', None)
        if unique_id is None:
            unique_id = job_id.create_unique_job_id()
        self.unique_id = unique_id
        self.view = output.View(app_args=self.args)
        self.logdir = None
        raw_log_level = settings.get_value('job.output',
                                           'loglevel',
                                           default='debug')
        mapping = {
            'info': logging.INFO,
            'debug': logging.DEBUG,
            'warning': logging.WARNING,
            'error': logging.ERROR,
            'critical': logging.CRITICAL
        }
        if raw_log_level in mapping:
            self.loglevel = mapping[raw_log_level]
        else:
            self.loglevel = logging.DEBUG
        self.show_job_log = getattr(self.args, 'show_job_log', False)
        self.silent = getattr(self.args, 'silent', False)

        if self.standalone:
            self.show_job_log = True
            if self.args is not None:
                setattr(self.args, 'show_job_log', True)

        if self.show_job_log:
            if not self.silent:
                output.add_console_handler(_TEST_LOGGER)
                _TEST_LOGGER.setLevel(self.loglevel)

        self.test_dir = data_dir.get_test_dir()
        self.test_index = 1
        self.status = "RUNNING"
        self.result_proxy = result.TestResultProxy()
        self.sysinfo = None
예제 #23
0
파일: job.py 프로젝트: cheliu/avocado
    def __init__(self, args=None):
        """
        Creates an instance of Job class.

        :param args: an instance of :class:`argparse.Namespace`.
        """
        self.args = args
        if args is not None:
            self.unique_id = args.unique_job_id or job_id.create_unique_job_id()
        else:
            self.unique_id = job_id.create_unique_job_id()
        self.logdir = data_dir.get_job_logs_dir(self.args, self.unique_id)
        self.logfile = os.path.join(self.logdir, "job.log")
        self.idfile = os.path.join(self.logdir, "id")

        with open(self.idfile, 'w') as id_file_obj:
            id_file_obj.write("%s\n" % self.unique_id)

        if self.args is not None:
            raw_log_level = args.job_log_level
            mapping = {'info': logging.INFO,
                       'debug': logging.DEBUG,
                       'warning': logging.WARNING,
                       'error': logging.ERROR,
                       'critical': logging.CRITICAL}
            if raw_log_level is not None and raw_log_level in mapping:
                self.loglevel = mapping[raw_log_level]
            else:
                self.loglevel = logging.DEBUG
            self.multiplex_files = args.multiplex_files
            self.show_job_log = args.show_job_log
            self.silent = args.silent
        else:
            self.loglevel = logging.DEBUG
            self.multiplex_files = None
            self.show_job_log = False
            self.silent = False
        if self.show_job_log:
            if not self.silent:
                test_logger = logging.getLogger('avocado.test')
                output.add_console_handler(test_logger)
                test_logger.setLevel(self.loglevel)
        self.test_dir = data_dir.get_test_dir()
        self.test_index = 1
        self.status = "RUNNING"
        self.result_proxy = result.TestResultProxy()
        self.view = output.View(app_args=self.args)
예제 #24
0
파일: job.py 프로젝트: PyLearner/avocado
    def __init__(self, args=None):
        """
        Creates an instance of Job class.

        :param args: an instance of :class:`argparse.Namespace`.
        """
        if args is None:
            args = argparse.Namespace()
        self.args = args
        self.standalone = getattr(self.args, 'standalone', False)
        unique_id = getattr(self.args, 'unique_job_id', None)
        if unique_id is None:
            unique_id = job_id.create_unique_job_id()
        self.unique_id = unique_id
        self.view = output.View(app_args=self.args)
        self.logdir = None
        raw_log_level = settings.get_value('job.output', 'loglevel',
                                           default='debug')
        mapping = {'info': logging.INFO,
                   'debug': logging.DEBUG,
                   'warning': logging.WARNING,
                   'error': logging.ERROR,
                   'critical': logging.CRITICAL}
        if raw_log_level in mapping:
            self.loglevel = mapping[raw_log_level]
        else:
            self.loglevel = logging.DEBUG
        self.show_job_log = getattr(self.args, 'show_job_log', False)
        self.silent = getattr(self.args, 'silent', False)

        if self.standalone:
            self.show_job_log = True
            if self.args is not None:
                setattr(self.args, 'show_job_log', True)

        if self.show_job_log:
            if not self.silent:
                output.add_console_handler(_TEST_LOGGER)
                _TEST_LOGGER.setLevel(self.loglevel)

        self.test_dir = data_dir.get_test_dir()
        self.test_index = 1
        self.status = "RUNNING"
        self.result_proxy = result.TestResultProxy()
        self.sysinfo = None
        self.timeout = getattr(self.args, 'job_timeout', 0)
예제 #25
0
    def discover_test(self, params):
        """
        Try to discover and resolve a test.

        :param params: dictionary with test parameters.
        :type params: dict
        :return: a test factory (a pair of test class and test parameters)
                 or `None`.
        """
        test_name = test_path = params.get('id')
        if os.path.exists(test_path):
            if os.access(test_path, os.R_OK) is False:
                return (AccessDeniedPath,
                        {'params': {'id': test_path}})
            path_analyzer = path.PathInspector(test_path)
            if path_analyzer.is_python():
                test_class, test_parameters = self._make_test(test_name,
                                                              test_path,
                                                              params)
            else:
                if os.access(test_path, os.X_OK):
                    test_class, test_parameters = self._make_simple_test(test_path,
                                                                         params)
                else:
                    test_class, test_parameters = self._make_not_a_test(test_path,
                                                                        params)
        else:
            if os.path.islink(test_path):
                try:
                    if not os.path.isfile(os.readlink(test_path)):
                        return BrokenSymlink, {'params': {'id': test_path}}
                except OSError:
                    return AccessDeniedPath, {'params': {'id': test_path}}

            # Try to resolve test ID (keep compatibility)
            rel_path = '%s.py' % test_name
            test_path = os.path.join(data_dir.get_test_dir(), rel_path)
            if os.path.exists(test_path):
                test_class, test_parameters = self._make_test(rel_path,
                                                              test_path,
                                                              params)
            else:
                test_class, test_parameters = self._make_missing_test(
                    test_name, params)
        return test_class, test_parameters
예제 #26
0
파일: loader.py 프로젝트: ypu/avocado
    def discover_test(self, params):
        """
        Try to discover and resolve a test.

        :param params: dictionary with test parameters.
        :type params: dict
        :return: a test factory (a pair of test class and test parameters)
                 or `None`.
        """
        test_name = test_path = params.get('id')
        if os.path.exists(test_path):
            if os.access(test_path, os.R_OK) is False:
                return (AccessDeniedPath,
                        {'params': {'id': test_path}})
            path_analyzer = path.PathInspector(test_path)
            if path_analyzer.is_python():
                test_class, test_parameters = self._make_test(test_name,
                                                              test_path,
                                                              params)
            else:
                if os.access(test_path, os.X_OK):
                    test_class, test_parameters = self._make_simple_test(test_path,
                                                                         params)
                else:
                    test_class, test_parameters = self._make_not_a_test(test_path,
                                                                        params)
        else:
            if os.path.islink(test_path):
                try:
                    if not os.path.isfile(os.readlink(test_path)):
                        return BrokenSymlink, {'params': {'id': test_path}}
                except OSError:
                    return AccessDeniedPath, {'params': {'id': test_path}}

            # Try to resolve test ID (keep compatibility)
            rel_path = '%s.py' % test_name
            test_path = os.path.join(data_dir.get_test_dir(), rel_path)
            if os.path.exists(test_path):
                test_class, test_parameters = self._make_test(rel_path,
                                                              test_path,
                                                              params)
            else:
                test_class, test_parameters = self._make_missing_test(
                    test_name, params)
        return test_class, test_parameters
예제 #27
0
파일: config.py 프로젝트: chloerh/avocado
    def run(self, args):
        view = output.View(use_paginator=(args.paginator == 'on'))
        try:
            view.notify(event="message", msg='Config files read (in order):')
            for cfg_path in settings.config_paths:
                view.notify(event="message", msg='    %s' % cfg_path)
            if settings.config_paths_failed:
                view.notify(event="minor", msg='')
                view.notify(event="error", msg='Config files that failed to read:')
                for cfg_path in settings.config_paths_failed:
                    view.notify(event="error", msg='    %s' % cfg_path)
            view.notify(event="minor", msg='')
            if not args.datadir:
                blength = 0
                for section in settings.config.sections():
                    for value in settings.config.items(section):
                        clength = len('%s.%s' % (section, value[0]))
                        if clength > blength:
                            blength = clength

                format_str = "    %-" + str(blength) + "s %s"

                view.notify(event="minor", msg=format_str % ('Section.Key', 'Value'))
                for section in settings.config.sections():
                    for value in settings.config.items(section):
                        config_key = ".".join((section, value[0]))
                        view.notify(event="minor", msg=format_str % (config_key, value[1]))
            else:
                view.notify(event="minor", msg="Avocado replaces config dirs that can't be accessed")
                view.notify(event="minor", msg="with sensible defaults. Please edit your local config")
                view.notify(event="minor", msg="file to customize values")
                view.notify(event="message", msg='')
                view.notify(event="message", msg='Avocado Data Directories:')
                view.notify(event="minor", msg='    base     ' + data_dir.get_base_dir())
                view.notify(event="minor", msg='    tests    ' + data_dir.get_test_dir())
                view.notify(event="minor", msg='    data     ' + data_dir.get_data_dir())
                view.notify(event="minor", msg='    logs     ' + data_dir.get_logs_dir())
        finally:
            view.cleanup()
예제 #28
0
파일: test.py 프로젝트: eduardok/avocado
 def action(self):
     raise exceptions.TestError('Test %s could not be found in the test '
                                'dir %s' %
                                (self.name, data_dir.get_test_dir()))
예제 #29
0
파일: test.py 프로젝트: FengYang/avocado
 def action(self):
     e_msg = ('Test %s could not be found in the test dir %s '
              '(or test path does not exist)' %
              (self.name, data_dir.get_test_dir()))
     raise exceptions.TestNotFoundError(e_msg)
예제 #30
0
파일: test.py 프로젝트: eduardok/avocado
    def __init__(self, methodName='runTest', name=None, params=None,
                 base_logdir=None, tag=None, job=None):
        """
        Initializes the test.

        :param methodName: Name of the main method to run. For the sake of
                           compatibility with the original unittest class,
                           you should not set this.
        :param name: Pretty name of the test name. For normal tests, written
                     with the avocado API, this should not be set, this is
                     reserved for running random executables as tests.
        :param base_logdir: Directory where test logs should go. If None
                            provided, it'll use
                            :func:`avocado.core.data_dir.get_job_logs_dir`.
        :param tag: Tag that differentiates 2 executions of the same test name.
                    Example: 'long', 'short', so we can differentiate
                    'sleeptest.long' and 'sleeptest.short'.
        :param job: The job that this test is part of.
        """
        if name is not None:
            self.name = name
        else:
            self.name = self.__class__.__name__

        if params is None:
            params = {}
        self.params = Params(params)
        self._raw_params = params

        shortname = self.params.get('shortname')
        s_tag = None
        if shortname:
            split_shortname = shortname.split('.')
            if len(split_shortname) > 1:
                s_tag = ".".join(split_shortname[1:])
        self.tag = tag or s_tag
        self.job = job
        self.basedir = os.path.join(data_dir.get_test_dir(), self.name)
        self.depsdir = os.path.join(self.basedir, 'deps')
        self.workdir = os.path.join(data_dir.get_tmp_dir(), self.name)
        if not os.path.isdir(self.workdir):
            os.makedirs(self.workdir)
        self.srcdir = os.path.join(self.workdir, 'src')
        if not os.path.isdir(self.srcdir):
            os.makedirs(self.srcdir)
        if base_logdir is None:
            base_logdir = data_dir.get_job_logs_dir()
        self.tagged_name = self.get_tagged_name(base_logdir)
        self.logdir = os.path.join(base_logdir, self.tagged_name)
        if not os.path.isdir(self.logdir):
            os.makedirs(self.logdir)
        self.logfile = os.path.join(self.logdir, 'debug.log')
        self.sysinfodir = os.path.join(self.logdir, 'sysinfo')

        self.log = logging.getLogger("avocado.test")

        self.log.info('START %s', self.tagged_name)
        self.log.debug('')
        self.log.debug('Test instance parameters:')

        # Set the helper set_default to the params object
        setattr(self.params, 'set_default', self._set_default)

        # Apply what comes from the params dict
        for key in sorted(self.params.keys()):
            self.log.debug('    %s = %s', key, self.params.get(key))
            setattr(self.params, key, self.params.get(key))
        self.log.debug('')

        # Apply what comes from the default_params dict
        self.log.debug('Default parameters:')
        for key in sorted(self.default_params.keys()):
            self.log.debug('    %s = %s', key, self.default_params.get(key))
            self.params.set_default(key, self.default_params[key])
        self.log.debug('')
        self.log.debug('Test instance params override defaults whenever available')
        self.log.debug('')

        # If there's a timeout set, log a timeout reminder
        if hasattr(self.params, 'timeout'):
            self.log.info('Test timeout set. Will wait %.2f s for '
                          'PID %s to end',
                          float(self.params.timeout), os.getpid())
            self.log.info('')

        self.debugdir = None
        self.resultsdir = None
        self.status = None
        self.fail_reason = None
        self.fail_class = None
        self.traceback = None
        self.text_output = None

        self.time_elapsed = None
        unittest.TestCase.__init__(self)
예제 #31
0
    def _run(self, args):
        """
        List available test modules.

        :param args: Command line args received from the list subparser.
        """
        self.view = output.View(app_args=args,
                                use_paginator=args.paginator == 'on')

        paths = [data_dir.get_test_dir()]
        if args.paths:
            paths = args.paths
        params_list = self.test_loader.discover_urls(paths)
        for params in params_list:
            params['omit_non_tests'] = False
        test_suite = self.test_loader.discover(params_list)
        error_msg_parts = self.test_loader.validate_ui(test_suite,
                                                       ignore_not_test=True,
                                                       ignore_access_denied=True,
                                                       ignore_broken_symlinks=True)
        if error_msg_parts:
            for error_msg in error_msg_parts:
                self.view.notify(event='error', msg=error_msg)
            self.view.cleanup()
            sys.exit(exit_codes.AVOCADO_FAIL)

        test_matrix = []
        stats = {'simple': 0,
                 'instrumented': 0,
                 'buggy': 0,
                 'missing': 0,
                 'not_a_test': 0,
                 'broken_symlink': 0,
                 'access_denied': 0}
        for cls, params in test_suite:
            id_label = ''
            type_label = cls.__name__

            if 'params' in params:
                id_label = params['params']['id']
            else:
                if 'name' in params:
                    id_label = params['name']
                elif 'path' in params:
                    id_label = params['path']

            if cls == test.SimpleTest:
                stats['simple'] += 1
                type_label = self.term_support.healthy_str('SIMPLE')
            elif cls == test.BuggyTest:
                stats['buggy'] += 1
                type_label = self.term_support.fail_header_str('BUGGY')
            elif cls == test.NotATest:
                if not args.verbose:
                    continue
                stats['not_a_test'] += 1
                type_label = self.term_support.warn_header_str('NOT_A_TEST')
            elif cls == test.MissingTest:
                stats['missing'] += 1
                type_label = self.term_support.fail_header_str('MISSING')
            elif cls == loader.BrokenSymlink:
                stats['broken_symlink'] += 1
                type_label = self.term_support.fail_header_str('BROKEN_SYMLINK')
            elif cls == loader.AccessDeniedPath:
                stats['access_denied'] += 1
                type_label = self.term_support.fail_header_str('ACCESS_DENIED')
            else:
                if issubclass(cls, test.Test):
                    stats['instrumented'] += 1
                    type_label = self.term_support.healthy_str('INSTRUMENTED')

            test_matrix.append((type_label, id_label))

        header = None
        if args.verbose:
            header = (self.term_support.header_str('Type'),
                      self.term_support.header_str('file'))
        for line in astring.tabular_output(test_matrix,
                                           header=header).splitlines():
            self.view.notify(event='minor', msg="%s" % line)

        if args.verbose:
            self.view.notify(event='minor', msg='')

            self.view.notify(event='message', msg=("SIMPLE: %s" %
                                                   stats['simple']))
            self.view.notify(event='message', msg=("INSTRUMENTED: %s" %
                                                   stats['instrumented']))
            self.view.notify(event='message', msg=("BUGGY: %s" %
                                                   stats['buggy']))
            self.view.notify(event='message', msg=("MISSING: %s" %
                                                   stats['missing']))
            self.view.notify(event='message', msg=("NOT_A_TEST: %s" %
                                                   stats['not_a_test']))
            self.view.notify(event='message', msg=("ACCESS_DENIED: %s" %
                                                   stats['access_denied']))
            self.view.notify(event='message', msg=("BROKEN_SYMLINK: %s" %
                                                   stats['broken_symlink']))
예제 #32
0
 def runTest(self):
     e_msg = ('Test %s could not be found in the test dir %s '
              '(or test path does not exist)' %
              (self.name, data_dir.get_test_dir()))
     raise exceptions.TestNotFoundError(e_msg)