提交 dd1919d4 编写于 作者: L Lukáš Doktor

mux: Improve the variant_id

Use the combination of path-ordered leaves names and a hash of combined
fingerprint as variant_id. This should improve human-readability of the
results and also it should produce machine-friendly unique names, which
change when values in variant are modified.

Because the leaves names are ordered by path, the order of yaml file
does not affect the variant_id. On the other hand any modified/added
value changes the fingerprint and therefor variant_id.

Important feature is also that the variant still contains the
default_params, but the variant-id is not affected by it.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 134e1144
......@@ -24,6 +24,7 @@ a custom Varianter plugin.
import collections
import itertools
import re
import sha
from . import output
from . import tree
......@@ -163,6 +164,16 @@ class MuxPlugin(object):
self.root = root
self.mux_path = mux_path
self.debug = debug
self.variant_ids = self._get_variant_ids()
def _get_variant_ids(self):
variant_ids = []
for variant in MuxTree(self.root):
variant.sort(key=lambda x: x.path)
fingerprint = "-".join(_.fingerprint() for _ in variant)
variant_ids.append("-".join(node.name for node in variant) + '-' +
sha.sha(fingerprint).hexdigest()[:4])
return variant_ids
def __iter__(self):
"""
......@@ -170,8 +181,8 @@ class MuxPlugin(object):
"""
if self.root is None:
return
for i, variant in enumerate(self.variants, 1):
yield {"variant_id": i,
for vid, variant in itertools.izip(self.variant_ids, self.variants):
yield {"variant_id": vid,
"variant": variant,
"mux_path": self.mux_path}
......
......@@ -15,7 +15,7 @@ basedir = os.path.abspath(basedir)
AVOCADO = os.environ.get("UNITTEST_AVOCADO_CMD", "./scripts/avocado")
DEBUG_OUT = """Variant 16: amd@examples/mux-environment.yaml, virtio@examples/mux-environment.yaml, mint@examples/mux-environment.yaml, debug@examples/mux-environment.yaml
DEBUG_OUT = """Variant mint-debug-amd-virtio-5e02: amd@examples/mux-environment.yaml, virtio@examples/mux-environment.yaml, mint@examples/mux-environment.yaml, debug@examples/mux-environment.yaml
/distro/mint:init => systemv@examples/mux-environment.yaml:/distro/mint
/env/debug:opt_CFLAGS => -O0 -g@examples/mux-environment.yaml:/env/debug
/hw/cpu/amd:cpu_CFLAGS => -march=athlon64@examples/mux-environment.yaml:/hw/cpu/amd
......
......@@ -204,6 +204,27 @@ class TestMuxTree(unittest.TestCase):
self.assertRaises(ValueError,
self.tree.get_node, '/non-existing-node')
def test_fingerprint_order(self):
"""
Checks whether different order changes the fingerprint
"""
children1 = (tree.TreeNode("child1"), tree.TreeNode("child2"))
tree1 = tree.TreeNode("root", children=children1)
children2 = (tree.TreeNode("child2"), tree.TreeNode("child1"))
tree2 = tree.TreeNode("root", children=children2)
mux1 = mux.MuxPlugin()
mux2 = mux.MuxPlugin()
mux1.initialize_mux(tree1, "", False)
mux2.initialize_mux(tree2, "", False)
mux1.update_defaults(tree.TreeNode())
mux2.update_defaults(tree.TreeNode())
variant1 = iter(mux1).next()
variant2 = iter(mux2).next()
self.assertNotEqual(variant1, variant2)
self.assertEqual(str(variant1), "{'mux_path': '', 'variant': "
"[TreeNode(name='child1'), TreeNode(name="
"'child2')], 'variant_id': 'child1-child2-9154'}")
class TestMultiplex(unittest.TestCase):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册