mirror of
https://github.com/home-assistant/core.git
synced 2026-04-20 16:39:02 +02:00
Portainer fix fetching swarm stacks (#167979)
This commit is contained in:
@@ -170,15 +170,34 @@ class PortainerCoordinator(DataUpdateCoordinator[dict[int, PortainerCoordinatorD
|
||||
docker_version,
|
||||
docker_info,
|
||||
docker_system_df,
|
||||
stacks,
|
||||
) = await asyncio.gather(
|
||||
self.portainer.get_containers(endpoint.id),
|
||||
self.portainer.docker_version(endpoint.id),
|
||||
self.portainer.docker_info(endpoint.id),
|
||||
self.portainer.docker_system_df(endpoint.id),
|
||||
self.portainer.get_stacks(endpoint.id),
|
||||
)
|
||||
|
||||
stack_requests = [self.portainer.get_stacks(endpoint_id=endpoint.id)]
|
||||
swarm_id = (
|
||||
docker_info.swarm.cluster.get("ID")
|
||||
if docker_info.swarm
|
||||
and docker_info.swarm.control_available
|
||||
and docker_info.swarm.cluster
|
||||
else None
|
||||
)
|
||||
if swarm_id:
|
||||
stack_requests.append(
|
||||
self.portainer.get_stacks(
|
||||
endpoint_id=endpoint.id, swarm_id=swarm_id
|
||||
)
|
||||
)
|
||||
|
||||
stacks = [
|
||||
stack
|
||||
for result in await asyncio.gather(*stack_requests)
|
||||
for stack in result
|
||||
]
|
||||
|
||||
prev_endpoint = self.data.get(endpoint.id) if self.data else None
|
||||
container_map: dict[str, PortainerContainerData] = {}
|
||||
stack_map: dict[str, PortainerStackData] = {
|
||||
|
||||
@@ -76,7 +76,9 @@
|
||||
"RemoteManagers": [],
|
||||
"Nodes": 4,
|
||||
"Managers": 3,
|
||||
"Cluster": {}
|
||||
"Cluster": {
|
||||
"ID": "swarm-cluster-id"
|
||||
}
|
||||
},
|
||||
"LiveRestoreEnabled": false,
|
||||
"Isolation": "default",
|
||||
|
||||
@@ -363,6 +363,21 @@ async def test_new_container_callback(
|
||||
) > len(entities)
|
||||
|
||||
|
||||
async def test_swarm_stacks_fetched_by_swarm_id(
|
||||
hass: HomeAssistant,
|
||||
mock_portainer_client: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test that on a Swarm manager get_stacks is called with both endpoint_id and swarm_id."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
calls = mock_portainer_client.get_stacks.call_args_list
|
||||
# Expect exactly two calls: one by endpoint_id, one by swarm_id
|
||||
assert len(calls) == 2
|
||||
assert calls[0].kwargs == {"endpoint_id": 1}
|
||||
assert calls[1].kwargs == {"endpoint_id": 1, "swarm_id": "swarm-cluster-id"}
|
||||
|
||||
|
||||
async def test_new_stack_callback(
|
||||
hass: HomeAssistant,
|
||||
mock_portainer_client: AsyncMock,
|
||||
|
||||
Reference in New Issue
Block a user