Skip to content

Commit 9f45a72

Browse files
committed
tests: updated integ tests
This commit contains multiple temporary changes which will go away once we make a patch release for v0.24 as well. Signed-off-by: George Pisaltu <[email protected]>
1 parent 981f53c commit 9f45a72

File tree

4 files changed

+100
-55
lines changed

4 files changed

+100
-55
lines changed

tests/framework/resources.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,19 @@ def get_stats(self):
9494
@staticmethod
9595
def create_json(
9696
amount_mb=None,
97+
amount_mib=None,
9798
deflate_on_oom=None,
9899
stats_polling_interval_s=None
99100
):
100101
"""Compose the json associated to this type of API request."""
101102
datax = {}
102103

103-
if amount_mb is not None:
104+
if amount_mib is None and amount_mb is not None:
104105
datax['amount_mb'] = amount_mb
105106

107+
if amount_mb is None and amount_mib is not None:
108+
datax['amount_mib'] = amount_mib
109+
106110
if deflate_on_oom is not None:
107111
datax['deflate_on_oom'] = deflate_on_oom
108112

tests/integration_tests/functional/test_api.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -843,19 +843,19 @@ def test_api_balloon(test_microvm_with_ssh_and_balloon):
843843
test_microvm.basic_config()
844844

845845
# Updating an inexistent balloon device should give an error.
846-
response = test_microvm.balloon.patch(amount_mb=0)
846+
response = test_microvm.balloon.patch(amount_mib=0)
847847
assert test_microvm.api_session.is_status_bad_request(response.status_code)
848848

849849
# Adding a memory balloon should be OK.
850850
response = test_microvm.balloon.put(
851-
amount_mb=1,
851+
amount_mib=1,
852852
deflate_on_oom=True
853853
)
854854
assert test_microvm.api_session.is_status_no_content(response.status_code)
855855

856856
# As is overwriting one.
857857
response = test_microvm.balloon.put(
858-
amount_mb=0,
858+
amount_mib=0,
859859
deflate_on_oom=False,
860860
stats_polling_interval_s=5
861861
)
@@ -864,18 +864,18 @@ def test_api_balloon(test_microvm_with_ssh_and_balloon):
864864
# Getting the device configuration should be available pre-boot.
865865
response = test_microvm.balloon.get()
866866
assert test_microvm.api_session.is_status_ok(response.status_code)
867-
assert response.json()['amount_mb'] == 0
867+
assert response.json()['amount_mib'] == 0
868868
assert response.json()['deflate_on_oom'] is False
869869
assert response.json()['stats_polling_interval_s'] == 5
870870

871871
# Updating an existing balloon device is forbidden before boot.
872-
response = test_microvm.balloon.patch(amount_mb=2)
872+
response = test_microvm.balloon.patch(amount_mib=2)
873873
assert test_microvm.api_session.is_status_bad_request(response.status_code)
874874

875875
# We can't have a balloon device with a target size greater than
876876
# the available amount of memory.
877877
response = test_microvm.balloon.put(
878-
amount_mb=1024,
878+
amount_mib=1024,
879879
deflate_on_oom=False,
880880
stats_polling_interval_s=5
881881
)
@@ -885,12 +885,12 @@ def test_api_balloon(test_microvm_with_ssh_and_balloon):
885885
test_microvm.start()
886886

887887
# Updating should fail as driver didn't have time to initialize.
888-
response = test_microvm.balloon.patch(amount_mb=4)
888+
response = test_microvm.balloon.patch(amount_mib=4)
889889
assert test_microvm.api_session.is_status_bad_request(response.status_code)
890890

891891
# Overwriting the existing device should give an error now.
892892
response = test_microvm.balloon.put(
893-
amount_mb=3,
893+
amount_mib=3,
894894
deflate_on_oom=False,
895895
stats_polling_interval_s=3
896896
)
@@ -901,11 +901,11 @@ def test_api_balloon(test_microvm_with_ssh_and_balloon):
901901
time.sleep(0.5)
902902

