Skip to content

Commit 6d371a6

Browse files
committed
ch: Add vm restart test
1 parent 7193ca2 commit 6d371a6

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

ch_integration_tests/tests/integration.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,58 @@ mod tests {
533533
"ch:///system"
534534
);
535535
}
536+
537+
#[test]
538+
fn test_vm_restart() {
539+
cleanup_libvirt_state();
540+
let mut libvirtd = spawn_libvirtd().unwrap();
541+
thread::sleep(std::time::Duration::new(5, 0));
542+
543+
let mut disk = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_owned());
544+
let guest = Guest::new(&mut disk);
545+
546+
let domain_path = guest.create_domain(VcpuConfig::default(), DEFAULT_RAM_SIZE);
547+
548+
let r = std::panic::catch_unwind(|| {
549+
spawn_virsh(&["create", domain_path.to_str().unwrap()])
550+
.unwrap()
551+
.wait_with_output()
552+
.unwrap();
553+
554+
guest.wait_vm_boot(None).unwrap();
555+
guest.ssh_command("sudo reboot").unwrap();
556+
guest.wait_vm_boot(None).unwrap();
557+
let reboot_count = guest
558+
.ssh_command("sudo journalctl | grep -c -- \"-- Reboot --\"")
559+
.unwrap()
560+
.trim()
561+
.parse::<u32>()
562+
.unwrap_or_default();
563+
assert_eq!(reboot_count, 1);
564+
565+
let list_output = spawn_virsh(&["list", "--all"])
566+
.unwrap()
567+
.wait_with_output()
568+
.unwrap();
569+
570+
let re = Regex::new(&format!(r"\s+\d+\s+{}\s+running", guest.vm_name)).unwrap();
571+
assert!(re.is_match(std::str::from_utf8(&list_output.stdout).unwrap().trim()));
572+
});
573+
574+
spawn_virsh(&["destroy", &guest.vm_name])
575+
.unwrap()
576+
.wait()
577+
.unwrap();
578+
579+
libvirtd.kill().unwrap();
580+
let libvirtd_output = libvirtd.wait_with_output().unwrap();
581+
582+
eprintln!(
583+
"libvirtd stdout\n\n{}\n\nlibvirtd stderr\n\n{}",
584+
std::str::from_utf8(&libvirtd_output.stdout).unwrap(),
585+
std::str::from_utf8(&libvirtd_output.stderr).unwrap()
586+
);
587+
588+
assert!(r.is_ok());
589+
}
536590
}

0 commit comments

Comments
 (0)