get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/140120/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 140120,
    "url": "http://patchwork.dpdk.org/api/patches/140120/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/20240514201436.2496-3-jspewock@iol.unh.edu/",
    "project": {
        "id": 1,
        "url": "http://patchwork.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<20240514201436.2496-3-jspewock@iol.unh.edu>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20240514201436.2496-3-jspewock@iol.unh.edu",
    "date": "2024-05-14T20:14:34",
    "name": "[v1,2/4] dts: add context manager for interactive shells",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "f3ac779f0ad05fa6d850ff42c28fd1f54d92936f",
    "submitter": {
        "id": 2772,
        "url": "http://patchwork.dpdk.org/api/people/2772/?format=api",
        "name": "Jeremy Spewock",
        "email": "jspewock@iol.unh.edu"
    },
    "delegate": {
        "id": 1,
        "url": "http://patchwork.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/20240514201436.2496-3-jspewock@iol.unh.edu/mbox/",
    "series": [
        {
            "id": 31928,
            "url": "http://patchwork.dpdk.org/api/series/31928/?format=api",
            "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=31928",
            "date": "2024-05-14T20:14:32",
            "name": "Add second scatter test case",
            "version": 1,
            "mbox": "http://patchwork.dpdk.org/series/31928/mbox/"
        }
    ],
    "comments": "http://patchwork.dpdk.org/api/patches/140120/comments/",
    "check": "warning",
    "checks": "http://patchwork.dpdk.org/api/patches/140120/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 78D0C4402B;\n\tTue, 14 May 2024 22:15:15 +0200 (CEST)",
            "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 4678D40685;\n\tTue, 14 May 2024 22:15:04 +0200 (CEST)",
            "from mail-qv1-f98.google.com (mail-qv1-f98.google.com\n [209.85.219.98]) by mails.dpdk.org (Postfix) with ESMTP id 18BE0402E4\n for <dev@dpdk.org>; Tue, 14 May 2024 22:15:03 +0200 (CEST)",
            "by mail-qv1-f98.google.com with SMTP id\n 6a1803df08f44-6a0ffaa079dso60305836d6.1\n for <dev@dpdk.org>; Tue, 14 May 2024 13:15:03 -0700 (PDT)",
            "from postal.iol.unh.edu (postal.iol.unh.edu.\n [2606:4100:3880:1234::84]) by smtp-relay.gmail.com with ESMTPS id\n 6a1803df08f44-6a15f1c74b4sm6989166d6.45.2024.05.14.13.15.02\n (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);\n Tue, 14 May 2024 13:15:02 -0700 (PDT)",
            "from iol.unh.edu (unknown\n [IPv6:2606:4100:3880:1271:90f9:1b64:f6e6:867f])\n by postal.iol.unh.edu (Postfix) with ESMTP id AF526605C373;\n Tue, 14 May 2024 16:15:01 -0400 (EDT)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=iol.unh.edu; s=unh-iol; t=1715717702; x=1716322502; darn=dpdk.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=Jtfuj6jzqI4VNeorE9qqlDchmlIjWTwmsghk9d2TjU8=;\n b=JqeI1Du4aaW7B3BlGMq9/4Zp6dYFrwBO1I1IIoC5E/QifCjn4ZGUchm5dG+jAsqjnn\n 1EWnYXxHI9/QT3g//3GZfYYd/MBVgaL8Qb0oDnMpWfR/cVdoDWd1lL/NEp/rALzQ61dA\n /uGBhz6Oh/TTmrWaEBQ9jBQ/kSjaDShyW3WxA=",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20230601; t=1715717702; x=1716322502;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n :subject:date:message-id:reply-to;\n bh=Jtfuj6jzqI4VNeorE9qqlDchmlIjWTwmsghk9d2TjU8=;\n b=RraOX84Ub1Hffueao/N61IxbSMlqGT/TTvwjQMFYA8XKM/lfTJjloLUOLDL2uoVj0a\n KEp2Qv6KON2AhlrSoZ+fl++gwE29r4CLHuqIIQiw4ySAPQFMW0WshqoNdSa03N3chNDI\n lDAulxke54vx6NmNjxgAxxRsbhIMrOsZa5MBDAJ2QbJVWbuWpxCjTrbUqV+fnTIZqwfM\n rbFx+/7o+/GMEVT9XWN2NinCep+Qmh3uCBHC3D3H+qWND9UtSu7noH160i7bZWAvnQlC\n 6T9MNRgySuPhyuBCbV+W7Kapv5j8ZTwe7eyMTx/LFaHhRVL/cROfLQisJN7jUfjcxM13\n ET/A==",
        "X-Gm-Message-State": "AOJu0Yz5NQckoBG2T0J+Aa9HrMRFDK2yZWIMqfSJHGOkYQKwyNz5H5v/\n uFTJ04TnzNU+jUarhNK/gk84m0ch8/nDhti5SM0dxMa6e+lp/k1/ZKKz3/Zh48/OpH2frPWJAfR\n gPCwO+/5XlcKw0Q5VHtOd5QeQg7CqLXRSlmBPooOaEZQM1dTt",
        "X-Google-Smtp-Source": "\n AGHT+IEHaL1ikE/B2v3tPo7juE1XyisgvS8bbnFA94FTEvMli47spogYTHUMQOFqwtq6mrr5Tfl7g1hKKo93",
        "X-Received": "by 2002:a05:6214:43c4:b0:6a0:ea1e:833d with SMTP id\n 6a1803df08f44-6a1679a6a4dmr247833186d6.27.1715717702434;\n Tue, 14 May 2024 13:15:02 -0700 (PDT)",
        "X-Relaying-Domain": "iol.unh.edu",
        "From": "jspewock@iol.unh.edu",
        "To": "yoan.picchi@foss.arm.com, Honnappa.Nagarahalli@arm.com,\n paul.szczepanek@arm.com, juraj.linkes@pantheon.tech, probb@iol.unh.edu,\n Luca.Vizzarro@arm.com, wathsala.vithanage@arm.com, thomas@monjalon.net",
        "Cc": "dev@dpdk.org,\n\tJeremy Spewock <jspewock@iol.unh.edu>",
        "Subject": "[PATCH v1 2/4] dts: add context manager for interactive shells",
        "Date": "Tue, 14 May 2024 16:14:34 -0400",
        "Message-ID": "<20240514201436.2496-3-jspewock@iol.unh.edu>",
        "X-Mailer": "git-send-email 2.44.0",
        "In-Reply-To": "<20240514201436.2496-1-jspewock@iol.unh.edu>",
        "References": "<20240514201436.2496-1-jspewock@iol.unh.edu>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org"
    },
    "content": "From: Jeremy Spewock <jspewock@iol.unh.edu>\n\nInteractive shells are managed in a way currently where they are closed\nand cleaned up at the time of garbage collection. Due to there being no\nguarantee of when this garbage collection happens in Python, there is no\nway to consistently know when an application will be closed without\nmanually closing the application yourself when you are done with it.\nThis doesn't cause a problem in cases where you can start another\ninstance of the same application multiple times on a server, but this\nisn't the case for primary applications in DPDK. The introduction of\nprimary applications, such as testpmd, adds a need for knowing previous\ninstances of the application have been stopped and cleaned up before\nstarting a new one, which the garbage collector does not provide.\n\nTo solve this problem, a new class is added which acts as a wrapper\naround the interactive shell that enforces that instances of the\napplication be managed using a context manager. Using a context manager\nguarantees that once you leave the scope of the block where the\napplication is being used for any reason, the application will be closed\nimmediately. This avoids the possibility of the shell not being closed\ndue to an exception being raised or user error.\n\ndepends-on: patch-139227 (\"dts: skip test cases based on capabilities\")\n\nSigned-off-by: Jeremy Spewock <jspewock@iol.unh.edu>\n---\n .../critical_interactive_shell.py             | 98 +++++++++++++++++++\n .../remote_session/interactive_shell.py       | 13 ++-\n dts/framework/remote_session/testpmd_shell.py |  4 +-\n dts/framework/testbed_model/sut_node.py       |  8 +-\n dts/tests/TestSuite_pmd_buffer_scatter.py     | 28 +++---\n dts/tests/TestSuite_smoke_tests.py            |  3 +-\n 6 files changed, 130 insertions(+), 24 deletions(-)\n create mode 100644 dts/framework/remote_session/critical_interactive_shell.py",
    "diff": "diff --git a/dts/framework/remote_session/critical_interactive_shell.py b/dts/framework/remote_session/critical_interactive_shell.py\nnew file mode 100644\nindex 0000000000..d61b203954\n--- /dev/null\n+++ b/dts/framework/remote_session/critical_interactive_shell.py\n@@ -0,0 +1,98 @@\n+r\"\"\"Wrapper around :class:`~.interactive_shell.InteractiveShell` that handles critical applications.\n+\n+Critical applications are defined as applications that require explicit clean-up before another\n+instance of some application can be started. In DPDK these are referred to as \"primary\n+applications\" and these applications take out a lock which stops other primary applications from\n+running. Much like :class:`~.interactive_shell.InteractiveShell`\\s,\n+:class:`CriticalInteractiveShell` is meant to be extended by subclasses that implement application\n+specific functionality and should never be instantiated directly.\n+\"\"\"\n+\n+from types import TracebackType\n+from typing import Callable, TypeVar\n+\n+from paramiko import SSHClient  # type: ignore[import]\n+\n+from framework.logger import DTSLogger\n+from framework.settings import SETTINGS\n+\n+from .interactive_shell import InteractiveShell\n+\n+CriticalInteractiveShellType = TypeVar(\n+    \"CriticalInteractiveShellType\", bound=\"CriticalInteractiveShell\"\n+)\n+\n+\n+class CriticalInteractiveShell(InteractiveShell):\n+    \"\"\"The base class for interactive critical applications.\n+\n+    This class is a wrapper around :class:`~.interactive_shell.InteractiveShell` and should always\n+    implement the exact same functionality with the primary difference being how the application\n+    is started and stopped. In contrast to normal interactive shells, this class does not start the\n+    application upon initialization of the class. Instead, the application is handled through a\n+    context manager. This allows for more explicit starting and stopping of the application, and\n+    more guarantees for when the application is cleaned up which are not present with normal\n+    interactive shells that get cleaned up upon garbage collection.\n+    \"\"\"\n+\n+    _get_priviledged_command: Callable[[str], str] | None\n+\n+    def __init__(\n+        self,\n+        interactive_session: SSHClient,\n+        logger: DTSLogger,\n+        get_privileged_command: Callable[[str], str] | None,\n+        app_args: str = \"\",\n+        timeout: float = SETTINGS.timeout,\n+    ) -> None:\n+        \"\"\"Store parameters for creating an interactive shell, but do not start the application.\n+\n+        Note that this method also does not create the channel for the application, as this is\n+        something that isn't needed until the application starts.\n+\n+        Args:\n+            interactive_session: The SSH session dedicated to interactive shells.\n+            logger: The logger instance this session will use.\n+            get_privileged_command: A method for modifying a command to allow it to use\n+                elevated privileges. If :data:`None`, the application will not be started\n+                with elevated privileges.\n+            app_args: The command line arguments to be passed to the application on startup.\n+            timeout: The timeout used for the SSH channel that is dedicated to this interactive\n+                shell. This timeout is for collecting output, so if reading from the buffer\n+                and no output is gathered within the timeout, an exception is thrown. The default\n+                value for this argument may be modified using the :option:`--timeout` command-line\n+                argument or the :envvar:`DTS_TIMEOUT` environment variable.\n+        \"\"\"\n+        self._interactive_session = interactive_session\n+        self._logger = logger\n+        self._timeout = timeout\n+        self._app_args = app_args\n+        self._get_priviledged_command = get_privileged_command\n+\n+    def __enter__(self: CriticalInteractiveShellType) -> CriticalInteractiveShellType:\n+        \"\"\"Enter the context block.\n+\n+        Upon entering a context block with this class, the desired behavior is to create the\n+        channel for the application to use, and then start the application.\n+\n+        Returns:\n+            Reference to the object for the application after it has been started.\n+        \"\"\"\n+        self._init_channel()\n+        self._start_application(self._get_priviledged_command)\n+        return self\n+\n+    def __exit__(self, type: BaseException, value: BaseException, traceback: TracebackType) -> None:\n+        \"\"\"Exit the context block.\n+\n+        Upon exiting a context block with this class, we want to ensure that the instance of the\n+        application is explicitly closed and properly cleaned up using it's close method. Note that\n+        because this method returns :data:`None` if an exception was raised within the block, it is\n+        not handled and will be re-raised after the application is closed.\n+\n+        Args:\n+            type: Type of exception that was thrown in the context block if there was one.\n+            value: Value of the exception thrown in the context block if there was one.\n+            traceback: Traceback of the exception thrown in the context block if there was one.\n+        \"\"\"\n+        self.close()\ndiff --git a/dts/framework/remote_session/interactive_shell.py b/dts/framework/remote_session/interactive_shell.py\nindex d1a9d8a6d2..08b8ba6a3e 100644\n--- a/dts/framework/remote_session/interactive_shell.py\n+++ b/dts/framework/remote_session/interactive_shell.py\n@@ -89,16 +89,19 @@ def __init__(\n                 and no output is gathered within the timeout, an exception is thrown.\n         \"\"\"\n         self._interactive_session = interactive_session\n-        self._ssh_channel = self._interactive_session.invoke_shell()\n-        self._stdin = self._ssh_channel.makefile_stdin(\"w\")\n-        self._stdout = self._ssh_channel.makefile(\"r\")\n-        self._ssh_channel.settimeout(timeout)\n-        self._ssh_channel.set_combine_stderr(True)  # combines stdout and stderr streams\n         self._logger = logger\n         self._timeout = timeout\n         self._app_args = app_args\n+        self._init_channel()\n         self._start_application(get_privileged_command)\n \n+    def _init_channel(self):\n+        self._ssh_channel = self._interactive_session.invoke_shell()\n+        self._stdin = self._ssh_channel.makefile_stdin(\"w\")\n+        self._stdout = self._ssh_channel.makefile(\"r\")\n+        self._ssh_channel.settimeout(self._timeout)\n+        self._ssh_channel.set_combine_stderr(True)  # combines stdout and stderr streams\n+\n     def _start_application(self, get_privileged_command: Callable[[str], str] | None) -> None:\n         \"\"\"Starts a new interactive application based on the path to the app.\n \ndiff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py\nindex cb4642bf3d..33b3e7c5a3 100644\n--- a/dts/framework/remote_session/testpmd_shell.py\n+++ b/dts/framework/remote_session/testpmd_shell.py\n@@ -26,7 +26,7 @@\n from framework.settings import SETTINGS\n from framework.utils import StrEnum\n \n-from .interactive_shell import InteractiveShell\n+from .critical_interactive_shell import CriticalInteractiveShell\n \n \n class TestPmdDevice(object):\n@@ -82,7 +82,7 @@ class TestPmdForwardingModes(StrEnum):\n     recycle_mbufs = auto()\n \n \n-class TestPmdShell(InteractiveShell):\n+class TestPmdShell(CriticalInteractiveShell):\n     \"\"\"Testpmd interactive shell.\n \n     The testpmd shell users should never use\ndiff --git a/dts/framework/testbed_model/sut_node.py b/dts/framework/testbed_model/sut_node.py\nindex 1fb536735d..7dd39fd735 100644\n--- a/dts/framework/testbed_model/sut_node.py\n+++ b/dts/framework/testbed_model/sut_node.py\n@@ -243,10 +243,10 @@ def get_supported_capabilities(\n         unsupported_capas: set[NicCapability] = set()\n         self._logger.debug(f\"Checking which capabilities from {capabilities} NIC are supported.\")\n         testpmd_shell = self.create_interactive_shell(TestPmdShell, privileged=True)\n-        for capability in capabilities:\n-            if capability not in supported_capas or capability not in unsupported_capas:\n-                capability.value(testpmd_shell, supported_capas, unsupported_capas)\n-        del testpmd_shell\n+        with testpmd_shell as running_testpmd:\n+            for capability in capabilities:\n+                if capability not in supported_capas or capability not in unsupported_capas:\n+                    capability.value(running_testpmd, supported_capas, unsupported_capas)\n         return supported_capas\n \n     def _set_up_build_target(self, build_target_config: BuildTargetConfiguration) -> None:\ndiff --git a/dts/tests/TestSuite_pmd_buffer_scatter.py b/dts/tests/TestSuite_pmd_buffer_scatter.py\nindex 3701c47408..41f6090a7e 100644\n--- a/dts/tests/TestSuite_pmd_buffer_scatter.py\n+++ b/dts/tests/TestSuite_pmd_buffer_scatter.py\n@@ -101,7 +101,7 @@ def pmd_scatter(self, mbsize: int) -> None:\n         Test:\n             Start testpmd and run functional test with preset mbsize.\n         \"\"\"\n-        testpmd = self.sut_node.create_interactive_shell(\n+        testpmd_shell = self.sut_node.create_interactive_shell(\n             TestPmdShell,\n             app_parameters=(\n                 \"--mbcache=200 \"\n@@ -112,17 +112,21 @@ def pmd_scatter(self, mbsize: int) -> None:\n             ),\n             privileged=True,\n         )\n-        testpmd.set_forward_mode(TestPmdForwardingModes.mac)\n-        testpmd.start()\n-\n-        for offset in [-1, 0, 1, 4, 5]:\n-            recv_payload = self.scatter_pktgen_send_packet(mbsize + offset)\n-            self._logger.debug(f\"Payload of scattered packet after forwarding: \\n{recv_payload}\")\n-            self.verify(\n-                (\"58 \" * 8).strip() in recv_payload,\n-                f\"Payload of scattered packet did not match expected payload with offset {offset}.\",\n-            )\n-        testpmd.stop()\n+        with testpmd_shell as testpmd:\n+            testpmd.set_forward_mode(TestPmdForwardingModes.mac)\n+            testpmd.start()\n+\n+            for offset in [-1, 0, 1, 4, 5]:\n+                recv_payload = self.scatter_pktgen_send_packet(mbsize + offset)\n+                self._logger.debug(\n+                    f\"Payload of scattered packet after forwarding: \\n{recv_payload}\"\n+                )\n+                self.verify(\n+                    (\"58 \" * 8).strip() in recv_payload,\n+                    \"Payload of scattered packet did not match expected payload with offset \"\n+                    f\"{offset}.\",\n+                )\n+            testpmd.stop()\n \n     def test_scatter_mbuf_2048(self) -> None:\n         \"\"\"Run the :meth:`pmd_scatter` test with `mbsize` set to 2048.\"\"\"\ndiff --git a/dts/tests/TestSuite_smoke_tests.py b/dts/tests/TestSuite_smoke_tests.py\nindex a553e89662..360e64eb5a 100644\n--- a/dts/tests/TestSuite_smoke_tests.py\n+++ b/dts/tests/TestSuite_smoke_tests.py\n@@ -100,7 +100,8 @@ def test_devices_listed_in_testpmd(self) -> None:\n             List all devices found in testpmd and verify the configured devices are among them.\n         \"\"\"\n         testpmd_driver = self.sut_node.create_interactive_shell(TestPmdShell, privileged=True)\n-        dev_list = [str(x) for x in testpmd_driver.get_devices()]\n+        with testpmd_driver as testpmd:\n+            dev_list = [str(x) for x in testpmd.get_devices()]\n         for nic in self.nics_in_node:\n             self.verify(\n                 nic.pci in dev_list,\n",
    "prefixes": [
        "v1",
        "2/4"
    ]
}