Blame SOURCES/0000-Issue-50712-Version-comparison-doesn-t-work-correctl.patch

8394b4
From b823da0b0e3f02a7972ebec4e714877d2ee2170e Mon Sep 17 00:00:00 2001
8394b4
From: Viktor Ashirov <vashirov@redhat.com>
8394b4
Date: Fri, 15 Nov 2019 11:55:07 +0100
8394b4
Subject: [PATCH 1/2] Issue 50712 - Version comparison doesn't work correctly
8394b4
 on git builds
8394b4
8394b4
Bug Description:
8394b4
`python3-packaging` is not shipped in RHEL8. But it's bundled with
8394b4
`setuptools` which is present in all major distributions.
8394b4
8394b4
Fix Description:
8394b4
Use `pkg_resources` module from `setuptools` which provides needed
8394b4
functionality, change lib389 and rpm dependencies accordingly.
8394b4
8394b4
Unfortunately, `pkg_resources.parse_version()` returns different
8394b4
objects for different strings too, so use `LegacyVersion` directly
8394b4
from `pkg_resources.extern.packaging.version`.
8394b4
8394b4
Fixes:   https://pagure.io/389-ds-base/issue/50712
8394b4
Relates: https://pagure.io/389-ds-base/issue/50706
8394b4
---
8394b4
 rpm/389-ds-base.spec.in               |  2 +-
8394b4
 src/lib389/lib389/tests/utils_test.py | 29 +++++++++++++++++++++++++++
8394b4
 src/lib389/lib389/utils.py            | 11 +++++-----
8394b4
 src/lib389/requirements.txt           |  2 +-
8394b4
 src/lib389/setup.py                   |  2 +-
8394b4
 5 files changed, 38 insertions(+), 8 deletions(-)
8394b4
8394b4
diff --git a/rpm/389-ds-base.spec.in b/rpm/389-ds-base.spec.in
8394b4
index e60b0f3c5..6f4a1e1a9 100644
8394b4
--- a/rpm/389-ds-base.spec.in
8394b4
+++ b/rpm/389-ds-base.spec.in
8394b4
@@ -130,7 +130,6 @@ BuildRequires:    python%{python3_pkgversion}-argcomplete
8394b4
 BuildRequires:    python%{python3_pkgversion}-argparse-manpage
8394b4
 BuildRequires:    python%{python3_pkgversion}-policycoreutils
8394b4
 BuildRequires:    python%{python3_pkgversion}-libselinux
8394b4
-BuildRequires:    python%{python3_pkgversion}-packaging
8394b4
 
8394b4
 # For cockpit
8394b4
 BuildRequires:    rsync
8394b4
@@ -303,6 +302,7 @@ Requires: python%{python3_pkgversion}-pyasn1-modules
8394b4
 Requires: python%{python3_pkgversion}-dateutil
8394b4
 Requires: python%{python3_pkgversion}-argcomplete
8394b4
 Requires: python%{python3_pkgversion}-libselinux
8394b4
+Requires: python%{python3_pkgversion}-setuptools
8394b4
 %{?python_provide:%python_provide python%{python3_pkgversion}-lib389}
8394b4
 
8394b4
 %description -n python%{python3_pkgversion}-lib389
8394b4
diff --git a/src/lib389/lib389/tests/utils_test.py b/src/lib389/lib389/tests/utils_test.py
8394b4
index 5378066b6..a696eb5c9 100644
8394b4
--- a/src/lib389/lib389/tests/utils_test.py
8394b4
+++ b/src/lib389/lib389/tests/utils_test.py
8394b4
@@ -145,6 +145,35 @@ def test_get_log_data(data):
8394b4
     assert display_log_data(before) == after
8394b4
 
8394b4
 
