|
| 1 | +use std assert |
| 2 | +use tap.nu |
| 3 | + |
| 4 | +def initial_build [] { |
| 5 | + tap begin "factory reset test" |
| 6 | + |
| 7 | + # Create test files that should be removed after factory reset |
| 8 | + print "Creating test files in /var and /etc" |
| 9 | + echo "test file in var" | save /var/test-file-factory-reset |
| 10 | + echo "test file in etc" | save /etc/test-file-factory-reset |
| 11 | + |
| 12 | + # Verify files were created |
| 13 | + assert ("/var/test-file-factory-reset" | path exists) |
| 14 | + assert ("/etc/test-file-factory-reset" | path exists) |
| 15 | + |
| 16 | + # Store the original deployment hash in a file |
| 17 | + let status = bootc status --json | from json |
| 18 | + let orig_stateroot = $status.status.booted.ostree.stateroot |
| 19 | + $orig_stateroot | save /var/tmp/tmt/orig_stateroot |
| 20 | + |
| 21 | + bootc install reset --experimental |
| 22 | + |
| 23 | + # sanity check that bootc status shows a new deployment with a non default stateroot |
| 24 | + let reset_status = bootc status --json | from json |
| 25 | + assert not equal $reset_status.status.otherDeployments.0.ostree.stateroot "default" |
| 26 | + |
| 27 | + print "Copying tmt into new stateroot" |
| 28 | + mount -o remount,rw /sysroot |
| 29 | + let stateroot = ls /sysroot/ostree/deploy |
| 30 | + cp -r /var/tmp/tmt $"($stateroot.1.name)/var/tmp" |
| 31 | + tmt-reboot |
| 32 | +} |
| 33 | + |
| 34 | +# The second boot; verify we're in the factory reset deployment |
| 35 | +def second_boot [] { |
| 36 | + print "Verifying factory reset completed successfully" |
| 37 | + let status = bootc status --json | from json |
| 38 | + let new_stateroot = $status.status.booted.ostree.stateroot |
| 39 | + let orig_stateroot = open /var/tmp/tmt/orig_stateroot |
| 40 | + assert ($orig_stateroot != $new_stateroot) "Should be booted into a new deployment" |
| 41 | + |
| 42 | + print "Checking that test files do not exist in the reset deployment" |
| 43 | + assert (not ("/var/test-file-factory-reset" | path exists)) "Test file in /var should not exist after factory reset" |
| 44 | + assert (not ("/etc/test-file-factory-reset" | path exists)) "Test file in /etc should not exist after factory reset" |
| 45 | + print "Factory reset verification completed successfully" |
| 46 | + tap ok |
| 47 | +} |
| 48 | + |
| 49 | +def main [] { |
| 50 | + # See https://tmt.readthedocs.io/en/stable/stories/features.html#reboot-during-test |
| 51 | + match $env.TMT_REBOOT_COUNT? { |
| 52 | + null | "0" => initial_build, |
| 53 | + "1" => second_boot, |
| 54 | + $o => { error make { msg: $"Invalid TMT_REBOOT_COUNT ($o)" } }, |
| 55 | + } |
| 56 | +} |
0 commit comments