From 0ba6a21599096cb6f7414002663acd7fb4a92100 Mon Sep 17 00:00:00 2001 From: Jan Scotka Date: Thu, 25 Jul 2019 11:39:05 +0200 Subject: [PATCH 1/2] PoC for testsets in L1 metadata, it allows to use simplier filter and have stored logic for filtering there --- examples/testsets/.fmf/version | 1 + examples/testsets/inittask1/main.fmf | 1 + examples/testsets/inittask1/setup.sh | 3 ++ examples/testsets/main.fmf | 15 ++++++ examples/testsets/simpletest/main.fmf | 4 ++ examples/testsets/simpletest/runtest.sh | 3 ++ .../simpletest/special-case1/main.fmf | 1 + .../simpletest/special-case2/main.fmf | 2 + fmf/cli.py | 50 +++++++++++++------ 9 files changed, 64 insertions(+), 16 deletions(-) create mode 100644 examples/testsets/.fmf/version create mode 100644 examples/testsets/inittask1/main.fmf create mode 100644 examples/testsets/inittask1/setup.sh create mode 100644 examples/testsets/main.fmf create mode 100644 examples/testsets/simpletest/main.fmf create mode 100644 examples/testsets/simpletest/runtest.sh create mode 100644 examples/testsets/simpletest/special-case1/main.fmf create mode 100644 examples/testsets/simpletest/special-case2/main.fmf diff --git a/examples/testsets/.fmf/version b/examples/testsets/.fmf/version new file mode 100644 index 00000000..d00491fd --- /dev/null +++ b/examples/testsets/.fmf/version @@ -0,0 +1 @@ +1 diff --git a/examples/testsets/inittask1/main.fmf b/examples/testsets/inittask1/main.fmf new file mode 100644 index 00000000..f9bf5131 --- /dev/null +++ b/examples/testsets/inittask1/main.fmf @@ -0,0 +1 @@ +test: setup.sh diff --git a/examples/testsets/inittask1/setup.sh b/examples/testsets/inittask1/setup.sh new file mode 100644 index 00000000..5249f771 --- /dev/null +++ b/examples/testsets/inittask1/setup.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo setup env diff --git a/examples/testsets/main.fmf b/examples/testsets/main.fmf new file mode 100644 index 00000000..ecedea0e --- /dev/null +++ b/examples/testsets/main.fmf @@ -0,0 +1,15 @@ + +/testsets: + provision: + memory: 4G + execute: + how: restraint + /testset1: + conditions: ["'inittask' in _node.name or 'simple' in tags"] + relevancy: + arch: "!s390x" + + /testset2: + conditions: ["'simple' in tags and 'extend' in tags"] + provision: + memory: 4G diff --git a/examples/testsets/simpletest/main.fmf b/examples/testsets/simpletest/main.fmf new file mode 100644 index 00000000..aee301f0 --- /dev/null +++ b/examples/testsets/simpletest/main.fmf @@ -0,0 +1,4 @@ +test: runtest.sh +author: jscotka +path: .. +tags: [simple] diff --git a/examples/testsets/simpletest/runtest.sh b/examples/testsets/simpletest/runtest.sh new file mode 100644 index 00000000..8c3cbfc3 --- /dev/null +++ b/examples/testsets/simpletest/runtest.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +exit 0 diff --git a/examples/testsets/simpletest/special-case1/main.fmf b/examples/testsets/simpletest/special-case1/main.fmf new file mode 100644 index 00000000..af0796e7 --- /dev/null +++ b/examples/testsets/simpletest/special-case1/main.fmf @@ -0,0 +1 @@ +params: ARG1=1 ARG2=1 diff --git a/examples/testsets/simpletest/special-case2/main.fmf b/examples/testsets/simpletest/special-case2/main.fmf new file mode 100644 index 00000000..99906f18 --- /dev/null +++ b/examples/testsets/simpletest/special-case2/main.fmf @@ -0,0 +1,2 @@ +params: ARG=1 +tags+: [extend] diff --git a/fmf/cli.py b/fmf/cli.py index 55dc91dd..8e63fd72 100644 --- a/fmf/cli.py +++ b/fmf/cli.py @@ -91,6 +91,9 @@ def options_select(self): group.add_argument( "--whole", dest="whole", action="store_true", help="Consider the whole tree (leaves only by default)") + group.add_argument( + "--testset", dest="testset", action="store_true", + help="Use filtering via testsets defined in fmf files, you can use options in fmf node for filtering (names, keys, conditions, filters) expected are lists") def options_formatting(self): """ Formating options """ @@ -151,6 +154,24 @@ def command_init(self): version.write("{0}\n".format(utils.VERSION)) print("Metadata tree '{0}' successfully initialized.".format(root)) + def _select(self, tree, brief, prune_opts, formatting, values, debug): + output = [] + for node in tree.prune(*prune_opts): + if brief: + show = node.show(brief=True) + else: + show = node.show( + brief=False, + formatting=formatting, + values=values) + # List source files when in debug mode + if debug: + for source in node.sources: + show += utils.color("{0}\n".format(source), "blue") + if show is not None: + output.append(show) + return output + def show(self, brief=False): """ Show metadata for each path given """ output = [] @@ -158,22 +179,19 @@ def show(self, brief=False): if self.options.verbose: utils.info("Checking {0} for metadata.".format(path)) tree = fmf.Tree(path) - for node in tree.prune( - self.options.whole, self.options.keys, self.options.names, - self.options.filters, self.options.conditions): - if brief: - show = node.show(brief=True) - else: - show = node.show( - brief=False, - formatting=self.options.formatting, - values=self.options.values) - # List source files when in debug mode - if self.options.debug: - for source in node.sources: - show += utils.color("{0}\n".format(source), "blue") - if show is not None: - output.append(show) + prune_opts = [self.options.whole, self.options.keys, self.options.names, self.options.filters, self.options.conditions] + if self.options.testset: + for node in tree.prune(*prune_opts): + prune_opts_testset = list() + prune_opts_testset.append(self.options.whole) + prune_opts_testset.append(node.data.get("keys", [])) + prune_opts_testset.append(node.data.get("names", [])) + prune_opts_testset.append(node.data.get("fitlers", [])) + prune_opts_testset.append(node.data.get("conditions", [])) + output += self._select(tree, brief, prune_opts_testset, self.options.formatting, self.options.values, + debug=self.options.debug) + else: + output += self._select(tree, brief, prune_opts, self.options.formatting, self.options.values, debug=self.options.debug) # Print output and summary if brief or self.options.formatting: From e96dbb91c9b19056e455fad86e8984c3309bd631 Mon Sep 17 00:00:00 2001 From: Jan Scotka Date: Thu, 25 Jul 2019 12:34:34 +0200 Subject: [PATCH 2/2] PoC for testsets in L1 metadata, it allows to use simplier filter and have stored logic for filtering there --- fmf/cli.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fmf/cli.py b/fmf/cli.py index 8e63fd72..0afe0baa 100644 --- a/fmf/cli.py +++ b/fmf/cli.py @@ -182,12 +182,12 @@ def show(self, brief=False): prune_opts = [self.options.whole, self.options.keys, self.options.names, self.options.filters, self.options.conditions] if self.options.testset: for node in tree.prune(*prune_opts): - prune_opts_testset = list() - prune_opts_testset.append(self.options.whole) - prune_opts_testset.append(node.data.get("keys", [])) - prune_opts_testset.append(node.data.get("names", [])) - prune_opts_testset.append(node.data.get("fitlers", [])) - prune_opts_testset.append(node.data.get("conditions", [])) + prune_opts_testset = [self.options.whole, + node.data.get("keys", []), + node.data.get("names", []), + node.data.get("fitlers", []), + node.data.get("conditions", []) + ] output += self._select(tree, brief, prune_opts_testset, self.options.formatting, self.options.values, debug=self.options.debug) else: