From e1db5ce2d05eab9c94d50e111463e1b6497af46f Mon Sep 17 00:00:00 2001 From: mcasquer Date: Wed, 11 Sep 2024 07:35:37 +0200 Subject: [PATCH] Adds new lint function for empty env files New function that raises a failure if the size of the environment file, if this one exists, is zero. Signed-off-by: mcasquer --- tmt/base.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tmt/base.py b/tmt/base.py index ebc3e34174..21d9806baa 100644 --- a/tmt/base.py +++ b/tmt/base.py @@ -2130,6 +2130,22 @@ def lint_unknown_keys(self) -> LinterReturn: yield LinterOutcome.PASS, 'correct keys are used' + def lint_empty_env_files(self) -> LinterReturn: + """ P001: env files are not empty """ + + env_files = self.node.get("environment-file") or [] + if len(env_files) > 0: + for env_file in env_files: + path = os.path.normpath(env_file) + size = os.path.getsize(path) + + if (path is not None and size == 0): + yield LinterOutcome.FAIL, f'the file "{env_file}" is empty' + + return + + yield LinterOutcome.PASS, 'no empty environment files found' + def lint_execute_not_defined(self) -> LinterReturn: """ P002: execute step must be defined with "how" """