|
4 | 4 |
|
5 | 5 | import fcntl
|
6 | 6 | import os
|
| 7 | +import platform |
7 | 8 | import subprocess
|
8 | 9 | import termios
|
9 | 10 | import time
|
10 | 11 |
|
11 | 12 | from framework.microvm import Serial
|
12 | 13 | from framework.state_machine import TestState
|
| 14 | +from framework.builder import MicrovmBuilder, SnapshotBuilder |
| 15 | +from framework.artifacts import SnapshotType |
13 | 16 | from framework import utils
|
14 | 17 | import host_tools.logging as log_tools
|
15 |
| -import host_tools.network as net_tools # pylint: disable=import-error |
| 18 | +import host_tools.network as net_tools |
16 | 19 |
|
17 | 20 |
|
18 | 21 | class WaitTerminal(TestState): # pylint: disable=too-few-public-methods
|
@@ -44,6 +47,53 @@ def handle_input(self, unused_serial, _) -> TestState:
|
44 | 47 | return self
|
45 | 48 |
|
46 | 49 |
|
| 50 | +def test_serial_after_snapshot(bin_cloner_path): |
| 51 | + """ |
| 52 | + Serial I/O after restoring from a snapshot. |
| 53 | +
|
| 54 | + @type: functional |
| 55 | + """ |
| 56 | + vm_builder = MicrovmBuilder(bin_cloner_path) |
| 57 | + vm_instance = vm_builder.build_vm_nano( |
| 58 | + diff_snapshots=False, |
| 59 | + daemonize=False, |
| 60 | + ) |
| 61 | + microvm = vm_instance.vm |
| 62 | + root_disk = vm_instance.disks[0] |
| 63 | + ssh_key = vm_instance.ssh_key |
| 64 | + |
| 65 | + microvm.start() |
| 66 | + serial = Serial(microvm) |
| 67 | + serial.open() |
| 68 | + # Image used for tests on aarch64 has autologon |
| 69 | + if platform.machine() == "x86_64": |
| 70 | + serial.rx(token='login: ') |
| 71 | + serial.tx("root") |
| 72 | + serial.rx("Password: ") |
| 73 | + serial.tx("root") |
| 74 | + |
| 75 | + snapshot_builder = SnapshotBuilder(microvm) |
| 76 | + disks = [root_disk.local_path()] |
| 77 | + # Create diff snapshot. |
| 78 | + snapshot = snapshot_builder.create(disks, |
| 79 | + ssh_key, |
| 80 | + SnapshotType.FULL) |
| 81 | + # Kill base microVM. |
| 82 | + microvm.kill() |
| 83 | + |
| 84 | + # Load microVM clone from snapshot. |
| 85 | + test_microvm, _ = vm_builder.build_from_snapshot(snapshot, |
| 86 | + resume=True, |
| 87 | + diff_snapshots=False, |
| 88 | + daemonize=False) |
| 89 | + serial = Serial(test_microvm) |
| 90 | + serial.open() |
| 91 | + serial.rx("#") |
| 92 | + serial.tx("pwd") |
| 93 | + res = serial.rx("#") |
| 94 | + assert "/root" in res |
| 95 | + |
| 96 | + |
47 | 97 | def test_serial_console_login(test_microvm_with_api):
|
48 | 98 | """
|
49 | 99 | Test serial console login.
|
|
0 commit comments