DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jeremy Spewock <jspewock@iol.unh.edu>
To: Luca Vizzarro <Luca.Vizzarro@arm.com>
Cc: yoan.picchi@foss.arm.com, Honnappa.Nagarahalli@arm.com,
	 paul.szczepanek@arm.com, juraj.linkes@pantheon.tech,
	probb@iol.unh.edu,  wathsala.vithanage@arm.com,
	thomas@monjalon.net, dev@dpdk.org
Subject: Re: [PATCH v1 2/4] dts: add context manager for interactive shells
Date: Wed, 29 May 2024 16:37:36 -0400	[thread overview]
Message-ID: <CAAA20UQgwCCDTxhS17fPNNhK3Xf3mST1xTW4pjQEvZNGrpga-Q@mail.gmail.com> (raw)
In-Reply-To: <3220a75e-5401-44c7-a64d-ee950e4aaf1f@arm.com>

On Mon, May 20, 2024 at 1:31 PM Luca Vizzarro <Luca.Vizzarro@arm.com> wrote:
>
> On 14/05/2024 21:14, jspewock@iol.unh.edu wrote:
> > +class CriticalInteractiveShell(InteractiveShell):
> <snip>
> > +    _get_priviledged_command: Callable[[str], str] | None
> typo: privileged

Ack.

> > +
> > +    def __init__(
> > +        self,
> > +        interactive_session: SSHClient,
> > +        logger: DTSLogger,
> > +        get_privileged_command: Callable[[str], str] | None,
> > +        app_args: str = "",
> > +        timeout: float = SETTINGS.timeout,
> > +    ) -> None:
> > +        """Store parameters for creating an interactive shell, but do not start the application.
> > +
> > +        Note that this method also does not create the channel for the application, as this is
> > +        something that isn't needed until the application starts.
> > +
> > +        Args:
> > +            interactive_session: The SSH session dedicated to interactive shells.
> > +            logger: The logger instance this session will use.
> > +            get_privileged_command: A method for modifying a command to allow it to use
> > +                elevated privileges. If :data:`None`, the application will not be started
> > +                with elevated privileges.
> > +            app_args: The command line arguments to be passed to the application on startup.
> > +            timeout: The timeout used for the SSH channel that is dedicated to this interactive
> > +                shell. This timeout is for collecting output, so if reading from the buffer
> > +                and no output is gathered within the timeout, an exception is thrown. The default
> > +                value for this argument may be modified using the :option:`--timeout` command-line
> > +                argument or the :envvar:`DTS_TIMEOUT` environment variable.
> > +        """
> > +        self._interactive_session = interactive_session
> > +        self._logger = logger
> > +        self._timeout = timeout
> > +        self._app_args = app_args
> > +        self._get_priviledged_command = get_privileged_command
> > +
> > +    def __enter__(self: CriticalInteractiveShellType) -> CriticalInteractiveShellType:
>
> This kind of type hinting is achievable with Python's own `Self`, which
> you can already add to this patch because mypy installs
> typing_extensions. Nevertheless, `Self` is also being introduced
> properly in my mypy update patch series.

This is a great point. I actually didn't know the `Self` annotation
was a thing at the time of writing, but saw you using it in some of
your own patches. I think that would fit much better here and will
make the change.

>
> > +
> > +    def __exit__(self, type: BaseException, value: BaseException, traceback: TracebackType) -> None:
> Since you are not using the arguments I'd just ignore them with `_`.

Good point. I initially left them in case there was some kind of need
for using them somehow in the future, but there really is no need for
them.

