aws_s3: warmup loader caches to remove blocking listdir calls (#180413)

This commit is contained in:
Patrick Vorgers
2026-08-29 20:14:04 +00:00
committed by Franck Nijhof
parent f96c7c7ed3
commit 338a39da46
4 changed files with 35 additions and 1 deletions
@@ -3,6 +3,7 @@
import logging
from typing import cast
from aiobotocore.config import AioConfig
from aiobotocore.session import AioSession
from botocore.exceptions import ClientError, ConnectionError, ParamValidationError
@@ -37,6 +38,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: S3ConfigEntry) -> bool:
endpoint_url=data.get(CONF_ENDPOINT_URL),
aws_secret_access_key=data[CONF_SECRET_ACCESS_KEY],
aws_access_key_id=data[CONF_ACCESS_KEY_ID],
config=AioConfig(warm_up_loader_caches=True),
).__aenter__()
await client.head_bucket(Bucket=data[CONF_BUCKET])
except ClientError as err:
@@ -3,6 +3,7 @@
from typing import Any, override
from urllib.parse import urlparse
from aiobotocore.config import AioConfig
from aiobotocore.session import AioSession
from botocore.exceptions import ClientError, ConnectionError, ParamValidationError
import voluptuous as vol
@@ -77,6 +78,7 @@ class S3ConfigFlow(ConfigFlow, domain=DOMAIN):
endpoint_url=user_input.get(CONF_ENDPOINT_URL),
aws_secret_access_key=user_input[CONF_SECRET_ACCESS_KEY],
aws_access_key_id=user_input[CONF_ACCESS_KEY_ID],
config=AioConfig(warm_up_loader_caches=True),
) as client:
await client.head_bucket(Bucket=user_input[CONF_BUCKET])
except ClientError:
+11 -1
View File
@@ -79,7 +79,17 @@ async def test_flow(
expected_data: dict,
) -> None:
"""Test config flow with and without prefix, including prefix normalization."""
result = await _async_start_flow(hass, user_input)
create_client = AsyncMock(name="create_client")
create_client.__aenter__.return_value.head_bucket.return_value = {}
with patch(
"homeassistant.components.aws_s3.config_flow.AioSession.create_client",
return_value=create_client,
) as patched_create_client:
result = await _async_start_flow(hass, user_input)
assert patched_create_client.call_args.kwargs["config"].warm_up_loader_caches
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == expected_title
assert result["data"] == expected_data
+20
View File
@@ -73,3 +73,23 @@ async def test_setup_entry_head_bucket_error(
)
await setup_integration(hass, mock_config_entry)
assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR
async def test_setup_entry_warms_loader_caches(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test that create_client passes warm_up_loader_caches config."""
with patch(
"homeassistant.components.aws_s3.AioSession.create_client"
) as create_client:
client_ctx = AsyncMock()
client = AsyncMock()
client_ctx.__aenter__.return_value = client
create_client.return_value = client_ctx
await setup_integration(hass, mock_config_entry)
create_client.assert_called_once()
_, kwargs = create_client.call_args
assert kwargs["config"].warm_up_loader_caches is True