On Tue, Oct 01, 2024 at 01:43:47PM +0100, Peter Maydell wrote:
> One common thing to want to do in an avocado test is log into
> the guest. The obvious way to do that would seem to be:
>
> self.wait_for_console_pattern('login:')
> exec_command(self, 'root')
> self.wait_for_console_pattern('Password:')
> exec_command(self, "passw0rd")
>
> This doesn't work; Thomas tells me that's because the
> wait_for_console_pattern function requires that the guest outputs
> a newline, but the 'login:' and 'Password:' prompt lines don't
> have a newline after them.
I presume the problem is ultimately this lne of code
which calls 'readline()'
try:
msg = console.readline().decode().strip()
except UnicodeDecodeError:
msg = None
if not msg:
continue
I would think we should change this to read a byte at
a time, trying the pattern match after each line until
it succeeeds.
It would have to gracefully handle unicode decode errors,
trying to get more bytes, instead of discarding the data,
because reading byte a time we might only have a partial
utf8 sequence. Or we could ensure that "console" is opened
with utf8 decoding by default instead of raw bytes.
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|