> > +        """Exit the context block.
> > +
> > +        Upon exiting a context block with this class, we want to ensure that the instance of the
> > +        application is explicitly closed and properly cleaned up using it's close method. Note that
> > +        because this method returns :data:`None` if an exception was raised within the block, it is
> > +        not handled and will be re-raised after the application is closed.
> > +
> > +        Args:
> > +            type: Type of exception that was thrown in the context block if there was one.
> > +            value: Value of the exception thrown in the context block if there was one.
> > +            traceback: Traceback of the exception thrown in the context block if there was one.
> > +        """
> > +        self.close()
>
> > diff --git a/dts/framework/remote_session/interactive_shell.py b/dts/framework/remote_session/interactive_shell.py
> > index d1a9d8a6d2..08b8ba6a3e 100644
> > --- a/dts/framework/remote_session/interactive_shell.py
> > +++ b/dts/framework/remote_session/interactive_shell.py
> > @@ -89,16 +89,19 @@ def __init__(
> >                   and no output is gathered within the timeout, an exception is thrown.
> >           """
> >           self._interactive_session = interactive_session
> > -        self._ssh_channel = self._interactive_session.invoke_shell()
> > -        self._stdin = self._ssh_channel.makefile_stdin("w")
> > -        self._stdout = self._ssh_channel.makefile("r")
> > -        self._ssh_channel.settimeout(timeout)
> > -        self._ssh_channel.set_combine_stderr(True)  # combines stdout and stderr streams
> >           self._logger = logger
> >           self._timeout = timeout
> >           self._app_args = app_args
> > +        self._init_channel()
> >           self._start_application(get_privileged_command)
> >
> > +    def _init_channel(self):
> > +        self._ssh_channel = self._interactive_session.invoke_shell()
> > +        self._stdin = self._ssh_channel.makefile_stdin("w")
> > +        self._stdout = self._ssh_channel.makefile("r")
> > +        self._ssh_channel.settimeout(self._timeout)
> > +        self._ssh_channel.set_combine_stderr(True)  # combines stdout and stderr streams
> > +
> >       def _start_application(self, get_privileged_command: Callable[[str], str] | None) -> None:
> >           """Starts a new interactive application based on the path to the app.
> >
> Hilariously I've made the same exact change in my testpmd params patch
> series!

I noticed this as well, it is very funny that we both thought to break
this into its own method. Must be a useful addition then!

> > diff --git a/dts/tests/TestSuite_pmd_buffer_scatter.py b/dts/tests/TestSuite_pmd_buffer_scatter.py
> > index 3701c47408..41f6090a7e 100644
> > --- a/dts/tests/TestSuite_pmd_buffer_scatter.py
> > +++ b/dts/tests/TestSuite_pmd_buffer_scatter.py
> > @@ -112,17 +112,21 @@ def pmd_scatter(self, mbsize: int) -> None:
> >               ),
> >               privileged=True,
> >           )
> > -        testpmd.set_forward_mode(TestPmdForwardingModes.mac)
> > -        testpmd.start()
> > -
> > -        for offset in [-1, 0, 1, 4, 5]:
> > -            recv_payload = self.scatter_pktgen_send_packet(mbsize + offset)
> > -            self._logger.debug(f"Payload of scattered packet after forwarding: \n{recv_payload}")
> > -            self.verify(
> > -                ("58 " * 8).strip() in recv_payload,
> > -                f"Payload of scattered packet did not match expected payload with offset {offset}.",
> > -            )
> > -        testpmd.stop()
> > +        with testpmd_shell as testpmd:
> > +            testpmd.set_forward_mode(TestPmdForwardingModes.mac)
> > +            testpmd.start()
> > +
> > +            for offset in [-1, 0, 1, 4, 5]:
> > +                recv_payload = self.scatter_pktgen_send_packet(mbsize + offset)
> > +                self._logger.debug(
> > +                    f"Payload of scattered packet after forwarding: \n{recv_payload}"
> > +                )
> > +                self.verify(
> > +                    ("58 " * 8).strip() in recv_payload,
> > +                    "Payload of scattered packet did not match expected payload with offset "
> > +                    f"{offset}.",
> > +                )
> > +            testpmd.stop()
>
> Since we are exiting the context, implicitly it means we want to stop
> and close. Can't we also implicit call stop when closing?

