Skip to content

Commit 60de2ec

Browse files
committed
reset: Initial tmt test for factory reset
Signed-off-by: ckyrouac <[email protected]>
1 parent e502bb0 commit 60de2ec

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed

crates/lib/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use crate::bootc_composefs::{
4242
switch::switch_composefs,
4343
update::upgrade_composefs,
4444
};
45-
use crate::deploy::{MergeState, RequiredHostSpec, RequiredHostSpec};
45+
use crate::deploy::{MergeState, RequiredHostSpec};
4646
use crate::lints;
4747
use crate::podstorage::set_additional_image_store;
4848
use crate::progress_jsonl::{ProgressWriter, RawProgressFd};

tmt/plans/integration.fmf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,10 @@ execute:
105105
- when: running_env != image_mode
106106
enabled: false
107107
because: tmt-reboot does not work with systemd reboot in testing farm environment
108+
109+
/test-28-factory-reset:
110+
summary: Factory reset
111+
discover:
112+
how: fmf
113+
test:
114+
- /tmt/tests/test-28-factory-reset
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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 stateroot
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+
# we need tmt in the new stateroot for second_boot
28+
print "Copying tmt into new stateroot"
29+
30+
# Get the new stateroot name from the staged deployment
31+
let new_stateroot = $reset_status.status.otherDeployments.0.ostree.stateroot
32+
print $"New stateroot: ($new_stateroot)"
33+
34+
# Mount /sysroot as read-write and copy tmt directory to the new deployment
35+
mount -o remount,rw /sysroot
36+
37+
# The new deployment is in /sysroot/ostree/deploy/<stateroot>/var/tmp
38+
let new_var_path = $"/sysroot/ostree/deploy/($new_stateroot)/var/tmp"
39+
print $"Copying /var/tmp/tmt to ($new_var_path)"
40+
mkdir $new_var_path
41+
cp -r /var/tmp/tmt $new_var_path
42+
43+
tmt-reboot
44+
}
45+
46+
# The second boot; verify we're in the factory reset deployment
47+
def second_boot [] {
48+
print "Verifying factory reset completed successfully"
49+
let status = bootc status --json | from json
50+
let new_stateroot = $status.status.booted.ostree.stateroot
51+
let orig_stateroot = open /var/tmp/tmt/orig_stateroot
52+
assert ($orig_stateroot != $new_stateroot) "Should be booted into a new deployment"
53+
54+
print "Checking that test files do not exist in the reset deployment"
55+
assert (not ("/var/test-file-factory-reset" | path exists)) "Test file in /var should not exist after factory reset"
56+
assert (not ("/etc/test-file-factory-reset" | path exists)) "Test file in /etc should not exist after factory reset"
57+
print "Factory reset verification completed successfully"
58+
tap ok
59+
}
60+
61+
def main [] {
62+
# See https://tmt.readthedocs.io/en/stable/stories/features.html#reboot-during-test
63+
match $env.TMT_REBOOT_COUNT? {
64+
null | "0" => initial_build,
65+
"1" => second_boot,
66+
$o => { error make { msg: $"Invalid TMT_REBOOT_COUNT ($o)" } },
67+
}
68+
}
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)