Allow IntegrationNotFound when checking config in safe mode (#56283)

Co-authored-by: Joakim Sørensen <hi@ludeeus.dev>
pull/56376/head
J. Nick Koston 2021-09-17 19:25:50 -10:00 committed by GitHub
parent bad6b2f7f5
commit eb98ac9415
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 5 deletions

View File

@ -125,8 +125,12 @@ async def async_check_ha_config_file( # noqa: C901
for domain in components:
try:
integration = await async_get_integration_with_requirements(hass, domain)
except (RequirementsNotFound, loader.IntegrationNotFound) as ex:
result.add_error(f"Component error: {domain} - {ex}")
except loader.IntegrationNotFound as ex:
if not hass.config.safe_mode:
result.add_error(f"Integration error: {domain} - {ex}")
continue
except RequirementsNotFound as ex:
result.add_error(f"Integration error: {domain} - {ex}")
continue
try:
@ -210,8 +214,11 @@ async def async_check_ha_config_file( # noqa: C901
hass, p_name
)
platform = p_integration.get_platform(domain)
except loader.IntegrationNotFound as ex:
if not hass.config.safe_mode:
result.add_error(f"Platform error {domain}.{p_name} - {ex}")
continue
except (
loader.IntegrationNotFound,
RequirementsNotFound,
ImportError,
) as ex:

View File

@ -7,6 +7,7 @@ from homeassistant.helpers.check_config import (
CheckConfigError,
async_check_ha_config_file,
)
from homeassistant.requirements import RequirementsNotFound
from tests.common import mock_platform, patch_yaml_files
@ -75,7 +76,7 @@ async def test_component_platform_not_found(hass):
assert res.keys() == {"homeassistant"}
assert res.errors[0] == CheckConfigError(
"Component error: beer - Integration 'beer' not found.", None, None
"Integration error: beer - Integration 'beer' not found.", None, None
)
# Only 1 error expected
@ -83,6 +84,42 @@ async def test_component_platform_not_found(hass):
assert not res.errors
async def test_component_requirement_not_found(hass):
"""Test errors if component with a requirement not found not found."""
# Make sure they don't exist
files = {YAML_CONFIG_FILE: BASE_CONFIG + "test_custom_component:"}
with patch(
"homeassistant.helpers.check_config.async_get_integration_with_requirements",
side_effect=RequirementsNotFound("test_custom_component", ["any"]),
), patch("os.path.isfile", return_value=True), patch_yaml_files(files):
res = await async_check_ha_config_file(hass)
log_ha_config(res)
assert res.keys() == {"homeassistant"}
assert res.errors[0] == CheckConfigError(
"Integration error: test_custom_component - Requirements for test_custom_component not found: ['any'].",
None,
None,
)
# Only 1 error expected
res.errors.pop(0)
assert not res.errors
async def test_component_not_found_safe_mode(hass):
"""Test no errors if component not found in safe mode."""
# Make sure they don't exist
files = {YAML_CONFIG_FILE: BASE_CONFIG + "beer:"}
hass.config.safe_mode = True
with patch("os.path.isfile", return_value=True), patch_yaml_files(files):
res = await async_check_ha_config_file(hass)
log_ha_config(res)
assert res.keys() == {"homeassistant"}
assert not res.errors
async def test_component_platform_not_found_2(hass):
"""Test errors if component or platform not found."""
# Make sure they don't exist
@ -103,6 +140,21 @@ async def test_component_platform_not_found_2(hass):
assert not res.errors
async def test_platform_not_found_safe_mode(hass):
"""Test no errors if platform not found in safe_mode."""
# Make sure they don't exist
files = {YAML_CONFIG_FILE: BASE_CONFIG + "light:\n platform: beer"}
hass.config.safe_mode = True
with patch("os.path.isfile", return_value=True), patch_yaml_files(files):
res = await async_check_ha_config_file(hass)
log_ha_config(res)
assert res.keys() == {"homeassistant", "light"}
assert res["light"] == []
assert not res.errors
async def test_package_invalid(hass):
"""Test a valid platform setup."""
files = {

View File

@ -74,7 +74,7 @@ def test_component_platform_not_found(mock_is_file, loop):
assert res["components"].keys() == {"homeassistant"}
assert res["except"] == {
check_config.ERROR_STR: [
"Component error: beer - Integration 'beer' not found."
"Integration error: beer - Integration 'beer' not found."
]
}
assert res["secret_cache"] == {}