Skip to content

Commit ea62c71

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

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-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: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
use std assert
2+
use tap.nu
3+
4+
bootc status
5+
6+
def initial_build [] {
7+
tap begin "factory reset test"
8+
9+
# Create test files that should be removed after factory reset
10+
print "Creating test files in /var and /etc"
11+
echo "test file in var" | save /var/test-file-factory-reset
12+
echo "test file in etc" | save /etc/test-file-factory-reset
13+
14+
# Verify files were created
15+
assert ("/var/test-file-factory-reset" | path exists)
16+
assert ("/etc/test-file-factory-reset" | path exists)
17+
18+
bootc install reset --experimental
19+
20+
# sanity check that bootc status shows a new deployment with a non default stateroot
21+
let reset_status = bootc status --json | from json
22+
assert not equal $reset_status.status.otherDeployments.0.ostree.stateroot "default"
23+
24+
# we need tmt in the new stateroot for second_boot
25+
print "Copying tmt into new stateroot"
26+
27+
# Get the new stateroot name from the staged deployment
28+
let new_stateroot = $reset_status.status.otherDeployments.0.ostree.stateroot
29+
print $"New stateroot: ($new_stateroot)"
30+
31+
# Mount /sysroot as read-write and copy tmt directory to the new deployment
32+
mount -o remount,rw /sysroot
33+
34+
let new_stateroot_path = $"/sysroot/ostree/deploy/($new_stateroot)"
35+
36+
# locate the workdir_root by looking backwards from a known static dir (TMT_PLAN_DATA)
37+
# e.g. TMT_PLAN_DATA=/var/tmp/tmt/run-035/tmt/plans/integration/test-28-factory-reset/data
38+
let workdir_root = ($env.TMT_PLAN_DATA | path dirname | path dirname | path dirname | path dirname | path dirname | path dirname )
39+
40+
# make sure workdir_root's full path exists in new stateroot
41+
mkdir $"($new_stateroot_path)/($workdir_root)"
42+
43+
# nu's cp doesn't have -T
44+
/usr/bin/cp -r -T $workdir_root $"($new_stateroot_path)/($workdir_root)"
45+
46+
tmt-reboot
47+
}
48+
49+
# The second boot; verify we're in the factory reset deployment
50+
def second_boot [] {
51+
print "Verifying factory reset completed successfully"
52+
let status = bootc status --json | from json
53+
assert not equal $status.status.booted.ostree.stateroot "default"
54+
55+
print "Checking that test files do not exist in the reset deployment"
56+
assert (not ("/var/test-file-factory-reset" | path exists)) "Test file in /var should not exist after factory reset"
57+
assert (not ("/etc/test-file-factory-reset" | path exists)) "Test file in /etc should not exist after factory reset"
58+
print "Factory reset verification completed successfully"
59+
tap ok
60+
}
61+
62+
def main [] {
63+
# See https://tmt.readthedocs.io/en/stable/stories/features.html#reboot-during-test
64+
match $env.TMT_REBOOT_COUNT? {
65+
null | "0" => initial_build,
66+
"1" => second_boot,
67+
$o => { error make { msg: $"Invalid TMT_REBOOT_COUNT ($o)" } },
68+
}
69+
}
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)