From patchwork Fri May 17 18:47:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Maximets X-Patchwork-Id: 1936602 X-Patchwork-Delegate: i.maximets@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VgwsC39CQz1yfq for ; Sat, 18 May 2024 04:46:07 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id D3D2182F92; Fri, 17 May 2024 18:46:04 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id apvyZaBYCxwd; Fri, 17 May 2024 18:46:04 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.9.56; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org AC0E782F20 Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id AC0E782F20; Fri, 17 May 2024 18:46:03 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 83385C007C; Fri, 17 May 2024 18:46:03 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 8DE8CC0037 for ; Fri, 17 May 2024 18:46:01 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 8911C8221E for ; Fri, 17 May 2024 18:46:01 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id oJPWaFPtSPCN for ; Fri, 17 May 2024 18:46:01 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=217.70.183.196; helo=relay4-d.mail.gandi.net; envelope-from=i.maximets@ovn.org; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp1.osuosl.org ABDBD81FC1 Authentication-Results: smtp1.osuosl.org; dmarc=none (p=none dis=none) header.from=ovn.org DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org ABDBD81FC1 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by smtp1.osuosl.org (Postfix) with ESMTPS id ABDBD81FC1 for ; Fri, 17 May 2024 18:46:00 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 50312E0004; Fri, 17 May 2024 18:45:58 +0000 (UTC) From: Ilya Maximets To: ovs-dev@openvswitch.org Date: Fri, 17 May 2024 20:47:11 +0200 Message-ID: <20240517184716.133519-2-i.maximets@ovn.org> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240517184716.133519-1-i.maximets@ovn.org> References: <20240517184716.133519-1-i.maximets@ovn.org> MIME-Version: 1.0 X-GND-Sasl: i.maximets@ovn.org Cc: Ilya Maximets Subject: [ovs-dev] [PATCH 1/2] atlocal: Fix setting HAVE_PYTEST on unexpected errors. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" If the python script throws an unexpected exception, the HAVE_PYTEST variable remains undefined. If at the same time dependencies are not actually present, pytest tests will fail instead of being skipped. Define the variable to 'no' on unexpected failures to skip the tests when dependencies cannot be verified. The issue can be reproduced on systems with python 3.12+ in case the deprecated 'pkg_resources' module is not available. Fixes: 445dceb88461 ("python: Introduce unit tests.") Signed-off-by: Ilya Maximets Acked-by: Eelco Chaudron --- tests/atlocal.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/atlocal.in b/tests/atlocal.in index f321bae55..466fd4ed4 100644 --- a/tests/atlocal.in +++ b/tests/atlocal.in @@ -242,5 +242,6 @@ with pathlib.Path(os.path.join(os.getenv("REQUIREMENT_PATH"))).open() as reqs: case $? in 0) HAVE_PYTEST=yes ;; 2) HAVE_PYTEST=no ;; - *) echo "$0: unexpected error probing Python unit test requirements" >&2 ;; + *) HAVE_PYTEST=no + echo "$0: unexpected error probing Python unit test requirements" >&2 ;; esac From patchwork Fri May 17 18:47:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Maximets X-Patchwork-Id: 1936603 X-Patchwork-Delegate: i.maximets@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VgwsF513dz1yfq for ; Sat, 18 May 2024 04:46:09 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id EA13F407CE; Fri, 17 May 2024 18:46:07 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id l7RqL5_mZDOX; Fri, 17 May 2024 18:46:06 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.9.56; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org B98E04079F Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id B98E04079F; Fri, 17 May 2024 18:46:06 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 91FA1C0077; Fri, 17 May 2024 18:46:06 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id EE549C007C for ; Fri, 17 May 2024 18:46:04 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id D9F446083C for ; Fri, 17 May 2024 18:46:04 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 1E4q1yeiVxwv for ; Fri, 17 May 2024 18:46:03 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=217.70.183.196; helo=relay4-d.mail.gandi.net; envelope-from=i.maximets@ovn.org; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org 7C84B60825 Authentication-Results: smtp3.osuosl.org; dmarc=none (p=none dis=none) header.from=ovn.org DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 7C84B60825 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by smtp3.osuosl.org (Postfix) with ESMTPS id 7C84B60825 for ; Fri, 17 May 2024 18:46:03 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 95FB1E0002; Fri, 17 May 2024 18:46:01 +0000 (UTC) From: Ilya Maximets To: ovs-dev@openvswitch.org Date: Fri, 17 May 2024 20:47:12 +0200 Message-ID: <20240517184716.133519-3-i.maximets@ovn.org> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240517184716.133519-1-i.maximets@ovn.org> References: <20240517184716.133519-1-i.maximets@ovn.org> MIME-Version: 1.0 X-GND-Spam-Score: 300 X-GND-Status: SPAM X-GND-Sasl: i.maximets@ovn.org Cc: Ilya Maximets Subject: [ovs-dev] [PATCH 2/2] atlocal: Replace deprecated pkg_resources. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" 'pkg_resources' module is deprecated and no longer available in newer versions of python, so pytest tests are skipped: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html Unfortunately, there is no direct replacement for it and functionality is scattered between different packages. Using a new standard library importlib.metadata to find installed packages and their versions. Using packaging.requirements to parse lines from the requirements file and compare versions. This covers all we need. The 'packaging' is a project used by pip and a dependency for many other libraries, so should be available for any supported verison of python. 'importlib' was introduced in python 3.8. Since we support older versions of python and 'packaging' is not part of the standard library, checking that import is possible and falling back to 'pkg_resources' if needed. We may remove the fallback when we stop supporting python below 3.8. Even though 'packaging' is a common dependency, added to the test requirements so it will not be missed in CI. Signed-off-by: Ilya Maximets Acked-by: Eelco Chaudron --- python/test_requirements.txt | 1 + tests/atlocal.in | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/python/test_requirements.txt b/python/test_requirements.txt index 5043c71e2..a1424506b 100644 --- a/python/test_requirements.txt +++ b/python/test_requirements.txt @@ -1,4 +1,5 @@ netaddr +packaging pyftpdlib pyparsing pytest diff --git a/tests/atlocal.in b/tests/atlocal.in index 466fd4ed4..8565a0bae 100644 --- a/tests/atlocal.in +++ b/tests/atlocal.in @@ -229,15 +229,31 @@ export UBSAN_OPTIONS REQUIREMENT_PATH=$abs_top_srcdir/python/test_requirements.txt $PYTHON3 -c ' import os import pathlib -import pkg_resources import sys +PACKAGING = True +try: + from packaging import requirements + from importlib import metadata +except ModuleNotFoundError: + PACKAGING = False + import pkg_resources + with pathlib.Path(os.path.join(os.getenv("REQUIREMENT_PATH"))).open() as reqs: - for req in pkg_resources.parse_requirements(reqs): - try: - pkg_resources.require(str(req)) - except pkg_resources.DistributionNotFound: - sys.exit(2) + if PACKAGING: + for req in reqs.readlines(): + try: + r = requirements.Requirement(req.strip()) + if metadata.version(r.name) not in r.specifier: + raise metadata.PackageNotFoundError + except metadata.PackageNotFoundError: + sys.exit(2) + else: + for req in pkg_resources.parse_requirements(reqs): + try: + pkg_resources.require(str(req)) + except pkg_resources.DistributionNotFound: + sys.exit(2) ' case $? in 0) HAVE_PYTEST=yes ;;