Repository navigation
fix(linbo_mkgrubimg): handle hosts of non-default schools - #180
Conversation
|
Thanks, I reviewed this and ran the tests locally: We'll merge once the lab test is done. For this PR that means a real run of Before merging, please change two things in the commit:
One note for the follow-up PR: |
0c2cbef to
f75c21c
Compare
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
f75c21c to
c32c829
Compare
|
Lab test on a linuxmuster 7.4 server (linuxmuster-linbo7 7.4.17, linuxmuster-base7 7.4.8), school The first version of this PR failed the criterion for host names with uppercase letters. Result with the updated commit:
For comparison, the installed 7.4.17 script with the same arguments creates Unrelated to this PR: |
Part of #178. As agreed there, this fixes existing bugs in
linbo-mkgrubimgfor 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 thandefault-school:getHostname()returns the hostname from devices.csv, lowercased and without a school prefix.linuxmuster-import-deviceswrites non-default schools' hosts with a<school>-prefix in DHCP andhostcfg. The image was created ashostcfg/pc01.imginstead ofhostcfg/abc-pc01.img, and--setfilenamenever found thehost abc-pc01DHCP entry, so it silently changed nothing.-nwas 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.--setfilenamedroppedoption nis-domainwhen it rewrote the DHCP host entry, although import-devices writes it next toextensions-path.Change
getSchoolFromDevicesFile()derives the school from the workstations file name, using the same path convention as base7'sreadDevicesCsv()(<school>/<school>.devices.csv, otherwisedefault-school). No new option is needed;-sis already taken by--setfilename.-nis looked up after all options are parsed. For a non-default school the hostname gets the<school>-prefix.abc-pc01, which the next import turns intoabc-abc-pc01.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 forgetSchoolFromDevicesFile().main(['-s', '-n', 'pc01', '-w', '<tmp>/abc/abc.devices.csv'])against temp files with the real base7 functions. Theenvironmentpaths pointed at the temp dir, andgrub-mkstandalone, the dhcp restart and base7's third-party imports (IPy, ldap3, ...) were stubbed. The image ishostcfg/abc-pc01.img, thehost abc-pc01entry gets itsfilenameand keepsnis-domain, and the devices.csv row keepspc01.Not changed (existing, separate)
-s, a host whose IP isDHCPis not updated in devices.csv, becauseipis replaced by0.0.0.0before the old row is built for the search.'host ' + hostname in contentalso matches longer hostnames (pc01matchespc010).