qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: John Snow <jsnow@redhat.com>
To: Robert Foley <robert.foley@linaro.org>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"QEMU Developers" <qemu-devel@nongnu.org>,
	"Cleber Rosa" <crosa@redhat.com>,
	"Peter Puhov" <peter.puhov@linaro.org>,
	"Alex Bennée" <alex.bennee@linaro.org>
Subject: Re: [PULL 10/41] python/qemu: Add ConsoleSocket for optional use in QEMUMachine
Date: Mon, 13 Jul 2020 09:57:17 -0400	[thread overview]
Message-ID: <9cec0aa2-afc8-43fd-31bc-d74e80588ecd@redhat.com> (raw)
In-Reply-To: <CAEyhzFsYb4KvDaeMGwjocSjU0QO957Eg_TQbi0oEr1c=rE5vwQ@mail.gmail.com>



On 7/11/20 12:15 PM, Robert Foley wrote:
> Hi,
> Thanks for the detailed feedback!  I will look at making these changes.
> 

Sorry that it came so late ...

> On Fri, 10 Jul 2020 at 15:20, John Snow <jsnow@redhat.com> wrote:
>>
>>
>>
>> On 7/7/20 3:08 AM, Alex Bennée wrote:
>>> From: Robert Foley <robert.foley@linaro.org>
>>>
>>
> <snip>
>>> +    def recv(self, n=1, sleep_delay_s=0.1):
>>> +        """Return chars from in memory buffer"""
>>> +        start_time = time.time()
>>> +        while len(self._buffer) < n:
>>> +            time.sleep(sleep_delay_s)
>>> +            elapsed_sec = time.time() - start_time
>>> +            if elapsed_sec > self._recv_timeout_sec:
>>> +                raise socket.timeout
>>> +        chars = ''.join([self._buffer.popleft() for i in range(n)])
>>> +        # We choose to use latin1 to remain consistent with
>>> +        # handle_read() and give back the same data as the user would
>>> +        # receive if they were reading directly from the
>>> +        # socket w/o our intervention.
>>> +        return chars.encode("latin1")
>>> +
>>
>> console_socket.py:89:4: W0221: Parameters differ from overridden 'recv'
>> method (arguments-differ)
>>
>> Seems pretty different from the asyncore.dispatcher recv method, is that
>> intentional?
> 
> The intention is that the API be the same as asyncore.dispatcher recv.
> The sleep_delay_s can be removed, and n is the same as buffer_size in
> asyncore.dispatcher recv.  Will plan to rename n -> buffer_size.
> 
>> https://github.com/python/cpython/blob/master/Lib/asyncore.py
>>
> <snip>
>>>      def __enter__(self):
>>>          return self
>>> @@ -580,7 +591,11 @@ class QEMUMachine:
>>>          Returns a socket connected to the console
>>>          """
>>>          if self._console_socket is None:
>>> -            self._console_socket = socket.socket(socket.AF_UNIX,
>>> -                                                 socket.SOCK_STREAM)
>>> -            self._console_socket.connect(self._console_address)
>>> +            if self._drain_console:
>>> +                self._console_socket = ConsoleSocket(self._console_address,
>>> +                                                    file=self._console_log_path)
>>
>> Needs one more space, but the line is already too long as-is.
>>
>>> +            else:
>>> +                self._console_socket = socket.socket(socket.AF_UNIX,
>>> +                                                     socket.SOCK_STREAM)
>>> +                self._console_socket.connect(self._console_address)
>>>          return self._console_socket
>>>
>>
>> This makes the typing for _console_socket really tough ... but
>> technically not a regression as the mypy code isn't merged yet.
> 
> From the comment on mypy, I understand that we need to return a
> constant type?
> 

It keeps the API simpler to do that, yeah.

> One option to provide a constant type is to simply always return
> ConsoleSocket here.
> 
> A few changes would be needed inside of ConsoleSocket,
> but essentially ConsoleSocket would handle the detail
> of draining the console (or not), and thus eliminate this
> if/else above reducing it to something like this:
> 
> self._console_socket = ConsoleSocket(self._console_address,
>                                      file=self._console_log_path,
>                                      drain=self._drain_console)
> 
> How does this sound?
> 
> Thanks & Regards,
> -Rob
> 

That would be one way, but I'm not sure how hard it will be because
other clients in the acceptance tests use the socket.makefile() routine
-- does that work for the asyncore object?

The other way would be to offer a .drain_console() style routine that
takes the existing console socket object, wraps it in the asyncore
dispatcher, and returns a new object with its own type and behaviors.

It looks like asyncore is deprecated already, so isolating it into its
own method would make it a bit easier to replace in the future, I'd think.

(I was working on prototyping something for you, but hadn't worked on it
much over the weekend!)

Thanks,
--js



  parent reply	other threads:[~2020-07-13 13:58 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-07  7:08 [PULL 00/41] testing updates (vm, gitlab, misc build fixes) Alex Bennée
2020-07-07  7:08 ` [PULL 01/41] crypto/linux_keyring: fix 'secret_keyring' configure test Alex Bennée
2020-07-07  7:08 ` [PULL 02/41] util/coroutine: Cleanup start_switch_fiber_ for TSAN Alex Bennée
2020-07-07  7:08 ` [PULL 03/41] tests/vm: pass args through to BaseVM's __init__ Alex Bennée
2020-07-07  7:08 ` [PULL 04/41] tests/vm: Add configuration to basevm.py Alex Bennée
2020-07-10 13:50   ` Alex Bennée
2020-07-07  7:08 ` [PULL 05/41] tests/vm: Added configuration file support Alex Bennée
2020-07-07  7:08 ` [PULL 06/41] tests/vm: Add common Ubuntu python module Alex Bennée
2020-07-07  7:08 ` [PULL 07/41] tests/vm: Added a new script for ubuntu.aarch64 Alex Bennée
2020-07-07  7:08 ` [PULL 08/41] tests/vm: Added a new script for centos.aarch64 Alex Bennée
2020-07-07  7:08 ` [PULL 09/41] tests/vm: change scripts to use self._config Alex Bennée
2020-07-07  7:08 ` [PULL 10/41] python/qemu: Add ConsoleSocket for optional use in QEMUMachine Alex Bennée
2020-07-10 19:20   ` John Snow
2020-07-11 16:15     ` Robert Foley
2020-07-11 17:45       ` Alex Bennée
2020-07-13 13:57       ` John Snow [this message]
2020-07-13 14:16         ` Philippe Mathieu-Daudé
2020-07-13 14:37           ` Eduardo Habkost
2020-07-07  7:08 ` [PULL 11/41] tests/vm: Add workaround to consume console Alex Bennée
2020-07-07  7:08 ` [PULL 12/41] tests/vm: switch from optsparse to argparse Alex Bennée
2020-07-07  7:08 ` [PULL 13/41] tests/vm: allow us to take advantage of MTTCG Alex Bennée
2020-07-07  7:08 ` [PULL 14/41] tests/docker: check for an parameters not empty string Alex Bennée
2020-07-07  7:08 ` [PULL 15/41] tests/docker: change tag naming scheme of our images Alex Bennée
2020-07-07  7:08 ` [PULL 16/41] .gitignore: un-ignore .gitlab-ci.d Alex Bennée
2020-07-07  7:08 ` [PULL 17/41] gitlab-ci: Fix the change rules after moving the YML files Alex Bennée
2020-07-07  7:08 ` [PULL 18/41] gitlab: introduce explicit "container" and "build" stages Alex Bennée
2020-07-07  7:08 ` [PULL 19/41] gitlab: build all container images during CI Alex Bennée
2020-07-07  7:08 ` [PULL 20/41] gitlab: convert jobs to use custom built containers Alex Bennée
2020-07-07  7:08 ` [PULL 21/41] gitlab: build containers with buildkit and metadata Alex Bennée
2020-07-07  7:08 ` [PULL 22/41] tests/docker: add --registry support to tooling Alex Bennée
2020-07-07  7:08 ` [PULL 23/41] tests/docker: add packages needed for check-acceptance Alex Bennée
2020-07-07  7:08 ` [PULL 24/41] tests/acceptance: skip s390x_ccw_vrtio_tcg on GitLab Alex Bennée
2020-07-07  7:08 ` [PULL 25/41] tests/acceptance: fix dtb path for machine_rx_gdbsim Alex Bennée
2020-07-07  7:08 ` [PULL 26/41] tests/acceptance: skip multicore mips_malta tests on GitLab Alex Bennée
2020-07-07  7:08 ` [PULL 27/41] tests/acceptance: skip LinuxInitrd 2gib with v4.16 " Alex Bennée
2020-07-07  7:08 ` [PULL 28/41] gitlab: add acceptance testing to system builds Alex Bennée
2020-09-08 19:54   ` Philippe Mathieu-Daudé
2020-09-09  6:03     ` Thomas Huth
2020-07-07  7:08 ` [PULL 29/41] tests/tcg: add more default compilers to configure.sh Alex Bennée
2020-07-07  7:08 ` [PULL 30/41] tests/docker: add a linux-user testing focused image Alex Bennée
2020-07-07  7:08 ` [PULL 31/41] linux-user/elfload: use MAP_FIXED_NOREPLACE in pgb_reserved_va Alex Bennée
2020-07-07  7:08 ` [PULL 32/41] gitlab: enable check-tcg for linux-user tests Alex Bennée
2020-07-07  7:08 ` [PULL 33/41] gitlab: add avocado asset caching Alex Bennée
2020-07-07  7:08 ` [PULL 34/41] gitlab: split build-disabled into two phases Alex Bennée
2020-07-07  7:08 ` [PULL 35/41] gitlab: limit re-builds of the containers Alex Bennée
2020-07-07  7:08 ` [PULL 36/41] containers.yml: build with docker.py tooling Alex Bennée
2020-07-07  7:08 ` [PULL 37/41] testing: add check-build target Alex Bennée
2020-07-07  7:08 ` [PULL 38/41] shippable: pull images from registry instead of building Alex Bennée
2020-07-07  7:08 ` [PULL 39/41] travis.yml: Test also the other targets on s390x Alex Bennée
2020-07-07  7:08 ` [PULL 40/41] tests/qht-bench: Adjust testing rate by -1 Alex Bennée
2020-07-07  7:08 ` [PULL 41/41] tests/qht-bench: Adjust threshold computation Alex Bennée
2020-07-07  9:39 ` [PULL 00/41] testing updates (vm, gitlab, misc build fixes) Alex Bennée
2020-07-09 11:31 ` Peter Maydell
2020-07-09 12:24   ` Philippe Mathieu-Daudé
2020-07-09 13:04     ` Peter Maydell
2020-07-09 15:46   ` Alex Bennée

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9cec0aa2-afc8-43fd-31bc-d74e80588ecd@redhat.com \
    --to=jsnow@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=crosa@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peter.puhov@linaro.org \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=robert.foley@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).