Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoC for testsets in L1 metadata, it allows to use simplier filter and have stored logic for filtering there #57

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/testsets/.fmf/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
1 change: 1 addition & 0 deletions examples/testsets/inittask1/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test: setup.sh
3 changes: 3 additions & 0 deletions examples/testsets/inittask1/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo setup env
15 changes: 15 additions & 0 deletions examples/testsets/main.fmf
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions examples/testsets/simpletest/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test: runtest.sh
author: jscotka
path: ..
tags: [simple]
3 changes: 3 additions & 0 deletions examples/testsets/simpletest/runtest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

exit 0
1 change: 1 addition & 0 deletions examples/testsets/simpletest/special-case1/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
params: ARG1=1 ARG2=1
2 changes: 2 additions & 0 deletions examples/testsets/simpletest/special-case2/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
params: ARG=1
tags+: [extend]
50 changes: 34 additions & 16 deletions fmf/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down Expand Up @@ -151,29 +154,44 @@ 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 = []
for path in self.options.paths or ["."]:
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 = [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:
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:
Expand Down