Skip to content

Commit

Permalink
Fix a bug when prune is used along with path (#3132)
Browse files Browse the repository at this point in the history
Co-authored-by: Petr Matyas <pmatyas@redhat.com>
  • Loading branch information
KwisatzHaderach and Petr Matyas committed Aug 7, 2024
1 parent e2e9bd4 commit 284a61d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
3 changes: 3 additions & 0 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ support for :ref:`cpu.vendor-name</spec/hardware/cpu>` and
The linting of tests, plans and stories has been extended by detecting
duplicate ids.

Test directories pruning now works correctly for nested fmf trees
and there is also a test for it.

tmt-1.34
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
11 changes: 9 additions & 2 deletions tests/discover/prune.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ rlJournalStart
rlRun "run=\$(mktemp -d)"
rlPhaseEnd

rlPhaseStartTest "Discover only"
rlRun -s "tmt run -i $run discover tests --name test1"
rlPhaseStartTest "Discover local"
rlRun -s "tmt run -i $run discover plans --name plan tests --name test1"
rlAssertExists "$run/plan/discover/default-0/tests/test1"
rlAssertNotExists "$run/plan/discover/default-0/tests/test2"
rlAssertNotExists "$run/plan/discover/default-0/tests/some-file"
rlPhaseEnd

rlPhaseStartTest "Discover remote with path"
rlRun -s "tmt run -i $run discover plans --name nested tests --name file"
rlAssertExists "$run/nested/discover/default-0/tests/file/test.sh"
rlAssertExists "$run/nested/discover/default-0/tests/scripts/random_file.sh"
rlAssertNotExists "$run/nested/discover/default-0/tests/dir-without-fmf"
rlPhaseEnd

rlPhaseStartCleanup
rlRun "rm -rf $run"
rlRun "popd"
Expand Down
9 changes: 9 additions & 0 deletions tests/discover/prune/nested.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
discover:
how: fmf
url: https://github.com/teemtee/tests
path: nested
prune: true
provision:
how: local
execute:
how: tmt
14 changes: 7 additions & 7 deletions tmt/steps/discover/fmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,19 +574,19 @@ def do_the_discovery(self, path: Optional[Path] = None) -> None:
if prune:
# Save fmf metadata
clonedir = self.clone_dirpath / 'tests'
for path in tmt.utils.filter_paths(self.testdir, ['.fmf']):
for path in tmt.utils.filter_paths(tree_path, [r'\.fmf']):
shutil.copytree(
path,
clonedir / path.relative_to(self.testdir),
clonedir / path.relative_to(tree_path),
dirs_exist_ok=True)

# Save upgrade plan
upgrade_path = self.get('upgrade_path')
if upgrade_path:
upgrade_path = f"{upgrade_path.lstrip('/')}.fmf"
(clonedir / upgrade_path).parent.mkdir()
shutil.copyfile(self.testdir / upgrade_path, clonedir / upgrade_path)
shutil.copymode(self.testdir / upgrade_path, clonedir / upgrade_path)
shutil.copyfile(tree_path / upgrade_path, clonedir / upgrade_path)
shutil.copymode(tree_path / upgrade_path, clonedir / upgrade_path)

# Prefix tests and handle library requires
for test in self._tests:
Expand All @@ -598,17 +598,17 @@ def do_the_discovery(self, path: Optional[Path] = None) -> None:
assert test.path is not None # narrow type
relative_test_path = test.path.unrooted()
shutil.copytree(
self.testdir / relative_test_path,
tree_path / relative_test_path,
clonedir / relative_test_path,
dirs_exist_ok=True)

# Copy all parent main.fmf files
parent_dir = relative_test_path
while parent_dir.resolve() != Path.cwd().resolve():
parent_dir = parent_dir.parent
if (self.testdir / parent_dir / 'main.fmf').exists():
if (tree_path / parent_dir / 'main.fmf').exists():
shutil.copyfile(
self.testdir / parent_dir / 'main.fmf',
tree_path / parent_dir / 'main.fmf',
clonedir / parent_dir / 'main.fmf')

# Prefix test path with 'tests' and possible 'path' prefix
Expand Down

0 comments on commit 284a61d

Please sign in to comment.