Skip to content

fix(linbo_mkgrubimg): handle hosts of non-default schools - #180

Merged
HappyBasher merged 2 commits into
linuxmuster:7.4from
TomlDev:fix/mkgrubimg-school-prefix
Oct 14, 2026
Merged

HappyBasher merged 2 commits into
linuxmuster:7.4from
TomlDev:fix/mkgrubimg-school-prefix

Conversation

@TomlDev

@TomlDev TomlDev commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Part of #178. As agreed there, this fixes existing bugs in linbo-mkgrubimg for non-default schools first, before the follow-up PR switches it to the school-qualified group.

Problem

linbo-mkgrubimg -n <host> -w <school>.devices.csv [-s] did not work for a school other than default-school:

  • getHostname() returns the hostname from devices.csv, lowercased and without a school prefix. linuxmuster-import-devices writes non-default schools' hosts with a <school>- prefix in DHCP and hostcfg. The image was created as hostcfg/pc01.img instead of hostcfg/abc-pc01.img, and --setfilename never found the host abc-pc01 DHCP entry, so it silently changed nothing.
  • -n was looked up while the options were still being parsed. With -n pc01 -w abc.devices.csv, the host was searched in default-school's devices.csv.
  • --setfilename dropped option nis-domain when it rewrote the DHCP host entry, although import-devices writes it next to extensions-path.

Change

  • New getSchoolFromDevicesFile() derives the school from the workstations file name, using the same path convention as base7's readDevicesCsv() (<school>/<school>.devices.csv, otherwise default-school). No new option is needed; -s is already taken by --setfilename.
  • -n is looked up after all options are parsed. For a non-default school the hostname gets the <school>- prefix.
  • The rewritten devices.csv row keeps the hostname exactly as it was read. Before, it was lowercased, and with the prefix it would have become abc-pc01, which the next import turns into abc-abc-pc01.
  • The rewritten DHCP entry keeps option nis-domain.

default-school: the only difference is that the devices.csv row keeps the hostname's original case.

Testing

  • pytest tests/python: 102 passed, including new tests for getSchoolFromDevicesFile().
  • Ran main(['-s', '-n', 'pc01', '-w', '<tmp>/abc/abc.devices.csv']) against temp files with the real base7 functions. The environment paths pointed at the temp dir, and grub-mkstandalone, the dhcp restart and base7's third-party imports (IPy, ldap3, ...) were stubbed. The image is hostcfg/abc-pc01.img, the host abc-pc01 entry gets its filename and keeps nis-domain, and the devices.csv row keeps pc01.

Not changed (existing, separate)

  • With -s, a host whose IP is DHCP is not updated in devices.csv, because ip is replaced by 0.0.0.0 before the old row is built for the search.
  • The check 'host ' + hostname in content also matches longer hostnames (pc01 matches pc010).

@HappyBasher

Copy link
Copy Markdown
Member

Thanks, I reviewed this and ran the tests locally: pytest tests/python gives 102 passed. The school lookup follows the same path convention as base7's readDevicesCsv(), and keeping the devices.csv row as read is the right call.

We'll merge once the lab test is done. For this PR that means a real run of linbo-mkgrubimg -s -n <host> -w <school>.devices.csv on a server with a non-default school, checking that hostcfg/<school>-<host>.img is created and the DHCP entry for <school>-<host> gets its filename and keeps nis-domain.

Before merging, please change two things in the commit:

  1. Add a Signed-off-by: trailer. It has to come from you as the author, so we can't add it for you. git rebase --signoff origin/7.4 and git push --force-with-lease will do it. We merge contributor PRs with a merge commit, so the commit message stays in the history.
  2. Replace Co-Authored-By: Claude <noreply@anthropic.com> with Assisted-by: Claude, as in your file headers. We don't use Co-Authored-By trailers.

One note for the follow-up PR: groupcfg, start.conf.<group> and extensions-path still use the unqualified group here. The follow-up that switches to the qualified id has to land together with the base7 helper, otherwise --setfilename writes a group that no longer matches the import.

@TomlDev
TomlDev force-pushed the fix/mkgrubimg-school-prefix branch 2 times, most recently from 0c2cbef to f75c21c Compare October 1, 2026 10:43
linbo-mkgrubimg -w <school>.devices.csv did not work for a school other
than default-school:

- getHostname() returns the hostname as written in devices.csv, but
  linuxmuster-import-devices prefixes non-default schools' hosts with
  "<school>-" in dhcp and hostcfg. The image was created under the
  unprefixed name, and --setfilename never found the "host <school>-<name>"
  dhcp entry, so it silently changed nothing.
- -n was resolved while the options were still being parsed, so with
  "-n <host> -w <file>" the host was looked up in default-school's
  devices.csv.

Derive the school from the workstations file name (same path convention
as base7's readDevicesCsv()), resolve -n after all options are parsed,
and prefix the hostname for non-default schools. The devices.csv row
keeps the unprefixed name it was read with.

Also keep "option nis-domain" when --setfilename rewrites the dhcp host
entry. It was dropped, although import-devices writes it next to
extensions-path.

Refs linuxmuster#178

Signed-off-by: Tom Lehmann <tom.lehmann@netzint.de>
Assisted-by: Claude
@TomlDev
TomlDev force-pushed the fix/mkgrubimg-school-prefix branch from f75c21c to c32c829 Compare October 1, 2026 11:41
@TomlDev

TomlDev commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Lab test on a linuxmuster 7.4 server (linuxmuster-linbo7 7.4.17, linuxmuster-base7 7.4.8), school agy, host PC02 (devices.csv row R101;PC02;win11_2026;..., existing hostcfg/agy-PC02.cfg and DHCP host agy-PC02). I ran the script from a scratch copy against a copy of agy/agy.devices.csv: linbo-mkgrubimg -s -n PC02 -w <copy>. The installed script and the real devices.csv were not touched, and the hostcfg and DHCP files were restored afterwards.

The first version of this PR failed the criterion for host names with uppercase letters. getHostname() returns host.lower(), while readDevicesCsv() and import-devices write <school>-<name> with the case of the devices.csv row, so the image became agy-pc02.img and the case-sensitive 'host agy-pc02' in content match found no DHCP entry. The updated commit takes the prefixed name from the devices.csv row (getQualifiedHostname(), with tests); default-school keeps the lowercased name.

Result with the updated commit:

  • hostcfg/agy-PC02.img is created ("successfully created").
  • The DHCP entry host agy-PC02 gets filename "boot/grub/hostcfg/agy-PC02.img" and keeps option host-name, option extensions-path "win11_2026" and option nis-domain "win11_2026".
  • The -w copy gets the filename in field 8 of the PC02 row.
  • default-school's host pc02 entry is unchanged (identical before and after).

For comparison, the installed 7.4.17 script with the same arguments creates hostcfg/pc02.img and rewrites default-school's host pc02 DHCP entry with agy's MAC and IP, dropping its nis-domain.

Unrelated to this PR: getHostname() fails with list index out of range (printed, then the usage text) when the devices.csv contains a blank line.

@HappyBasher
HappyBasher merged commit e1a49de into linuxmuster:7.4 Oct 14, 2026
3 checks passed
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