8394b4
+@pytest.mark.parametrize('ds_ver, cmp_ver', [
8394b4
+    ('1.3.1', '1.3.2'),
8394b4
+    ('1.3.1', '1.3.10'),
8394b4
+    ('1.3.2', '1.3.10'),
8394b4
+    ('1.3.9', ('1.3.10', '1.4.2.0')),
8394b4
+    ('1.4.0.1', ('1.3.9', '1.4.1.0', '1.4.2.1')),
8394b4
+    ('1.4.1', '1.4.2.0-20191115gitbadc0ffee' ),
8394b4
+])
8394b4
+def test_ds_is_older_versions(ds_ver, cmp_ver):
8394b4
+    if isinstance(cmp_ver, tuple):
8394b4
+        assert ds_is_related('older', ds_ver, *cmp_ver)
8394b4
+    else:
8394b4
+        assert ds_is_related('older', ds_ver, cmp_ver)
8394b4
+
8394b4
+@pytest.mark.parametrize('ds_ver, cmp_ver', [
8394b4
+    ('1.3.2', '1.3.1'),
8394b4
+    ('1.3.10', '1.3.1'),
8394b4
+    ('1.3.10', '1.3.2'),
8394b4
+    ('1.3.10', ('1.3.9', '1.4.2.0')),
8394b4
+    ('1.4.2.1', ('1.3.9', '1.4.0.1', '1.4.2.0')),
8394b4
+    ('1.4.2.0-20191115gitbadc0ffee', '1.4.1' ),
8394b4
+])
8394b4
+def test_ds_is_newer_versions(ds_ver, cmp_ver):
8394b4
+    if isinstance(cmp_ver, tuple):
8394b4
+        assert ds_is_related('newer', ds_ver, *cmp_ver)
8394b4
+    else:
8394b4
+        assert ds_is_related('newer', ds_ver, cmp_ver)
8394b4
+
8394b4
+
8394b4
 if __name__ == "__main__":
8394b4
     CURRENT_FILE = os.path.realpath(__file__)
8394b4
     pytest.main("-s -v %s" % CURRENT_FILE)
8394b4
diff --git a/src/lib389/lib389/utils.py b/src/lib389/lib389/utils.py
8394b4
index 3234cdccb..b9eacfdea 100644
8394b4
--- a/src/lib389/lib389/utils.py
8394b4
+++ b/src/lib389/lib389/utils.py
8394b4
@@ -40,7 +40,7 @@ import shlex
8394b4
 import operator
8394b4
 import subprocess
8394b4
 import math
8394b4
-from packaging.version import LegacyVersion
8394b4
+from pkg_resources.extern.packaging.version import LegacyVersion
8394b4
 from socket import getfqdn
8394b4
 from ldapurl import LDAPUrl
8394b4
 from contextlib import closing
8394b4
@@ -1067,13 +1067,12 @@ def get_ds_version():
8394b4
     return p.version
8394b4
 
8394b4
 
8394b4
-def ds_is_related(relation, *ver):
8394b4
+def ds_is_related(relation, ds_ver, *ver):
8394b4
     """
8394b4
     Return a result of a comparison between the current version of ns-slapd and a provided version.
8394b4
     """
8394b4
     ops = {'older': operator.lt,
8394b4
            'newer': operator.ge}
8394b4
-    ds_ver = get_ds_version()
8394b4
     if len(ver) > 1:
8394b4
         for cmp_ver in ver:
8394b4
             if cmp_ver.startswith(ds_ver[:3]):
8394b4
@@ -1086,14 +1085,16 @@ def ds_is_older(*ver):
8394b4
     """
8394b4
     Return True if the current version of ns-slapd is older than a provided version
8394b4
     """
8394b4
-    return ds_is_related('older', *ver)
8394b4
+    ds_ver = get_ds_version()
8394b4
+    return ds_is_related('older', ds_ver, *ver)
8394b4
 
8394b4
 
8394b4
 def ds_is_newer(*ver):
8394b4
     """
8394b4
     Return True if the current version of ns-slapd is newer than a provided version
8394b4
     """
8394b4
-    return ds_is_related('newer', *ver)
8394b4
+    ds_ver = get_ds_version()
8394b4
+    return ds_is_related('newer', ds_ver, *ver)
8394b4
 
8394b4
 
8394b4
 def gentime_to_datetime(gentime):
8394b4
diff --git a/src/lib389/requirements.txt b/src/lib389/requirements.txt
8394b4
index 5cce1d04b..eb2475f3b 100644
8394b4
--- a/src/lib389/requirements.txt
8394b4
+++ b/src/lib389/requirements.txt
8394b4
@@ -6,4 +6,4 @@ six
8394b4
 argcomplete
8394b4
 argparse-manpage
8394b4
 python-ldap
8394b4
-packaging
8394b4
+setuptools
8394b4
diff --git a/src/lib389/setup.py b/src/lib389/setup.py
8394b4
index f2e404333..056173936 100644
8394b4
--- a/src/lib389/setup.py
8394b4
+++ b/src/lib389/setup.py
8394b4
@@ -82,7 +82,7 @@ setup(
8394b4
         'argcomplete',
8394b4
         'argparse-manpage',
8394b4
         'python-ldap',
8394b4
-        'packaging',
8394b4
+        'setuptools',
8394b4
         ],
8394b4
 
8394b4
     cmdclass={
8394b4
-- 
8394b4
2.21.0
8394b4