From 9da4ea20a908b38306960a7eabf90a3837a32d6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Thu, 13 Oct 2022 15:28:30 +0200 Subject: [PATCH] Add unhealthy reasons to block message (#3948) --- supervisor/jobs/decorator.py | 2 +- tests/jobs/test_job_decorator.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/supervisor/jobs/decorator.py b/supervisor/jobs/decorator.py index 9c3356303..d990d9e8b 100644 --- a/supervisor/jobs/decorator.py +++ b/supervisor/jobs/decorator.py @@ -179,7 +179,7 @@ class Job(CoreSysAttributes): if JobCondition.HEALTHY in used_conditions and not self.sys_core.healthy: raise JobConditionException( - f"'{self._method.__qualname__}' blocked from execution, system is not healthy" + f"'{self._method.__qualname__}' blocked from execution, system is not healthy - {', '.join(self.sys_resolution.unhealthy)}" ) if ( diff --git a/tests/jobs/test_job_decorator.py b/tests/jobs/test_job_decorator.py index 3eb5d02d9..cde306439 100644 --- a/tests/jobs/test_job_decorator.py +++ b/tests/jobs/test_job_decorator.py @@ -488,3 +488,27 @@ async def test_auto_update(coresys: CoreSys): coresys.updater.auto_update = False assert not await test.execute() + + +async def test_unhealthy(coresys: CoreSys, caplog: pytest.LogCaptureFixture): + """Test the healthy decorator when unhealthy.""" + + class TestClass: + """Test class.""" + + def __init__(self, coresys: CoreSys): + """Initialize the test class.""" + self.coresys = coresys + + @Job(conditions=[JobCondition.HEALTHY]) + async def execute(self) -> bool: + """Execute the class method.""" + return True + + test = TestClass(coresys) + coresys.resolution.unhealthy = UnhealthyReason.SETUP + assert not await test.execute() + assert "blocked from execution, system is not healthy - setup" in caplog.text + + coresys.jobs.ignore_conditions = [JobCondition.HEALTHY] + assert await test.execute()