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

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