Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
Enable auto login for qemu SUT
Browse files Browse the repository at this point in the history
This patch add the possibility to handle qemu images with auto login
and to handle the first PS1 shown after boot.

Signed-off-by: Andrea Cervesato <[email protected]>
  • Loading branch information
acerv committed Feb 9, 2023
1 parent b278052 commit 75d8ad3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions ltp/qemu_sut.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def __init__(self) -> None:
self._virtfs = None
self._serial_type = None
self._opts = None
self._user = None
self._prompt = None

@property
def name(self) -> str:
Expand All @@ -45,6 +47,7 @@ def config_help(self) -> dict:
return {
"image": "qcow2 image location",
"image_overlay": "image_overlay: image copy location",
"user": "username used to login. If empty, it won't be used (default: 'root')",
"password": "root password (default: root)",
"system": "system architecture (default: x86_64)",
"ram": "RAM of the VM (default: 2G)",
Expand All @@ -53,6 +56,7 @@ def config_help(self) -> dict:
"virtfs": "directory to mount inside VM",
"ro_image": "path of the image that will exposed as read only",
"options": "user defined options",
"first_prompt": "first shell prompt string (default: '#')",
}

def _get_transport(self) -> str:
Expand Down Expand Up @@ -131,20 +135,21 @@ def _get_command(self) -> str:
return cmd

def _login(self, timeout: float, iobuffer: IOBuffer) -> None:
self._wait_for("login:", timeout, iobuffer)
self._write_stdin("root\n")
if self._user:
self._wait_for("login:", timeout, iobuffer)
self._write_stdin(f"{self._user}\n")

if self._password:
self._wait_for("Password:", 5, iobuffer)
self._write_stdin(f"{self._password}\n")

time.sleep(0.2)

self._wait_for("#", 5, iobuffer)
self._wait_for(self._prompt, timeout, iobuffer)
time.sleep(0.2)

self._write_stdin("stty -echo; stty cols 1024\n")
self._wait_for("#", 5, None)
self._wait_for(self._prompt, 5, None)

_, retcode, _ = self._exec("export PS1=''", 5, None)
if retcode != 0:
Expand Down Expand Up @@ -179,12 +184,14 @@ def setup(self, **kwargs: dict) -> None:
self._image = kwargs.get("image", None)
self._image_overlay = kwargs.get("image_overlay", None)
self._ro_image = kwargs.get("ro_image", None)
self._user = kwargs.get("user", "root")
self._password = kwargs.get("password", "root")
self._ram = kwargs.get("ram", "2G")
self._smp = kwargs.get("smp", "2")
self._virtfs = kwargs.get("virtfs", None)
self._serial_type = kwargs.get("serial", "isa")
self._opts = kwargs.get("options", None)
self._prompt = kwargs.get("first_prompt", "#")

system = kwargs.get("system", "x86_64")
self._qemu_cmd = f"qemu-system-{system}"
Expand Down Expand Up @@ -216,3 +223,6 @@ def setup(self, **kwargs: dict) -> None:

if self._serial_type not in ["isa", "virtio"]:
raise SUTError("Serial protocol must be isa or virtio")

if not self._prompt:
raise SUTError("first_prompt is not defined")

0 comments on commit 75d8ad3

Please sign in to comment.