Skip to content

Commit 0ba1339

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 c3cabd4 commit 0ba1339

File tree

4 files changed

+60
-49
lines changed

4 files changed

+60
-49
lines changed

tests/framework/resources.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ def get_stats(self):
9393

9494
@staticmethod
9595
def create_json(
96-
amount_mb=None,
96+
amount_mib=None,
9797
deflate_on_oom=None,
9898
stats_polling_interval_s=None
9999
):
100100
"""Compose the json associated to this type of API request."""
101101
datax = {}
102102

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

106106
if deflate_on_oom is not None:
107107
datax['deflate_on_oom'] = deflate_on_oom

tests/integration_tests/functional/test_api.py

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

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

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

855855
# As is overwriting one.
856856
response = test_microvm.balloon.put(
857-
amount_mb=0,
857+
amount_mib=0,
858858
deflate_on_oom=False,
859859
stats_polling_interval_s=5
860860
)
@@ -863,18 +863,18 @@ def test_api_balloon(test_microvm_with_ssh_and_balloon):
863863
# Getting the device configuration should be available pre-boot.
864864
response = test_microvm.balloon.get()
865865
assert test_microvm.api_session.is_status_ok(response.status_code)
866-
assert response.json()['amount_mb'] == 0
866+
assert response.json()['amount_mib'] == 0
867867
assert response.json()['deflate_on_oom'] is False
868868
assert response.json()['stats_polling_interval_s'] == 5
869869

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

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

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

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

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

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

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

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

tests/integration_tests/functional/test_balloon.py

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -126,24 +126,29 @@ def _test_rss_memory_lower(test_microvm):
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+
response = test_microvm.balloon.patch(amount_mib=200)
130+
assert test_microvm.api_session.is_status_no_content(
131+
response.status_code
132+
)
131133

132134
# Get initial rss consumption.
133135
init_rss = get_stable_rss_mem_by_pid(firecracker_pid)
134136

135137
# 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)
138+
response = test_microvm.balloon.patch(amount_mib=0)
139+
assert test_microvm.api_session.is_status_no_content(
140+
response.status_code
141+
)
138142
# This call will internally wait for rss to become stable.
139143
_ = get_stable_rss_mem_by_pid(firecracker_pid)
140144

141145
# Dirty memory, then inflate balloon and get ballooned rss consumption.
142146
make_guest_dirty_memory(ssh_connection)
143147

144-
response = test_microvm.balloon.patch(amount_mb=200)
145-
146-
assert test_microvm.api_session.is_status_no_content(response.status_code)
148+
response = test_microvm.balloon.patch(amount_mib=200)
149+
assert test_microvm.api_session.is_status_no_content(
150+
response.status_code
151+
)
147152
balloon_rss = get_stable_rss_mem_by_pid(firecracker_pid)
148153

149154
# Check that the ballooning reclaimed the memory.
@@ -164,7 +169,7 @@ def test_rss_memory_lower(test_microvm_with_ssh_and_balloon, network_config):
164169

