88
99use std:: process:: Command ;
1010
11- use crate :: { get_bck_command, get_test_image} ;
11+ use crate :: { get_bck_command, get_libvirt_connect_args , get_test_image} ;
1212
1313/// Test that base disk is created and reused for multiple VMs
1414pub fn test_base_disk_creation_and_reuse ( ) {
1515 let bck = get_bck_command ( ) . unwrap ( ) ;
1616 let test_image = get_test_image ( ) ;
17+ let connect_args = get_libvirt_connect_args ( ) ;
1718
1819 // Generate unique names for test VMs
1920 let timestamp = std:: time:: SystemTime :: now ( )
@@ -33,20 +34,13 @@ pub fn test_base_disk_creation_and_reuse() {
3334
3435 // Create first VM - this should create a new base disk
3536 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" ) ;
37+ let mut vm1_cmd = Command :: new ( "timeout" ) ;
38+ vm1_cmd. args ( [ "300s" , & bck, "libvirt" , "run" ] ) ;
39+ for arg in & connect_args {
40+ vm1_cmd. arg ( arg) ;
41+ }
42+ vm1_cmd. args ( [ "--name" , & vm1_name, "--filesystem" , "ext4" , & test_image] ) ;
43+ let vm1_output = vm1_cmd. output ( ) . expect ( "Failed to create first VM" ) ;
5044
5145 let vm1_stdout = String :: from_utf8_lossy ( & vm1_output. stdout ) ;
5246 let vm1_stderr = String :: from_utf8_lossy ( & vm1_output. stderr ) ;
@@ -69,20 +63,13 @@ pub fn test_base_disk_creation_and_reuse() {
6963
7064 // Create second VM - this should reuse the base disk
7165 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" ) ;
66+ let mut vm2_cmd = Command :: new ( "timeout" ) ;
67+ vm2_cmd. args ( [ "300s" , & bck, "libvirt" , "run" ] ) ;
68+ for arg in & connect_args {
69+ vm2_cmd. arg ( arg) ;
70+ }
71+ vm2_cmd. args ( [ "--name" , & vm2_name, "--filesystem" , "ext4" , & test_image] ) ;
72+ let vm2_output = vm2_cmd. output ( ) . expect ( "Failed to create second VM" ) ;
8673
8774 let vm2_stdout = String :: from_utf8_lossy ( & vm2_output. stdout ) ;
8875 let vm2_stderr = String :: from_utf8_lossy ( & vm2_output. stderr ) ;
@@ -110,13 +97,16 @@ pub fn test_base_disk_creation_and_reuse() {
11097/// Test base-disks list command
11198pub fn test_base_disks_list_command ( ) {
11299 let bck = get_bck_command ( ) . unwrap ( ) ;
100+ let connect_args = get_libvirt_connect_args ( ) ;
113101
114102 println ! ( "Testing base-disks list command" ) ;
115103
116- let output = Command :: new ( & bck)
117- . args ( [ "libvirt" , "base-disks" , "list" ] )
118- . output ( )
119- . expect ( "Failed to run base-disks list" ) ;
104+ let mut cmd = Command :: new ( & bck) ;
105+ cmd. args ( [ "libvirt" , "base-disks" , "list" ] ) ;
106+ for arg in & connect_args {
107+ cmd. arg ( arg) ;
108+ }
109+ let output = cmd. output ( ) . expect ( "Failed to run base-disks list" ) ;
120110
121111 let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
122112 let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
@@ -149,11 +139,16 @@ pub fn test_base_disks_list_command() {
149139/// Test base-disks prune command with dry-run
150140pub fn test_base_disks_prune_dry_run ( ) {
151141 let bck = get_bck_command ( ) . unwrap ( ) ;
142+ let connect_args = get_libvirt_connect_args ( ) ;
152143
153144 println ! ( "Testing base-disks prune --dry-run command" ) ;
154145
155- let output = Command :: new ( & bck)
156- . args ( [ "libvirt" , "base-disks" , "prune" , "--dry-run" ] )
146+ let mut cmd = Command :: new ( & bck) ;
147+ cmd. args ( [ "libvirt" , "base-disks" , "prune" , "--dry-run" ] ) ;
148+ for arg in & connect_args {
149+ cmd. arg ( arg) ;
150+ }
151+ let output = cmd
157152 . output ( )
158153 . expect ( "Failed to run base-disks prune --dry-run" ) ;
159154
@@ -185,6 +180,7 @@ pub fn test_base_disks_prune_dry_run() {
185180pub fn test_vm_disk_references_base ( ) {
186181 let bck = get_bck_command ( ) . unwrap ( ) ;
187182 let test_image = get_test_image ( ) ;
183+ let connect_args = get_libvirt_connect_args ( ) ;
188184
189185 let timestamp = std:: time:: SystemTime :: now ( )
190186 . duration_since ( std:: time:: UNIX_EPOCH )
@@ -197,20 +193,13 @@ pub fn test_vm_disk_references_base() {
197193 cleanup_domain ( & vm_name) ;
198194
199195 // 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" ) ;
196+ let mut vm_cmd = Command :: new ( "timeout" ) ;
197+ vm_cmd. args ( [ "300s" , & bck, "libvirt" , "run" ] ) ;
198+ for arg in & connect_args {
199+ vm_cmd. arg ( arg) ;
200+ }
201+ vm_cmd. args ( [ "--name" , & vm_name, "--filesystem" , "ext4" , & test_image] ) ;
202+ let output = vm_cmd. output ( ) . expect ( "Failed to create VM" ) ;
214203
215204 if !output. status . success ( ) {
216205 let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
@@ -220,10 +209,12 @@ pub fn test_vm_disk_references_base() {
220209 }
221210
222211 // Get VM disk path from domain XML
223- let dumpxml_output = Command :: new ( "virsh" )
224- . args ( & [ "dumpxml" , & vm_name] )
225- . output ( )
226- . expect ( "Failed to dump domain XML" ) ;
212+ let mut dumpxml_cmd = Command :: new ( "virsh" ) ;
213+ for arg in & connect_args {
214+ dumpxml_cmd. arg ( arg) ;
215+ }
216+ dumpxml_cmd. args ( & [ "dumpxml" , & vm_name] ) ;
217+ let dumpxml_output = dumpxml_cmd. output ( ) . expect ( "Failed to dump domain XML" ) ;
227218
228219 if !dumpxml_output. status . success ( ) {
229220 cleanup_domain ( & vm_name) ;
@@ -261,18 +252,26 @@ pub fn test_vm_disk_references_base() {
261252
262253/// Helper function to cleanup domain and its disk
263254fn cleanup_domain ( domain_name : & str ) {
255+ let connect_args = get_libvirt_connect_args ( ) ;
264256 println ! ( "Cleaning up domain: {}" , domain_name) ;
265257
266258 // Stop domain if running
267- let _ = Command :: new ( "virsh" )
268- . args ( & [ "destroy" , domain_name] )
269- . output ( ) ;
259+ let mut destroy_cmd = Command :: new ( "virsh" ) ;
260+ for arg in & connect_args {
261+ destroy_cmd. arg ( arg) ;
262+ }
263+ destroy_cmd. args ( & [ "destroy" , domain_name] ) ;
264+ let _ = destroy_cmd. output ( ) ;
270265
271266 // Use bcvk libvirt rm for proper cleanup
272267 let bck = get_bck_command ( ) . unwrap ( ) ;
273- let cleanup_output = Command :: new ( & bck)
274- . args ( & [ "libvirt" , "rm" , domain_name, "--force" , "--stop" ] )
275- . output ( ) ;
268+ let mut cleanup_cmd = Command :: new ( & bck) ;
269+ cleanup_cmd. args ( & [ "libvirt" , "rm" , domain_name] ) ;
270+ for arg in & connect_args {
271+ cleanup_cmd. arg ( arg) ;
272+ }
273+ cleanup_cmd. args ( & [ "--force" , "--stop" ] ) ;
274+ let cleanup_output = cleanup_cmd. output ( ) ;
276275
277276 if let Ok ( output) = cleanup_output {
278277 if output. status . success ( ) {
0 commit comments