Skip to content

Commit

Permalink
Merge pull request avocado-framework#3948 from chloerh/console
Browse files Browse the repository at this point in the history
vt_console:Skip waiting screen when login via console
  • Loading branch information
dzhengfy committed Jul 25, 2024
2 parents c6256eb + 814c7d6 commit 289525e
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions virttest/vt_console.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import logging
import threading
import time

from aexpect import remote

LOG = logging.getLogger("avocado." + __name__)


class ConsoleError(Exception):
"""A base class for console errors."""
Expand Down Expand Up @@ -73,14 +76,29 @@ def __login(
self._console.set_linesep(linesep)
self._console.set_status_test_command(status_test_command)

is_responsive = False
reset_str = "Press any key to stop system reset"
end_time = time.time() + timeout
while time.time() < end_time:
if self._console.is_responsive():
is_responsive = True
break
if not is_responsive:
raise ConsoleNotResponsiveError("Console is not responsive.")
self._console.read_nonblocking()
latest_output = "\n".join(self._console.get_output().splitlines()[-50:])

# If system is waiting for any key to stop reset, we'll wait after
# timeout(usually 5s) to avoid entering interactive screen
if reset_str in latest_output:
time.sleep(1)
continue
else:
# If the "Press any key to stop system reset" screen is passed,
# we don't need to wait anymore
if reset_str in self._console.get_output():
break
else:
# Only check output of the first 500 lines since the
# "system reset" screen appears at the beginning of
# system booting. If there's no such string in console
# within 500 lines, there shouldn't be any at all
if len(self._console.get_output().strip()) > 500:
break

remote.handle_prompts(self._console, username, password, prompt, timeout)

Expand Down

0 comments on commit 289525e

Please sign in to comment.