Skip to content

Commit 209e3c0

Browse files
committed
reset: Initial tmt test for factory reset
1 parent 83e4ee9 commit 209e3c0

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

crates/lib/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::bootc_composefs::{
3434
finalize::composefs_native_finalize, rollback::composefs_rollback, status::composefs_booted,
3535
switch::switch_composefs, update::upgrade_composefs,
3636
};
37-
use crate::deploy::{MergeState, RequiredHostSpec, RequiredHostSpec};
37+
use crate::deploy::{MergeState, RequiredHostSpec};
3838
use crate::lints;
3939
use crate::progress_jsonl::{ProgressWriter, RawProgressFd};
4040
use crate::spec::Host;

tmt/plans/integration.fmf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,10 @@ execute:
5353
how: fmf
5454
test:
5555
- /tmt/tests/test-25-soft-reboot
56+
57+
/test-26-factory-reset:
58+
summary: Factory reset
59+
discover:
60+
how: fmf
61+
test:
62+
- /tmt/tests/test-26-factory-reset
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
print "Copying tmt into new stateroot"
24+
mount -o remount,rw /sysroot
25+
let stateroot = ls /sysroot/ostree/deploy
26+
cp -r /var/tmp/tmt $"($stateroot.1.name)/var/tmp"
27+
tmt-reboot
28+
}
29+
30+
# The second boot; verify we're in the factory reset deployment
31+
def second_boot [] {
32+
print "Verifying factory reset completed successfully"
33+
let status = bootc status --json | from json
34+
let new_stateroot = $status.status.booted.ostree.stateroot
35+
let orig_stateroot = open /var/tmp/tmt/orig_stateroot
36+
assert ($orig_stateroot != $new_stateroot) "Should be booted into a new deployment"
37+
38+
print "Checking that test files do not exist in the reset deployment"
39+
assert (not ("/var/test-file-factory-reset" | path exists)) "Test file in /var should not exist after factory reset"
40+
assert (not ("/etc/test-file-factory-reset" | path exists)) "Test file in /etc should not exist after factory reset"
41+
print "Factory reset verification completed successfully"
42+
tap ok
43+
}
44+
45+
def main [] {
46+
# See https://tmt.readthedocs.io/en/stable/stories/features.html#reboot-during-test
47+
match $env.TMT_REBOOT_COUNT? {
48+
null | "0" => initial_build,
49+
"1" => second_boot,
50+
$o => { error make { msg: $"Invalid TMT_REBOOT_COUNT ($o)" } },
51+
}
52+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
summary: Execute factory reset tests
2+
test: nu booted/test-factory-reset.nu
3+
duration: 30m

0 commit comments

Comments
 (0)