Пример #1
0
    def to_str(self, summary, variants, **kwargs):
        """
        See :meth:`avocado.core.plugin_interfaces.Varianter.to_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.root,
                                       verbose=summary - 1,
                                       use_utf8=kwargs.get("use_utf8", None))
            # ascii is a subset of UTF-8, let's use always UTF-8 to decode here
            out.append(tree_repr.decode('utf-8'))
            out.append("")

        if variants:
            # variants == 0 means disable, but in plugin it's brief
            out.append("Multiplex variants (%s):" % len(self))
            for variant in self:
                out.extend(
                    varianter.variant_to_str(variant, variants - 1, kwargs))
        return "\n".join(out)
Пример #2
0
    def run(self, args):
        log = logging.getLogger("avocado.app")
        err = None
        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)
        variants = args.avocado_variants
        try:
            variants.parse(args)
        except (IOError, ValueError) as details:
            log.error("Unable to parse variants: %s", details)
            sys.exit(exit_codes.AVOCADO_JOB_FAIL)
        if args.tree:
            if args.contents:
                verbose = 1
            else:
                verbose = 0
            if args.inherit:
                verbose += 2
            use_utf8 = settings.get_value("runner.output",
                                          "utf8",
                                          key_type=bool,
                                          default=None)
            log.debug(tree.tree_view(variants.variants.root, verbose,
                                     use_utf8))
            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)

        sys.exit(exit_codes.AVOCADO_ALL_OK)
Пример #3
0
 def test_basic_functions(self):
     # repr
     self.assertEqual("MuxTreeNode(name='hw')", repr(self.tree.children[0]))
     # str
     self.assertEqual("/distro/mint: init=systemv",
                      str(self.tree.children[1].children[1]))
     # len
     self.assertEqual(8, len(self.tree))  # number of leaves
     # __iter__
     self.assertEqual(8, sum((1 for _ in self.tree)))  # number of leaves
     # .root
     self.assertEqual(id(self.tree),
                      id(self.tree.children[0].children[0].children[0].root)
                      )
     # .parents
     self.assertEqual(['hw', ''], self.tree.children[0].children[0].parents)
     # environment / (root)
     self.assertEqual({}, self.tree.environment)
     # environment /hw (nodes first)
     self.assertEqual({'corruptlist': ['upper_node_list']},
                      self.tree.children[0].environment)
     cpu = self.tree.children[0].children[0]
     # environment /hw/cpu (mixed env)
     self.assertEqual({'corruptlist': ['upper_node_list'],
                       'joinlist': ['first_item']},
                      cpu.environment)
     # environment /hw/cpu/amd (list extension)
     vals = {'corruptlist': ['upper_node_list'],
             'cpu_CFLAGS': '-march=athlon64',
             'joinlist': ['first_item', 'second', 'third']}
     self.assertEqual(vals, cpu.children[1].environment)
     # environment /hw/cpu/arm (deep env)
     vals = {'corruptlist': ['upper_node_list'], 'joinlist': ['first_item'],
             'cpu_CFLAGS': '-mabi=apcs-gnu '
             '-march=armv8-a -mtune=arm8'}
     self.assertEqual(vals, cpu.children[2].environment)
     # environment /hw/disk (list -> string)
     vals = {'corruptlist': 'nonlist', 'disk_type': 'virtio'}
     disk = self.tree.children[0].children[1]
     self.assertEqual(vals, disk.environment)
     # environment /hw/disk/scsi (string -> list)
     vals = {'corruptlist': ['againlist'], 'disk_type': 'scsi'}
     self.assertEqual(vals, disk.children[0].environment)
     # environment /env
     vals = {'opt_CFLAGS': '-Os'}
     self.assertEqual(vals, self.tree.children[2].environment)
     # leaves order
     leaves = ['intel', 'amd', 'arm', 'scsi', 'virtio', 'fedora', 'mint',
               'prod']
     self.assertEqual(leaves, self.tree.get_leaves())
     # ascii contain all leaves and doesn't raise any exceptions
     ascii = tree.tree_view(self.tree, 0, False)
     for leaf in leaves:
         self.assertIn(leaf, ascii, "Leaf %s not in asci:\n%s"
                       % (leaf, ascii))
Пример #4
0
    def run(self, args):
        log = logging.getLogger("avocado.app")
        err = None
        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 = args.mux
        try:
            mux.parse(args)
        except (IOError, ValueError) as details:
            log.error("Unable to parse mux: %s", details)
            sys.exit(exit_codes.AVOCADO_JOB_FAIL)
        if args.tree:
            if args.contents:
                verbose = 1
            else:
                verbose = 0
            if args.inherit:
                verbose += 2
            use_utf8 = settings.get_value("runner.output", "utf8",
                                          key_type=bool, default=None)
            log.debug(tree.tree_view(mux.variants.root, verbose, use_utf8))
            sys.exit(exit_codes.AVOCADO_ALL_OK)

        log.info('Variants generated:')
        for (index, tpl) in enumerate(mux.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)

        sys.exit(exit_codes.AVOCADO_ALL_OK)
Пример #5
0
    def to_str(self, summary, variants, **kwargs):
        """
        See :meth:`avocado.core.plugin_interfaces.Varianter.to_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.root, verbose=summary - 1,
                                       use_utf8=kwargs.get("use_utf8", None))
            out.append(tree_repr)
            out.append("")

        if variants:
            # variants == 0 means disable, but in plugin it's brief
            out.append("Multiplex variants (%s):" % len(self))
            for variant in self:
                out.extend(varianter.variant_to_str(variant, variants - 1,
                                                    kwargs, self.debug))
        return "\n".join(out)
Пример #6
0
 def test_basic_functions(self):
     # repr
     self.assertEqual("MuxTreeNode(name='hw')", repr(self.tree.children[0]))
     # str
     self.assertEqual(u"/distro/\u0161mint: init=systemv",
                      astring.to_text(self.tree.children[1].children[1]))
     # len
     self.assertEqual(8, len(self.tree))  # number of leaves
     # __iter__
     self.assertEqual(8, sum((1 for _ in self.tree)))  # number of leaves
     # .root
     self.assertEqual(
         id(self.tree),
         id(self.tree.children[0].children[0].children[0].root))
     # .parents
     self.assertEqual(['hw', ''], self.tree.children[0].children[0].parents)
     # environment / (root)
     self.assertEqual({}, self.tree.environment)
     # environment /hw (nodes first)
     self.assertEqual({'corruptlist': ['upper_node_list']},
                      self.tree.children[0].environment)
     cpu = self.tree.children[0].children[0]
     # environment /hw/cpu (mixed env)
     self.assertEqual(
         {
             'corruptlist': ['upper_node_list'],
             'joinlist': ['first_item']
         }, cpu.environment)
     # environment /hw/cpu/amd (list extension)
     vals = {
         'corruptlist': ['upper_node_list'],
         'cpu_CFLAGS': '-march=athlon64',
         'joinlist': ['first_item', 'second', 'third']
     }
     self.assertEqual(vals, cpu.children[1].environment)
     # environment /hw/cpu/arm (deep env)
     vals = {
         'corruptlist': ['upper_node_list'],
         'joinlist': ['first_item'],
         'cpu_CFLAGS': '-mabi=apcs-gnu '
         '-march=armv8-a -mtune=arm8'
     }
     self.assertEqual(vals, cpu.children[2].environment)
     # environment /hw/disk (list -> string)
     vals = {'corruptlist': 'nonlist', 'disk_type': 'virtio'}
     disk = self.tree.children[0].children[1]
     self.assertEqual(vals, disk.environment)
     # environment /hw/disk/scsi (string -> list)
     vals = {'corruptlist': ['againlist'], 'disk_type': 'scsi'}
     self.assertEqual(vals, disk.children[0].environment)
     # environment /env
     vals = {'opt_CFLAGS': '-Os'}
     self.assertEqual(vals, self.tree.children[2].environment)
     # leaves order
     leaves = [
         'intel', 'amd', 'arm', 'scsi', 'virtio', 'fedora', u'\u0161mint',
         'prod'
     ]
     self.assertEqual(leaves, self.tree.get_leaves())
     tree_view = tree.tree_view(self.tree, 0, False)
     # ascii treeview contains only ascii chars
     tree_view.decode('ascii')
     # ascii treeview contain all leaves
     for leaf in leaves:
         # In ascii mode we replace non-ascii character using
         # xmlcharrefreplace, make sure this is performed
         leaf = leaf.encode('ascii', errors='xmlcharrefreplace')
         self.assertIn(leaf, tree_view,
                       "Leaf %s not in ascii:\n%s" % (leaf, tree_view))
Пример #7
0
 def test_basic_functions(self):
     # repr
     self.assertEqual("MuxTreeNode(name='hw')", repr(self.tree.children[0]))
     # str
     self.assertEqual(
         "/distro/\u0161mint: init=systemv",
         astring.to_text(self.tree.children[1].children[1]),
     )
     # len
     self.assertEqual(8, len(self.tree))  # number of leaves
     # __iter__
     self.assertEqual(8, sum((1 for _ in self.tree)))  # number of leaves
     # .root
     self.assertEqual(
         id(self.tree), id(self.tree.children[0].children[0].children[0].root)
     )
     # .parents
     self.assertEqual(["hw", ""], self.tree.children[0].children[0].parents)
     # environment / (root)
     self.assertEqual({}, self.tree.environment)
     # environment /hw (nodes first)
     self.assertEqual(
         {"corruptlist": ["upper_node_list"]}, self.tree.children[0].environment
     )
     cpu = self.tree.children[0].children[0]
     # environment /hw/cpu (mixed env)
     self.assertEqual(
         {"corruptlist": ["upper_node_list"], "joinlist": ["first_item"]},
         cpu.environment,
     )
     # environment /hw/cpu/amd (list extension)
     vals = {
         "corruptlist": ["upper_node_list"],
         "cpu_CFLAGS": "-march=athlon64",
         "joinlist": ["first_item", "second", "third"],
     }
     self.assertEqual(vals, cpu.children[1].environment)
     # environment /hw/cpu/arm (deep env)
     vals = {
         "corruptlist": ["upper_node_list"],
         "joinlist": ["first_item"],
         "cpu_CFLAGS": "-mabi=apcs-gnu " "-march=armv8-a -mtune=arm8",
     }
     self.assertEqual(vals, cpu.children[2].environment)
     # environment /hw/disk (list -> string)
     vals = {"corruptlist": "nonlist", "disk_type": "virtio"}
     disk = self.tree.children[0].children[1]
     self.assertEqual(vals, disk.environment)
     # environment /hw/disk/scsi (string -> list)
     vals = {"corruptlist": ["againlist"], "disk_type": "scsi"}
     self.assertEqual(vals, disk.children[0].environment)
     # environment /env
     vals = {"opt_CFLAGS": "-Os"}
     self.assertEqual(vals, self.tree.children[2].environment)
     # leaves order
     leaves = [
         "intel",
         "amd",
         "arm",
         "scsi",
         "virtio",
         "fedora",
         "\u0161mint",
         "prod",
     ]
     self.assertEqual(leaves, self.tree.get_leaves())
     tree_view = tree.tree_view(self.tree, 0, False)
     # ascii treeview contains only ascii chars
     tree_view.decode("ascii")
     # ascii treeview contain all leaves
     for leaf in leaves:
         # In ascii mode we replace non-ascii character using
         # xmlcharrefreplace, make sure this is performed
         leaf = leaf.encode("ascii", errors="xmlcharrefreplace")
         self.assertIn(leaf, tree_view, f"Leaf {leaf} not in ascii:\n{tree_view}")
Пример #8
0
    def run(self, args):
        self._activate(args)
        log = logging.getLogger("avocado.app")
        err = None
        if args.tree and args.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)
        try:
            mux_tree = multiplexer.yaml2tree(args.multiplex_files,
                                             args.filter_only, args.filter_out,
                                             args.debug)
        except IOError as details:
            log.error(details.strerror)
            sys.exit(exit_codes.AVOCADO_JOB_FAIL)
        if args.system_wide:
            mux_tree.merge(args.default_multiplex_tree)
        mux_tree.merge(self._from_args_tree)
        if args.tree:
            if args.contents:
                verbose = 1
            else:
                verbose = 0
            if args.inherit:
                verbose += 2
            use_utf8 = settings.get_value("runner.output", "utf8",
                                          key_type=bool, default=None)
            log.debug(tree.tree_view(mux_tree, verbose, use_utf8))
            sys.exit(exit_codes.AVOCADO_ALL_OK)

        variants = multiplexer.MuxTree(mux_tree)
        log.info('Variants generated:')
        for (index, tpl) in enumerate(variants):
            if not args.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)

        sys.exit(exit_codes.AVOCADO_ALL_OK)
Пример #9
0
 def test_basic_functions(self):
     # repr
     self.assertEqual("MuxTreeNode(name='hw')",
                      repr(self.tree.children[0]))
     # str
     self.assertEqual(u"/distro/\u0161mint: init=systemv",
                      astring.to_text(self.tree.children[1].children[1]))
     # len
     self.assertEqual(8, len(self.tree))  # number of leaves
     # __iter__
     self.assertEqual(8, sum((1 for _ in self.tree)))  # number of leaves
     # .root
     self.assertEqual(id(self.tree),
                      id(self.tree.children[0].children[0].children[0].root)
                      )
     # .parents
     self.assertEqual(['hw', ''], self.tree.children[0].children[0].parents)
     # environment / (root)
     self.assertEqual({}, self.tree.environment)
     # environment /hw (nodes first)
     self.assertEqual({'corruptlist': ['upper_node_list']},
                      self.tree.children[0].environment)
     cpu = self.tree.children[0].children[0]
     # environment /hw/cpu (mixed env)
     self.assertEqual({'corruptlist': ['upper_node_list'],
                       'joinlist': ['first_item']},
                      cpu.environment)
     # environment /hw/cpu/amd (list extension)
     vals = {'corruptlist': ['upper_node_list'],
             'cpu_CFLAGS': '-march=athlon64',
             'joinlist': ['first_item', 'second', 'third']}
     self.assertEqual(vals, cpu.children[1].environment)
     # environment /hw/cpu/arm (deep env)
     vals = {'corruptlist': ['upper_node_list'], 'joinlist': ['first_item'],
             'cpu_CFLAGS': '-mabi=apcs-gnu '
             '-march=armv8-a -mtune=arm8'}
     self.assertEqual(vals, cpu.children[2].environment)
     # environment /hw/disk (list -> string)
     vals = {'corruptlist': 'nonlist', 'disk_type': 'virtio'}
     disk = self.tree.children[0].children[1]
     self.assertEqual(vals, disk.environment)
     # environment /hw/disk/scsi (string -> list)
     vals = {'corruptlist': ['againlist'], 'disk_type': 'scsi'}
     self.assertEqual(vals, disk.children[0].environment)
     # environment /env
     vals = {'opt_CFLAGS': '-Os'}
     self.assertEqual(vals, self.tree.children[2].environment)
     # leaves order
     leaves = ['intel', 'amd', 'arm', 'scsi', 'virtio', 'fedora',
               u'\u0161mint', 'prod']
     self.assertEqual(leaves, self.tree.get_leaves())
     tree_view = tree.tree_view(self.tree, 0, False)
     # ascii treeview contains only ascii chars
     tree_view.decode('ascii')
     # ascii treeview contain all leaves
     for leaf in leaves:
         # In ascii mode we replace non-ascii character using
         # xmlcharrefreplace, make sure this is performed
         leaf = leaf.encode('ascii', errors='xmlcharrefreplace')
         self.assertIn(leaf, tree_view, "Leaf %s not in ascii:\n%s"
                       % (leaf, tree_view))
Пример #10
0
class Multiplex(CLICmd):
    """
    Implements the avocado 'multiplex' subcommand
    """

    name = 'multiplex'
    description = 'Generate a list of dictionaries with params from a multiplex file'

    def __init__(self, *args, **kwargs):
        super(Multiplex, self).__init__(*args, **kwargs)
        self._from_args_tree = tree.TreeNode()

    def configure(self, parser):
        if multiplexer.MULTIPLEX_CAPABLE is False:
            return

        parser = super(Multiplex, self).configure(parser)
        parser.add_argument('multiplex_files',
                            nargs='+',
                            help='Path(s) to a multiplex file(s)')

        parser.add_argument('--filter-only',
                            nargs='*',
                            default=[],
                            help='Filter only path(s) from multiplexing')

        parser.add_argument('--filter-out',
                            nargs='*',
                            default=[],
                            help='Filter out path(s) from multiplexing')
        parser.add_argument('-s',
                            '--system-wide',
                            action='store_true',
                            help="Combine the files with the default "
                            "tree.")
        parser.add_argument('-c',
                            '--contents',
                            action='store_true',
                            default=False,
                            help="Shows the node content "
                            "(variables)")
        parser.add_argument('--mux-inject',
                            default=[],
                            nargs='*',
                            help="Inject [path:]key:node values into "
                            "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.")
        tree_parser = parser.add_argument_group("tree view options")
        tree_parser.add_argument('-t',
                                 '--tree',
                                 action='store_true',
                                 default=False,
                                 help='Shows the multiplex '
                                 'tree structure')
        tree_parser.add_argument('-i',
                                 '--inherit',
                                 action="store_true",
                                 help="Show the inherited values")

    def _activate(self, args):
        # Extend default multiplex tree of --env values
        for value in getattr(args, "mux_inject", []):
            value = value.split(':', 2)
            if len(value) < 2:
                raise ValueError("key:value pairs required, found only %s" %
                                 (value))
            elif len(value) == 2:
                self._from_args_tree.value[value[0]] = value[1]
            else:
                node = self._from_args_tree.get_node(value[0], True)
                node.value[value[1]] = value[2]

    def run(self, args):
        self._activate(args)
        view = output.View(app_args=args)
        err = None
        if args.tree and args.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:
            view.notify(event="minor", msg=self.parser.format_help())
            view.notify(event="error", msg=err)
            sys.exit(exit_codes.AVOCADO_FAIL)
        try:
            mux_tree = multiplexer.yaml2tree(args.multiplex_files,
                                             args.filter_only, args.filter_out,
                                             args.debug)
        except IOError, details:
            view.notify(event='error', msg=details.strerror)
            sys.exit(exit_codes.AVOCADO_JOB_FAIL)
        if args.system_wide:
            mux_tree.merge(args.default_multiplex_tree)
        mux_tree.merge(self._from_args_tree)
        if args.tree:
            if args.contents:
                verbose = 1
            else:
                verbose = 0
            if args.inherit:
                verbose += 2
            use_utf8 = settings.get_value("runner.output",
                                          "utf8",
                                          key_type=bool,
                                          default=None)
            view.notify(event='minor',
                        msg=tree.tree_view(mux_tree, verbose, use_utf8))
            sys.exit(exit_codes.AVOCADO_ALL_OK)

        variants = multiplexer.MuxTree(mux_tree)
        view.notify(event='message', msg='Variants generated:')
        for (index, tpl) in enumerate(variants):
            if not args.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
                ])
            view.notify(event='minor',
                        msg='%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):
                    view.notify(event='minor', msg=fmt % record)

        sys.exit(exit_codes.AVOCADO_ALL_OK)