From 786f00d8de9c5b012e58b6c150e5947833ef06ad Mon Sep 17 00:00:00 2001 From: Jacob Callahan Date: Thu, 7 Mar 2024 16:58:39 -0500 Subject: [PATCH] Revert ssh2-python submodule This change reverts those introduced to add submodule-based inclusion of the ssh2-python dependency. Additionally, I added a attempt to reconnect to dead sessions (when servers reboot). --- .github/workflows/codeql-analysis.yml | 3 --- .github/workflows/python-publish.yml | 4 ---- .gitmodules | 3 --- Dockerfile | 7 +++---- broker/session.py | 10 +++++++++- broker/vendored/ssh2-python | 1 - pyproject.toml | 3 ++- 7 files changed, 14 insertions(+), 17 deletions(-) delete mode 100644 .gitmodules delete mode 160000 broker/vendored/ssh2-python diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 6fc3dc24..2f23d890 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -25,8 +25,6 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 - with: - submodules: recursive - name: Initialize CodeQL uses: github/codeql-action/init@v3 @@ -50,7 +48,6 @@ jobs: - name: Unit Tests env: BROKER_DIRECTORY: "${{ github.workspace }}/broker_dir" - PWD: "${{ github.workspace }}" run: | pip install uv uv venv diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index bd706a9d..08469c6e 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -17,16 +17,12 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Setup and Build - env: - PWD: "${{ github.workspace }}" run: | pip install uv uv venv diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index c8001c9a..00000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "broker/vendored/ssh2-python"] - path = broker/vendored/ssh2-python - url = https://github.com/jacobcallahan/ssh2-python.git diff --git a/Dockerfile b/Dockerfile index 096ccc25..34c60bb8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,16 @@ FROM fedora MAINTAINER https://github.com/SatelliteQE -ENV PWD /root/broker - RUN dnf -y install make cmake gcc-c++ zlib-devel \ openssl-devel git python3-pip python3-devel which\ && dnf clean all -WORKDIR $PWD -COPY . $PWD +WORKDIR /root/broker +COPY . /root/broker RUN pip install uv +RUN uv venv && source .venv/bin/activate RUN uv pip install -e . ENTRYPOINT ["broker"] diff --git a/broker/session.py b/broker/session.py index 4f3a5ea8..f6ed3b68 100644 --- a/broker/session.py +++ b/broker/session.py @@ -19,6 +19,7 @@ try: from ssh2 import sftp as ssh2_sftp + from ssh2.exceptions import SocketSendError from ssh2.session import Session as ssh2_Session SFTP_MODE = ( @@ -160,7 +161,14 @@ def _read(channel): def run(self, command, timeout=0): """Run a command on the host and return the results.""" self.session.set_timeout(helpers.translate_timeout(timeout)) - channel = self.session.open_session() + try: + channel = self.session.open_session() + except SocketSendError as err: + logger.warning( + f"Encountered connection issue. Attempting to reconnect and retry.\n{err}" + ) + del self._session + channel = self.session.open_session() channel.execute( command, ) diff --git a/broker/vendored/ssh2-python b/broker/vendored/ssh2-python deleted file mode 160000 index abbbf867..00000000 --- a/broker/vendored/ssh2-python +++ /dev/null @@ -1 +0,0 @@ -Subproject commit abbbf86709046ee04b21d2b9c80d288d44c67a9c diff --git a/pyproject.toml b/pyproject.toml index 467b6d54..0818aded 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ dependencies = [ "packaging", "pyyaml", "setuptools", - "ssh2-python @ file://${PWD}/broker/vendored/ssh2-python", + "ssh2-python@git+https://github.com/jacobcallahan/ssh2-python.git", ] dynamic = ["version"] # dynamic fields to update on build - version via setuptools_scm @@ -152,6 +152,7 @@ ignore = [ "D213", # Multi-line docstring summary should start at the second line "D406", # Section name should end with a newline "D407", # Section name underlining + "D413", # Missing blank line after last section "E501", # line too long "E731", # do not assign a lambda expression, use a def "PLR0913", # Too many arguments to function call ({c_args} > {max_args})