Check dependency of --just-phase

JIRA: COMPOSE-4020
Signed-off-by: Haibo Lin <hlin@redhat.com>
This commit is contained in:
Haibo Lin 2020-01-06 11:42:05 +08:00 committed by lsedlar
parent 3750d6795f
commit 3f111b559f
3 changed files with 34 additions and 3 deletions

View File

@ -131,11 +131,12 @@ def check_umask(logger):
'expect files with broken permissions.', mask)
def check_skip_phases(logger, skip_phases):
def check_skip_phases(logger, skip_phases, just_phases):
"""Check if skipped phases are needed by other phase.
:param logger: logger instance for reporting error
:param skip_phases: list of skipped phases
:param just_phases: list of phases just run
:returns: True if checking passed else False
"""
needed_by = {
@ -144,7 +145,9 @@ def check_skip_phases(logger, skip_phases):
}
fail = False
for k, v in needed_by.items():
if k in skip_phases and needed_by[k] not in skip_phases:
if (k in skip_phases and needed_by[k] not in skip_phases) or (
needed_by[k] in just_phases and k not in just_phases
):
fail = True
logger.error("%s phase is skipped but it's needed by %s phase" % (k, v))

View File

@ -223,7 +223,7 @@ def main():
if not pungi.checks.check(conf):
sys.exit(1)
pungi.checks.check_umask(logger)
if not pungi.checks.check_skip_phases(logger, opts.skip_phase):
if not pungi.checks.check_skip_phases(logger, opts.skip_phase, opts.just_phase):
sys.exit(1)
errors, warnings = pungi.checks.validate(conf)

View File

@ -572,3 +572,31 @@ class TestUmask(unittest.TestCase):
[mock.call.warning('Unusually strict umask detected (0%03o), '
'expect files with broken permissions.', 0o044)]
)
class TestCheckSkipPhases(unittest.TestCase):
def test_skip_phase(self):
logger = mock.Mock()
passed = checks.check_skip_phases(logger, ["gather"], [])
self.assertFalse(passed)
self.assertEqual(
logger.mock_calls,
[
mock.call.error(
"gather phase is skipped but it's needed by createrepo phase"
)
],
)
def test_just_phase(self):
logger = mock.Mock()
passed = checks.check_skip_phases(logger, [], ["gather"])
self.assertFalse(passed)
self.assertEqual(
logger.mock_calls,
[
mock.call.error(
"pkgset phase is skipped but it's needed by gather phase"
)
],
)