903903
# But updating should be OK.
904-
response = test_microvm.balloon.patch(amount_mb=4)
904+
response = test_microvm.balloon.patch(amount_mib=4)
905905
assert test_microvm.api_session.is_status_no_content(response.status_code)
906906

907907
# Check we can't request more than the total amount of VM memory.
908-
response = test_microvm.balloon.patch(amount_mb=300)
908+
response = test_microvm.balloon.patch(amount_mib=300)
909909
assert test_microvm.api_session.is_status_bad_request(response.status_code)
910910

911911
# Check we can't disable statistics as they were enabled at boot.
@@ -916,14 +916,14 @@ def test_api_balloon(test_microvm_with_ssh_and_balloon):
916916
# Getting the device configuration should be available post-boot.
917917
response = test_microvm.balloon.get()
918918
assert test_microvm.api_session.is_status_ok(response.status_code)
919-
assert response.json()['amount_mb'] == 4
919+
assert response.json()['amount_mib'] == 4
920920
assert response.json()['deflate_on_oom'] is False
921921
assert response.json()['stats_polling_interval_s'] == 5
922922

923923
# Check we can't overflow the `num_pages` field in the config space by
924924
# requesting too many MB. There are 256 4K pages in a MB. Here, we are
925925
# requesting u32::MAX / 128.
926-
response = test_microvm.balloon.patch(amount_mb=33554432)
926+
response = test_microvm.balloon.patch(amount_mib=33554432)
927927
assert test_microvm.api_session.is_status_bad_request(response.status_code)
928928

929929

tests/integration_tests/functional/test_balloon.py

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -119,31 +119,54 @@ def copy_util_to_rootfs(rootfs_path, util):
119119
subprocess.check_call("rmdir tmpfs", shell=True)
120120

121121

122-
def _test_rss_memory_lower(test_microvm):
122+
def _test_rss_memory_lower(test_microvm, use_legacy_api=False):
123123
"""Check inflating the balloon makes guest use less rss memory."""
124124
# Get the firecracker pid, and open an ssh connection.
125125
firecracker_pid = test_microvm.jailer_clone_pid
126126
ssh_connection = net_tools.SSHConnection(test_microvm.ssh_config)
127127

128128
# Using deflate_on_oom, get the RSS as low as possible
129-
response = test_microvm.balloon.patch(amount_mb=200)
130-
assert test_microvm.api_session.is_status_no_content(response.status_code)
129+
if use_legacy_api:
130+
response = test_microvm.balloon.patch(amount_mb=200)
131+
assert test_microvm.api_session.is_status_no_content(
132+
response.status_code
133+
)
134+
else:
135+
response = test_microvm.balloon.patch(amount_mib=200)
136+
assert test_microvm.api_session.is_status_no_content(
137+
response.status_code
138+
)
131139

132140
# Get initial rss consumption.
133141
init_rss = get_stable_rss_mem_by_pid(firecracker_pid)
134142

135143
# Get the balloon back to 0.
136-
response = test_microvm.balloon.patch(amount_mb=0)
137-
assert test_microvm.api_session.is_status_no_content(response.status_code)
144+
if use_legacy_api:
145+
response = test_microvm.balloon.patch(amount_mb=0)
146+
assert test_microvm.api_session.is_status_no_content(
147+
response.status_code
148+
)
149+
else:
150+
response = test_microvm.balloon.patch(amount_mib=0)
151+
assert test_microvm.api_session.is_status_no_content(
152+
response.status_code
153+
)
138154
# This call will internally wait for rss to become stable.
139155
_ = get_stable_rss_mem_by_pid(firecracker_pid)
140156

141157
# Dirty memory, then inflate balloon and get ballooned rss consumption.
142158
make_guest_dirty_memory(ssh_connection)
143159

