Skip to content

Commit 7fbe8c8

Browse files
committed
tmt: Remove one level of test enumeration duplication
Previously we duplicated all test names *three* times: - In the plan fmf - In the test fmf - In the test binary itself Now while we could be using plans better, because we're provisioning with bcvk now we have to basically bypass the plan stuff and directly run a test. So use the plans for logical grouping, but change our runner code to just directly run the tests. Signed-off-by: Colin Walters <[email protected]>
1 parent e99410d commit 7fbe8c8

File tree

3 files changed

+59
-119
lines changed

3 files changed

+59
-119
lines changed

crates/xtask/src/xtask.rs

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -491,18 +491,18 @@ fn generate_random_suffix() -> String {
491491
.collect()
492492
}
493493

494-
/// Sanitize a plan name for use in a VM name
494+
/// Sanitize a name for use in a VM name
495495
/// Replaces non-alphanumeric characters (except - and _) with dashes
496-
/// Returns "plan" if the result would be empty
497-
fn sanitize_plan_name(plan: &str) -> String {
498-
let sanitized = plan
496+
/// Returns "tmt" if the result would be empty
497+
fn sanitize_name(name: &str) -> String {
498+
let sanitized = name
499499
.replace('/', "-")
500500
.replace(|c: char| !c.is_alphanumeric() && c != '-' && c != '_', "-")
501501
.trim_matches('-')
502502
.to_string();
503503

504504
if sanitized.is_empty() {
505-
"plan".to_string()
505+
"tmt".to_string()
506506
} else {
507507
sanitized
508508
}
@@ -560,38 +560,38 @@ fn run_tmt(sh: &Shell, args: &RunTmtArgs) -> Result<()> {
560560
// Change to workdir for running tmt commands
561561
let _dir = sh.push_dir(workdir);
562562

563-
// Get the list of plans
564-
println!("Discovering test plans...");
565-
let plans_output = cmd!(sh, "tmt plan ls")
563+
// Get the list of tests
564+
println!("Discovering tests...");
565+
let tests_output = cmd!(sh, "tmt test ls")
566566
.read()
567567
.context("Getting list of test plans")?;
568568

569-
let mut plans: Vec<&str> = plans_output
569+
let mut tests: Vec<&str> = tests_output
570570
.lines()
571571
.map(|line| line.trim())
572572
.filter(|line| !line.is_empty() && line.starts_with("/"))
573573
.collect();
574574

575-
// Filter plans based on user arguments
575+
// Filter tests based on user arguments
576576
if !filter_args.is_empty() {
577-
let original_count = plans.len();
578-
plans.retain(|plan| filter_args.iter().any(|arg| plan.contains(arg.as_str())));
579-
if plans.len() < original_count {
577+
let original_count = tests.len();
578+
tests.retain(|t| filter_args.iter().any(|arg| t.contains(arg.as_str())));
579+
if tests.len() < original_count {
580580
println!(
581-
"Filtered from {} to {} plan(s) based on arguments: {:?}",
581+
"Filtered from {} to {} test(s) based on arguments: {:?}",
582582
original_count,
583-
plans.len(),
583+
tests.len(),
584584
filter_args
585585
);
586586
}
587587
}
588588

589-
if plans.is_empty() {
590-
println!("No test plans found");
589+
if tests.is_empty() {
590+
println!("No tests found");
591591
return Ok(());
592592
}
593593

594-
println!("Found {} test plan(s): {:?}", plans.len(), plans);
594+
println!("Found {} test(s): {:?}", tests.len(), tests);
595595

596596
// Generate a random suffix for VM names
597597
let random_suffix = generate_random_suffix();
@@ -600,18 +600,17 @@ fn run_tmt(sh: &Shell, args: &RunTmtArgs) -> Result<()> {
600600
let mut all_passed = true;
601601
let mut test_results = Vec::new();
602602

603-
// Run each plan in its own VM
604-
for plan in plans {
605-
let plan_name = sanitize_plan_name(plan);
606-
let vm_name = format!("bootc-tmt-{}-{}", random_suffix, plan_name);
603+
// Run each test in its own VM
604+
for test in tests {
605+
let test_name = sanitize_name(test);
606+
let vm_name = format!("bootc-tmt-{}-{}", random_suffix, test_name);
607607

608608
println!("\n========================================");
609-
println!("Running plan: {}", plan);
609+
println!("Running test: {}", test);
610610
println!("VM name: {}", vm_name);
611611
println!("========================================\n");
612612

613613
// Launch VM with bcvk
614-
615614
let launch_result = cmd!(
616615
sh,
617616
"bcvk libvirt run --name {vm_name} --detach {COMMON_INST_ARGS...} {image}"
@@ -620,9 +619,9 @@ fn run_tmt(sh: &Shell, args: &RunTmtArgs) -> Result<()> {
620619
.context("Launching VM with bcvk");
621620

622621
if let Err(e) = launch_result {
623-
eprintln!("Failed to launch VM for plan {}: {:#}", plan, e);
622+
eprintln!("Failed to launch VM for test {test}: {e:#}");
624623
all_passed = false;
625-
test_results.push((plan.to_string(), false));
624+
test_results.push((test.to_string(), false));
626625
continue;
627626
}
628627

@@ -645,10 +644,10 @@ fn run_tmt(sh: &Shell, args: &RunTmtArgs) -> Result<()> {
645644
let (ssh_port, ssh_key) = match vm_info {
646645
Ok((port, key)) => (port, key),
647646
Err(e) => {
648-
eprintln!("Failed to get VM info for plan {}: {:#}", plan, e);
647+
eprintln!("Failed to get VM info for plan {test}: {e:#}");
649648
cleanup_vm();
650649
all_passed = false;
651-
test_results.push((plan.to_string(), false));
650+
test_results.push((test.to_string(), false));
652651
continue;
653652
}
654653
};
@@ -661,10 +660,10 @@ fn run_tmt(sh: &Shell, args: &RunTmtArgs) -> Result<()> {
661660
let key_file = match key_file {
662661
Ok(f) => f,
663662
Err(e) => {
664-
eprintln!("Failed to create SSH key file for plan {}: {:#}", plan, e);
663+
eprintln!("Failed to create SSH key file for plan {test}: {e:#}");
665664
cleanup_vm();
666665
all_passed = false;
667-
test_results.push((plan.to_string(), false));
666+
test_results.push((test.to_string(), false));
668667
continue;
669668
}
670669
};
@@ -675,19 +674,19 @@ fn run_tmt(sh: &Shell, args: &RunTmtArgs) -> Result<()> {
675674
let key_path = match key_path {
676675
Ok(p) => p,
677676
Err(e) => {
678-
eprintln!("Failed to convert key path for plan {}: {:#}", plan, e);
677+
eprintln!("Failed to convert key path for test {test}: {e:#}");
679678
cleanup_vm();
680679
all_passed = false;
681-
test_results.push((plan.to_string(), false));
680+
test_results.push((test.to_string(), false));
682681
continue;
683682
}
684683
};
685684

686685
if let Err(e) = std::fs::write(&key_path, ssh_key) {
687-
eprintln!("Failed to write SSH key for plan {}: {:#}", plan, e);
686+
eprintln!("Failed to write SSH key for test {test}: {e:#}");
688687
cleanup_vm();
689688
all_passed = false;
690-
test_results.push((plan.to_string(), false));
689+
test_results.push((test.to_string(), false));
691690
continue;
692691
}
693692

@@ -696,38 +695,38 @@ fn run_tmt(sh: &Shell, args: &RunTmtArgs) -> Result<()> {
696695
use std::os::unix::fs::PermissionsExt;
697696
let perms = std::fs::Permissions::from_mode(0o600);
698697
if let Err(e) = std::fs::set_permissions(&key_path, perms) {
699-
eprintln!("Failed to set key permissions for plan {}: {:#}", plan, e);
698+
eprintln!("Failed to set key permissions for test {test}: {e:#}");
700699
cleanup_vm();
701700
all_passed = false;
702-
test_results.push((plan.to_string(), false));
701+
test_results.push((test.to_string(), false));
703702
continue;
704703
}
705704
}
706705

707706
// Verify SSH connectivity
708707
println!("Verifying SSH connectivity...");
709708
if let Err(e) = verify_ssh_connectivity(sh, ssh_port, &key_path) {
710-
eprintln!("SSH verification failed for plan {}: {:#}", plan, e);
709+
eprintln!("SSH verification failed for test {test}: {e:#}");
711710
cleanup_vm();
712711
all_passed = false;
713-
test_results.push((plan.to_string(), false));
712+
test_results.push((test.to_string(), false));
714713
continue;
715714
}
716715

717716
println!("SSH connectivity verified");
718717

719718
let ssh_port_str = ssh_port.to_string();
720719

721-
// Run tmt for this specific plan using connect provisioner
722-
println!("Running tmt tests for plan {}...", plan);
720+
// Run tmt for this specific test using connect provisioner
721+
println!("Running tmt test {}...", test);
723722

724-
// Run tmt for this specific plan
725-
// Note: provision must come before plan for connect to work properly
723+
// Run tmt for this specific test
724+
// Note: provision must come before tests for connect to work properly
726725
let context = context.clone();
727726
let how = ["--how=connect", "--guest=localhost", "--user=root"];
728727
let test_result = cmd!(
729728
sh,
730-
"tmt {context...} run --all -e TMT_SCRIPTS_DIR=/var/lib/tmt/scripts provision {how...} --port {ssh_port_str} --key {key_path} plan --name {plan}"
729+
"tmt {context...} run --all -e TMT_SCRIPTS_DIR=/var/lib/tmt/scripts provision {how...} --port {ssh_port_str} --key {key_path} tests --name {test}"
731730
)
732731
.run();
733732

@@ -736,13 +735,13 @@ fn run_tmt(sh: &Shell, args: &RunTmtArgs) -> Result<()> {
736735

737736
match test_result {
738737
Ok(_) => {
739-
println!("Plan {} completed successfully", plan);
740-
test_results.push((plan.to_string(), true));
738+
println!("Test {} completed successfully", test);
739+
test_results.push((test.to_string(), true));
741740
}
742741
Err(e) => {
743-
eprintln!("Plan {} failed: {:#}", plan, e);
742+
eprintln!("Test {} failed: {:#}", test, e);
744743
all_passed = false;
745-
test_results.push((plan.to_string(), false));
744+
test_results.push((test.to_string(), false));
746745
}
747746
}
748747

@@ -775,14 +774,14 @@ fn run_tmt(sh: &Shell, args: &RunTmtArgs) -> Result<()> {
775774
println!("\n========================================");
776775
println!("Test Summary");
777776
println!("========================================");
778-
for (plan, passed) in &test_results {
777+
for (test_name, passed) in &test_results {
779778
let status = if *passed { "PASSED" } else { "FAILED" };
780-
println!("{}: {}", plan, status);
779+
println!("{}: {}", test_name, status);
781780
}
782781
println!("========================================\n");
783782

784783
if !all_passed {
785-
anyhow::bail!("Some test plans failed");
784+
anyhow::bail!("Some tests failed");
786785
}
787786

788787
Ok(())

tmt/plans/integration.fmf

Lines changed: 9 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -35,80 +35,20 @@ prepare:
3535
execute:
3636
how: tmt
3737

38-
/readonly-tests:
39-
summary: Execute booted readonly/nondestructive tests
38+
# Regular tests (no special requirements)
39+
/all-tests:
40+
summary: All integration tests
4041
discover:
4142
how: fmf
42-
test:
43-
- /tmt/tests/test-01-readonly
43+
filter: tag:-image-mode-only
4444

45-
/test-20-local-upgrade:
46-
summary: Execute local upgrade tests
45+
# Image-mode-only tests
46+
/image-mode-tests:
47+
summary: Tests requiring image mode
4748
discover:
4849
how: fmf
49-
test:
50-
- /tmt/tests/test-20-local-upgrade
51-
52-
/test-21-logically-bound-switch:
53-
summary: Execute logically bound images tests for switching images
54-
discover:
55-
how: fmf
56-
test:
57-
- /tmt/tests/test-21-logically-bound-switch
58-
59-
/test-22-logically-bound-install:
60-
summary: Execute logically bound images tests for switching images
61-
discover:
62-
how: fmf
63-
test:
64-
- /tmt/tests/test-22-logically-bound-install
65-
66-
/test-23-install-outside-container:
67-
summary: Execute tests for installing outside of a container
68-
discover:
69-
how: fmf
70-
test:
71-
- /tmt/tests/test-23-install-outside-container
72-
73-
/test-24-local-upgrade-reboot:
74-
summary: Execute local upgrade tests with automated reboot
75-
discover:
76-
how: fmf
77-
test:
78-
- /tmt/tests/test-24-local-upgrade-reboot
79-
80-
/test-25-soft-reboot:
81-
summary: Soft reboot support
82-
discover:
83-
how: fmf
84-
test:
85-
- /tmt/tests/test-25-soft-reboot
86-
87-
/test-26-examples-build:
88-
summary: Test bootc examples build scripts
89-
discover:
90-
how: fmf
91-
test:
92-
- /tmt/tests/test-26-examples-build
50+
filter: tag:image-mode-only
9351
adjust:
9452
- when: running_env != image_mode
9553
enabled: false
96-
because: packit tests use RPM bootc and does not install /usr/lib/bootc/initramfs-setup
97-
98-
/test-27-custom-selinux-policy:
99-
summary: Execute restorecon test on system with custom selinux policy
100-
discover:
101-
how: fmf
102-
test:
103-
- /tmt/tests/test-27-custom-selinux-policy
104-
adjust:
105-
- when: running_env != image_mode
106-
enabled: false
107-
because: tmt-reboot does not work with systemd reboot in testing farm environment (see bug-soft-reboot.md)
108-
109-
/test-28-factory-reset:
110-
summary: Factory reset
111-
discover:
112-
how: fmf
113-
test:
114-
- /tmt/tests/test-28-factory-reset
54+
because: these tests require features only available in image mode
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
summary: Execute custom selinux policy test
2+
tag: [image-mode-only]
23
test: nu booted/test-custom-selinux-policy.nu
34
duration: 30m

0 commit comments

Comments
 (0)