165170
# Add a memory balloon.
166171
response = test_microvm.balloon.put(
167-
amount_mb=0,
172+
amount_mib=0,
168173
deflate_on_oom=True,
169174
stats_polling_interval_s=0
170175
)
@@ -191,7 +196,7 @@ def test_inflate_reduces_free(test_microvm_with_ssh_and_balloon,
191196

192197
# Install deflated balloon.
193198
response = test_microvm.balloon.put(
194-
amount_mb=0,
199+
amount_mib=0,
195200
deflate_on_oom=False,
196201
stats_polling_interval_s=1
197202
)
@@ -208,7 +213,7 @@ def test_inflate_reduces_free(test_microvm_with_ssh_and_balloon,
208213
available_mem_deflated = get_free_mem_ssh(ssh_connection)
209214

210215
# Inflate 64 MB == 16384 page balloon.
211-
response = test_microvm.balloon.patch(amount_mb=64)
216+
response = test_microvm.balloon.patch(amount_mib=64)
212217
assert test_microvm.api_session.is_status_no_content(response.status_code)
213218
# This call will internally wait for rss to become stable.
214219
_ = get_stable_rss_mem_by_pid(firecracker_pid)
@@ -235,7 +240,7 @@ def test_deflate_on_oom_true(test_microvm_with_ssh_and_balloon,
235240

236241
# Add a deflated memory balloon.
237242
response = test_microvm.balloon.put(
238-
amount_mb=0,
243+
amount_mib=0,
239244
deflate_on_oom=True,
240245
stats_polling_interval_s=0
241246
)
@@ -249,7 +254,7 @@ def test_deflate_on_oom_true(test_microvm_with_ssh_and_balloon,
249254
ssh_connection = net_tools.SSHConnection(test_microvm.ssh_config)
250255

251256
# Inflate the balloon
252-
response = test_microvm.balloon.patch(amount_mb=172)
257+
response = test_microvm.balloon.patch(amount_mib=172)
253258
assert test_microvm.api_session.is_status_no_content(response.status_code)
254259
# This call will internally wait for rss to become stable.
255260
_ = get_stable_rss_mem_by_pid(firecracker_pid)
@@ -276,7 +281,7 @@ def test_deflate_on_oom_false(test_microvm_with_ssh_and_balloon,
276281

277282
# Add a memory balloon.
278283
response = test_microvm.balloon.put(
279-
amount_mb=0,
284+
amount_mib=0,
280285
deflate_on_oom=False,
281286
stats_polling_interval_s=0
282287
)
@@ -290,7 +295,7 @@ def test_deflate_on_oom_false(test_microvm_with_ssh_and_balloon,
290295
ssh_connection = net_tools.SSHConnection(test_microvm.ssh_config)
291296

292297
# Inflate the balloon.
293-
response = test_microvm.balloon.patch(amount_mb=172)
298+
response = test_microvm.balloon.patch(amount_mib=172)
294299
assert test_microvm.api_session.is_status_no_content(response.status_code)
295300
# This call will internally wait for rss to become stable.
296301
_ = get_stable_rss_mem_by_pid(firecracker_pid)
@@ -313,7 +318,7 @@ def test_reinflate_balloon(test_microvm_with_ssh_and_balloon, network_config):
313318

314319
# Add a deflated memory balloon.
315320
response = test_microvm.balloon.put(
316-
amount_mb=0,
321+
amount_mib=0,
317322
deflate_on_oom=True,
318323
stats_polling_interval_s=0
319324
)
@@ -329,12 +334,12 @@ def test_reinflate_balloon(test_microvm_with_ssh_and_balloon, network_config):
329334
# First inflate the balloon to free up the uncertain amount of memory
330335
# used by the kernel at boot and establish a baseline, then give back
331336
# the memory.
332-
response = test_microvm.balloon.patch(amount_mb=200)
337+
response = test_microvm.balloon.patch(amount_mib=200)
333338
assert test_microvm.api_session.is_status_no_content(response.status_code)
334339
# This call will internally wait for rss to become stable.
335340
_ = get_stable_rss_mem_by_pid(firecracker_pid)
336341

337-
response = test_microvm.balloon.patch(amount_mb=0)
342+
response = test_microvm.balloon.patch(amount_mib=0)
338343
assert test_microvm.api_session.is_status_no_content(response.status_code)
339344
# This call will internally wait for rss to become stable.
340345
_ = get_stable_rss_mem_by_pid(firecracker_pid)
@@ -344,12 +349,12 @@ def test_reinflate_balloon(test_microvm_with_ssh_and_balloon, network_config):
344349
first_reading = get_stable_rss_mem_by_pid(firecracker_pid)
345350

346351
# Now inflate the balloon.
347-
response = test_microvm.balloon.patch(amount_mb=200)
352+
response = test_microvm.balloon.patch(amount_mib=200)
348353
assert test_microvm.api_session.is_status_no_content(response.status_code)
349354
second_reading = get_stable_rss_mem_by_pid(firecracker_pid)
350355

351356
# Now deflate the balloon.
352-
response = test_microvm.balloon.patch(amount_mb=0)
357+
response = test_microvm.balloon.patch(amount_mib=0)
353358
assert test_microvm.api_session.is_status_no_content(response.status_code)
354359
# This call will internally wait for rss to become stable.
355360
_ = get_stable_rss_mem_by_pid(firecracker_pid)
@@ -359,7 +364,7 @@ def test_reinflate_balloon(test_microvm_with_ssh_and_balloon, network_config):
359364
third_reading = get_stable_rss_mem_by_pid(firecracker_pid)
360365

361366
# Now inflate the balloon again.
362-
response = test_microvm.balloon.patch(amount_mb=200)
367+
response = test_microvm.balloon.patch(amount_mib=200)
363368
assert test_microvm.api_session.is_status_no_content(response.status_code)
364369
fourth_reading = get_stable_rss_mem_by_pid(firecracker_pid)
365370

@@ -385,7 +390,7 @@ def test_size_reduction(test_microvm_with_ssh_and_balloon, network_config):
385390

386391
# Add a memory balloon.
387392
response = test_microvm.balloon.put(
388-
amount_mb=0,
393+
amount_mib=0,
389394
deflate_on_oom=True,
390395
stats_polling_interval_s=0
391396
)
@@ -406,7 +411,7 @@ def test_size_reduction(test_microvm_with_ssh_and_balloon, network_config):
406411
time.sleep(5)
407412

408413
# Now inflate the balloon.
409-
response = test_microvm.balloon.patch(amount_mb=40)
414+
response = test_microvm.balloon.patch(amount_mib=40)
410415
assert test_microvm.api_session.is_status_no_content(response.status_code)
411416

412417
# Check memory usage again.
@@ -430,7 +435,7 @@ def test_stats(test_microvm_with_ssh_and_balloon, network_config):
430435

431436
# Add a memory balloon with stats enabled.
432437
response = test_microvm.balloon.put(
433-
amount_mb=0,
438+
amount_mib=0,
434439
deflate_on_oom=True,
435440
stats_polling_interval_s=1
436441
)
@@ -458,7 +463,7 @@ def test_stats(test_microvm_with_ssh_and_balloon, network_config):
458463
assert initial_stats['major_faults'] < after_workload_stats['major_faults']
459464

460465
# Now inflate the balloon with 10MB of pages.
461-
response = test_microvm.balloon.patch(amount_mb=10)
466+
response = test_microvm.balloon.patch(amount_mib=10)
462467
assert test_microvm.api_session.is_status_no_content(response.status_code)
463468
# This call will internally wait for rss to become stable.
464469
_ = get_stable_rss_mem_by_pid(firecracker_pid)
@@ -478,7 +483,7 @@ def test_stats(test_microvm_with_ssh_and_balloon, network_config):
478483

479484
# Deflate the balloon.check that the stats show the increase in
480485
# available memory.
481-
response = test_microvm.balloon.patch(amount_mb=0)
486+
response = test_microvm.balloon.patch(amount_mib=0)
482487
assert test_microvm.api_session.is_status_no_content(response.status_code)
483488
# This call will internally wait for rss to become stable.
484489
_ = get_stable_rss_mem_by_pid(firecracker_pid)
@@ -537,7 +542,7 @@ def _test_balloon_snapshot(context):
537542

538543
# Add a memory balloon with stats enabled.
539544
response = basevm.balloon.put(
540-
amount_mb=0,
545+
amount_mib=0,
541546
deflate_on_oom=True,
542547
stats_polling_interval_s=1
543548
)
@@ -557,7 +562,7 @@ def _test_balloon_snapshot(context):
557562
first_reading = get_stable_rss_mem_by_pid(firecracker_pid)
558563

559564
# Now inflate the balloon with 20MB of pages.
560-
response = basevm.balloon.patch(amount_mb=20)
565+
response = basevm.balloon.patch(amount_mib=20)
561566
assert basevm.api_session.is_status_no_content(response.status_code)
562567

563568
# Check memory usage again.
@@ -601,7 +606,7 @@ def _test_balloon_snapshot(context):
601606
assert fourth_reading > third_reading
602607

603608
# Inflate the balloon with another 20MB of pages.
604-
response = microvm.balloon.patch(amount_mb=40)
609+
response = microvm.balloon.patch(amount_mib=40)
605610
assert microvm.api_session.is_status_no_content(response.status_code)
606611

607612
fifth_reading = get_stable_rss_mem_by_pid(firecracker_pid)
@@ -653,7 +658,7 @@ def _test_snapshot_compatibility(context):
653658

654659
# Add a memory balloon with stats enabled.
655660
response = microvm.balloon.put(
656-
amount_mb=0,
661+
amount_mib=0,
657662
deflate_on_oom=True,
658663
stats_polling_interval_s=1
659664
)
@@ -731,7 +736,7 @@ def _test_memory_scrub(context):
731736

732737
# Add a memory balloon with stats enabled.
733738
response = microvm.balloon.put(
734-
amount_mb=0,
739+
amount_mib=0,
735740
deflate_on_oom=True,
736741
stats_polling_interval_s=1
737742
)
@@ -745,7 +750,7 @@ def _test_memory_scrub(context):
745750
make_guest_dirty_memory(ssh_connection, amount=(60 * MB_TO_PAGES))
746751

747752
# Now inflate the balloon with 60MB of pages.
748-
response = microvm.balloon.patch(amount_mb=60)
753+
response = microvm.balloon.patch(amount_mib=60)
749754
assert microvm.api_session.is_status_no_content(response.status_code)
750755

751756
# Get the firecracker pid, and open an ssh connection.
@@ -755,7 +760,7 @@ def _test_memory_scrub(context):
755760
_ = get_stable_rss_mem_by_pid(firecracker_pid)
756761

757762
# Deflate the balloon completely.
758-
response = microvm.balloon.patch(amount_mb=0)
763+
response = microvm.balloon.patch(amount_mib=0)
759764
assert microvm.api_session.is_status_no_content(response.status_code)
760765

761766
# Wait for the deflate to complete.

tests/integration_tests/functional/test_snapshot_advanced.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,13 @@ def test_restore_old_version_all_devices(bin_cloner_path):
138138
logger.debug(microvm.log_data)
139139

140140

141-
def validate_all_devices(logger, microvm, ifaces, drives, balloon):
141+
def validate_all_devices(
142+
logger,
143+
microvm,
144+
ifaces,
145+
drives,
146+
balloon
147+
):
142148
"""Perform a basic validation for all devices of a microvm."""
143149
# Test that net devices have connectivity after restore.
144150
for iface in ifaces:
@@ -199,7 +205,7 @@ def create_snapshot_helper(bin_cloner_path, logger, target_version=None,
199205

200206
# Add a memory balloon with stats enabled.
201207
response = vm.balloon.put(
202-
amount_mb=0,
208+
amount_mib=0,
203209
deflate_on_oom=True,
204210
stats_polling_interval_s=1
205211
)

0 commit comments

Comments
 (0)