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

varianter: Change the variant format

Currently the variant format is (variant_id, (variant, mux_path)) which
is not really scalable, nor user friendly. Let's use a dictionary
instead.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 62829d0b
......@@ -116,7 +116,9 @@ class MuxPlugin(object):
if self.root is None:
return
for i, variant in enumerate(self.variants, 1):
yield i, (variant, self.mux_path)
yield {"variant_id": i,
"variant": variant,
"mux_path": self.mux_path}
def update_defaults(self, defaults):
"""
......@@ -152,9 +154,9 @@ class MuxPlugin(object):
# variants == 0 means disable, but in plugin it's brief
contents = variants - 1
out.append("Multiplex variants:")
for (index, tpl) in enumerate(self.variants):
for variant in self:
if not self.debug:
paths = ', '.join([x.path for x in tpl])
paths = ', '.join([x.path for x in variant["variant"]])
else:
color = output.TERM_SUPPORT.LOWLIGHT
cend = output.TERM_SUPPORT.ENDC
......@@ -162,12 +164,13 @@ class MuxPlugin(object):
getattr(_, 'yaml',
"Unknown"),
cend)
for _ in tpl])
for _ in variant["variant"]])
out.append('%sVariant %s: %s' % ('\n' if contents else '',
index + 1, paths))
variant["variant_id"],
paths))
if contents:
env = set()
for node in tpl:
for node in variant["variant"]:
for key, value in node.environment.iteritems():
origin = node.environment_origin[key].path
env.add(("%s:%s" % (origin, key), str(value)))
......
......@@ -213,7 +213,14 @@ class VarianterPlugin(Plugin):
@abc.abstractmethod
def __iter__(self):
"""
Yield variant in form of (variant_id, (variant, mux_path))
Yields all variants
The variant is defined as dictionary with at least:
* variant_id - name of the current variant
* variant - AvocadoParams-compatible variant (usually a list)
* mux_path - default path(s)
:yield variant
"""
@abc.abstractmethod
......
......@@ -477,7 +477,8 @@ class TestRunner(object):
:return: Yields tuple(test_factory including params, variant id)
:raises ValueError: When variant and template declare params.
"""
for variant, params in variants.itertests():
for variant in variants.itertests():
params = variant.get("variant")
if params:
if "params" in template[1]:
msg = ("Unable to use test variants %s, params are already"
......
......@@ -82,8 +82,12 @@ class TestName(object):
else:
self.str_uid = str(uid)
self.name = name or "<unknown>"
self.variant = variant
self.str_variant = "" if variant is None else ";" + str(variant)
self.variant = variant["variant_id"] if variant else None
if variant is None:
self.str_variant = ""
else:
self.str_variant = (";" + str(variant["variant_id"])
if variant["variant_id"] else "")
def __str__(self):
return "%s-%s%s" % (self.str_uid, self.name, self.str_variant)
......
......@@ -415,9 +415,16 @@ class Varianter(object):
def itertests(self):
"""
Yield variant-id and test params
Yields all variants of all plugins
:yield (variant-id, (list of leaves, list of default paths))
The variant is defined as dictionary with at least:
* variant_id - name of the current variant
* variant - AvocadoParams-compatible variant (usually a list of
TreeNodes but dict or simply None are also possible
values)
* mux_path - default path(s)
:yield variant
"""
if self._no_variants: # Copy template and modify it's params
plugins_variants = self._variant_plugins.map_method("__iter__")
......@@ -427,4 +434,6 @@ class Varianter(object):
for variant in iter(iter_variants):
yield variant
else: # No variants, use template
yield None, (self._default_params.get_leaves(), "/run")
yield {"variant": self._default_params.get_leaves(),
"variant_id": None,
"mux_path": "/run"}
......@@ -500,6 +500,8 @@ class RemoteTestRunner(TestRunner):
for tst in results['tests']:
name = tst['test'].split('-', 1)
name = [name[0]] + name[1].split(';')
if len(name) == 3:
name[2] = {"variant_id": name[2]}
name = TestName(*name, no_digits=-1)
state = dict(name=name,
time_elapsed=tst['time'],
......
......@@ -65,18 +65,19 @@ class TestClassTestUnit(unittest.TestCase):
# Everything fits
check(1, "a" * 253, None, "1-" + ("a" * 253))
check(2, "a" * 251, 1, "2-" + ("a" * 251) + ";1")
check(99, "a" * 249, 88, "99-" + ("a" * 249) + ";88")
check(2, "a" * 251, {"variant_id": 1}, "2-" + ("a" * 251) + ";1")
check(99, "a" * 249, {"variant_id": 88}, "99-" + ("a" * 249) + ";88")
# Shrink name
check(3, "a" * 252, 1, "3-" + ('a' * 251) + ";1")
check(3, "a" * 252, {"variant_id": 1}, "3-" + ('a' * 251) + ";1")
# Shrink variant
check("a" * 253, "whatever", 99, "a" * 253 + ";9")
check("a" * 254, "whatever", 99, "a" * 254 + ";")
check("a" * 253, "whatever", {"variant_id": 99}, "a" * 253 + ";9")
check("a" * 254, "whatever", {"variant_id": 99}, "a" * 254 + ";")
# No variant
tst = check("a" * 255, "whatever", "whatever-else", "a" * 255)
tst = check("a" * 255, "whatever", {"variant_id": "whatever-else"},
"a" * 255)
# Impossible to store (uid does not fit
self.assertRaises(AssertionError, check, "a" * 256, "whatever", "else",
None)
self.assertRaises(AssertionError, check, "a" * 256, "whatever",
{"variant_id": "else"}, None)
self.assertEqual(os.path.basename(tst.workdir),
os.path.basename(tst.logdir))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册