Skip to content

Commit

Permalink
Add a new lint check for empty environment files (#3204)
Browse files Browse the repository at this point in the history
New function that raises a failure if the size of
the environment file, if this one exists, is zero.

Signed-off-by: mcasquer <[email protected]>
Co-authored-by: Petr Šplíchal <[email protected]>
  • Loading branch information
mcasquer and psss authored Nov 5, 2024
1 parent 214be3d commit 5cfc6e9
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ The :ref:`/plugins/provision/beaker` provision plugin gains
support for :ref:`system.model-name</spec/hardware/system>` and
:ref:`system.vendor-name</spec/hardware/system>` hardware requirements.

The ``tmt lint`` command now reports a failure if empty
environment files are found.


tmt-1.38.0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
Empty file added tests/lint/plan/data/empty_env
Empty file.
5 changes: 5 additions & 0 deletions tests/lint/plan/data/empty_env_file.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
summary: Empty environment file plan
environment-file:
- empty_env
execute:
script: tmt --help
1 change: 1 addition & 0 deletions tests/lint/plan/data/env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test=test
2 changes: 2 additions & 0 deletions tests/lint/plan/data/good.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ summary: Basic smoke test
execute:
script: tmt --help
id: 9c73e336-983e-4349-9586-b63c20ea2b89
environment-file:
- env
4 changes: 4 additions & 0 deletions tests/lint/plan/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ rlJournalStart

rlRun -s "$tmt plan lint invalid_url" 1
rlAssertGrep "fail P005 remote fmf id in \"default-0\" is invalid, repo 'http://invalid-url' cannot be cloned" $rlRun_LOG
rlAssertGrep "skip P008 no environment files found" $rlRun_LOG

rlRun -s "$tmt plan lint invalid_ref" 1
rlAssertGrep "fail P005 remote fmf id in \"default-0\" is invalid, git ref 'invalid-ref-123456' is invalid" $rlRun_LOG
Expand All @@ -71,6 +72,9 @@ rlJournalStart
rlRun -s "$tmt plan lint invalid-plugin-key" 0
rlAssertGrep 'warn C000 key "wrong" not recognized by schema$' $rlRun_LOG
rlAssertGrep 'warn C000 key "wrong" not recognized by schema /schemas/prepare/feature' $rlRun_LOG

rlRun -s "$tmt plan lint empty_env_file" 1
rlAssertGrep "fail P008 the environment file '.*/tests/lint/plan/data/empty_env' is empty" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "P007: step phases require existing guests and roles"
Expand Down
17 changes: 17 additions & 0 deletions tmt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,23 @@ def _lint_step(step: str) -> LinterReturn:
yield from _lint_step('execute')
yield from _lint_step('finish')

def lint_empty_env_files(self) -> LinterReturn:
""" P008: environment files are not empty """

env_files = self.node.get("environment-file") or []

if not env_files:
yield LinterOutcome.SKIP, 'no environment files found'
return

for env_file in env_files:
env_file = (self.anchor_path / Path(env_file)).resolve()
if not env_file.stat().st_size:
yield LinterOutcome.FAIL, f"the environment file '{env_file}' is empty"
return

yield LinterOutcome.PASS, 'no empty environment files'

def wake(self) -> None:
""" Wake up all steps """

Expand Down

0 comments on commit 5cfc6e9

Please sign in to comment.