Exemplo n.º 1
0
 def test_eq(self):
     # Copy
     tree2 = copy.deepcopy(self.tree)
     self.assertEqual(self.tree, tree2)
     # Additional node
     child = mux.MuxTreeNode("20", {'name': 'Heisenbug'})
     tree2.children[1].children[1].add_child(child)
     self.assertNotEqual(self.tree, tree2)
     # Should match again
     child.detach()
     self.assertEqual(self.tree, tree2)
     # Missing node
     tree2.children[1].children[1].detach()
     self.assertNotEqual(self.tree, tree2)
     self.assertEqual(self.tree.children[0], tree2.children[0])
     # Different value
     tree2.children[0].children[0].children[0].value = {'something': 'else'}
     self.assertNotEqual(self.tree.children[0], tree2.children[0])
     tree3 = mux.MuxTreeNode()
     self.assertNotEqual(tree3, tree2)
     # Merge
     tree3.merge(tree2)
     self.assertEqual(tree3, tree2)
     # Add_child existing
     tree3.add_child(tree2.children[0])
     self.assertEqual(tree3, tree2)
Exemplo n.º 2
0
 def test_tree_mux_node(self):
     """
     Check the extension of fingerprint in MuxTreeNode
     """
     node1 = tree.TreeNode("node1", {"foo": "bar"})
     node1m = mux.MuxTreeNode("node1", {"foo": "bar"})
     node1m_fingerprint = node1m.fingerprint()
     self.assertNotEqual(node1.fingerprint(), node1m_fingerprint)
     node1mduplicate = mux.MuxTreeNode("node1", {"foo": "bar"})
     self.assertEqual(node1m_fingerprint, node1mduplicate.fingerprint())
     node1mb_ctrl = mux.MuxTreeNode("node1", {"foo": "bar"})
     node1mb_ctrl.ctrl = [mux.Control(0, 0)]
     self.assertNotEqual(node1m_fingerprint, node1mb_ctrl.fingerprint())
Exemplo n.º 3
0
 def test_merge_trees(self):
     tree2 = copy.deepcopy(self.tree)
     tree3 = mux.MuxTreeNode()
     tree3.add_child(mux.MuxTreeNode('hw', {'another_value': 'bbb'}))
     tree3.children[0].add_child(mux.MuxTreeNode('nic'))
     tree3.children[0].children[0].add_child(mux.MuxTreeNode('default'))
     tree3.children[0].children[0].add_child(
         mux.MuxTreeNode('virtio', {'nic': 'virtio'}))
     tree3.children[0].add_child(
         mux.MuxTreeNode('cpu', {'test_value': ['z']}))
     tree2.merge(tree3)
     exp = [
         'intel', 'amd', 'arm', 'scsi', 'virtio', 'default', 'virtio',
         'fedora', 'mint', 'prod'
     ]
     self.assertEqual(exp, tree2.get_leaves())
     self.assertEqual(
         {
             'corruptlist': ['upper_node_list'],
             'another_value': 'bbb'
         }, tree2.children[0].value)
     self.assertEqual({
         'joinlist': ['first_item'],
         'test_value': ['z']
     }, tree2.children[0].children[0].value)
     self.assertFalse(tree2.children[0].children[2].children[0].value)
     self.assertEqual({'nic': 'virtio'},
                      tree2.children[0].children[2].children[1].value)
