5
5
import logging
6
6
import time
7
7
8
+ import pytest
8
9
from retry import retry
9
10
10
11
from framework .builder import MicrovmBuilder , SnapshotBuilder , SnapshotType
@@ -152,65 +153,34 @@ def test_inflate_reduces_free(test_microvm_with_api):
152
153
153
154
154
155
# pylint: disable=C0103
155
- def test_deflate_on_oom_true (test_microvm_with_api ):
156
+ @pytest .mark .parametrize ("deflate_on_oom" , [True , False ])
157
+ def test_deflate_on_oom (test_microvm_with_api , deflate_on_oom ):
156
158
"""
157
- Verify that setting the `deflate_on_oom` to True works correctly.
158
- """
159
- test_microvm = test_microvm_with_api
160
- test_microvm .spawn ()
161
- test_microvm .basic_config ()
162
- test_microvm .add_net_iface ()
159
+ Verify that setting the `deflate_on_oom` option works correctly.
163
160
164
- # Add a deflated memory balloon.
165
- response = test_microvm .balloon .put (
166
- amount_mib = 0 , deflate_on_oom = True , stats_polling_interval_s = 0
167
- )
168
- assert test_microvm .api_session .is_status_no_content (response .status_code )
161
+ https://github.com/firecracker-microvm/firecracker/blob/main/docs/ballooning.md
169
162
170
- # Start the microvm.
171
- test_microvm .start ()
172
- firecracker_pid = test_microvm .jailer_clone_pid
163
+ deflate_on_oom=True
173
164
174
- # We get an initial reading of the RSS, then calculate the amount
175
- # we need to inflate the balloon with by subtracting it from the
176
- # VM size and adding an offset of 10 MiB in order to make sure we
177
- # get a lower reading than the initial one.
178
- initial_rss = get_stable_rss_mem_by_pid (firecracker_pid )
179
- inflate_size = 256 - int (initial_rss / 1024 ) + 10
180
-
181
- # Inflate the balloon
182
- response = test_microvm .balloon .patch (amount_mib = inflate_size )
183
- assert test_microvm .api_session .is_status_no_content (response .status_code )
184
- # This call will internally wait for rss to become stable.
185
- _ = get_stable_rss_mem_by_pid (firecracker_pid )
186
-
187
- # Check that using memory doesn't lead to an out of memory error.
188
- # Note that due to `test_deflate_on_oom_false`, we know that
189
- # if `deflate_on_oom` were set to False, then such an error
190
- # would have happened.
191
- make_guest_dirty_memory (test_microvm .ssh )
165
+ should not result in an OOM kill
192
166
167
+ deflate_on_oom=False
193
168
194
- # pylint: disable=C0103
195
- def test_deflate_on_oom_false (test_microvm_with_api ):
196
- """
197
- Verify that setting the `deflate_on_oom` to False works correctly.
169
+ should result in an OOM kill
198
170
"""
199
171
test_microvm = test_microvm_with_api
200
172
test_microvm .spawn ()
201
173
test_microvm .basic_config ()
202
174
test_microvm .add_net_iface ()
203
175
204
- # Add a memory balloon.
176
+ # Add a deflated memory balloon.
205
177
response = test_microvm .balloon .put (
206
- amount_mib = 0 , deflate_on_oom = False , stats_polling_interval_s = 0
178
+ amount_mib = 0 , deflate_on_oom = deflate_on_oom , stats_polling_interval_s = 0
207
179
)
208
180
assert test_microvm .api_session .is_status_no_content (response .status_code )
209
181
210
182
# Start the microvm.
211
183
test_microvm .start ()
212
-
213
- # Get an ssh connection to the microvm.
214
184
firecracker_pid = test_microvm .jailer_clone_pid
215
185
216
186
# We get an initial reading of the RSS, then calculate the amount
@@ -220,14 +190,14 @@ def test_deflate_on_oom_false(test_microvm_with_api):
220
190
initial_rss = get_stable_rss_mem_by_pid (firecracker_pid )
221
191
inflate_size = 256 - int (initial_rss / 1024 ) + 10
222
192
223
- # Inflate the balloon.
193
+ # Inflate the balloon
224
194
response = test_microvm .balloon .patch (amount_mib = inflate_size )
225
195
assert test_microvm .api_session .is_status_no_content (response .status_code )
226
196
# This call will internally wait for rss to become stable.
227
197
_ = get_stable_rss_mem_by_pid (firecracker_pid )
228
198
229
- # Check that using memory does lead to an out of memory error.
230
- make_guest_dirty_memory (test_microvm .ssh , should_oom = True )
199
+ # Check that using memory leads an out of memory error (or not) .
200
+ make_guest_dirty_memory (test_microvm .ssh , should_oom = not deflate_on_oom )
231
201
232
202
233
203
# pylint: disable=C0103
0 commit comments