mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-12-10 00:39:22 -06:00
* Migrate to Ruff for lint and format * Fix pylint issues * DBus property sets into normal awaitable methods * Fix tests relying on separate tasks in connect * Fixes from feedback
76 lines
2.0 KiB
Python
76 lines
2.0 KiB
Python
"""Test OSAgent dbus interface."""
|
|
# pylint: disable=import-error
|
|
from dbus_fast.aio.message_bus import MessageBus
|
|
import pytest
|
|
|
|
from supervisor.dbus.agent import OSAgent
|
|
|
|
from tests.common import mock_dbus_services
|
|
from tests.dbus_service_mocks.base import DBusServiceMock
|
|
from tests.dbus_service_mocks.os_agent import OSAgent as OSAgentService
|
|
|
|
|
|
@pytest.fixture(name="os_agent_service")
|
|
async def fixture_os_agent_service(
|
|
os_agent_services: dict[str, DBusServiceMock],
|
|
) -> OSAgentService:
|
|
"""Mock OS Agent dbus service."""
|
|
yield os_agent_services["os_agent"]
|
|
|
|
|
|
async def test_dbus_osagent(
|
|
os_agent_service: OSAgentService, dbus_session_bus: MessageBus
|
|
):
|
|
"""Test OS Agent properties."""
|
|
os_agent = OSAgent()
|
|
|
|
assert os_agent.version is None
|
|
assert os_agent.diagnostics is None
|
|
|
|
await os_agent.connect(dbus_session_bus)
|
|
|
|
assert os_agent.version == "1.1.0"
|
|
assert os_agent.diagnostics
|
|
|
|
os_agent_service.emit_properties_changed({"Diagnostics": False})
|
|
await os_agent_service.ping()
|
|
assert os_agent.diagnostics is False
|
|
|
|
os_agent_service.emit_properties_changed({}, ["Diagnostics"])
|
|
await os_agent_service.ping()
|
|
await os_agent_service.ping()
|
|
assert os_agent.diagnostics is True
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"skip_service",
|
|
[
|
|
"os_agent",
|
|
"agent_apparmor",
|
|
"agent_datadisk",
|
|
],
|
|
)
|
|
async def test_dbus_osagent_connect_error(
|
|
skip_service: str, dbus_session_bus: MessageBus, caplog: pytest.LogCaptureFixture
|
|
):
|
|
"""Test OS Agent errors during connect."""
|
|
os_agent_services = {
|
|
"os_agent": None,
|
|
"agent_apparmor": None,
|
|
"agent_cgroup": None,
|
|
"agent_datadisk": None,
|
|
"agent_system": None,
|
|
"agent_boards": None,
|
|
"agent_boards_yellow": None,
|
|
}
|
|
os_agent_services.pop(skip_service)
|
|
await mock_dbus_services(
|
|
os_agent_services,
|
|
dbus_session_bus,
|
|
)
|
|
|
|
os_agent = OSAgent()
|
|
await os_agent.connect(dbus_session_bus)
|
|
|
|
assert "No OS-Agent support on the host" in caplog.text
|