Exemplo n.º 4
0
def create_from_yaml(paths, debug=False):
    """
    Create tree structure from yaml-like file
    :param fileobj: File object to be processed
    :raise SyntaxError: When yaml-file is corrupted
    :return: Root of the created tree structure
    """
    def _merge(data, path):
        """ Normal run """
        tmp = _create_from_yaml(path)
        if tmp:
            data.merge(tmp)

    def _merge_debug(data, path):
        """ Use NamedTreeNodeDebug magic """
        node_cls = tree.get_named_tree_cls(path, mux.MuxTreeNodeDebug)
        tmp = _create_from_yaml(path, node_cls)
        if tmp:
            data.merge(tmp)

    if not debug:
        data = mux.MuxTreeNode()
        merge = _merge
    else:
        data = mux.MuxTreeNodeDebug()
        merge = _merge_debug

    path = None
    try:
        for path in paths:
            merge(data, path)
    # Yaml can raise IndexError on some files
    except (yaml.YAMLError, IndexError) as details:
        if 'mapping values are not allowed in this context' in str(details):
            details = ("%s\nMake sure !tags and colons are separated by a "
                       "space (eg. !include :)" % details)
        msg = "Invalid multiplex file '%s': %s" % (path, details)
        raise IOError(2, msg, path)
    return data
Exemplo n.º 5
0
 def test_empty(self):
     act = tuple(varianter.MuxTree(mux.MuxTreeNode()))
     self.assertEqual(act, (['', ],))
Exemplo n.º 6
0
    def initialize(self, args):
        # Deprecated filters
        only = getattr(args, "filter_only", None)
        if only:
            self._log_deprecation_msg("--filter-only", "--mux-filter-only")
            mux_filter_only = getattr(args, "mux_filter_only")
            if mux_filter_only:
                args.mux_filter_only = mux_filter_only + only
            else:
                args.mux_filter_only = only
        out = getattr(args, "filter_out", None)
        if out:
            self._log_deprecation_msg("--filter-out", "--mux-filter-out")
            mux_filter_out = getattr(args, "mux_filter_out")
            if mux_filter_out:
                args.mux_filter_out = mux_filter_out + out
            else:
                args.mux_filter_out = out
        if args.avocado_variants.debug:
            data = mux.MuxTreeNodeDebug()
        else:
            data = mux.MuxTreeNode()

        debug = getattr(args, "mux_debug", False)

        # Merge the multiplex
        multiplex_files = getattr(args, "mux_yaml", None)
        if multiplex_files:
            try:
                data.merge(create_from_yaml(multiplex_files, debug))
            except IOError as details:
                error_msg = "%s : %s" % (details.strerror, details.filename)
                logging.getLogger("avocado.app").error(error_msg)
                if args.subcommand == 'run':
                    sys.exit(exit_codes.AVOCADO_JOB_FAIL)
                else:
                    sys.exit(exit_codes.AVOCADO_FAIL)

        # Deprecated --multiplex option
        multiplex_files = getattr(args, "multiplex", None)
        if multiplex_files:
            self._log_deprecation_msg("--multiplex", "--mux-yaml")
            try:
                data.merge(create_from_yaml(multiplex_files, debug))
                from_yaml = create_from_yaml(multiplex_files, debug)
                args.avocado_variants.data_merge(from_yaml)
            except IOError as details:
                error_msg = "%s : %s" % (details.strerror, details.filename)
                logging.getLogger("avocado.app").error(error_msg)
                if args.subcommand == 'run':
                    sys.exit(exit_codes.AVOCADO_JOB_FAIL)
                else:
                    sys.exit(exit_codes.AVOCADO_FAIL)

        # Extend default multiplex tree of --mux-inject values
        for inject in getattr(args, "mux_inject", []):
            entry = inject.split(':', 3)
            if len(entry) < 2:
                raise ValueError("key:entry pairs required, found only %s"
                                 % (entry))
            elif len(entry) == 2:   # key, entry
                entry.insert(0, '')  # add path='' (root)
            data.get_node(entry[0], True).value[entry[1]] = entry[2]

        mux_filter_only = getattr(args, 'mux_filter_only', None)
        mux_filter_out = getattr(args, 'mux_filter_out', None)
        data = mux.apply_filters(data, mux_filter_only, mux_filter_out)
        if data != mux.MuxTreeNode():
            mux_path = getattr(args, "mux_path", ["/run/*"])
            if mux_path is None:
                mux_path = ["/run/*"]
            self.initialize_mux(data, mux_path, debug)