From a8203594b358a25d7b144becbb7a0bd77e961347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zachar?= Date: Fri, 31 Oct 2025 16:59:00 +0100 Subject: [PATCH] Add gating Remove existing tests and keep just bundled testsuite. --- gating.yaml | 6 +++ plan.fmf | 18 ++++++- tests/ipv6-noproxy-cidr/main.fmf | 7 --- tests/ipv6-noproxy-cidr/repro.py | 74 ---------------------------- tests/ipv6-noproxy-cidr/server.py | 25 ---------- tests/smoke/main.fmf | 6 --- tests/smoke/runtest.sh | 54 --------------------- tests/smoke/test.py | 11 ----- tests/upstream/main.fmf | 14 ------ tests/upstream/runtest.sh | 80 ------------------------------- 10 files changed, 22 insertions(+), 273 deletions(-) create mode 100644 gating.yaml delete mode 100644 tests/ipv6-noproxy-cidr/main.fmf delete mode 100644 tests/ipv6-noproxy-cidr/repro.py delete mode 100644 tests/ipv6-noproxy-cidr/server.py delete mode 100644 tests/smoke/main.fmf delete mode 100755 tests/smoke/runtest.sh delete mode 100644 tests/smoke/test.py delete mode 100644 tests/upstream/main.fmf delete mode 100755 tests/upstream/runtest.sh diff --git a/gating.yaml b/gating.yaml new file mode 100644 index 0000000..2c7ed80 --- /dev/null +++ b/gating.yaml @@ -0,0 +1,6 @@ +--- !Policy +product_versions: + - rhel-* +decision_context: osci_compose_gate +rules: + - !PassingTestCaseRule {test_case_name: osci.brew-build.tier0.functional} diff --git a/plan.fmf b/plan.fmf index 32fd69f..b648a3b 100644 --- a/plan.fmf +++ b/plan.fmf @@ -1,5 +1,19 @@ execute: how: tmt -discover: - how: fmf + +discover: + how: shell + dist-git-source: true + + tests: + - name: unit + test: | + pip3.14 install trustme httpbin~=0.10.0 pytest-httpbin==2.1.0 "PySocks>=1.5.6, !=1.5.7" + + cd $(dirname $TMT_SOURCE_DIR/*/tests) + pytest-3.14 -v tests/ + require: + - python3.14-requests + - python3.14-pytest + - python3.14-pip diff --git a/tests/ipv6-noproxy-cidr/main.fmf b/tests/ipv6-noproxy-cidr/main.fmf deleted file mode 100644 index d1fbe51..0000000 --- a/tests/ipv6-noproxy-cidr/main.fmf +++ /dev/null @@ -1,7 +0,0 @@ -require: -- nmap-ncat -- python3 -- python3-requests - -test: "${PYTHON:-python3} repro.py" -tty: "true" diff --git a/tests/ipv6-noproxy-cidr/repro.py b/tests/ipv6-noproxy-cidr/repro.py deleted file mode 100644 index 000ca17..0000000 --- a/tests/ipv6-noproxy-cidr/repro.py +++ /dev/null @@ -1,74 +0,0 @@ -import subprocess -import requests -import os -import time -import atexit - -subprocesses = [] - -python = os.environ.get("PYTHON","python3") -server_url = os.environ.get("SERVER_URL", None) -testing_no_proxy = os.environ.get("TESTING_NO_PROXY", None) - -# Clean up -@atexit.register -def cleanup(): - print("Cleaning up subprocesses") - for process in subprocesses: - process.terminate() - - time.sleep(1) - - for process in subprocesses: - process.wait() - -# Part one, assert that everything works -if server_url is None: - print("starting server") - p = subprocess.Popen([python, "server.py"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - subprocesses.append(p) - time.sleep(1) - server_url = "http://[::1]:8888" - no_proxy = "::1/128" -else: - print(f"using provided {server_url} as server") - print(f"using provided {testing_no_proxy} as NO_PROXY value") - assert testing_no_proxy, "TESTING_NO_PROXY envar missing" - -# Send request and check the response - -print("sending first request") -assert requests.get(server_url, timeout=2).text.startswith("Hello") - - -# Part two, dummy proxy causes timeout, that's fine - -# Start proxy -print("starting proxy") -p = subprocess.Popen(["nc", "-k", "-l", "10000"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) -subprocesses.append(p) -time.sleep(1) - -# Set proxy to environment -os.environ["HTTP_PROXY"] = "http://127.0.0.1:10000" - -# Send request, expect timeout because proxy is dummy and do not respond -print("Sending request via proxy") -try: - requests.get(server_url, timeout=2) -except requests.exceptions.ReadTimeout: - print("timeout is fine, expected") - pass - -# Part three, NO_PROXY bypass the proxy and the request should work as before - -os.environ["NO_PROXY"] = testing_no_proxy or no_proxy - -print("sending last request") -try: - assert requests.get(server_url, timeout=2).text.startswith("Hello") -except requests.exceptions.ReadTimeout: - print("PROBLEM - the last request timed out, NO_PROXY setting does not work!") - raise SystemExit(1) -else: - print("OK - NO_PROXY setting works fine - the last request bypassed proxy") diff --git a/tests/ipv6-noproxy-cidr/server.py b/tests/ipv6-noproxy-cidr/server.py deleted file mode 100644 index 2d2c603..0000000 --- a/tests/ipv6-noproxy-cidr/server.py +++ /dev/null @@ -1,25 +0,0 @@ -from http.server import SimpleHTTPRequestHandler, HTTPServer -import socket -import sys -class IPv6OnlyHandler(SimpleHTTPRequestHandler): - def do_GET(self): - client_address = self.client_address[0] - # Check if the client address is an IPv6 address - if ":" in client_address: - self.send_response(200) - self.send_header('Content-type', 'text/plain') - self.end_headers() - self.wfile.write(b'Hello') - else: - # Raise a RuntimeError if the client address is an IPv4 address - raise SystemExit(f"IPv4 address ({client_address}) detected. Only IPv6 addresses are allowed.") - -class HTTPServerV6(HTTPServer): - address_family = socket.AF_INET6 - -if __name__ == '__main__': - # Use IPv6 address and port 8080 - server_address = ('::', 8888) - httpd = HTTPServerV6(server_address, IPv6OnlyHandler) - print('Server running on port 8888...') - httpd.serve_forever() diff --git a/tests/smoke/main.fmf b/tests/smoke/main.fmf deleted file mode 100644 index b10b038..0000000 --- a/tests/smoke/main.fmf +++ /dev/null @@ -1,6 +0,0 @@ -summary: Basic sanity test for python-requests -test: ./runtest.sh -framework: beakerlib -require: - - python3-requests -duration: 5m diff --git a/tests/smoke/runtest.sh b/tests/smoke/runtest.sh deleted file mode 100755 index 3a28ed0..0000000 --- a/tests/smoke/runtest.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/bash -# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# -# runtest.sh of /CoreOS/python-requests/Sanity/smoke -# Description: Basic sanity test for python-requests module. -# Author: Adam Kolar -# -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# -# Copyright (c) 2013 Red Hat, Inc. All rights reserved. -# -# This copyrighted material is made available to anyone wishing -# to use, modify, copy, or redistribute it subject to the terms -# and conditions of the GNU General Public License version 2. -# -# This program is distributed in the hope that it will be -# useful, but WITHOUT ANY WARRANTY; without even the implied -# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public -# License along with this program; if not, write to the Free -# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -# Boston, MA 02110-1301, USA. -# -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -# Include Beaker environment -. /usr/share/beakerlib/beakerlib.sh || exit 1 - -PACKAGES=${PACKAGES:-"python3-requests"} - -PYTHON=${PYTHON:-"python"} -TEST="test.py" - -rlJournalStart - rlPhaseStartSetup - rlAssertRpm --all - rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory" - rlRun "cp $TEST $TmpDir" - rlRun "pushd $TmpDir" - rlPhaseEnd - - rlPhaseStartTest - rlRun "$PYTHON $TEST" 0 "Running sanity test for python requests" - rlPhaseEnd - - rlPhaseStartCleanup - rlRun "popd" - rlRun "rm -r $TmpDir" 0 "Removing tmp directory" - rlPhaseEnd -rlJournalPrintText -rlJournalEnd diff --git a/tests/smoke/test.py b/tests/smoke/test.py deleted file mode 100644 index e296ef0..0000000 --- a/tests/smoke/test.py +++ /dev/null @@ -1,11 +0,0 @@ -import requests -from requests import * - -class ExceptionRequests(Exception): - pass - -if __name__=="__main__": - r=requests.get('https://redhat.com') - if r.status_code!=200 or \ - not r.text or r.encoding.lower() != 'utf-8': - raise ExceptionRequests("Sanity error") diff --git a/tests/upstream/main.fmf b/tests/upstream/main.fmf deleted file mode 100644 index d5d026a..0000000 --- a/tests/upstream/main.fmf +++ /dev/null @@ -1,14 +0,0 @@ -summary: Runs upstream test suite -require: - - python3-requests - - python3-pip - - python3-pytest - - python3-cryptography - - python3-devel - - python3-httpbin - - rpm-build - - gcc - - gcc-c++ -test: ./runtest.sh -framework: beakerlib -duration: 30m diff --git a/tests/upstream/runtest.sh b/tests/upstream/runtest.sh deleted file mode 100755 index 5254bd6..0000000 --- a/tests/upstream/runtest.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/bin/bash -# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# -# runtest.sh of /CoreOS/python-requests/Sanity/upstream -# Description: Runs upstream test suite -# Author: Lukas Zachar -# -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# -# Copyright (c) 2019 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing -# to use, modify, copy, or redistribute it subject to the terms -# and conditions of the GNU General Public License version 2. -# -# This program is distributed in the hope that it will be -# useful, but WITHOUT ANY WARRANTY; without even the implied -# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public -# License along with this program; if not, write to the Free -# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -# Boston, MA 02110-1301, USA. -# -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -# Include Beaker environment -. /usr/share/beakerlib/beakerlib.sh || exit 1 - -PACKAGES="${PACKAGES:-python3-requests}" -PYTHON="${PYTHON:-python}" - -rlJournalStart - rlPhaseStartSetup - rlAssertRpm --all - rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory" - rlRun "pushd $TmpDir" - - # So we can inject version of srpm - if [[ -z "$FORCE_SRPM" ]]; then - rlRun "rlFetchSrcForInstalled $(rpm --qf '%{name}' -qf $($PYTHON -c 'import requests;print(requests.__file__)'))" - else - rlRun "rlRpmDownload $FORCE_SRPM" - fi - rlRun "rpm -i --define '_topdir $TmpDir' --nodeps *rpm" - rlRun "rpmbuild -bp --define '_topdir $TmpDir' --nodeps $TmpDir/SPECS/*" - - # Remove module from extracted sources so installed one is used - rlRun "rm -rf $TmpDir/BUILD/*requests*/requests*/src" - - # pip-install libraries not in the repos - # pytest is installed in fmf requirement - rlRun "$PYTHON -m pip install pytest-mock==3.14.0 trustme==1.2.0 werkzeug==3.1.3 \ - pytest-httpbin==2.1.0" - - # Move to test dir, print what is there - rlRun "cd $(dirname $TmpDir/BUILD/*requests*/requests*/tests)" - rlRun "touch tests/requirements-dev.txt" - rlRun "find . -type f" - rlRun "yum repolist" - rlRun "$PYTHON -m pip list" - rlPhaseEnd - - rlPhaseStartTest "$EXTRA_PARAMS" - # test_unicode_header_name hangs with urllib3 < 2 - rlRun 'pytest -v -p no:warnings --junit-xml $TmpDir/result.xml -k "not test_use_proxy_from_environment and not test_unicode_header_name"' - - rlAssertGrep '