Skip to content

Let linuxmusterTools import without a configured linuxmuster.net - #26

Open
TomlDev wants to merge 1 commit into
linuxmuster:lmn74from
edulution-io:fix-import-without-samba
Open

Let linuxmusterTools import without a configured linuxmuster.net#26
TomlDev wants to merge 1 commit into
linuxmuster:lmn74from
edulution-io:fix-import-without-samba

Conversation

@TomlDev

@TomlDev TomlDev commented Aug 5, 2026

Copy link
Copy Markdown

linuxmusterTools cannot be imported on a machine that has no configured linuxmuster.net, because two module-level side effects assume one is present:

  • lmnconfig/samba.py runs /usr/bin/net conf list at import time, unguarded — FileNotFoundError where samba is not installed.
  • lmnconfig/sophomorix.py reads the ROLE_USER section of /usr/share/sophomorix/devel/sophomorix.iniConfigParser.read() silently ignores the missing file, so the lookup raises KeyError.

Importing anything from linuxmusterTools.linbo reaches both, through linbo.configdeviceslmnconfig.

The visible consequence is the test suite: linuxmusterTools/lmnconfig/pytests/ does not fail off-server, it fails to collect. test_samba.py already records this in its module docstring — "computed as a module-level side effect at import time … not re-testable/mockable per test case, so it is intentionally left untested here". Since no workflow runs the tests, this is only visible to someone trying to run them on a workstation.

What changed

Both sites now behave like the code directly beside them, which already guards the same class of problem — the smb.conf read in samba.py sits in a try/except, and SchoolConfig checks os.path.isfile before opening:

  • A missing or failing net leaves SHARES_LIST empty and DFS empty, and logs the reason at error level, in the wording the neighbouring handler already uses.
  • A missing sophomorix.ini warns, and userrole falls back to an empty list via .get().

Behaviour on a configured server is unchanged — both paths only trigger where the command or the file is absent.

Tests

The 38 existing lmnconfig tests pass. Three new ones cover the added paths: import surviving a missing net binary, import surviving a net call that exits non-zero, and SophomorixIni with no ROLE_USER section.

Reverting the two source files while keeping the tests reproduces the original failure — the suite stops at collection with FileNotFoundError: '/usr/bin/net', which is the point of the change.

I did not touch the version; that is the maintainers' bumpversion step.

lmnconfig/samba.py ran `/usr/bin/net conf list` as an unguarded
module-level side effect, and lmnconfig/sophomorix.py read the ROLE_USER
section of a sophomorix.ini that need not exist. Importing anything from
linuxmusterTools.linbo reaches both through linbo.config -> devices ->
lmnconfig, so on any machine without a configured linuxmuster.net the
whole package failed to import with FileNotFoundError or KeyError.

That is what stops the pytests from running anywhere but a server: the
lmnconfig suite does not fail, it fails to collect. test_samba.py says
so in its own module docstring, and no workflow runs the tests.

Both sites now behave like the code directly next to them, which already
guarded the same class of problem: the smb.conf read in samba.py sits in
a try/except, and SchoolConfig checks os.path.isfile before opening.
A missing or failing `net` leaves SHARES_LIST and DFS empty and logs the
reason; a missing sophomorix.ini leaves the role lists empty and warns.

Behaviour on a configured server is unchanged. The 38 existing lmnconfig
tests pass, and three cover the new paths.
@kiarn

kiarn commented Aug 5, 2026

Copy link
Copy Markdown
Member

Hello @TomlDev,

linuxmusterTools cannot be imported on a machine that has no configured linuxmuster.net.

Yes, that's a wanted behavior: lmntools must be run on an installed linuxmuster.net server.
lmntools is per design built in this way, why should it be any different ?

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.

2 participants