mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
Downgrade dhcp log message error message when running without CAP_NET_RAW (#45157)
This commit is contained in:
parent
a1368ad3ed
commit
7fada806af
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
from threading import Event, Thread
|
from threading import Event, Thread
|
||||||
|
|
||||||
from scapy.error import Scapy_Exception
|
from scapy.error import Scapy_Exception
|
||||||
@ -70,7 +71,12 @@ class DHCPWatcher(Thread):
|
|||||||
stop_filter=lambda _: self._stop_event.is_set(),
|
stop_filter=lambda _: self._stop_event.is_set(),
|
||||||
)
|
)
|
||||||
except (Scapy_Exception, OSError) as ex:
|
except (Scapy_Exception, OSError) as ex:
|
||||||
_LOGGER.info("Cannot watch for dhcp packets: %s", ex)
|
if os.geteuid() == 0:
|
||||||
|
_LOGGER.error("Cannot watch for dhcp packets: %s", ex)
|
||||||
|
else:
|
||||||
|
_LOGGER.debug(
|
||||||
|
"Cannot watch for dhcp packets without root or CAP_NET_RAW: %s", ex
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
def handle_dhcp_packet(self, packet):
|
def handle_dhcp_packet(self, packet):
|
||||||
|
@ -281,8 +281,8 @@ async def test_setup_and_stop(hass):
|
|||||||
wait_event.set()
|
wait_event.set()
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_fails(hass):
|
async def test_setup_fails_as_root(hass, caplog):
|
||||||
"""Test we handle sniff setup failing."""
|
"""Test we handle sniff setup failing as root."""
|
||||||
|
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
@ -293,10 +293,37 @@ async def test_setup_fails(hass):
|
|||||||
|
|
||||||
wait_event = threading.Event()
|
wait_event = threading.Event()
|
||||||
|
|
||||||
with patch("homeassistant.components.dhcp.sniff", side_effect=Scapy_Exception):
|
with patch("os.geteuid", return_value=0), patch(
|
||||||
|
"homeassistant.components.dhcp.sniff", side_effect=Scapy_Exception
|
||||||
|
):
|
||||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
wait_event.set()
|
wait_event.set()
|
||||||
|
assert "Cannot watch for dhcp packets" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
|
async def test_setup_fails_non_root(hass, caplog):
|
||||||
|
"""Test we handle sniff setup failing as non-root."""
|
||||||
|
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
dhcp.DOMAIN,
|
||||||
|
{},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
wait_event = threading.Event()
|
||||||
|
|
||||||
|
with patch("os.geteuid", return_value=10), patch(
|
||||||
|
"homeassistant.components.dhcp.sniff", side_effect=Scapy_Exception
|
||||||
|
):
|
||||||
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
wait_event.set()
|
||||||
|
assert "Cannot watch for dhcp packets without root or CAP_NET_RAW" in caplog.text
|
||||||
|
Loading…
x
Reference in New Issue
Block a user