diff --git a/avocado/core/job.py b/avocado/core/job.py index 8468f369e1bf111b605a5034097c6dcc9badb50d..0ad1e2fc18102900fea9b80392d71620b3e60607 100644 --- a/avocado/core/job.py +++ b/avocado/core/job.py @@ -39,7 +39,6 @@ from . import exceptions from . import job_id from . import output from . import varianter -from . import tree from . import test from . import jobdata from .output import STD_OUTPUT @@ -366,31 +365,16 @@ class Job(object): job_log.info('logs ' + self.logdir) job_log.info('') - def _log_variants_tree(self, variant): - job_log = _TEST_LOGGER - tree_repr = tree.tree_view(variant.variants.root, verbose=True, - use_utf8=False) - if tree_repr: - job_log.info('Multiplex tree representation:') - for line in tree_repr.splitlines(): - job_log.info(line) - job_log.info('') + def _log_variants(self, variants): + lines = variants.to_str(summary=1, variants=1, use_utf8=False) + for line in lines.splitlines(): + _TEST_LOGGER.info(line) def _log_tmp_dir(self): job_log = _TEST_LOGGER job_log.info('Temporary dir: %s', data_dir.get_tmp_dir()) job_log.info('') - def _log_variants(self, variant): - job_log = _TEST_LOGGER - - for (index, tpl) in enumerate(variant.variants): - paths = ', '.join([x.path for x in tpl]) - job_log.info('Variant %s: %s', index + 1, paths) - - if variant.variants: - job_log.info('') - def _log_job_debug_info(self, mux): """ Log relevant debug information to the job log. @@ -399,9 +383,8 @@ class Job(object): self._log_avocado_version() self._log_avocado_config() self._log_avocado_datadir() - self._log_variants_tree(mux) - self._log_tmp_dir() self._log_variants(mux) + self._log_tmp_dir() self._log_job_id() def create_test_suite(self): diff --git a/avocado/core/varianter.py b/avocado/core/varianter.py index 1dfe25f04c4b9d35cc3a8e12a368395536286aaf..1a38ee74590b52fcefdaba531bc1e5f43e893023 100644 --- a/avocado/core/varianter.py +++ b/avocado/core/varianter.py @@ -24,6 +24,7 @@ import itertools import logging import re +from . import output from . import tree @@ -459,6 +460,60 @@ class Varianter(object): return self.data.merge(tree) + def to_str(self, summary=0, variants=0, **kwargs): + """ + Return human readable representation + + The summary/variants accepts verbosity where 0 means do not display + at all and maximum is up to the plugin. + + :param summary: How verbose summary to output (int) + :param variants: How verbose list of variants to output (int) + :param kwargs: Other free-form arguments + :rtype: str + """ + if not self.variants: + return "" + out = [] + if summary: + # Log tree representation + out.append("Multiplex tree representation:") + # summary == 0 means disable, but in plugin it's brief + tree_repr = tree.tree_view(self.variants.root, verbose=summary - 1, + use_utf8=kwargs.get("use_utf8")) + out.append(tree_repr) + out.append("") + + if variants: + # variants == 0 means disable, but in plugin it's brief + contents = variants - 1 + out.append("Multiplex variants:") + for (index, tpl) in enumerate(self.variants): + if not self.debug: + paths = ', '.join([x.path for x in tpl]) + else: + color = output.TERM_SUPPORT.LOWLIGHT + cend = output.TERM_SUPPORT.ENDC + paths = ', '.join(["%s%s@%s%s" % (_.name, color, + getattr(_, 'yaml', + "Unknown"), + cend) + for _ in tpl]) + out.append('%sVariant %s: %s' % ('\n' if contents else '', + index + 1, paths)) + if contents: + env = set() + for node in tpl: + for key, value in node.environment.iteritems(): + origin = node.environment_origin[key].path + env.add(("%s:%s" % (origin, key), str(value))) + if not env: + continue + fmt = ' %%-%ds => %%s' % max([len(_[0]) for _ in env]) + for record in sorted(env): + out.append(fmt % record) + return "\n".join(out) + def get_number_of_tests(self, test_suite): """ :return: overall number of tests * number of variants diff --git a/avocado/plugins/diff.py b/avocado/plugins/diff.py index d552fe28d53692b07f74a89a3b540a44b4d24859..7b564a675e7a391e84c1239d9610f1e39934a868 100644 --- a/avocado/plugins/diff.py +++ b/avocado/plugins/diff.py @@ -371,19 +371,7 @@ class Diff(CLICmd): results = [] variants = jobdata.retrieve_variants(resultsdir) if variants is not None: - env = set() - for (index, tpl) in enumerate(variants.variants): - paths = ', '.join([x.path for x in tpl]) - results.append('Variant %s: %s\n' % (index + 1, paths)) - for node in tpl: - for key, value in node.environment.iteritems(): - origin = node.environment_origin[key].path - env.add(("%s:%s" % (origin, key), str(value))) - if not env: - continue - fmt = ' %%-%ds => %%s\n' % max([len(_[0]) for _ in env]) - for record in sorted(env): - results.append(fmt % record) + results.extend(variants.to_str(0, 2).splitlines()) else: results.append('Not found\n') diff --git a/avocado/plugins/multiplex.py b/avocado/plugins/multiplex.py index f234496055759d5da1877c6601bbb355515f8f0d..c621bce5b735670e718b4e3912728caabe5b61ed 100644 --- a/avocado/plugins/multiplex.py +++ b/avocado/plugins/multiplex.py @@ -15,7 +15,7 @@ import logging import sys -from avocado.core import exit_codes, output +from avocado.core import exit_codes from avocado.core import tree from avocado.core.plugin_interfaces import CLICmd from avocado.core.settings import settings @@ -82,29 +82,13 @@ class Multiplex(CLICmd): sys.exit(exit_codes.AVOCADO_ALL_OK) log.info('Variants generated:') - for (index, tpl) in enumerate(variants.variants): - if not args.mux_debug: - paths = ', '.join([x.path for x in tpl]) - else: - color = output.TERM_SUPPORT.LOWLIGHT - cend = output.TERM_SUPPORT.ENDC - paths = ', '.join(["%s%s@%s%s" % (_.name, color, - getattr(_, 'yaml', - "Unknown"), - cend) - for _ in tpl]) - log.debug('%sVariant %s: %s', '\n' if args.contents else '', - index + 1, paths) - if args.contents: - env = set() - for node in tpl: - for key, value in node.environment.iteritems(): - origin = node.environment_origin[key].path - env.add(("%s:%s" % (origin, key), str(value))) - if not env: - continue - fmt = ' %%-%ds => %%s' % max([len(_[0]) for _ in env]) - for record in sorted(env): - log.debug(fmt, *record) + if args.mux_debug: + # In this version `avocado_variants.debug` is not set properly, + # let's force-enable it before calling to_str to + # get the expected results. + args.avocado_variants.debug = True + variants = args.avocado_variants.to_str(0, 3 if args.contents else 2) + for line in variants.splitlines(): + log.debug(line) sys.exit(exit_codes.AVOCADO_ALL_OK)