From 3423ca96cb1183dca78dd25f557df06571bcd359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= Date: Tue, 4 Oct 2016 19:44:09 +0200 Subject: [PATCH] avocado.core.parser: Introduce "mux_debug" option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The mux need to support debugging the options. This is a basic implementation which allows requesting mux to use TreeNodeDebug. Then it's the plugin's job to check whether mux uses debug (`mux.debug`) and act accordingly. In this basic implementation the debug is only enabled for `--multiplex` and `@None` is used for other injects (like `--mux-inject`) Signed-off-by: Lukáš Doktor --- avocado/core/multiplexer.py | 20 ++++++++++++-------- avocado/core/parser.py | 2 +- avocado/plugins/multiplex.py | 12 ++++++------ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/avocado/core/multiplexer.py b/avocado/core/multiplexer.py index 1ff73e64..deb25558 100644 --- a/avocado/core/multiplexer.py +++ b/avocado/core/multiplexer.py @@ -391,22 +391,27 @@ class Mux(object): This is a multiplex object which multiplexes the test_suite. """ - def __init__(self): + def __init__(self, debug=False): + """ + :param debug: Store whether this instance should debug the mux + :note: people need to check whether mux uses debug and reflect that + in order to provide the right results. + """ self._has_multiple_variants = None self.variants = None - self.data = tree.TreeNode() + self.debug = debug + self.data = tree.TreeNodeDebug() if debug else tree.TreeNode() self._mux_path = None - def parse(self, args, debug=False): + def parse(self, args): """ Apply options defined on the cmdline :param args: Parsed cmdline arguments - :param debug: Whether to debug the mux parsing """ filter_only = getattr(args, 'filter_only', None) filter_out = getattr(args, 'filter_out', None) - self._parse_basic_injects(args, debug) + self._parse_basic_injects(args) mux_tree = tree.apply_filters(self.data, filter_only, filter_out) self.variants = MuxTree(mux_tree) self._mux_path = getattr(args, 'mux_path', None) @@ -417,17 +422,16 @@ class Mux(object): self.data_inject = _report_mux_already_parsed self.data_merge = _report_mux_already_parsed - def _parse_basic_injects(self, args, debug): + def _parse_basic_injects(self, args): """ Inject data from the basic injects defined by Mux :param args: Parsed cmdline arguments - :param debug: Whether to debug the mux parsing """ # Merge the multiplex_files multiplex_files = getattr(args, "multiplex", None) if multiplex_files: - self.data_merge(yaml2tree(multiplex_files, debug=debug)) + self.data_merge(yaml2tree(multiplex_files, debug=self.debug)) # FIXME: Backward compatibility params, to be removed when 36 LTS is # discontinued diff --git a/avocado/core/parser.py b/avocado/core/parser.py index cb38fc25..9ac4b1f6 100644 --- a/avocado/core/parser.py +++ b/avocado/core/parser.py @@ -125,7 +125,7 @@ class Parser(object): dest='subcommand') # Allow overriding default params by plugins - self.args.mux = multiplexer.Mux() + self.args.mux = multiplexer.Mux(getattr(self.args, "mux-debug", False)) # FIXME: Backward compatibility params, to be removed when 36 LTS is # discontinued self.args.default_avocado_params = tree.TreeNode() diff --git a/avocado/plugins/multiplex.py b/avocado/plugins/multiplex.py index 6b74e6c9..05535ced 100644 --- a/avocado/plugins/multiplex.py +++ b/avocado/plugins/multiplex.py @@ -57,8 +57,8 @@ class Multiplex(CLICmd): "the final multiplex tree.") env_parser = parser.add_argument_group("environment view options") env_parser.add_argument('-d', '--debug', action='store_true', - default=False, help="Debug multiplexed " - "files.") + dest="mux_debug", default=False, + help="Debug the multiplex tree.") tree_parser = parser.add_argument_group("tree view options") tree_parser.add_argument('-t', '--tree', action='store_true', default=False, help='Shows the multiplex ' @@ -69,17 +69,17 @@ class Multiplex(CLICmd): def run(self, args): log = logging.getLogger("avocado.app") err = None - if args.tree and args.debug: + if args.tree and args.mux_debug: err = "Option --tree is incompatible with --debug." elif not args.tree and args.inherit: err = "Option --inherit can be only used with --tree" if err: log.error(err) sys.exit(exit_codes.AVOCADO_FAIL) - mux = multiplexer.Mux() + mux = multiplexer.Mux(args.mux_debug) root = mux.data try: - mux.parse(args, debug=args.debug) + mux.parse(args) except (IOError, ValueError) as details: log.error("Unable to parse mux: %s", details) sys.exit(exit_codes.AVOCADO_JOB_FAIL) @@ -97,7 +97,7 @@ class Multiplex(CLICmd): log.info('Variants generated:') for (index, tpl) in enumerate(mux.variants): - if not args.debug: + if not args.mux_debug: paths = ', '.join([x.path for x in tpl]) else: color = output.TERM_SUPPORT.LOWLIGHT -- GitLab