From ac2e3e931e62d5ac03fabcda56f9438d759715f8 Mon Sep 17 00:00:00 2001 From: Philippe Pepiot Date: Sat, 29 Mar 2025 09:10:28 +0100 Subject: [PATCH 1/4] Fix tests failing due to expiration date passed We can't login once expiration date is reached, so bump it to 2030-01-01 --- images/debian_bookworm/Dockerfile | 2 +- test/test_modules.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/images/debian_bookworm/Dockerfile b/images/debian_bookworm/Dockerfile index 8fc65c15..940c97d5 100644 --- a/images/debian_bookworm/Dockerfile +++ b/images/debian_bookworm/Dockerfile @@ -58,7 +58,7 @@ RUN echo "user:foo" | chpasswd RUN echo "*nat\n:PREROUTING ACCEPT [0:0]\n:INPUT ACCEPT [0:0]\n:OUTPUT ACCEPT [0:0]\n:POSTROUTING ACCEPT [0:0]\n-A PREROUTING -d 192.168.0.1/32 -j REDIRECT\nCOMMIT\n*filter\n:INPUT ACCEPT [0:0]\n:FORWARD ACCEPT [0:0]\n:OUTPUT ACCEPT [0:0]\n-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT\nCOMMIT" > /etc/iptables/rules.v4 # Expiration date for user "user" -RUN chage -E 20000 -m 7 -M 90 user +RUN chage -E 2030-01-01 -m 7 -M 90 user # Some python3 virtualenv RUN virtualenv /v diff --git a/test/test_modules.py b/test/test_modules.py index 15416344..2b53b996 100644 --- a/test/test_modules.py +++ b/test/test_modules.py @@ -246,7 +246,7 @@ def test_user_user(host): def test_user_expiration_date(host): assert host.user("root").expiration_date is None - assert host.user("user").expiration_date == (datetime.datetime(2024, 10, 4, 0, 0)) + assert host.user("user").expiration_date == datetime.datetime(2030, 1, 1) def test_nonexistent_user(host): From bc07842b2c59afaf1b57fc5a4c2b1d44a7016d11 Mon Sep 17 00:00:00 2001 From: Philippe Pepiot Date: Sat, 29 Mar 2025 11:51:57 +0100 Subject: [PATCH 2/4] Follow changes in ansible shell module Now stdout/stderr lives in json encoded module_stdout key. --- test/test_backends.py | 5 +++-- testinfra/backend/ansible.py | 16 ++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/test/test_backends.py b/test/test_backends.py index c3b717d5..2b11157a 100644 --- a/test/test_backends.py +++ b/test/test_backends.py @@ -86,8 +86,9 @@ def test_encoding(host): elif host.backend.get_connection_type() == "ansible" and host.backend.force_ansible: # XXX: this encoding issue comes directly from ansible # not sure how to handle this... - assert cmd.stderr == ( - "ls: impossible d'accéder à '/é': " "Aucun fichier ou dossier de ce type" + assert ( + cmd.stderr + == "ls: impossible d'acc\udce9der \udce0 '/é': Aucun fichier ou dossier de ce type" ) else: assert cmd.stderr_bytes == ( diff --git a/testinfra/backend/ansible.py b/testinfra/backend/ansible.py index 61bf25f8..70079f76 100644 --- a/testinfra/backend/ansible.py +++ b/testinfra/backend/ansible.py @@ -10,6 +10,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import json import logging import pprint from typing import Any, Optional @@ -56,12 +57,15 @@ def run(self, command: str, *args: str, **kwargs: Any) -> base.CommandResult: if host is not None: return host.run(command) out = self.run_ansible("shell", module_args=command, check=False) - return self.result( - out["rc"], - self.encode(command), - out["stdout"], - out["stderr"], - ) + if "module_stdout" in out: + data = json.loads(out["module_stdout"]) + stdout = data["stdout"] + stderr = data["stderr"] + else: + # bw compat + stdout = out["stdout"] + stderr = out["stderr"] + return self.result(out["rc"], self.encode(command), stdout, stderr) def run_ansible( self, module_name: str, module_args: Optional[str] = None, **kwargs: Any From 58680e894faae1afe1af6bec1826ca6fd750583d Mon Sep 17 00:00:00 2001 From: Philippe Pepiot Date: Sat, 29 Mar 2025 11:52:48 +0100 Subject: [PATCH 3/4] Fix salt tests Seems salt python package doesn't pull its dependencies... So install them manually, at least thoses required use salt.client python api. --- images/debian_bookworm/Dockerfile | 7 +------ test-requirements.txt | 7 ++++++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/images/debian_bookworm/Dockerfile b/images/debian_bookworm/Dockerfile index 940c97d5..d6b4d5f8 100644 --- a/images/debian_bookworm/Dockerfile +++ b/images/debian_bookworm/Dockerfile @@ -66,12 +66,7 @@ RUN /v/bin/pip install -U pip RUN /v/bin/pip install 'requests==2.30.0' # install salt -ARG _BUILD_DEPS="gcc g++ libc6-dev python3-dev" -RUN apt update && apt install -y $_BUILD_DEPS && \ - python3 -m pip install --break-system-packages --no-cache salt && \ - apt -y purge $_BUILD_DEPS && \ - apt -y autoremove --purge && \ - rm -rf /var/lib/apt/lists/* +RUN python3 -m pip install --break-system-packages --no-cache salt tornado distro looseversion msgpack pyyaml packaging jinja2 ENV LANG fr_FR.ISO-8859-15 ENV LANGUAGE fr_FR diff --git a/test-requirements.txt b/test-requirements.txt index afc3067f..577601ff 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,6 +2,11 @@ pytest-cov pytest-xdist paramiko types-paramiko -salt pywinrm ansible +salt +# XXX: salt.client dependencies +tornado +distro +looseversion +msgpack From d07873b9f352d9d706c95e0e114b1c420319b9b3 Mon Sep 17 00:00:00 2001 From: Philippe Pepiot Date: Sat, 29 Mar 2025 12:00:38 +0100 Subject: [PATCH 4/4] Use python 3.11 during tests --- .github/workflows/release.yml | 4 ++-- .github/workflows/tox.yml | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ce6e0bc2..43480215 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,10 +19,10 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 # needed by setuptools-scm - - name: Switch to using Python 3.9 by default + - name: Switch to using Python 3.11 by default uses: actions/setup-python@v5 with: - python-version: "3.9" + python-version: "3.11" - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index c9dc37ad..d9ce3307 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -43,13 +43,13 @@ jobs: strategy: fail-fast: false matrix: - toxenv: [docs, packaging, py39] + toxenv: [docs, packaging, py311] steps: - uses: actions/checkout@v4 - - name: Set up Python 3.9 + - name: Set up Python 3.11 uses: actions/setup-python@v5 with: - python-version: "3.9" + python-version: "3.11" - name: Install dependencies run: | python -m pip install --upgrade pip