144-
response = test_microvm.balloon.patch(amount_mb=200)
145-
146-
assert test_microvm.api_session.is_status_no_content(response.status_code)
160+
if use_legacy_api:
161+
response = test_microvm.balloon.patch(amount_mb=200)
162+
assert test_microvm.api_session.is_status_no_content(
163+
response.status_code
164+
)
165+
else:
166+
response = test_microvm.balloon.patch(amount_mib=200)
167+
assert test_microvm.api_session.is_status_no_content(
168+
response.status_code
169+
)
147170
balloon_rss = get_stable_rss_mem_by_pid(firecracker_pid)
148171

149172
# Check that the ballooning reclaimed the memory.
@@ -164,7 +187,7 @@ def test_rss_memory_lower(test_microvm_with_ssh_and_balloon, network_config):
164187

165188
# Add a memory balloon.
166189
response = test_microvm.balloon.put(
167-
amount_mb=0,
190+
amount_mib=0,
168191
deflate_on_oom=True,
169192
stats_polling_interval_s=0
170193
)
@@ -191,7 +214,7 @@ def test_inflate_reduces_free(test_microvm_with_ssh_and_balloon,
191214

192215
# Install deflated balloon.
193216
response = test_microvm.balloon.put(
194-
amount_mb=0,
217+
amount_mib=0,
195218
deflate_on_oom=False,
196219
stats_polling_interval_s=1
197220
)
@@ -208,7 +231,7 @@ def test_inflate_reduces_free(test_microvm_with_ssh_and_balloon,
208231
available_mem_deflated = get_free_mem_ssh(ssh_connection)
209232

210233
# Inflate 64 MB == 16384 page balloon.
211-
response = test_microvm.balloon.patch(amount_mb=64)
234+
response = test_microvm.balloon.patch(amount_mib=64)
212235
assert test_microvm.api_session.is_status_no_content(response.status_code)
213236
# This call will internally wait for rss to become stable.
214237
_ = get_stable_rss_mem_by_pid(firecracker_pid)
@@ -235,7 +258,7 @@ def test_deflate_on_oom_true(test_microvm_with_ssh_and_balloon,
235258

236259
# Add a deflated memory balloon.
237260
response = test_microvm.balloon.put(
238-
amount_mb=0,
261+
amount_mib=0,
239262
deflate_on_oom=True,
240263
stats_polling_interval_s=0
241264
)
@@ -249,7 +272,7 @@ def test_deflate_on_oom_true(test_microvm_with_ssh_and_balloon,
249272
ssh_connection = net_tools.SSHConnection(test_microvm.ssh_config)
250273

251274
# Inflate the balloon
252-
response = test_microvm.balloon.patch(amount_mb=172)
275+
response = test_microvm.balloon.patch(amount_mib=172)
253276
assert test_microvm.api_session.is_status_no_content(response.status_code)
254277
# This call will internally wait for rss to become stable.
255278
_ = get_stable_rss_mem_by_pid(firecracker_pid)
@@ -276,7 +299,7 @@ def test_deflate_on_oom_false(test_microvm_with_ssh_and_balloon,
276299

277300
# Add a memory balloon.
278301
response = test_microvm.balloon.put(
279-
amount_mb=0,
302+
amount_mib=0,
280303
deflate_on_oom=False,
281304
stats_polling_interval_s=0
282305
)
@@ -290,7 +313,7 @@ def test_deflate_on_oom_false(test_microvm_with_ssh_and_balloon,
290313
ssh_connection = net_tools.SSHConnection(test_microvm.ssh_config)
291314

292315
# Inflate the balloon.
293-
response = test_microvm.balloon.patch(amount_mb=172)
316+
response = test_microvm.balloon.patch(amount_mib=172)
294317
assert test_microvm.api_session.is_status_no_content(response.status_code)
295318
# This call will internally wait for rss to become stable.
296319
_ = get_stable_rss_mem_by_pid(firecracker_pid)
@@ -313,7 +336,7 @@ def test_reinflate_balloon(test_microvm_with_ssh_and_balloon, network_config):
313336

314337
# Add a deflated memory balloon.
315338
response = test_microvm.balloon.put(
316-
amount_mb=0,
339+
amount_mib=0,
317340
deflate_on_oom=True,
318341
stats_polling_interval_s=0
319342
)
@@ -329,12 +352,12 @@ def test_reinflate_balloon(test_microvm_with_ssh_and_balloon, network_config):
329352
# First inflate the balloon to free up the uncertain amount of memory
330353
# used by the kernel at boot and establish a baseline, then give back
331354
# the memory.
332-
response = test_microvm.balloon.patch(amount_mb=200)
355+
response = test_microvm.balloon.patch(amount_mib=200)
333356
assert test_microvm.api_session.is_status_no_content(response.status_code)
334357
# This call will internally wait for rss to become stable.
335358
_ = get_stable_rss_mem_by_pid(firecracker_pid)
336359

337-
response = test_microvm.balloon.patch(amount_mb=0)
360+
response = test_microvm.balloon.patch(amount_mib=0)
338361
assert test_microvm.api_session.is_status_no_content(response.status_code)
339362
# This call will internally wait for rss to become stable.
340363
_ = get_stable_rss_mem_by_pid(firecracker_pid)
@@ -344,12 +367,12 @@ def test_reinflate_balloon(test_microvm_with_ssh_and_balloon, network_config):
344367
first_reading = get_stable_rss_mem_by_pid(firecracker_pid)
345368

346369
# Now inflate the balloon.
347-
response = test_microvm.balloon.patch(amount_mb=200)
370+
response = test_microvm.balloon.patch(amount_mib=200)
348371
assert test_microvm.api_session.is_status_no_content(response.status_code)
349372
second_reading = get_stable_rss_mem_by_pid(firecracker_pid)
350373

351374
# Now deflate the balloon.
352-
response = test_microvm.balloon.patch(amount_mb=0)
375+
response = test_microvm.balloon.patch(amount_mib=0)
353376
assert test_microvm.api_session.is_status_no_content(response.status_code)
354377
# This call will internally wait for rss to become stable.
355378
_ = get_stable_rss_mem_by_pid(firecracker_pid)
@@ -359,7 +382,7 @@ def test_reinflate_balloon(test_microvm_with_ssh_and_balloon, network_config):
359382
third_reading = get_stable_rss_mem_by_pid(firecracker_pid)
360383

361384
# Now inflate the balloon again.
362-
response = test_microvm.balloon.patch(amount_mb=200)
385+
response = test_microvm.balloon.patch(amount_mib=200)
363386
assert test_microvm.api_session.is_status_no_content(response.status_code)
364387
fourth_reading = get_stable_rss_mem_by_pid(firecracker_pid)
365388

@@ -385,7 +408,7 @@ def test_size_reduction(test_microvm_with_ssh_and_balloon, network_config):
385408

386409
# Add a memory balloon.
387410
response = test_microvm.balloon.put(
388-
amount_mb=0,
411+
amount_mib=0,
389412
deflate_on_oom=True,
390413
stats_polling_interval_s=0
391414
)
@@ -406,7 +429,7 @@ def test_size_reduction(test_microvm_with_ssh_and_balloon, network_config):
406429
time.sleep(5)
407430

408431
# Now inflate the balloon.
409-
response = test_microvm.balloon.patch(amount_mb=40)
432+
response = test_microvm.balloon.patch(amount_mib=40)
410433
assert test_microvm.api_session.is_status_no_content(response.status_code)
411434

412435
# Check memory usage again.
@@ -430,7 +453,7 @@ def test_stats(test_microvm_with_ssh_and_balloon, network_config):
430453

431454
# Add a memory balloon with stats enabled.
432455
response = test_microvm.balloon.put(
433-
amount_mb=0,
456+
amount_mib=0,
434457
deflate_on_oom=True,
435458
stats_polling_interval_s=1
436459
)
@@ -458,7 +481,7 @@ def test_stats(test_microvm_with_ssh_and_balloon, network_config):
458481
assert initial_stats['major_faults'] < after_workload_stats['major_faults']
459482

460483
# Now inflate the balloon with 10MB of pages.
461-
response = test_microvm.balloon.patch(amount_mb=10)
484+
response = test_microvm.balloon.patch(amount_mib=10)
462485
assert test_microvm.api_session.is_status_no_content(response.status_code)
463486
# This call will internally wait for rss to become stable.
464487
_ = get_stable_rss_mem_by_pid(firecracker_pid)
@@ -478,7 +501,7 @@ def test_stats(test_microvm_with_ssh_and_balloon, network_config):
478501

479502
# Deflate the balloon.check that the stats show the increase in
480503
# available memory.
481-
response = test_microvm.balloon.patch(amount_mb=0)
504+
response = test_microvm.balloon.patch(amount_mib=0)
482505
assert test_microvm.api_session.is_status_no_content(response.status_code)
483506
# This call will internally wait for rss to become stable.
484507
_ = get_stable_rss_mem_by_pid(firecracker_pid)
@@ -537,7 +560,7 @@ def _test_balloon_snapshot(context):
537560

538561
# Add a memory balloon with stats enabled.
539562
response = basevm.balloon.put(
540-
amount_mb=0,
563+
amount_mib=0,
541564
deflate_on_oom=True,
542565
stats_polling_interval_s=1
543566
)
@@ -557,7 +580,7 @@ def _test_balloon_snapshot(context):
557580
first_reading = get_stable_rss_mem_by_pid(firecracker_pid)
558581

559582
# Now inflate the balloon with 20MB of pages.
560-
response = basevm.balloon.patch(amount_mb=20)
583+
response = basevm.balloon.patch(amount_mib=20)
561584
assert basevm.api_session.is_status_no_content(response.status_code)
562585

563586
# Check memory usage again.
@@ -601,7 +624,7 @@ def _test_balloon_snapshot(context):
601624
assert fourth_reading > third_reading
602625

603626
# Inflate the balloon with another 20MB of pages.
604-
response = microvm.balloon.patch(amount_mb=40)
627+
response = microvm.balloon.patch(amount_mib=40)
605628
assert microvm.api_session.is_status_no_content(response.status_code)
606629

607630
fifth_reading = get_stable_rss_mem_by_pid(firecracker_pid)
@@ -653,7 +676,7 @@ def _test_snapshot_compatibility(context):
653676

654677
# Add a memory balloon with stats enabled.
655678
response = microvm.balloon.put(
656-
amount_mb=0,
679+
amount_mib=0,
657680
deflate_on_oom=True,
658681
stats_polling_interval_s=1
659682
)
@@ -731,7 +754,7 @@ def _test_memory_scrub(context):
731754

732755
# Add a memory balloon with stats enabled.
733756
response = microvm.balloon.put(
734-
amount_mb=0,
757+
amount_mib=0,
735758
deflate_on_oom=True,
736759
stats_polling_interval_s=1
737760
)
@@ -745,7 +768,7 @@ def _test_memory_scrub(context):
745768
make_guest_dirty_memory(ssh_connection, amount=(60 * MB_TO_PAGES))
746769

747770
# Now inflate the balloon with 60MB of pages.
748-
response = microvm.balloon.patch(amount_mb=60)
771+
response = microvm.balloon.patch(amount_mib=60)
749772
assert microvm.api_session.is_status_no_content(response.status_code)
750773

751774
# Get the firecracker pid, and open an ssh connection.
@@ -755,7 +778,7 @@ def _test_memory_scrub(context):
755778
_ = get_stable_rss_mem_by_pid(firecracker_pid)
756779

757780
# Deflate the balloon completely.
758-
response = microvm.balloon.patch(amount_mb=0)
781+
response = microvm.balloon.patch(amount_mib=0)
759782
assert microvm.api_session.is_status_no_content(response.status_code)
760783

761784
# Wait for the deflate to complete.

0 commit comments

Comments
 (0)