Skip to content

Commit 03deaec

Browse files
committed
test(snapshot): verify network data integrity after cross-kernel restore
Add check_network_data_integrity helper that generates random bytes on the host, pushes them to the guest via SSH command-line (base64-encoded to survive argv), has the guest decode and sha256 them, and asserts the guest-side hash matches the host-side hash. This exercises the full virtio-net RX path end-to-end beyond simple connectivity checks. Signed-off-by: Jack Thomson <jackabt@amazon.com>
1 parent 04708b2 commit 03deaec

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

tests/framework/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
# SPDX-License-Identifier: Apache-2.0
33
"""Generic utility functions that are used in the framework."""
44

5+
import base64
56
import errno
7+
import hashlib
68
import json
79
import logging
810
import os
@@ -578,6 +580,19 @@ def check_entropy(ssh_connection):
578580
ssh_connection.check_output("dd if=/dev/hwrng of=/dev/null bs=4096 count=1")
579581

580582

583+
def check_network_data_integrity(ssh_connection, size_bytes=64 * 1024):
584+
"""Push random bytes to the guest over SSH and verify the guest-side sha256
585+
matches the host-side hash. Exercises the virtio-net RX path end-to-end."""
586+
payload = os.urandom(size_bytes)
587+
host_hash = hashlib.sha256(payload).hexdigest()
588+
b64 = base64.b64encode(payload).decode("ascii")
589+
_, stdout, _ = ssh_connection.check_output(f"echo {b64} | base64 -d | sha256sum")
590+
guest_hash = stdout.strip().split()[0]
591+
assert (
592+
guest_hash == host_hash
593+
), f"Guest hash {guest_hash} does not match host hash {host_hash}"
594+
595+
581596
@retry(wait=wait_fixed(0.5), stop=stop_after_attempt(5), reraise=True)
582597
def wait_process_running(process):
583598
"""Wait for a process to run.

tests/integration_tests/functional/test_snapshot_restore_cross_kernel.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from framework.defs import FC_WORKSPACE_DIR
1414
from framework.utils import (
1515
check_entropy,
16+
check_network_data_integrity,
1617
generate_mmds_get_request,
1718
generate_mmds_session_token,
1819
guest_run_fio_iteration,
@@ -129,6 +130,9 @@ def test_snap_restore_from_artifacts(
129130
logger.info("Testing net device %s...", iface["iface"].dev_name)
130131
vm.ssh_iface(idx).check_output("true")
131132

133+
logger.info("Testing network data integrity...")
134+
check_network_data_integrity(vm.ssh)
135+
132136
logger.info("Testing data store behavior...")
133137
_test_mmds(vm, vm.iface["eth3"]["iface"])
134138

0 commit comments

Comments
 (0)