1212# - a VM (--vm)
1313# - the first network on the host can be used to reach the host
1414
15- vif_limit = 16
16- interface_name = "enX"
17- vcpus = '8'
15+ VIF_LIMIT = 16
16+ VCPUS = '8'
1817
1918# There is a ResourceWarning due to background=True on an ssh call
2019# We do ensure the processes are killed
@@ -24,57 +23,58 @@ class TestVIFLimit:
2423 def test_vif_limit (self , host_with_saved_yum_state , imported_vm ):
2524 host = host_with_saved_yum_state
2625 vm = imported_vm
26+ interface_name = "enX"
27+
2728 if (vm .is_running ()):
2829 logging .info ("VM already running, shutting it down first" )
2930 vm .shutdown (verify = True )
3031
3132 network_uuid = vm .vifs ()[0 ].param_get ('network-uuid' )
3233 existing_vifs = len (vm .vifs ())
3334
34- logging .info (f'Get { vcpus } vCPUs for the VM' )
35+ logging .info (f'Get { VCPUS } vCPUs for the VM' )
3536 original_vcpus_max = vm .param_get ('VCPUs-max' )
3637 original_vcpus_at_startup = vm .param_get ('VCPUs-at-startup' )
37- vm .param_set ('VCPUs-max' , vcpus )
38- vm .param_set ('VCPUs-at-startup' , vcpus )
38+ vm .param_set ('VCPUs-max' , VCPUS )
39+ vm .param_set ('VCPUs-at-startup' , VCPUS )
3940
4041 logging .info ('Create VIFs before starting the VM' )
4142 vifs = []
42- for i in range (existing_vifs , vif_limit ):
43+ for i in range (existing_vifs , VIF_LIMIT ):
4344 vif = vm .create_vif (i , network_uuid = network_uuid )
4445 vifs .append (vif )
4546
4647 vm .start ()
4748 vm .wait_for_os_booted ()
48-
49- logging .info ('Verify the interfaces exist in the guest' )
50- for i in range (0 , vif_limit ):
51- if vm .ssh_with_result ([f'test -d /sys/class/net/{ interface_name } { i } ' ]).returncode != 0 :
52- guest_error = vm .ssh_with_result (['dmesg | grep -B1 -A3 xen_netfront' ]).stdout
53- logging .error ("dmesg:\n %s" , guest_error )
54- assert False , "The interface does not exist in the guest, check dmesg output above for errors"
55-
56- logging .info ('Configure interfaces' )
57- config = '\n ' .join ([f'iface { interface_name } { i } inet dhcp\n '
58- f'auto { interface_name } { i } '
59- for i in range (existing_vifs , vif_limit )])
60- vm .ssh ([f'echo "{ config } " >> /etc/network/interfaces' ])
61-
62- logging .info ('Install iperf3 on VM and host' )
63- if vm .ssh_with_result (['apt install iperf3 --assume-yes' ]).returncode != 0 :
64- assert False , "Failed to install iperf3 on the VM"
65- host .yum_install (['iperf3' ])
66-
67- logging .info ('Reconfigure VM networking' )
68- if vm .ssh_with_result (['systemctl restart networking' ]).returncode != 0 :
69- assert False , "Failed to configure networking"
70-
71- # Test iperf on all interfaces in parallel
72- # Clean up on exceptions
7349 try :
50+ logging .info ('Verify the interfaces exist in the guest' )
51+ for i in range (0 , VIF_LIMIT ):
52+ if vm .ssh_with_result ([f'test -d /sys/class/net/{ interface_name } { i } ' ]).returncode != 0 :
53+ guest_error = vm .ssh_with_result (['dmesg | grep -B1 -A3 xen_netfront' ]).stdout
54+ logging .error ("dmesg:\n %s" , guest_error )
55+ assert False , "The interface does not exist in the guest, check dmesg output above for errors"
56+
57+ logging .info ('Configure interfaces' )
58+ config = '\n ' .join ([f'iface { interface_name } { i } inet dhcp\n '
59+ f'auto { interface_name } { i } '
60+ for i in range (existing_vifs , VIF_LIMIT )])
61+ vm .ssh ([f'echo "{ config } " >> /etc/network/interfaces' ])
62+
63+ logging .info ('Install iperf3 on VM and host' )
64+ if vm .ssh_with_result (['apt install iperf3 --assume-yes' ]).returncode != 0 :
65+ assert False , "Failed to install iperf3 on the VM"
66+ host .yum_install (['iperf3' ])
67+
68+ logging .info ('Reconfigure VM networking' )
69+ if vm .ssh_with_result (['systemctl restart networking' ]).returncode != 0 :
70+ assert False , "Failed to configure networking"
71+
72+ # Test iperf on all interfaces in parallel
73+ # Clean up on exceptions
7474 logging .info ('Create separate iperf servers on the host' )
7575 with tempfile .NamedTemporaryFile ('w' ) as host_script :
7676 iperf_configs = [f'iperf3 -s -p { 5100 + i } &'
77- for i in range (0 , vif_limit )]
77+ for i in range (0 , VIF_LIMIT )]
7878 host_script .write ('\n ' .join (iperf_configs ))
7979 host_script .flush ()
8080 host .scp (host_script .name , host_script .name )
@@ -86,7 +86,7 @@ def test_vif_limit(self, host_with_saved_yum_state, imported_vm):
8686 iperf_configs = [f'iperf3 --no-delay -c { host .hostname_or_ip } '
8787 f'-p { 5100 + i } --bind-dev { interface_name } { i } '
8888 f'--interval 0 --parallel 1 --time 30 &'
89- for i in range (0 , vif_limit )]
89+ for i in range (0 , VIF_LIMIT )]
9090 vm_script .write ('\n ' .join (iperf_configs ))
9191 vm_script .flush ()
9292 vm .scp (vm_script .name , vm_script .name )
@@ -101,4 +101,4 @@ def test_vif_limit(self, host_with_saved_yum_state, imported_vm):
101101 vm .param_set ('VCPUs-max' , original_vcpus_max )
102102 for vif in vifs :
103103 vif .destroy ()
104- host .ssh ('killall iperf3' )
104+ host .ssh ('killall iperf3 || true ' )
0 commit comments