Skip to content

fix(net): don't fail on sysfs attributes that are directories - #7123

Open
wak327 wants to merge 1 commit into
canonical:mainfrom
wak327:fix/net-sysfs-attribute-is-directory
Open

wak327 wants to merge 1 commit into
canonical:mainfrom
wak327:fix/net-sysfs-attribute-is-directory

Conversation

@wak327

@wak327 wak327 commented Sep 30, 2026

Copy link
Copy Markdown

Proposed Commit Message

fix(net): don't fail on sysfs attributes that are directories

read_sys_net() lets callers handle a missing sysfs attribute through
on_enoent, but only for ENOENT and ENOTDIR. For mac802154_hwsim WPAN
interfaces, device/device links to a directory, so reading it raised
IsADirectoryError out of device_devid(). That made get_interfaces()
fail, and with it network configuration in the init-local stage.

Handle EISDIR like a missing attribute, so device_devid() returns None
for such interfaces.

Fixes GH-4257

Additional Context

Fixes #4257

In the sysfs layout from the report, /sys/class/net/wpan1/device/device links to /sys/devices/platform/mac802154_hwsim, which is a directory. Reading it raised IsADirectoryError (EISDIR). read_sys_net() passes ENOENT and ENOTDIR to on_enoent, but not EISDIR, so the error escaped read_sys_net_safe() and device_devid() and made get_interfaces() fail.

With this change device_devid() returns None for such interfaces, the same as for interfaces without device/device. Callers that don't pass on_enoent still get the exception.

New tests cover three cases, and all three fail without the fix:

  • read_sys_net() passes a directory to on_enoent
  • device_devid() with the WPAN layout from the report
  • get_interfaces() lists a WPAN interface next to an ethernet one

I don't have 802.15.4 hardware or the mac802154_hwsim module loaded here, so the reported layout is reproduced in the unit tests. Verified with the pinned black, isort, ruff, pylint and mypy, and the full unit suite passes (5,782 tests).

Test Steps

On a machine where mac802154_hwsim is available:

sudo modprobe mac802154_hwsim
python3 -c 'from cloudinit import net; print(net.get_interfaces())'
tox -e py3 -- tests/unittests/net/test_init.py

Without this change the get_interfaces() call raises IsADirectoryError, as in the report. With it, the call should return normally.

Merge type

  • Squash merge using "Proposed Commit Message"
  • Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)

read_sys_net() lets callers handle a missing sysfs attribute through
on_enoent, but only for ENOENT and ENOTDIR. For mac802154_hwsim WPAN
interfaces, device/device links to a directory, so reading it raised
IsADirectoryError out of device_devid(). That made get_interfaces()
fail, and with it network configuration in the init-local stage.

Handle EISDIR like a missing attribute, so device_devid() returns None
for such interfaces.

Fixes canonicalGH-4257
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Presence of mac802154_hwsim WPAN network interfaces causes network setup to fail

1 participant