get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 119484,
    "url": "http://patches.dpdk.org/api/patches/119484/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20221104110523.511367-7-juraj.linkes@pantheon.tech/",
    "project": {
        "id": 1,
        "url": "http://patches.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": "<20221104110523.511367-7-juraj.linkes@pantheon.tech>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20221104110523.511367-7-juraj.linkes@pantheon.tech",
    "date": "2022-11-04T11:05:20",
    "name": "[v8,6/9] dts: add ssh session module",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "bb2c8ea93064c4a1b276f7043f40f1d1271cef33",
    "submitter": {
        "id": 1626,
        "url": "http://patches.dpdk.org/api/people/1626/?format=api",
        "name": "Juraj Linkeš",
        "email": "juraj.linkes@pantheon.tech"
    },
    "delegate": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20221104110523.511367-7-juraj.linkes@pantheon.tech/mbox/",
    "series": [
        {
            "id": 25575,
            "url": "http://patches.dpdk.org/api/series/25575/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=25575",
            "date": "2022-11-04T11:05:14",
            "name": "dts: ssh connection to a node",
            "version": 8,
            "mbox": "http://patches.dpdk.org/series/25575/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/119484/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/119484/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 54EA7A00C5;\n\tFri,  4 Nov 2022 12:06:09 +0100 (CET)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 2100142D3B;\n\tFri,  4 Nov 2022 12:05:40 +0100 (CET)",
            "from lb.pantheon.sk (lb.pantheon.sk [46.229.239.20])\n by mails.dpdk.org (Postfix) with ESMTP id F3CA842D3A\n for <dev@dpdk.org>; Fri,  4 Nov 2022 12:05:38 +0100 (CET)",
            "from localhost (localhost [127.0.0.1])\n by lb.pantheon.sk (Postfix) with ESMTP id 0DF5A1BA5AB;\n Fri,  4 Nov 2022 12:05:38 +0100 (CET)",
            "from lb.pantheon.sk ([127.0.0.1])\n by localhost (lb.pantheon.sk [127.0.0.1]) (amavisd-new, port 10024)\n with ESMTP id pSWDT9BHOqCG; Fri,  4 Nov 2022 12:05:35 +0100 (CET)",
            "from entguard.lab.pantheon.local (unknown [46.229.239.141])\n by lb.pantheon.sk (Postfix) with ESMTP id E46E71BA5AE;\n Fri,  4 Nov 2022 12:05:28 +0100 (CET)"
        ],
        "X-Virus-Scanned": "amavisd-new at siecit.sk",
        "From": "=?utf-8?q?Juraj_Linke=C5=A1?= <juraj.linkes@pantheon.tech>",
        "To": "thomas@monjalon.net, Honnappa.Nagarahalli@arm.com, ohilyard@iol.unh.edu,\n lijuan.tu@intel.com, kda@semihalf.com, bruce.richardson@intel.com",
        "Cc": "dev@dpdk.org, =?utf-8?q?Juraj_Linke=C5=A1?= <juraj.linkes@pantheon.tech>",
        "Subject": "[PATCH v8 6/9] dts: add ssh session module",
        "Date": "Fri,  4 Nov 2022 11:05:20 +0000",
        "Message-Id": "<20221104110523.511367-7-juraj.linkes@pantheon.tech>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<20221104110523.511367-1-juraj.linkes@pantheon.tech>",
        "References": "<20221103151934.450887-1-juraj.linkes@pantheon.tech>\n <20221104110523.511367-1-juraj.linkes@pantheon.tech>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "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": "The module uses the pexpect python library and implements connection to\na node and two ways to interact with the node:\n1. Send a string with specified prompt which will be matched after\n   the string has been sent to the node.\n2. Send a command to be executed. No prompt is specified here.\n\nSigned-off-by: Owen Hilyard <ohilyard@iol.unh.edu>\nSigned-off-by: Juraj Linkeš <juraj.linkes@pantheon.tech>\n---\n dts/framework/exception.py                  |  56 ++++++\n dts/framework/remote_session/__init__.py    |  12 ++\n dts/framework/remote_session/ssh_session.py | 184 ++++++++++++++++++++\n dts/framework/utils.py                      |  12 ++\n 4 files changed, 264 insertions(+)\n create mode 100644 dts/framework/exception.py\n create mode 100644 dts/framework/remote_session/ssh_session.py\n create mode 100644 dts/framework/utils.py",
    "diff": "diff --git a/dts/framework/exception.py b/dts/framework/exception.py\nnew file mode 100644\nindex 0000000000..8b2f08a8f0\n--- /dev/null\n+++ b/dts/framework/exception.py\n@@ -0,0 +1,56 @@\n+# SPDX-License-Identifier: BSD-3-Clause\n+# Copyright(c) 2010-2014 Intel Corporation\n+# Copyright(c) 2022 PANTHEON.tech s.r.o.\n+# Copyright(c) 2022 University of New Hampshire\n+\n+\"\"\"\n+User-defined exceptions used across the framework.\n+\"\"\"\n+\n+\n+class SSHTimeoutError(Exception):\n+    \"\"\"\n+    Command execution timeout.\n+    \"\"\"\n+\n+    command: str\n+    output: str\n+\n+    def __init__(self, command: str, output: str):\n+        self.command = command\n+        self.output = output\n+\n+    def __str__(self) -> str:\n+        return f\"TIMEOUT on {self.command}\"\n+\n+    def get_output(self) -> str:\n+        return self.output\n+\n+\n+class SSHConnectionError(Exception):\n+    \"\"\"\n+    SSH connection error.\n+    \"\"\"\n+\n+    host: str\n+\n+    def __init__(self, host: str):\n+        self.host = host\n+\n+    def __str__(self) -> str:\n+        return f\"Error trying to connect with {self.host}\"\n+\n+\n+class SSHSessionDeadError(Exception):\n+    \"\"\"\n+    SSH session is not alive.\n+    It can no longer be used.\n+    \"\"\"\n+\n+    host: str\n+\n+    def __init__(self, host: str):\n+        self.host = host\n+\n+    def __str__(self) -> str:\n+        return f\"SSH session with {self.host} has died\"\ndiff --git a/dts/framework/remote_session/__init__.py b/dts/framework/remote_session/__init__.py\nindex 9bb042a482..a227d8db22 100644\n--- a/dts/framework/remote_session/__init__.py\n+++ b/dts/framework/remote_session/__init__.py\n@@ -1,2 +1,14 @@\n # SPDX-License-Identifier: BSD-3-Clause\n # Copyright(c) 2022 PANTHEON.tech s.r.o.\n+\n+from framework.config import NodeConfiguration\n+from framework.logger import DTSLOG\n+\n+from .remote_session import RemoteSession\n+from .ssh_session import SSHSession\n+\n+\n+def create_remote_session(\n+    node_config: NodeConfiguration, name: str, logger: DTSLOG\n+) -> RemoteSession:\n+    return SSHSession(node_config, name, logger)\ndiff --git a/dts/framework/remote_session/ssh_session.py b/dts/framework/remote_session/ssh_session.py\nnew file mode 100644\nindex 0000000000..7ec327054d\n--- /dev/null\n+++ b/dts/framework/remote_session/ssh_session.py\n@@ -0,0 +1,184 @@\n+# SPDX-License-Identifier: BSD-3-Clause\n+# Copyright(c) 2010-2014 Intel Corporation\n+# Copyright(c) 2022 PANTHEON.tech s.r.o.\n+# Copyright(c) 2022 University of New Hampshire\n+\n+import time\n+\n+from pexpect import pxssh  # type: ignore\n+\n+from framework.config import NodeConfiguration\n+from framework.exception import SSHConnectionError, SSHSessionDeadError, SSHTimeoutError\n+from framework.logger import DTSLOG\n+from framework.utils import GREEN, RED\n+\n+from .remote_session import RemoteSession\n+\n+\n+class SSHSession(RemoteSession):\n+    \"\"\"\n+    Module for creating Pexpect SSH sessions to a node.\n+    \"\"\"\n+\n+    session: pxssh.pxssh\n+    magic_prompt: str\n+\n+    def __init__(\n+        self,\n+        node_config: NodeConfiguration,\n+        session_name: str,\n+        logger: DTSLOG,\n+    ):\n+        self.magic_prompt = \"MAGIC PROMPT\"\n+        super(SSHSession, self).__init__(node_config, session_name, logger)\n+\n+    def _connect(self) -> None:\n+        \"\"\"\n+        Create connection to assigned node.\n+        \"\"\"\n+        retry_attempts = 10\n+        login_timeout = 20 if self.port else 10\n+        password_regex = (\n+            r\"(?i)(?:password:)|(?:passphrase for key)|(?i)(password for .+:)\"\n+        )\n+        try:\n+            for retry_attempt in range(retry_attempts):\n+                self.session = pxssh.pxssh(encoding=\"utf-8\")\n+                try:\n+                    self.session.login(\n+                        self.ip,\n+                        self.username,\n+                        self.password,\n+                        original_prompt=\"[$#>]\",\n+                        port=self.port,\n+                        login_timeout=login_timeout,\n+                        password_regex=password_regex,\n+                    )\n+                    break\n+                except Exception as e:\n+                    self.logger.warning(e)\n+                    time.sleep(2)\n+                    self.logger.info(\n+                        f\"Retrying connection: retry number {retry_attempt + 1}.\"\n+                    )\n+            else:\n+                raise Exception(f\"Connection to {self.hostname} failed\")\n+\n+            self.send_expect(\"stty -echo\", \"#\")\n+            self.send_expect(\"stty columns 1000\", \"#\")\n+        except Exception as e:\n+            self.logger.error(RED(str(e)))\n+            if getattr(self, \"port\", None):\n+                suggestion = (\n+                    f\"\\nSuggestion: Check if the firewall on {self.hostname} is \"\n+                    f\"stopped.\\n\"\n+                )\n+                self.logger.info(GREEN(suggestion))\n+\n+            raise SSHConnectionError(self.hostname)\n+\n+    def send_expect(\n+        self, command: str, prompt: str, timeout: float = 15, verify: bool = False\n+    ) -> str | int:\n+        try:\n+            ret = self.send_expect_base(command, prompt, timeout)\n+            if verify:\n+                ret_status = self.send_expect_base(\"echo $?\", prompt, timeout)\n+                try:\n+                    retval = int(ret_status)\n+                    if retval:\n+                        self.logger.error(f\"Command: {command} failure!\")\n+                        self.logger.error(ret)\n+                        return retval\n+                    else:\n+                        return ret\n+                except ValueError:\n+                    return ret\n+            else:\n+                return ret\n+        except Exception as e:\n+            self.logger.error(\n+                f\"Exception happened in [{command}] and output is \"\n+                f\"[{self._get_output()}]\"\n+            )\n+            raise e\n+\n+    def send_expect_base(self, command: str, prompt: str, timeout: float) -> str:\n+        self._clean_session()\n+        original_prompt = self.session.PROMPT\n+        self.session.PROMPT = prompt\n+        self._send_line(command)\n+        self._prompt(command, timeout)\n+\n+        before = self._get_output()\n+        self.session.PROMPT = original_prompt\n+        return before\n+\n+    def _clean_session(self) -> None:\n+        self.session.PROMPT = self.magic_prompt\n+        self.get_output(timeout=0.01)\n+        self.session.PROMPT = self.session.UNIQUE_PROMPT\n+\n+    def _send_line(self, command: str) -> None:\n+        if not self.is_alive():\n+            raise SSHSessionDeadError(self.hostname)\n+        if len(command) == 2 and command.startswith(\"^\"):\n+            self.session.sendcontrol(command[1])\n+        else:\n+            self.session.sendline(command)\n+\n+    def _prompt(self, command: str, timeout: float) -> None:\n+        if not self.session.prompt(timeout):\n+            raise SSHTimeoutError(command, self._get_output()) from None\n+\n+    def get_output(self, timeout: float = 15) -> str:\n+        \"\"\"\n+        Get all output before timeout\n+        \"\"\"\n+        try:\n+            self.session.prompt(timeout)\n+        except Exception:\n+            pass\n+\n+        before = self._get_output()\n+        self._flush()\n+\n+        return before\n+\n+    def _get_output(self) -> str:\n+        if not self.is_alive():\n+            raise SSHSessionDeadError(self.hostname)\n+        before = self.session.before.rsplit(\"\\r\\n\", 1)[0]\n+        if before == \"[PEXPECT]\":\n+            return \"\"\n+        return before\n+\n+    def _flush(self) -> None:\n+        \"\"\"\n+        Clear all session buffer\n+        \"\"\"\n+        self.session.buffer = \"\"\n+        self.session.before = \"\"\n+\n+    def is_alive(self) -> bool:\n+        return self.session.isalive()\n+\n+    def _send_command(self, command: str, timeout: float) -> str:\n+        try:\n+            self._clean_session()\n+            self._send_line(command)\n+        except Exception as e:\n+            raise e\n+\n+        output = self.get_output(timeout=timeout)\n+        self.session.PROMPT = self.session.UNIQUE_PROMPT\n+        self.session.prompt(0.1)\n+\n+        return output\n+\n+    def _close(self, force: bool = False) -> None:\n+        if force is True:\n+            self.session.close()\n+        else:\n+            if self.is_alive():\n+                self.session.logout()\ndiff --git a/dts/framework/utils.py b/dts/framework/utils.py\nnew file mode 100644\nindex 0000000000..9c1975a22f\n--- /dev/null\n+++ b/dts/framework/utils.py\n@@ -0,0 +1,12 @@\n+# SPDX-License-Identifier: BSD-3-Clause\n+# Copyright(c) 2010-2014 Intel Corporation\n+# Copyright(c) 2022 PANTHEON.tech s.r.o.\n+# Copyright(c) 2022 University of New Hampshire\n+\n+\n+def GREEN(text: str) -> str:\n+    return f\"\\u001B[32;1m{str(text)}\\u001B[0m\"\n+\n+\n+def RED(text: str) -> str:\n+    return f\"\\u001B[31;1m{str(text)}\\u001B[0m\"\n",
    "prefixes": [
        "v8",
        "6/9"
    ]
}