From e5c79c1dba8df4bcb45ceb0e7e195e071b74771c Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Tue, 10 Nov 2026 08:33:03 -0600 Subject: [PATCH] Branch FOS imaging on an OS class, not on osid lists (fos#204) determineOS "$osid" "$family" now sets one global, osClass. Ids 1-7 keep their own class (xp, vista, win98, winother, win7). Every other id takes its class from the server's osfamily= (windows, linux, macos, other). With no family, FOS falls back to the family of the ids it knows. A family from the server wins over the fallback. All 20 osid comparisons outside determineOS() now test osClass, so a new OS id needs no FOS release. fog.checkin and fog.debug pass the family. fog.capone passes none and exports an empty osfamily. Capone still aborts on an unknown id. completeTasking() matched osid 51 and 99 by accident, through the repeat in +( ). The site now includes `other`, so 99 keeps its branch. For 99, changeHostname() has no 99/other arm, so no registry was written before and none is now. What 99 keeps is the NTFS mount with remove_hiberfile, which removes hiberfil.sys. Osid 51 (Chromium OS) shares the linux class with 50, so it loses that NTFS mount and hiberfile removal. It never wrote a registry. See ADR-0022. Adds tests/checks/os-class.sh, docs/adr/0022-os-class.md, and the CLAUDE.md and tests/README.md entries. The golden fixture is not recaptured. Co-Authored-By: Claude Opus 5.5 --- .../FOG/FOS/rootfs_overlay/bin/fog.capone | 3 + .../FOG/FOS/rootfs_overlay/bin/fog.checkin | 2 +- .../FOG/FOS/rootfs_overlay/bin/fog.debug | 2 +- .../FOG/FOS/rootfs_overlay/bin/fog.download | 16 +- .../FOG/FOS/rootfs_overlay/bin/fog.upload | 8 +- .../rootfs_overlay/usr/share/fog/lib/funcs.sh | 113 +++++-- .../usr/share/fog/lib/partition-funcs.sh | 4 +- CLAUDE.md | 14 + docs/adr/0022-os-class.md | 76 +++++ tests/README.md | 10 + tests/checks/lvm.sh | 1 + tests/checks/mbr-extended.sh | 1 + tests/checks/ntfs-shrink-retry.sh | 1 + tests/checks/os-class.sh | 308 ++++++++++++++++++ tests/golden/run.sh | 1 + 15 files changed, 515 insertions(+), 45 deletions(-) create mode 100644 docs/adr/0022-os-class.md create mode 100755 tests/checks/os-class.sh diff --git a/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.capone b/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.capone index a33f6fcf..7f0bdc93 100755 --- a/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.capone +++ b/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.capone @@ -105,6 +105,9 @@ export type="down" export mac=$(getMACAddresses) export img export osid +# The Capone menu sends no osfamily=, and fog.checkin reads it again on the +# way through fog -> fog.download. Clear it so a Capone image never inherits one. +export osfamily="" export imgType export imgPartitionType export imgFormat diff --git a/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.checkin b/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.checkin index d670d17f..ae801cf8 100755 --- a/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.checkin +++ b/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.checkin @@ -38,7 +38,7 @@ esac debugPause verifyNetworkConnection dots "Checking Operating System" -[[ -z $deployed ]] && determineOS "$osid" +[[ -z $deployed ]] && determineOS "$osid" "$osfamily" echo "$osname" dots "Checking CPU Cores" cores=$(nproc) diff --git a/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.debug b/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.debug index c0a38f10..570b2b14 100755 --- a/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.debug +++ b/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.debug @@ -33,7 +33,7 @@ mbrfile="" defaultpart2start="" disks="" hd="" -[[ -n $osid ]] && determineOS "$osid" +[[ -n $osid ]] && determineOS "$osid" "$osfamily" [[ -n $osid ]] && echo "osid=$osid" echo "osname=$osname" echo "mbrfile=$mbrfile" diff --git a/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.download b/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.download index bd045211..9aafe55b 100755 --- a/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.download +++ b/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.download @@ -24,12 +24,12 @@ preparePartitions() { echo " * Preparing Partition layout" case $imgType in [Nn]) - case $osid in - 4|50|51) + case $osClass in + winother|linux) [[ ! -d $imagePath ]] && handleError "Unable to locate image store ($0)\n Args Passed: $*" prepareResizeDownloadPartitions "$hd" 1 "$imagePath" "$osid" "$imgPartitionType" ;; - [1-2]) + xp|vista) [[ ! -f $imagePath && ! -f $imagePath/$img && ! -d $imagePath ]] && handleError "Unable to locate image store ($0)\n Args Passed: $*" [[ -d $imagePath && -f $imagePath/$img ]] && imagePath="$imagePath/$img" if [[ -d $imagePath ]]; then @@ -72,7 +72,7 @@ preparePartitions() { done fi ;; - [5-7]|9|10|11) + win7|winmodern) [[ ! -d $imagePath && ! -f $imagePath/sys.img.000 ]] && handleError "Unable to locate image store ($0)\n Args Passed: $*" sfdiskOriginalPartitionFileName "$imagePath" "1" sfdiskLegacyOriginalPartitionFileName "$imagePath" "1" @@ -241,14 +241,14 @@ putDataBack() { ;; n|mps|mpa) [[ $imgType == +(n|mps) ]] && disks="$hd" - case $osid in - [1-2]) + case $osClass in + xp|vista) [[ ! -f $imagePath && ! -d $imagePath ]] && handleError "Fatal Error: Could not locate file ($0)\n Args Passed: $*" ;; - [5-7]|9|10|11) + win7|winmodern) [[ ! -d $imagePath && ! -f $imagePath/sys.img.000 ]] && handleError "Fatal Error: Could not locate file ($0)\n Args Passed: $*" ;; - 4|50|51) + winother|linux) [[ ! -d $imagePath ]] && handleError "Fatal Error: could not locate file ($0)\n Args Passed: $*" ;; esac diff --git a/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.upload b/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.upload index ec2a5e26..eaf67b75 100755 --- a/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.upload +++ b/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.upload @@ -38,7 +38,7 @@ beginUpload() { parts="" getPartitions "$hd" [[ ${#parts} -lt 1 ]] && handleError "No partitions found ($0)\n Args Passed: $*" - [[ $osid == @([1-2]|[4-7]|9|10|11) ]] && win7partcnt=$(echo $parts | wc -w) + [[ $osClass == @(xp|vista|winother|win7|winmodern) ]] && win7partcnt=$(echo $parts | wc -w) dots "Checking for fixed partitions" part_number=0 for part in $parts; do @@ -85,8 +85,8 @@ beginUpload() { debugPause echo " * Total Partition count of: $partscnt" debugPause - case $osid in - [4-7]|9|10|11|50|51) + case $osClass in + winother|win7|winmodern|linux) echo " * Setting up any additional fixed parts" part_number=0 for part in $parts; do @@ -183,7 +183,7 @@ beginUpload() { runPartprobe "$hd" echo "Done" debugPause - [[ $osid -eq 2 ]] && correctVistaMBR "$hd" + [[ $osClass == vista ]] && correctVistaMBR "$hd" getPartitions "$hd" for part in $parts; do expandPartition "$part" "$fixed_size_partitions" diff --git a/Buildroot/board/FOG/FOS/rootfs_overlay/usr/share/fog/lib/funcs.sh b/Buildroot/board/FOG/FOS/rootfs_overlay/usr/share/fog/lib/funcs.sh index 62682a23..8268d9c1 100644 --- a/Buildroot/board/FOG/FOS/rootfs_overlay/usr/share/fog/lib/funcs.sh +++ b/Buildroot/board/FOG/FOS/rootfs_overlay/usr/share/fog/lib/funcs.sh @@ -111,7 +111,7 @@ verifyNetworkConnection() { } # Verifies that the OS is valid for resizing validResizeOS() { - [[ $osid != @([1-2]|4|[5-7]|9|10|11|50|51) ]] && handleError " * Invalid operating system id: $osname ($osid) (${FUNCNAME[0]})\n Args Passed: $*" + [[ $osClass != @(xp|vista|winother|win7|winmodern|linux) ]] && handleError " * Invalid operating system id: $osname ($osid) (${FUNCNAME[0]})\n Args Passed: $*" } # Gets the graphics information from the system getGraphics() { @@ -734,12 +734,12 @@ shrinkPartition() { debugPause dots "Resizing partition $part" getPartBlockSize "$part" "part_block_size" - case $osid in - [1-2]|4) + case $osClass in + xp|vista|winother) resizePartition "$part" "$(calculate "$sizentfsresize*1024")" "$imagePath" - [[ $osid -eq 2 ]] && correctVistaMBR "$disk" + [[ $osClass == vista ]] && correctVistaMBR "$disk" ;; - [5-7]|9|10|11) + win7|winmodern) [[ $part_number -eq $win7partcnt ]] && part_start=$(blkid -po udev $part 2>/dev/null | awk -F= '/PART_ENTRY_OFFSET=/{printf("%.0f\n",$2*'$part_block_size'/1000)}') || part_start=1048576 if [[ -z $part_start || $part_start -lt 1 ]]; then echo "Failed" @@ -1117,11 +1117,11 @@ getValidRestorePartitions() { continue fi fi - case $osid in - [1-2]) + case $osClass in + xp|vista) [[ ! -f $imagePath ]] && imgpart="$imagePath/d${disk_number}p${part_number}.img${split}" || imgpart="$imagePath" ;; - 4|[5-7]|9|10|11) + winother|win7|winmodern) [[ ! -f $imagePath/sys.img.000 ]] && imgpart="$imagePath/d${disk_number}p${part_number}.img${split}" if [[ -z $imgpart ]]; then case $win7partcnt in @@ -1219,11 +1219,11 @@ changeHostname() { ntfs-3g -o remove_hiberfile,rw $part /ntfs >/tmp/ntfs-mount-output 2>&1 checkStatus $? "done-pause" " * Could not mount $part (${FUNCNAME[0]})\n Args Passed: $*\n Reason: $(cat /tmp/ntfs-mount-output | tr -d \\0)" if [[ ! -f /usr/share/fog/lib/EOFREG ]]; then - case $osid in - 1) + case $osClass in + xp) regfile="$REG_LOCAL_MACHINE_XP" ;; - 2|4|[5-7]|9|10|11) + vista|winother|win7|winmodern) regfile="$REG_LOCAL_MACHINE_7" ;; esac @@ -1266,7 +1266,7 @@ changeHostname() { fixWin7boot() { local part="$1" [[ -z $part ]] && handleError "No partition passed (${FUNCNAME[0]})\n Args Passed: $*" - [[ $osid != [5-7] ]] && return + [[ $osClass != win7 ]] && return local fstype="" fsTypeSetting "$part" [[ $fstype != ntfs ]] && return @@ -1328,8 +1328,8 @@ clearMountedDevices() { ;; esac fi - case $osid in - 4|[5-7]|9|10|11) + case $osClass in + winother|win7|winmodern) local fstype="" fsTypeSetting "$part" REG_HOSTNAME_MOUNTED_DEVICES_7="\MountedDevices" @@ -1380,8 +1380,8 @@ removePageFile() { local fstype="" fsTypeSetting "$part" [[ ! $ignorepg -eq 1 ]] && return - case $osid in - [1-2]|4|[5-7]|9|10|11|50|51) + case $osClass in + xp|vista|winother|win7|winmodern|linux) case $fstype in ntfs) dots "Mounting partition ($part)" @@ -1431,75 +1431,125 @@ removePageFile() { } # Sets OS mbr, as needed, and returns the Name # based on the OS id passed. +# Also sets osClass, the one value every other site branches on (ADR-0022). # # $1 the osid to determine the os and mbr +# $2 the OS family from the server (windows|linux|macos|other), optional determineOS() { local osid="$1" + local family="$2" + local fallback="" + local label="" [[ -z $osid ]] && handleError "No os id passed (${FUNCNAME[0]})\n Args Passed: $*" + osClass="" + # Ids 1-7 are frozen: they keep their own class and ignore the family. + # Every other id takes its class from the family. The fallback is the + # family FOS assumes for an id it knows, when the server sends none. case $osid in 1) + osClass="xp" osname="Windows XP" mbrfile="/usr/share/fog/mbr/xp.mbr" ;; 2) + osClass="vista" osname="Windows Vista" mbrfile="/usr/share/fog/mbr/vista.mbr" ;; 3) + osClass="win98" osname="Windows 98" mbrfile="" ;; 4) + osClass="winother" osname="Windows (Other)" mbrfile="" ;; 5) + osClass="win7" osname="Windows 7" mbrfile="/usr/share/fog/mbr/win7.mbr" defaultpart2start="206848s" ;; 6) + osClass="win7" osname="Windows 8" mbrfile="/usr/share/fog/mbr/win8.mbr" defaultpart2start="718848s" ;; 7) + osClass="win7" osname="Windows 8.1" mbrfile="/usr/share/fog/mbr/win8.mbr" defaultpart2start="718848s" ;; 8) + fallback="macos" osname="Apple Mac OS" mbrfile="" ;; 9) + fallback="windows" osname="Windows 10" mbrfile="" ;; 10) + fallback="windows" osname="Windows 11" mbrfile="" ;; 11) + fallback="windows" osname="Windows Server" mbrfile="" ;; 50) + fallback="linux" osname="Linux" mbrfile="" ;; 51) + fallback="linux" osname="Chromium OS" mbrfile="" ;; 99) + fallback="other" osname="Other OS" mbrfile="" ;; *) - handleError " * Invalid OS ID ($osid) (${FUNCNAME[0]})\n Args Passed: $*" + osname="" + mbrfile="" + ;; + esac + [[ -n $osClass ]] && return + # A non-empty family from the server wins over the fallback. + [[ -z $family ]] && family="$fallback" + [[ -z $family ]] && handleError " * Invalid OS ID ($osid) (${FUNCNAME[0]})\n Args Passed: $*" + case $family in + windows) + osClass="winmodern" + label="Windows" + ;; + linux) + osClass="linux" + label="Linux" + ;; + macos) + osClass="mac" + label="macOS" + ;; + other) + osClass="other" + label="Other OS" + ;; + *) + handleError " * Invalid OS family ($family) for OS ID ($osid) (${FUNCNAME[0]})\n Args Passed: $*" ;; esac + [[ -z $osname ]] && osname="$label (osid $osid)" } # Converts the string (seconds) passed to human understanding # @@ -1817,7 +1867,12 @@ completeTasking() { . ${postdownpath}fog.postdownload fi [[ $capone -eq 1 ]] && exit 0 - if [[ $osid == +([1-2]|4|[5-7]|9|10|11) ]]; then + # `other` keeps osid 99, which the old +( ) pattern matched as "9" "9". + # changeHostname() has no 99/other arm, so no registry is written + # for 99, on the base or now. What 99 keeps is the NTFS mount with + # remove_hiberfile (it removes hiberfil.sys). Osid 51 shares the + # linux class with 50 and loses that mount. See ADR-0022. + if [[ $osClass == @(xp|vista|winother|win7|winmodern|other) ]]; then for disk in $disks; do getPartitions "$disk" for part in $parts; do @@ -2001,8 +2056,8 @@ handleError() { # Windows 2000/XP, Vista: # Linux: if [[ -n $2 ]]; then - case $osid in - [1-2]|4|[5-7]|9|10|11|50|51) + case $osClass in + xp|vista|winother|win7|winmodern|linux) if [[ -n "$hd" ]]; then getPartitions "$hd" for part in $parts; do @@ -2413,8 +2468,8 @@ savePartitionTablesAndBootLoaders() { case $hasgpt in 0) strdots="Saving Partition Tables (MBR)" - case $osid in - 4|50|51) + case $osClass in + winother|linux) [[ $disk_number -eq 1 ]] && strdots="Saving Partition Tables and GRUB (MBR)" ;; esac @@ -2936,8 +2991,8 @@ restorePartitionTablesAndBootLoaders() { global_gptcheck="yes" echo "Done" else - case $osid in - 50|51) + case $osClass in + linux) strdots="Restoring Partition Tables and GRUB (MBR)" ;; *) @@ -3140,14 +3195,14 @@ restorePartition() { imgpart="$imagePath" ;; n|mps|mpa) - case $osid in - [1-2]) + case $osClass in + xp|vista) [[ -f $imagePath ]] && imgpart="$imagePath" || imgpart="$imagePath/d${disk_number}p${part_number}.img${split}" ;; - 4|8|50|51|99) + winother|mac|linux|other) imgpart="$imagePath/d${disk_number}p${part_number}.img${split}" ;; - [5-7]|9|10|11) + win7|winmodern) [[ ! -f $imagePath/sys.img.000 ]] && imgpart="$imagePath/d${disk_number}p${part_number}.img${split}" if [[ -z $imgpart ]] ;then [[ -r $imagePath/sys.img.000 ]] && win7partcnt=1 @@ -3291,7 +3346,7 @@ performRestore() { restorePartition "$restorepart" "$disk_number" "$imagePath" "$mc" [[ $imgType =~ [Nn] ]] && restoreEBR "$restorepart" "$tmpebrfilename" [[ $imgType =~ [Nn] ]] && expandPartition "$restorepart" "$fixed_size_partitions" - [[ $osid == +([5-7]) && $imgType =~ [Nn] ]] && fixWin7boot "$restorepart" + [[ $osClass == win7 && $imgType =~ [Nn] ]] && fixWin7boot "$restorepart" done restoreparts="" echo " * Resetting UUIDs for $disk" diff --git a/Buildroot/board/FOG/FOS/rootfs_overlay/usr/share/fog/lib/partition-funcs.sh b/Buildroot/board/FOG/FOS/rootfs_overlay/usr/share/fog/lib/partition-funcs.sh index 5e305c3d..3e3074c7 100644 --- a/Buildroot/board/FOG/FOS/rootfs_overlay/usr/share/fog/lib/partition-funcs.sh +++ b/Buildroot/board/FOG/FOS/rootfs_overlay/usr/share/fog/lib/partition-funcs.sh @@ -481,8 +481,8 @@ processSfdisk() { local minstart=$(awk -F'[ ,]+' '/start/{if ($4) print $4}' $data | sort -n | head -1) local chunksize="" getPartBlockSize "$disk" "chunksize" - case $osid in - [1-2]) + case $osClass in + xp|vista) [[ -z $minstart ]] && { minstart=63 chunksize=$sectorsize diff --git a/CLAUDE.md b/CLAUDE.md index 150d197b..36882433 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -181,6 +181,7 @@ tests/checks/multicast-receiver.sh # udp-receiver gets --start-timeout from m tests/checks/fixparts-binary-present.sh # fs.patch builds fixparts, which runFixparts() calls (fos#194) tests/checks/tmp-size.sh # /tmp is real tmpfs, sized from ramdisk_size= and clamped (ADR-0021) tests/checks/perftest.sh # Performance Test task: rates, sampled image, dev/ share, bottleneck (fos#55) +tests/checks/os-class.sh # osClass truth table vs the pre-change osid lists; new ids from osfamily=; errors; callers (ADR-0022, fos#204) tests/checks/package-mirrors.sh # build.sh's package mirror fallback and hash enforcement ``` @@ -417,6 +418,19 @@ and add a new ADR for any similarly hard-to-reverse decision: `/tmp` was never capped. SHMEM/TMPFS are now on and `S00tmpsize` sizes `/tmp` from `ramdisk_size=` (FOG_KERNEL_RAMDISK_SIZE), clamped to half of RAM. Guarded by `tests/checks/initrd-format.sh` and `tests/checks/tmp-size.sh`. +- **0022 — OS class.** Sites no longer branch on osid lists such as + `[5-7]|9|10|11`. `determineOS "$osid" "$family"` sets one global, `osClass`, + and every site tests it. Frozen ids stay osid-keyed: 1 `xp`, 2 `vista`, + 3 `win98`, 4 `winother`, 5-7 `win7`. Every other id is family-keyed + (`windows` gives `winmodern`, `linux`, `macos` gives `mac`, `other`), so a new + Windows, Linux, macOS or Other id needs no FOS release. The family comes from + `osfamily=` and is optional: empty means a built-in fallback for the ids FOS + knows (8, 9-11, 50/51, 99), and a non-empty family from the server wins. The + family is an argument, not a global: `fog.checkin` and `fog.debug` pass it, + `fog.capone` does not and exports an empty `osfamily`, so a Capone image never + inherits one. Empty family plus unknown osid, or a bad family on a + non-frozen id, is fatal (ADR-0003). Do not add an osid comparison outside + `determineOS()`. Guarded by `tests/checks/os-class.sh`. General conventions to preserve when editing `funcs.sh`/`partition-funcs.sh`: diff --git a/docs/adr/0022-os-class.md b/docs/adr/0022-os-class.md new file mode 100644 index 00000000..c785c54b --- /dev/null +++ b/docs/adr/0022-os-class.md @@ -0,0 +1,76 @@ +# Branch on an OS class, not on osid lists + +FOS branched on lists of osids, such as `[5-7]|9|10|11`, at 20 sites outside `determineOS()`. +`determineOS()` also aborted on any osid it did not know. So every new OS row +in FOG needed a FOS release. + +We decided **FOS resolves one global, `osClass`, once, and every site +branches on `osClass`.** `determineOS "$osid" "$family"` sets it. + +## The rule + +| osid | osClass | Rule | +|---|---|---| +| 1 | `xp` | frozen id; the family is ignored | +| 2 | `vista` | frozen id | +| 3 | `win98` | frozen id | +| 4 | `winother` | frozen id | +| 5, 6, 7 | `win7` | frozen ids | +| any other id | from the family | `windows` gives `winmodern`, `linux` gives `linux`, `macos` gives `mac`, `other` gives `other` | + +- Ids 1-7 stay keyed on the osid. They are historical, no new id joins them, + and a family cannot tell XP from Windows 11. +- Every other set is open-ended, so it is keyed on the family. A new Windows id + maps to `winmodern`, the newest Windows behavior. +- The family is optional. The server sends it as `osfamily=` on the kernel + command line. When it is empty, FOS uses a built-in fallback for the ids it + knows: 8 is `macos`, 9/10/11 are `windows`, 50/51 are `linux`, 99 is `other`. + So an init works against a server that sends no `osfamily=`. +- A non-empty family wins over the fallback. `osid=9` with family `linux` + gives `linux`. The server is authoritative. +- An empty family with an unknown osid calls `handleError`. A family outside + the four values, for a non-frozen id, also calls `handleError` (ADR-0003). +- For an unknown osid, `osname` is `Windows (osid N)`, `Linux (osid N)`, + `macOS (osid N)` or `Other OS (osid N)`, and `mbrfile` is empty. + +## Why the family is an argument + +`fog.checkin` and `fog.debug` pass `"$osfamily"`. `fog.capone` does not, +because its image comes from the Capone listing and not from the kernel +command line. `fog.capone` also exports an empty `osfamily`, because `fog` runs +`fog.download` and `fog.checkin` next, and they read `$osfamily` again. A +global read inside `determineOS()` would let a Capone image inherit a family +meant for another image. A new osid in a Capone listing still aborts. That +needs a server change to the Capone string, and is a follow-on. + +## Consequences + +- Each site keeps the same branch for every existing osid, with the family + empty or equal to the seeded family. This includes the differences between + sites: `fog.upload` still uses `[4-7]` where other sites use `[5-7]`, which + is `winother|win7|winmodern` there. +- One site did not keep its branch. `completeTasking()` tested + `[[ $osid == +([1-2]|4|[5-7]|9|10|11) ]]`. The `+( )` repeats the group, so + it also matched 51 and 99 by accident. Osid 50 did not match. The site now + includes `other` only to keep the base's branch for osid 99. `changeHostname()` + has no `99` or `other` arm, so for osid 99 `regfile` stays empty and no + registry is written, on the base and now. What 99 keeps is the NTFS mount: + `changeHostname` mounts each NTFS partition with `ntfs-3g -o + remove_hiberfile,rw`, which removes `hiberfil.sys`. A failed mount aborts + through `checkStatus` and `handleError`. 50 and 51 share a class, so a class + test cannot keep 51. For osid 51 (Chromium OS), `changeHostname` no longer + runs after a deploy, so the NTFS mount and the hiberfile removal are lost. + It never wrote a registry. +- A function that takes `osid` as an argument (`savePartitionTablesAndBootLoaders`, + `restorePartitionTablesAndBootLoaders`) now reads the global `osClass`. Its + `osid` argument is still checked, and no longer decides a branch. Every + caller passes the global `osid`, so the two agree. +- A test that calls a site function must call `determineOS "$osid"` first. + +## Guard + +`tests/checks/os-class.sh` holds the osid lists the sites had before the +change. It runs them against the `osClass` patterns in the real source for +every known osid, with the family empty and seeded. It also covers new ids, +the conflict, every error, the callers, and the absence of any osid +comparison outside `determineOS()`. diff --git a/tests/README.md b/tests/README.md index 4e6750c0..11b740e1 100644 --- a/tests/README.md +++ b/tests/README.md @@ -322,6 +322,16 @@ tests/checks/perftest.sh # stream cut mid-way, scaling compressed rates # to uncompressed, and which stage it blames. # See fos#55 +tests/checks/os-class.sh + # osClass (ADR-0022): a truth table of the osid + # lists each site had before the change, run + # against the osClass patterns in the real source + # for every known osid with the family empty and + # seeded; new ids resolved from the family, the + # server-wins conflict and every error; the + # callers that pass the family; and no osid + # comparison left outside determineOS(). See + # fos#204 tests/checks/package-mirrors.sh # build.sh's package-mirror seeding: resolves each # package's version/source/site out of its own .mk diff --git a/tests/checks/lvm.sh b/tests/checks/lvm.sh index eb1efdf2..14d55e23 100755 --- a/tests/checks/lvm.sh +++ b/tests/checks/lvm.sh @@ -333,6 +333,7 @@ run() { imgPartitionType="all" imgType="n" osid=50 + determineOS "$osid" storage="STUBSTORE" img="STUBIMG" percent=25 diff --git a/tests/checks/mbr-extended.sh b/tests/checks/mbr-extended.sh index 88680c47..fcf6f234 100755 --- a/tests/checks/mbr-extended.sh +++ b/tests/checks/mbr-extended.sh @@ -368,6 +368,7 @@ run_funcs() { uploadFormat() { :; } getServerDiskSpaceAvailable() { echo "lots"; } imgFormat=5; imgPartitionType="all"; imgType="n"; osid=50 + determineOS "$osid" storage="STUBSTORE"; img="STUBIMG" eval "$1" echo "RETURNED" diff --git a/tests/checks/ntfs-shrink-retry.sh b/tests/checks/ntfs-shrink-retry.sh index a2d05cc0..a0b94e19 100755 --- a/tests/checks/ntfs-shrink-retry.sh +++ b/tests/checks/ntfs-shrink-retry.sh @@ -136,6 +136,7 @@ run_shrink() { resetFlag() { :; } percent=5 osid=9 + determineOS "$osid" win7partcnt=0 imagePath="$SANDBOX/images" shrinkPartition /dev/sda3 "$SANDBOX/images/d1.original.fstypes" "" diff --git a/tests/checks/os-class.sh b/tests/checks/os-class.sh new file mode 100755 index 00000000..10f7b6d1 --- /dev/null +++ b/tests/checks/os-class.sh @@ -0,0 +1,308 @@ +#!/bin/bash +# +# Assertion harness for the OS class (ADR-0022, fos#204). +# +# tests/checks/os-class.sh # run all cases, exit non-zero on any failure +# +# FOS used to branch on lists of osids (`[5-7]|9|10|11`) at 20 sites, and +# determineOS() aborted on any id it did not know. Now determineOS() resolves +# one global, osClass, from the osid and the optional server family, and every +# site branches on osClass. +# +# Case one is the truth table. For each site it holds the osid list the site +# had BEFORE the change. These lists come from the source on origin/master +# (559abc1), not from the rewritten code. The harness takes the osClass +# patterns out of the real rewritten source, runs both against every known +# osid (1-11, 50, 51, 99) with the family empty and with the seeded family, and +# asserts that both take the same branch. A site that sits in no list (win98 +# in most of them) takes "no branch" in both. +# +# Case two covers determineOS() itself: frozen ids, new ids that resolve from +# the family, the server-wins conflict, and every error. +# +# Case three covers the call sites that pass the family, and asserts that the +# osid comparisons are gone from everything outside determineOS(). +# +# Mechanism mirrors tests/checks/ntfs-shrink-retry.sh: source a sandbox copy of +# the library and override handleError AFTER sourcing so an abort is +# observable. + +HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +OVERLAY="$HERE/../../Buildroot/board/FOG/FOS/rootfs_overlay" +REPO_LIB="$OVERLAY/usr/share/fog/lib" +BIN="$OVERLAY/bin" + +[[ -f $REPO_LIB/funcs.sh ]] || { echo "ERROR: cannot find funcs.sh under $REPO_LIB" >&2; exit 2; } + +SANDBOX="$(mktemp -d)" +trap 'rm -rf "$SANDBOX"' EXIT + +cp "$REPO_LIB/partition-funcs.sh" "$SANDBOX/partition-funcs.sh" +sed -e "s#^\. /usr/share/fog/lib/partition-funcs\.sh#. $SANDBOX/partition-funcs.sh#" \ + "$REPO_LIB/funcs.sh" > "$SANDBOX/funcs.sh" + +PASS=0 +FAIL=0 +pass() { PASS=$((PASS + 1)); } +fail() { echo "FAIL: $1"; [[ -n $2 ]] && echo " $2"; FAIL=$((FAIL + 1)); } +eq() { # eq