[CI]: Console restore integration test
import fcntl
import os
+import platform
import subprocess
import termios
import time
from framework.microvm import Serial
from framework.state_machine import TestState
+from framework.builder import MicrovmBuilder, SnapshotBuilder
+from framework.artifacts import SnapshotType
from framework import utils
import host_tools.logging as log_tools
-import host_tools.network as net_tools # pylint: disable=import-error
+import host_tools.network as net_tools
class WaitTerminal(TestState): # pylint: disable=too-few-public-methods
@@ -44,6 +47,53 @@ class TestFinished(TestState): # pylint: disable=too-few-public-methods
return self
+def test_serial_after_snapshot(bin_cloner_path):
+ """
+ Serial I/O after restoring from a snapshot.
+
+ @type: functional
+ """
+ vm_builder = MicrovmBuilder(bin_cloner_path)
+ vm_instance = vm_builder.build_vm_nano(
+ diff_snapshots=False,
+ daemonize=False,
+ )
+ microvm = vm_instance.vm
+ root_disk = vm_instance.disks[0]
+ ssh_key = vm_instance.ssh_key
+
+ microvm.start()
+ serial = Serial(microvm)
+ serial.open()
+ # Image used for tests on aarch64 has autologon
+ if platform.machine() == "x86_64":
+ serial.rx(token='login: ')
+ serial.tx("root")
+ serial.rx("Password: ")
+ serial.tx("root")
+
+ snapshot_builder = SnapshotBuilder(microvm)
+ disks = [root_disk.local_path()]
+ # Create diff snapshot.
+ snapshot = snapshot_builder.create(disks,
+ ssh_key,
+ SnapshotType.FULL)
+ # Kill base microVM.
+ microvm.kill()
+
+ # Load microVM clone from snapshot.
+ test_microvm, _ = vm_builder.build_from_snapshot(snapshot,
+ resume=True,
+ diff_snapshots=False,
+ daemonize=False)
+ serial = Serial(test_microvm)
+ serial.open()
+ serial.rx("#")
+ serial.tx("pwd")
+ res = serial.rx("#")
+ assert "/root" in res
+
+
def test_serial_console_login(test_microvm_with_api):
"""
Test serial console login.
