8
8
from host_tools .network import SSHConnection
9
9
10
10
11
- @pytest .fixture (params = [None ])
12
- def uvm_with_rng (uvm_plain , request ):
13
- """Fixture of a microvm with virtio-rng configured"""
14
- rate_limiter = request .param
15
- uvm = uvm_plain
11
+ def uvm_with_rng_booted (microvm_factory , guest_kernel , rootfs , rate_limiter ):
12
+ """Return a booted microvm with virtio-rng configured"""
13
+ uvm = microvm_factory .build (guest_kernel , rootfs )
16
14
uvm .spawn (log_level = "INFO" )
17
15
uvm .basic_config (vcpu_count = 2 , mem_size_mib = 256 )
18
16
uvm .add_net_iface ()
@@ -23,6 +21,34 @@ def uvm_with_rng(uvm_plain, request):
23
21
return uvm
24
22
25
23
24
+ def uvm_with_rng_restored (microvm_factory , guest_kernel , rootfs , rate_limiter ):
25
+ """Return a restored uvm with virtio-rng configured"""
26
+ uvm = uvm_with_rng_booted (microvm_factory , guest_kernel , rootfs , rate_limiter )
27
+ snapshot = uvm .snapshot_full ()
28
+ uvm .kill ()
29
+ uvm2 = microvm_factory .build_from_snapshot (snapshot )
30
+ uvm2 .rng_rate_limiter = uvm .rng_rate_limiter
31
+ return uvm2
32
+
33
+
34
+ @pytest .fixture (params = [uvm_with_rng_booted , uvm_with_rng_restored ])
35
+ def uvm_ctor (request ):
36
+ """Fixture to return uvms with different constructors"""
37
+ return request .param
38
+
39
+
40
+ @pytest .fixture (params = [None ])
41
+ def rate_limiter (request ):
42
+ """Fixture to return different rate limiters"""
43
+ return request .param
44
+
45
+
46
+ @pytest .fixture
47
+ def uvm_any (microvm_factory , uvm_ctor , guest_kernel , rootfs , rate_limiter ):
48
+ """Return booted and restored uvms"""
49
+ return uvm_ctor (microvm_factory , guest_kernel , rootfs , rate_limiter )
50
+
51
+
26
52
def list_rng_available (ssh_connection : SSHConnection ) -> list [str ]:
27
53
"""Returns a list of rng devices available in the VM"""
28
54
return (
@@ -62,35 +88,17 @@ def test_rng_not_present(uvm_nano):
62
88
), "virtio_rng device should not be available in the uvm"
63
89
64
90
65
- def test_rng_present (uvm_with_rng ):
91
+ def test_rng_present (uvm_any ):
66
92
"""
67
93
Test a guest microVM with an entropy defined configured and ensure
68
94
that we can access `/dev/hwrng`
69
95
"""
70
96
71
- vm = uvm_with_rng
97
+ vm = uvm_any
72
98
assert_virtio_rng_is_current_hwrng_device (vm .ssh )
73
99
check_entropy (vm .ssh )
74
100
75
101
76
- def test_rng_snapshot (uvm_with_rng , microvm_factory ):
77
- """
78
- Test that a virtio-rng device is functional after resuming from
79
- a snapshot
80
- """
81
-
82
- vm = uvm_with_rng
83
- assert_virtio_rng_is_current_hwrng_device (vm .ssh )
84
- check_entropy (vm .ssh )
85
- snapshot = vm .snapshot_full ()
86
-
87
- new_vm = microvm_factory .build ()
88
- new_vm .spawn ()
89
- new_vm .restore_from_snapshot (snapshot , resume = True )
90
- assert_virtio_rng_is_current_hwrng_device (new_vm .ssh )
91
- check_entropy (new_vm .ssh )
92
-
93
-
94
102
def _get_percentage_difference (measured , base ):
95
103
"""Return the percentage delta between the arguments."""
96
104
if measured == base :
@@ -199,7 +207,7 @@ def _rate_limiter_id(rate_limiter):
199
207
200
208
# parametrize the RNG rate limiter
201
209
@pytest .mark .parametrize (
202
- "uvm_with_rng " ,
210
+ "rate_limiter " ,
203
211
[
204
212
{"bandwidth" : {"size" : 1000 , "refill_time" : 100 }},
205
213
{"bandwidth" : {"size" : 10000 , "refill_time" : 100 }},
@@ -208,16 +216,14 @@ def _rate_limiter_id(rate_limiter):
208
216
indirect = True ,
209
217
ids = _rate_limiter_id ,
210
218
)
211
- def test_rng_bw_rate_limiter (uvm_with_rng ):
219
+ @pytest .mark .parametrize ("uvm_ctor" , [uvm_with_rng_booted ], indirect = True )
220
+ def test_rng_bw_rate_limiter (uvm_any ):
212
221
"""
213
222
Test that rate limiter without initial burst budget works
214
223
"""
215
- vm = uvm_with_rng
216
- # _start_vm_with_rng(vm, rate_limiter)
217
-
224
+ vm = uvm_any
218
225
size = vm .rng_rate_limiter ["bandwidth" ]["size" ]
219
226
refill_time = vm .rng_rate_limiter ["bandwidth" ]["refill_time" ]
220
-
221
227
expected_kbps = size / refill_time
222
228
223
229
assert_virtio_rng_is_current_hwrng_device (vm .ssh )
0 commit comments