From dd1919d4fd8bce9b12dc0f16542b98ce79c7f56a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= Date: Wed, 12 Apr 2017 11:22:41 +0200 Subject: [PATCH] mux: Improve the variant_id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Lukáš Doktor --- avocado/core/mux.py | 15 +++++++++++++-- selftests/functional/test_multiplex.py | 2 +- selftests/unit/test_mux.py | 21 +++++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/avocado/core/mux.py b/avocado/core/mux.py index ddc4fcc6..3aaeb074 100644 --- a/avocado/core/mux.py +++ b/avocado/core/mux.py @@ -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} diff --git a/selftests/functional/test_multiplex.py b/selftests/functional/test_multiplex.py index 9426246b..0f39439d 100644 --- a/selftests/functional/test_multiplex.py +++ b/selftests/functional/test_multiplex.py @@ -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 diff --git a/selftests/unit/test_mux.py b/selftests/unit/test_mux.py index 20cc4951..c96b4a65 100644 --- a/selftests/unit/test_mux.py +++ b/selftests/unit/test_mux.py @@ -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): -- GitLab