88
99use std:: process:: Command ;
1010
11- use crate :: { get_bck_command, get_test_image} ;
11+ use crate :: { get_bck_command, get_test_image, run_bcvk } ;
1212
1313/// Test that base disk is created and reused for multiple VMs
1414pub fn test_base_disk_creation_and_reuse ( ) {
15- let bck = get_bck_command ( ) . unwrap ( ) ;
1615 let test_image = get_test_image ( ) ;
1716
1817 // Generate unique names for test VMs
@@ -33,74 +32,60 @@ pub fn test_base_disk_creation_and_reuse() {
3332
3433 // Create first VM - this should create a new base disk
3534 println ! ( "Creating first VM (should create base disk)..." ) ;
36- let vm1_output = Command :: new ( "timeout" )
37- . args ( [
38- "300s" ,
39- & bck,
40- "libvirt" ,
41- "run" ,
42- "--name" ,
43- & vm1_name,
44- "--filesystem" ,
45- "ext4" ,
46- & test_image,
47- ] )
48- . output ( )
49- . expect ( "Failed to create first VM" ) ;
50-
51- let vm1_stdout = String :: from_utf8_lossy ( & vm1_output. stdout ) ;
52- let vm1_stderr = String :: from_utf8_lossy ( & vm1_output. stderr ) ;
53-
54- println ! ( "VM1 stdout: {}" , vm1_stdout) ;
55- println ! ( "VM1 stderr: {}" , vm1_stderr) ;
56-
57- if !vm1_output. status . success ( ) {
35+ let vm1_output = run_bcvk ( & [
36+ "libvirt" ,
37+ "run" ,
38+ "--name" ,
39+ & vm1_name,
40+ "--filesystem" ,
41+ "ext4" ,
42+ & test_image,
43+ ] )
44+ . expect ( "Failed to create first VM" ) ;
45+
46+ println ! ( "VM1 stdout: {}" , vm1_output. stdout) ;
47+ println ! ( "VM1 stderr: {}" , vm1_output. stderr) ;
48+
49+ if !vm1_output. success ( ) {
5850 cleanup_domain ( & vm1_name) ;
5951 cleanup_domain ( & vm2_name) ;
6052
61- panic ! ( "Failed to create first VM: {}" , vm1_stderr ) ;
53+ panic ! ( "Failed to create first VM: {}" , vm1_output . stderr ) ;
6254 }
6355
6456 // Verify base disk was created
6557 assert ! (
66- vm1_stdout . contains( "Using base disk" ) || vm1_stdout . contains( "base disk" ) ,
58+ vm1_output . stdout . contains( "Using base disk" ) || vm1_output . stdout . contains( "base disk" ) ,
6759 "Should mention base disk creation"
6860 ) ;
6961
7062 // Create second VM - this should reuse the base disk
7163 println ! ( "Creating second VM (should reuse base disk)..." ) ;
72- let vm2_output = Command :: new ( "timeout" )
73- . args ( [
74- "300s" ,
75- & bck,
76- "libvirt" ,
77- "run" ,
78- "--name" ,
79- & vm2_name,
80- "--filesystem" ,
81- "ext4" ,
82- & test_image,
83- ] )
84- . output ( )
85- . expect ( "Failed to create second VM" ) ;
86-
87- let vm2_stdout = String :: from_utf8_lossy ( & vm2_output. stdout ) ;
88- let vm2_stderr = String :: from_utf8_lossy ( & vm2_output. stderr ) ;
89-
90- println ! ( "VM2 stdout: {}" , vm2_stdout) ;
91- println ! ( "VM2 stderr: {}" , vm2_stderr) ;
64+ let vm2_output = run_bcvk ( & [
65+ "libvirt" ,
66+ "run" ,
67+ "--name" ,
68+ & vm2_name,
69+ "--filesystem" ,
70+ "ext4" ,
71+ & test_image,
72+ ] )
73+ . expect ( "Failed to create second VM" ) ;
74+
75+ println ! ( "VM2 stdout: {}" , vm2_output. stdout) ;
76+ println ! ( "VM2 stderr: {}" , vm2_output. stderr) ;
9277
9378 // Cleanup before assertions
9479 cleanup_domain ( & vm1_name) ;
9580 cleanup_domain ( & vm2_name) ;
9681
97- if !vm2_output. status . success ( ) {
98- panic ! ( "Failed to create second VM: {}" , vm2_stderr ) ;
82+ if !vm2_output. success ( ) {
83+ panic ! ( "Failed to create second VM: {}" , vm2_output . stderr ) ;
9984 }
10085
10186 // Verify base disk was reused (should be faster and mention using existing)
10287 assert ! (
103- vm2_stdout . contains( "Using base disk" ) || vm2_stdout . contains( "base disk" ) ,
88+ vm2_output . stdout . contains( "Using base disk" ) || vm2_output . stdout . contains( "base disk" ) ,
10489 "Should mention using base disk"
10590 ) ;
10691
@@ -183,7 +168,6 @@ pub fn test_base_disks_prune_dry_run() {
183168
184169/// Test that VM disks reference base disks correctly
185170pub fn test_vm_disk_references_base ( ) {
186- let bck = get_bck_command ( ) . unwrap ( ) ;
187171 let test_image = get_test_image ( ) ;
188172
189173 let timestamp = std:: time:: SystemTime :: now ( )
@@ -197,26 +181,21 @@ pub fn test_vm_disk_references_base() {
197181 cleanup_domain ( & vm_name) ;
198182
199183 // Create VM
200- let output = Command :: new ( "timeout" )
201- . args ( [
202- "300s" ,
203- & bck,
204- "libvirt" ,
205- "run" ,
206- "--name" ,
207- & vm_name,
208- "--filesystem" ,
209- "ext4" ,
210- & test_image,
211- ] )
212- . output ( )
213- . expect ( "Failed to create VM" ) ;
214-
215- if !output. status . success ( ) {
216- let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
184+ let output = run_bcvk ( & [
185+ "libvirt" ,
186+ "run" ,
187+ "--name" ,
188+ & vm_name,
189+ "--filesystem" ,
190+ "ext4" ,
191+ & test_image,
192+ ] )
193+ . expect ( "Failed to create VM" ) ;
194+
195+ if !output. success ( ) {
217196 cleanup_domain ( & vm_name) ;
218197
219- panic ! ( "Failed to create VM: {}" , stderr) ;
198+ panic ! ( "Failed to create VM: {}" , output . stderr) ;
220199 }
221200
222201 // Get VM disk path from domain XML
0 commit comments