Skip to content

Commit bb0d266

Browse files
authored
Merge pull request #7499 from chaen/v8.0_fix_flaky
[8.0] use pytest-reruns instead of flaky
2 parents 3eef22c + 0768ab5 commit bb0d266

File tree

5 files changed

+34
-21
lines changed

5 files changed

+34
-21
lines changed

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ dependencies:
6363
- pytest >=3.6
6464
- pytest-cov >=2.2.0
6565
- pytest-mock
66+
- pytest-rerunfailures
6667
- setuptools-scm
6768
- shellcheck
6869
- typer
6970
- typer-cli
70-
- flaky
7171
# docs
7272
- pygments >=1.5
7373
- sphinx

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ server =
8585
tornado-m2crypto
8686
importlib_resources
8787
testing =
88-
flaky
8988
hypothesis
9089
mock
9190
parameterized
9291
pytest
9392
pytest-cov
9493
pytest-mock
94+
pytest-rerunfailures
9595
pycodestyle
9696

9797
[options.entry_points]

src/DIRAC/Core/DISET/private/Transports/SSL/M2Utils.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
"""
55
import os
66
import tempfile
7+
import M2Crypto
8+
from packaging.version import Version
79
from M2Crypto import SSL, m2, X509
810

11+
912
from DIRAC.Core.DISET import DEFAULT_SSL_CIPHERS, DEFAULT_SSL_METHODS
1013
from DIRAC.Core.Security import Locations
1114
from DIRAC.Core.Security.m2crypto.X509Chain import X509Chain
@@ -15,6 +18,30 @@
1518
DEBUG_M2CRYPTO = os.getenv("DIRAC_DEBUG_M2CRYPTO", "No").lower() in ("yes", "true")
1619

1720

21+
VERIFY_ALLOW_PROXY_CERTS = 0
22+
23+
# If the version of M2Crypto is recent enough, there is an API
24+
# to accept proxy certificate, and we do not need to rely on
25+
# OPENSSL_ALLOW_PROXY_CERT environment variable
26+
# which was removed as of openssl 1.1
27+
# We need this to be merged in M2Crypto: https://gitlab.com/m2crypto/m2crypto/merge_requests/236
28+
# We set the proper verify flag to the X509Store of the context
29+
# as described here https://www.openssl.org/docs/man1.1.1/man7/proxy-certificates.html
30+
if hasattr(SSL, "verify_allow_proxy_certs"):
31+
VERIFY_ALLOW_PROXY_CERTS = SSL.verify_allow_proxy_certs # pylint: disable=no-member
32+
# As of M2Crypto 0.37, the `verify_allow_proxy_certs` flag was moved
33+
# to X509 (https://gitlab.com/m2crypto/m2crypto/-/merge_requests/238)
34+
# It is more consistent with all the other flags,
35+
# but pySSL had it in SSL. Well...
36+
elif hasattr(X509, "verify_allow_proxy_certs"):
37+
VERIFY_ALLOW_PROXY_CERTS = X509.verify_allow_proxy_certs # pylint: disable=no-member
38+
# As of M2Crypto 0.38, M2Crypto did not export the symbol correctly
39+
# Anymore
40+
# https://gitlab.com/m2crypto/m2crypto/-/issues/298
41+
elif Version(M2Crypto.__version__) >= Version("0.38.0"):
42+
VERIFY_ALLOW_PROXY_CERTS = 64
43+
44+
1845
def __loadM2SSLCTXHostcert(ctx):
1946
"""Load hostcert & key from the default location and set them as the
2047
credentials for SSL context ctx.
@@ -125,21 +152,9 @@ def getM2SSLContext(ctx=None, **kwargs):
125152
raise RuntimeError(f"CA path ({caPath}) is not a valid directory")
126153
ctx.load_verify_locations(capath=caPath)
127154

128-
# If the version of M2Crypto is recent enough, there is an API
129-
# to accept proxy certificate, and we do not need to rely on
130-
# OPENSSL_ALLOW_PROXY_CERT environment variable
131-
# which was removed as of openssl 1.1
132-
# We need this to be merged in M2Crypto: https://gitlab.com/m2crypto/m2crypto/merge_requests/236
133-
# We set the proper verify flag to the X509Store of the context
134-
# as described here https://www.openssl.org/docs/man1.1.1/man7/proxy-certificates.html
135-
if hasattr(SSL, "verify_allow_proxy_certs"):
136-
ctx.get_cert_store().set_flags(SSL.verify_allow_proxy_certs) # pylint: disable=no-member
137-
# As of M2Crypto 0.37, the `verify_allow_proxy_certs` flag was moved
138-
# to X509 (https://gitlab.com/m2crypto/m2crypto/-/merge_requests/238)
139-
# It is more consistent with all the other flags,
140-
# but pySSL had it in SSL. Well...
141-
if hasattr(X509, "verify_allow_proxy_certs"):
142-
ctx.get_cert_store().set_flags(X509.verify_allow_proxy_certs) # pylint: disable=no-member
155+
# Allow proxy certificates to be used
156+
if VERIFY_ALLOW_PROXY_CERTS:
157+
ctx.get_cert_store().set_flags(VERIFY_ALLOW_PROXY_CERTS)
143158

144159
# Other parameters
145160
sslMethods = kwargs.get("sslMethods", DEFAULT_SSL_METHODS)

src/DIRAC/Core/Utilities/test/Test_Profiler.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from subprocess import Popen
66

77
import pytest
8-
from flaky import flaky
98

109
import DIRAC
1110
from DIRAC.Core.Utilities.Profiler import Profiler
@@ -78,7 +77,7 @@ def test_base():
7877
assert resWC["Value"] >= res["Value"]
7978

8079

81-
@flaky(max_runs=10, min_passes=2)
80+
@pytest.mark.flaky(reruns=10)
8281
def test_cpuUsage():
8382
mainProcess = Popen(
8483
[

src/DIRAC/FrameworkSystem/private/standardLogging/test/Test_Logging_GetSubLogger.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Test SubLogger
33
"""
44
import pytest
5-
from flaky import flaky
65
from DIRAC.FrameworkSystem.private.standardLogging.LogLevels import LogLevels
76

87

@@ -52,7 +51,7 @@ def test_getSubLoggerObject():
5251
# Run the tests for all the log levels and exceptions
5352
# We may need to rerun the test if we are unlucky and the timestamps
5453
# don't match
55-
@flaky(max_runs=3)
54+
@pytest.mark.flaky(reruns=3)
5655
@pytest.mark.parametrize("logLevel", ["exception"] + [lvl.lower() for lvl in LogLevels.getLevelNames()])
5756
def test_localSubLoggerObject(logLevel):
5857
"""

0 commit comments

Comments
 (0)