def test_advanced_yaml(self): tree2 = tree.create_from_yaml(['examples/mux-selftest-advanced.yaml']) exp = ['intel', 'amd', 'arm', 'scsi', 'virtio', 'fedora', '6', '7', 'gentoo', 'mint', 'prod', 'new_node'] act = tree2.get_leaves() oldroot = tree2.children[0] self.assertEqual(exp, act) self.assertEqual(tree2.children[0].children[0].path, "/virt/hw") self.assertEqual({'enterprise': True}, oldroot.children[1].children[1].value) self.assertEqual({'new_init': 'systemd'}, oldroot.children[1].children[0].value) self.assertEqual({'is_cool': True}, oldroot.children[1].children[2].value) self.assertEqual({'new_value': 'something'}, oldroot.children[3].children[0].children[0].value) # multiplex root (always True) self.assertEqual(tree2.multiplex, True) # multiplex /virt/ self.assertEqual(tree2.children[0].multiplex, True) # multiplex /virt/hw self.assertEqual(tree2.children[0].children[0].multiplex, True) # multiplex /virt/distro self.assertEqual(tree2.children[0].children[1].multiplex, False) # multiplex /virt/env self.assertEqual(tree2.children[0].children[2].multiplex, False) # multiplex /virt/absolutly self.assertEqual(tree2.children[0].children[3].multiplex, True) # multiplex /virt/distro/fedora self.assertEqual(tree2.children[0].children[1].children[0].multiplex, True)
def test_advanced_yaml(self): tree2 = tree.create_from_yaml(['/:' + PATH_PREFIX + 'examples/mux-' 'selftest-advanced.yaml']) exp = ['intel', 'amd', 'arm', 'scsi', 'virtio', 'fedora', '6', '7', 'gentoo', 'mint', 'prod', 'new_node'] act = tree2.get_leaves() oldroot = tree2.children[0] self.assertEqual(exp, act) self.assertEqual(tree2.children[0].children[0].path, "/virt/hw") self.assertEqual({'enterprise': True}, oldroot.children[1].children[1].value) self.assertEqual({'new_init': 'systemd'}, oldroot.children[1].children[0].value) self.assertEqual({'is_cool': True}, oldroot.children[1].children[2].value) self.assertEqual({'new_value': 'something'}, oldroot.children[3].children[0].children[0].value) # multiplex root (always True) self.assertEqual(tree2.multiplex, None) # multiplex /virt/ self.assertEqual(tree2.children[0].multiplex, None) # multiplex /virt/hw self.assertEqual(tree2.children[0].children[0].multiplex, None) # multiplex /virt/distro self.assertEqual(tree2.children[0].children[1].multiplex, True) # multiplex /virt/env self.assertEqual(tree2.children[0].children[2].multiplex, True) # multiplex /virt/absolutely self.assertEqual(tree2.children[0].children[3].multiplex, None) # multiplex /virt/distro/fedora self.assertEqual(tree2.children[0].children[1].children[0].multiplex, None)
def multiplex_yamls(input_yamls, filter_only=None, filter_out=None, debug=False): if filter_only is None: filter_only = [] if filter_out is None: filter_out = [] input_tree = tree.create_from_yaml(input_yamls, debug) # TODO: Process filters and multiplex simultaneously final_tree = tree.apply_filters(input_tree, filter_only, filter_out) result = MuxTree(final_tree) return result
def multiplex_yamls(input_yamls, filter_only=None, filter_out=None, debug=False): if filter_only is None: filter_only = [] if filter_out is None: filter_out = [] input_tree = tree.create_from_yaml(input_yamls, debug) final_tree = tree.apply_filters(input_tree, filter_only, filter_out) leaves = (x for x in final_tree.iter_leaves() if x.parent is not None) variants = multiplex(leaves) return variants
def parse_yamls(input_yamls, filter_only=None, filter_out=None, debug=False): if filter_only is None: filter_only = [] if filter_out is None: filter_out = [] input_tree = tree.create_from_yaml(input_yamls, debug) # TODO: Process filters and multiplex simultaneously final_tree = tree.apply_filters(input_tree, filter_only, filter_out) leaves, pools = tree2pools(final_tree, final_tree.multiplex) if leaves: # Add remaining leaves (they are not variants, only endpoints pools.extend(leaves) return pools
def multiplex_yamls(input_yamls, filter_only=None, filter_out=None, debug=False): if filter_only is None: filter_only = [] if filter_out is None: filter_out = [] input_tree = tree.create_from_yaml(input_yamls, debug) # TODO: Process filters and multiplex simultaneously final_tree = tree.apply_filters(input_tree, filter_only, filter_out) leaves, pools = tree2pools(final_tree, final_tree.multiplex) if leaves: # Add remaining leaves (they are not variants, only endpoints pools.extend(leaves) return itertools.product(*pools) # *magic required pylint: disable=W0142
def run(self, args): view = output.View(app_args=args) multiplex_files = args.multiplex_files if args.tree: view.notify(event='message', msg='Config file tree structure:') t = tree.create_from_yaml(multiplex_files) t = tree.apply_filters(t, args.filter_only, args.filter_out) view.notify(event='minor', msg=t.get_ascii(attributes=args.attr)) sys.exit(exit_codes.AVOCADO_ALL_OK) try: variants = multiplexer.multiplex_yamls(multiplex_files, args.filter_only, args.filter_out, args.debug) except IOError, details: view.notify(event='error', msg="%s: '%s'" % (details.strerror, details.filename)) sys.exit(exit_codes.AVOCADO_JOB_FAIL)
def run(self, args): view = output.View(app_args=args) multiplex_files = tuple(os.path.abspath(_) for _ in args.multiplex_files) for path in multiplex_files: if not os.path.isfile(path): view.notify(event='error', msg='Invalid multiplex file %s' % path) sys.exit(exit_codes.AVOCADO_JOB_FAIL) if args.tree: view.notify(event='message', msg='Config file tree structure:') t = tree.create_from_yaml(multiplex_files) t = tree.apply_filters(t, args.filter_only, args.filter_out) view.notify(event='minor', msg=t.get_ascii()) sys.exit(exit_codes.AVOCADO_ALL_OK) variants = multiplexer.multiplex_yamls(multiplex_files, args.filter_only, args.filter_out, args.debug) 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, _.yaml, cend) for _ in tpl]) view.notify(event='minor', msg='\nVariant %s: %s' % (index + 1, paths)) if args.contents: env = {} for node in tpl: env.update(node.environment) for k in sorted(env.keys()): view.notify(event='minor', msg=' %s: %s' % (k, env[k])) sys.exit(exit_codes.AVOCADO_ALL_OK)
def run(self, args): view = output.View(app_args=args) multiplex_files = tuple( os.path.abspath(_) for _ in args.multiplex_files) for path in multiplex_files: if not os.path.isfile(path): view.notify(event='error', msg='Invalid multiplex file %s' % path) sys.exit(exit_codes.AVOCADO_JOB_FAIL) if args.tree: view.notify(event='message', msg='Config file tree structure:') t = tree.create_from_yaml(multiplex_files) t = tree.apply_filters(t, args.filter_only, args.filter_out) view.notify(event='minor', msg=t.get_ascii()) sys.exit(exit_codes.AVOCADO_ALL_OK) variants = multiplexer.multiplex_yamls(multiplex_files, args.filter_only, args.filter_out, args.debug) 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, _.yaml, cend) for _ in tpl]) view.notify(event='minor', msg='\nVariant %s: %s' % (index + 1, paths)) if args.contents: env = {} for node in tpl: env.update(node.environment) for k in sorted(env.keys()): view.notify(event='minor', msg=' %s: %s' % (k, env[k])) sys.exit(exit_codes.AVOCADO_ALL_OK)
import itertools import sys if sys.version_info[:2] == (2, 6): import unittest2 as unittest else: import unittest from avocado import multiplexer from avocado.core import tree TREE = tree.create_from_yaml(['examples/mux-selftest.yaml']) def combine(leaves_pools): """ Joins remaining leaves and pools and create product """ if leaves_pools[0]: leaves_pools[1].extend(leaves_pools[0]) return itertools.product(*leaves_pools[1]) class TestMultiplex(unittest.TestCase): tree = TREE mux_full = tuple(combine(multiplexer.tree2pools(tree))) def test_empty(self): act = tuple(combine(multiplexer.tree2pools(tree.TreeNode()))) self.assertEqual(act, ((),)) def test_partial(self):
import pickle import sys from avocado.core import multiplexer from avocado.core import tree if sys.version_info[:2] == (2, 6): import unittest2 as unittest else: import unittest if __name__ == "__main__": PATH_PREFIX = "../../../../" else: PATH_PREFIX = "" TREE = tree.create_from_yaml(['/:' + PATH_PREFIX + 'examples/mux-selftest.yaml']) def combine(leaves_pools): """ Joins remaining leaves and pools and create product """ if leaves_pools[0]: leaves_pools[1].extend(leaves_pools[0]) return itertools.product(*leaves_pools[1]) class TestMultiplex(unittest.TestCase): tree = TREE mux_full = tuple(multiplexer.MuxTree(tree)) def test_empty(self): act = tuple(multiplexer.MuxTree(tree.TreeNode()))
def create_variants_from_yaml(input_yaml, filter_only=[], filter_out=[]): input_tree = tree.create_from_yaml(input_yaml) final_tree = tree.apply_filters(input_tree, filter_only, filter_out) leaves = (x for x in final_tree.iter_leaves() if x.parent is not None) variants = multiplex(leaves) return variants
import pickle import sys from avocado.core import multiplexer from avocado.core import tree if sys.version_info[:2] == (2, 6): import unittest2 as unittest else: import unittest if __name__ == "__main__": PATH_PREFIX = "../../../../" else: PATH_PREFIX = "" TREE = tree.create_from_yaml( ['/:' + PATH_PREFIX + 'examples/mux-selftest.yaml']) def combine(leaves_pools): """ Joins remaining leaves and pools and create product """ if leaves_pools[0]: leaves_pools[1].extend(leaves_pools[0]) return itertools.product(*leaves_pools[1]) class TestMultiplex(unittest.TestCase): tree = TREE mux_full = tuple(multiplexer.MuxTree(tree)) def test_empty(self): act = tuple(multiplexer.MuxTree(tree.TreeNode()))
def setUp(self): self.mux_tree = tree.create_from_yaml(['/:' + PATH_PREFIX + 'examples/mux-selftest.yaml']) self.mux_full = tuple(multiplexer.MuxTree(self.mux_tree))
def setUp(self): self.mux_tree = tree.create_from_yaml( ['/:' + PATH_PREFIX + 'examples/mux-selftest.yaml']) self.mux_full = tuple(multiplexer.MuxTree(self.mux_tree))
class TestTree(unittest.TestCase): # Share tree with all tests tree = tree.create_from_yaml(['examples/mux-selftest.yaml']) def test_node_order(self): self.assertIsInstance(self.tree, tree.TreeNode) self.assertEqual('hw', self.tree.children[0]) self.assertEqual({'cpu_CFLAGS': '-march=core2'}, self.tree.children[0].children[0].children[0].value) disk = self.tree.children[0].children[1] self.assertEqual('scsi', disk.children[0]) self.assertEqual({'disk_type': 'scsi', 'corruptlist': ['againlist']}, disk.children[0].value) self.assertEqual('virtio', disk.children[1]) self.assertEqual({}, disk.children[1].value) self.assertEqual('distro', self.tree.children[1]) self.assertEqual('env', self.tree.children[2]) self.assertEqual({'opt_CFLAGS': '-O2'}, self.tree.children[2].children[0].value) def test_eq(self): # Copy tree2 = copy.deepcopy(self.tree) self.assertEqual(self.tree, tree2) # Additional node child = tree.TreeNode("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 = tree.TreeNode() 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) def test_links(self): """ Verify child->parent links """ for leaf in self.tree: self.assertEqual(leaf.root, self.tree) def test_basic_functions(self): # repr self.assertEqual("TreeNode(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()) # asci contain all leaves and doesn't raise any exceptions ascii = self.tree.get_ascii() for leaf in leaves: self.assertIn(leaf, ascii, "Leaf %s not in asci:\n%s" % (leaf, ascii)) def test_filters(self): tree2 = copy.deepcopy(self.tree) exp = ['intel', 'amd', 'arm', 'fedora', 'mint', 'prod'] act = tree.apply_filters(tree2, filter_only=['/hw/cpu', '']).get_leaves() self.assertEqual(exp, act) tree2 = copy.deepcopy(self.tree) exp = ['scsi', 'virtio', 'fedora', 'mint', 'prod'] act = tree.apply_filters(tree2, filter_out=['/hw/cpu', '']).get_leaves() self.assertEqual(exp, act) def test_merge_trees(self): tree2 = copy.deepcopy(self.tree) tree3 = tree.TreeNode() tree3.add_child(tree.TreeNode('hw', {'another_value': 'bbb'})) tree3.children[0].add_child(tree.TreeNode('nic')) tree3.children[0].children[0].add_child(tree.TreeNode('default')) tree3.children[0].children[0].add_child(tree.TreeNode('virtio', {'nic': 'virtio'} )) tree3.children[0].add_child(tree.TreeNode('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) def test_advanced_yaml(self): tree2 = tree.create_from_yaml(['examples/mux-selftest-advanced.yaml']) exp = ['intel', 'amd', 'arm', 'scsi', 'virtio', 'fedora', '6', '7', 'gentoo', 'mint', 'prod', 'new_node'] act = tree2.get_leaves() oldroot = tree2.children[0] self.assertEqual(exp, act) self.assertEqual(tree2.children[0].children[0].path, "/virt/hw") self.assertEqual({'enterprise': True}, oldroot.children[1].children[1].value) self.assertEqual({'new_init': 'systemd'}, oldroot.children[1].children[0].value) self.assertEqual({'is_cool': True}, oldroot.children[1].children[2].value) self.assertEqual({'new_value': 'something'}, oldroot.children[3].children[0].children[0].value) # multiplex root (always True) self.assertEqual(tree2.multiplex, True) # multiplex /virt/ self.assertEqual(tree2.children[0].multiplex, True) # multiplex /virt/hw self.assertEqual(tree2.children[0].children[0].multiplex, True) # multiplex /virt/distro self.assertEqual(tree2.children[0].children[1].multiplex, False) # multiplex /virt/env self.assertEqual(tree2.children[0].children[2].multiplex, False) # multiplex /virt/absolutly self.assertEqual(tree2.children[0].children[3].multiplex, True) # multiplex /virt/distro/fedora self.assertEqual(tree2.children[0].children[1].children[0].multiplex, True)