It wouldn't hurt to also stop when we close I suppose. I really just
left close as something explicit because start is also something we do
more explicitly. When you quit testpmd in the close method it's going
to stop forwarding no matter what anyway, so I guess this isn't really
needed in the first place. Regardless, I can add something that stops
for you before quitting out of testpmd in the exit method, that will
at least save us some extra lines.

  reply	other threads:[~2024-05-29 20:37 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-14 20:14 [PATCH v1 0/4] Add second scatter test case jspewock
2024-05-14 20:14 ` [PATCH v1 1/4] dts: improve starting and stopping interactive shells jspewock
2024-05-20 17:17   ` Luca Vizzarro
2024-05-22 13:43   ` Patrick Robb
2024-05-14 20:14 ` [PATCH v1 2/4] dts: add context manager for " jspewock
2024-05-20 17:30   ` Luca Vizzarro
2024-05-29 20:37     ` Jeremy Spewock [this message]
2024-05-22 13:53   ` Patrick Robb
2024-05-29 20:37     ` Jeremy Spewock
2024-05-14 20:14 ` [PATCH v1 3/4] dts: add methods for modifying MTU to testpmd shell jspewock
2024-05-20 17:35   ` Luca Vizzarro
2024-05-29 20:38     ` Jeremy Spewock
2024-05-22 16:10   ` Patrick Robb
2024-05-14 20:14 ` [PATCH v1 4/4] dts: add test case that utilizes offload to pmd_buffer_scatter jspewock
2024-05-20 17:56   ` Luca Vizzarro
2024-05-29 20:40     ` Jeremy Spewock
2024-05-30  9:47       ` Luca Vizzarro
2024-05-30 16:33 ` [PATCH v2 0/4] Add second scatter test case jspewock
2024-05-30 16:33   ` [PATCH v2 1/4] dts: improve starting and stopping interactive shells jspewock
2024-05-31 16:37     ` Luca Vizzarro
2024-05-31 21:07       ` Jeremy Spewock
2024-05-30 16:33   ` [PATCH v2 2/4] dts: add context manager for " jspewock
2024-05-31 16:38     ` Luca Vizzarro
2024-05-30 16:33   ` [PATCH v2 3/4] dts: add methods for modifying MTU to testpmd shell jspewock
2024-05-31 16:34     ` Luca Vizzarro
2024-05-31 21:08       ` Jeremy Spewock
2024-06-10 14:35         ` Juraj Linkeš
2024-05-30 16:33   ` [PATCH v2 4/4] dts: add test case that utilizes offload to pmd_buffer_scatter jspewock
2024-05-31 16:33     ` Luca Vizzarro
2024-05-31 21:08       ` Jeremy Spewock
2024-06-05 21:31 ` [PATCH v3 0/4] Add second scatter test case jspewock
2024-06-05 21:31   ` [PATCH v3 1/4] dts: improve starting and stopping interactive shells jspewock
2024-06-10 13:36     ` Juraj Linkeš
2024-06-10 19:27       ` Jeremy Spewock
2024-06-05 21:31   ` [PATCH v3 2/4] dts: add context manager for " jspewock
2024-06-10 14:31     ` Juraj Linkeš
2024-06-10 20:06       ` Jeremy Spewock
2024-06-11  9:17         ` Juraj Linkeš
2024-06-11 15:33           ` Jeremy Spewock
2024-06-12  8:37             ` Juraj Linkeš
2024-06-05 21:31   ` [PATCH v3 3/4] dts: add methods for modifying MTU to testpmd shell jspewock
2024-06-10 15:03     ` Juraj Linkeš
2024-06-10 20:07       ` Jeremy Spewock
2024-06-05 21:31   ` [PATCH v3 4/4] dts: add test case that utilizes offload to pmd_buffer_scatter jspewock
2024-06-10 15:22     ` Juraj Linkeš
2024-06-10 20:08       ` Jeremy Spewock
2024-06-11  9:22         ` Juraj Linkeš
2024-06-11 15:33           ` Jeremy Spewock
2024-06-13 18:15 ` [PATCH v4 0/4] Add second scatter test case jspewock
2024-06-13 18:15   ` [PATCH v4 1/4] dts: add context manager for interactive shells jspewock
2024-06-18 15:47     ` Juraj Linkeš
2024-06-13 18:15   ` [PATCH v4 2/4] dts: improve starting and stopping " jspewock
2024-06-18 15:54     ` Juraj Linkeš
2024-06-18 16:47       ` Jeremy Spewock
2024-06-13 18:15   ` [PATCH v4 3/4] dts: add methods for modifying MTU to testpmd shell jspewock
2024-06-19  8:16     ` Juraj Linkeš
2024-06-20 19:23       ` Jeremy Spewock
2024-06-13 18:15   ` [PATCH v4 4/4] dts: add test case that utilizes offload to pmd_buffer_scatter jspewock
2024-06-19  8:51     ` Juraj Linkeš
2024-06-20 19:24       ` Jeremy Spewock

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=CAAA20UQgwCCDTxhS17fPNNhK3Xf3mST1xTW4pjQEvZNGrpga-Q@mail.gmail.com \
    --to=jspewock@iol.unh.edu \
    --cc=Honnappa.Nagarahalli@arm.com \
    --cc=Luca.Vizzarro@arm.com \
    --cc=dev@dpdk.org \
    --cc=juraj.linkes@pantheon.tech \
    --cc=paul.szczepanek@arm.com \
    --cc=probb@iol.unh.edu \
    --cc=thomas@monjalon.net \
    --cc=wathsala.vithanage@arm.com \
    --cc=yoan.picchi@foss.arm.com \
    /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).