stx-update: backport a patch to remove dependency on yum 82/3582/1
authorJackie Huang <jackie.huang@windriver.com>
Mon, 4 May 2020 09:20:01 +0000 (17:20 +0800)
committerJackie Huang <jackie.huang@windriver.com>
Tue, 5 May 2020 13:57:14 +0000 (21:57 +0800)
rpmUtils.miscutils.stringToVersion is provided by yum, which is
not availble in yocto and is replaced by dnf, and it's the same
situation in the later stx release on centos 8, so backport
a patch from later stx release to remove the dependency on yum.

Issue-ID: INF-72
Signed-off-by: Jackie Huang <jackie.huang@windriver.com>
Change-Id: I1f26a717d7fd75e7077eabe060284bfa3c1a826b

meta-stx/recipes-core/stx-update/files/0001-Remove-use-of-rpmUtils.miscutils-from-cgcs-patch.patch [new file with mode: 0644]
meta-stx/recipes-core/stx-update/stx-update.bb

diff --git a/meta-stx/recipes-core/stx-update/files/0001-Remove-use-of-rpmUtils.miscutils-from-cgcs-patch.patch b/meta-stx/recipes-core/stx-update/files/0001-Remove-use-of-rpmUtils.miscutils-from-cgcs-patch.patch
new file mode 100644 (file)
index 0000000..8fdfd01
--- /dev/null
@@ -0,0 +1,173 @@
+From a6912bf7cffaade9647d8921816cc30db85630bb Mon Sep 17 00:00:00 2001
+From: Don Penney <don.penney@windriver.com>
+Date: Sun, 22 Dec 2019 22:45:18 -0500
+Subject: [PATCH] Remove use of rpmUtils.miscutils from cgcs-patch
+
+The rpmUtils.miscutils.stringToVersion function will not be available
+in CentOS8, as it is not currently provided for python3. A similar
+function exists in cgcs_patch.patch_functions, using regex to parse
+the version from an RPM filename. This update adds a new function,
+expand_pkgver, implemented in a similar fashion using regex, providing
+the same capability as rpmUtils.miscutils.stringToVersion.
+
+Change-Id: I2a04f3dbf85d62c87ca1afcf988b672aafceb642
+Story: 2006228
+Task: 37871
+Signed-off-by: Don Penney <don.penney@windriver.com>
+---
+ cgcs-patch/cgcs-patch/cgcs_patch/patch_agent.py        | 11 +++++------
+ cgcs-patch/cgcs-patch/cgcs_patch/patch_controller.py   |  6 +++---
+ cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py    | 18 ++++++++++++++++++
+ .../cgcs-patch/cgcs_patch/tests/test_patch_agent.py    |  2 --
+ .../cgcs_patch/tests/test_patch_controller.py          |  2 --
+ .../cgcs-patch/cgcs_patch/tests/test_patch_utils.py    | 14 ++++++++++++++
+ 6 files changed, 40 insertions(+), 13 deletions(-)
+
+diff --git a/cgcs-patch/cgcs-patch/cgcs_patch/patch_agent.py b/cgcs-patch/cgcs-patch/cgcs_patch/patch_agent.py
+index ed6f67e..547db52 100644
+--- a/cgcs-patch/cgcs-patch/cgcs_patch/patch_agent.py
++++ b/cgcs-patch/cgcs-patch/cgcs_patch/patch_agent.py
+@@ -19,9 +19,8 @@ import sys
+ import yaml
+ import shutil
+-from rpmUtils.miscutils import stringToVersion  # pylint: disable=import-error
+-
+ from cgcs_patch.patch_functions import configure_logging
++from cgcs_patch.patch_functions import parse_pkgver
+ from cgcs_patch.patch_functions import LOG
+ import cgcs_patch.config as cfg
+ from cgcs_patch.base import PatchService
+@@ -519,8 +518,8 @@ class PatchAgent(PatchService):
+                 #     1, if first arg is higher version
+                 #     0, if versions are same
+                 #     -1, if first arg is lower version
+-                rc = rpm.labelCompare(stringToVersion(version),
+-                                      stringToVersion(stored_ver))
++                rc = rpm.labelCompare(parse_pkgver(version),
++                                      parse_pkgver(stored_ver))
+                 if rc > 0:
+                     # Update version
+@@ -709,8 +708,8 @@ class PatchAgent(PatchService):
+                     compare_version = base_version
+                 # Compare the installed version to what's in the repo
+-                rc = rpm.labelCompare(stringToVersion(installed_version),
+-                                      stringToVersion(compare_version))
++                rc = rpm.labelCompare(parse_pkgver(installed_version),
++                                      parse_pkgver(compare_version))
+                 if rc == 0:
+                     # Versions match, nothing to do.
+                     continue
+diff --git a/cgcs-patch/cgcs-patch/cgcs_patch/patch_controller.py b/cgcs-patch/cgcs-patch/cgcs_patch/patch_controller.py
+index 60b2b14..79a6401 100644
+--- a/cgcs-patch/cgcs-patch/cgcs_patch/patch_controller.py
++++ b/cgcs-patch/cgcs-patch/cgcs_patch/patch_controller.py
+@@ -17,7 +17,7 @@ import rpm
+ import os
+ import gc
+-from rpmUtils.miscutils import stringToVersion  # pylint: disable=import-error
++from cgcs_patch.patch_functions import parse_pkgver
+ from wsgiref import simple_server
+ from cgcs_patch.api import app
+@@ -776,8 +776,8 @@ class PatchController(PatchService):
+                         # Ignore epoch
+                         patch_ver = patch_ver.split(':')[1]
+-                    rc = rpm.labelCompare(stringToVersion(installed_ver),
+-                                          stringToVersion(patch_ver))
++                    rc = rpm.labelCompare(parse_pkgver(installed_ver),
++                                          parse_pkgver(patch_ver))
+                     if self.patch_data.metadata[patch_id]["repostate"] == constants.AVAILABLE:
+                         # The RPM is not expected to be installed.
+diff --git a/cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py b/cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py
+index 211c2c9..5866e8b 100644
+--- a/cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py
++++ b/cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py
+@@ -176,6 +176,24 @@ def parse_rpm_filename(filename):
+     return (pkgname, arch, PackageVersion(epoch, version, release))
++def parse_pkgver(pkgver):
++    # Version format is:
++    # [<epoch>:]<version>-<release>
++    #
++    pattern = re.compile(r'((([^:]):)?)([^-]+)((-(.*))?)$')
++
++    m = pattern.match(pkgver)
++
++    if m is None:
++        raise ValueError("Package version does not match expected format: %s" % pkgver)
++
++    epoch = m.group(3)
++    version = m.group(4)
++    release = m.group(7)
++
++    return (epoch, version, release)
++
++
+ class PackageVersion(object):
+     """
+     The PackageVersion class provides a structure for RPM version information,
+diff --git a/cgcs-patch/cgcs-patch/cgcs_patch/tests/test_patch_agent.py b/cgcs-patch/cgcs-patch/cgcs_patch/tests/test_patch_agent.py
+index c953e4f..bd1eef9 100644
+--- a/cgcs-patch/cgcs-patch/cgcs_patch/tests/test_patch_agent.py
++++ b/cgcs-patch/cgcs-patch/cgcs_patch/tests/test_patch_agent.py
+@@ -10,8 +10,6 @@ import sys
+ import testtools
+ sys.modules['rpm'] = mock.Mock()
+-sys.modules['rpmUtils'] = mock.Mock()
+-sys.modules['rpmUtils.miscutils'] = mock.Mock()
+ import cgcs_patch.patch_agent  # noqa: E402
+diff --git a/cgcs-patch/cgcs-patch/cgcs_patch/tests/test_patch_controller.py b/cgcs-patch/cgcs-patch/cgcs_patch/tests/test_patch_controller.py
+index 1c603b2..1db4b68 100644
+--- a/cgcs-patch/cgcs-patch/cgcs_patch/tests/test_patch_controller.py
++++ b/cgcs-patch/cgcs-patch/cgcs_patch/tests/test_patch_controller.py
+@@ -10,8 +10,6 @@ import sys
+ import testtools
+ sys.modules['rpm'] = mock.Mock()
+-sys.modules['rpmUtils'] = mock.Mock()
+-sys.modules['rpmUtils.miscutils'] = mock.Mock()
+ import cgcs_patch.patch_controller  # noqa: E402
+diff --git a/cgcs-patch/cgcs-patch/cgcs_patch/tests/test_patch_utils.py b/cgcs-patch/cgcs-patch/cgcs_patch/tests/test_patch_utils.py
+index a5eb8d4..653c65a 100644
+--- a/cgcs-patch/cgcs-patch/cgcs_patch/tests/test_patch_utils.py
++++ b/cgcs-patch/cgcs-patch/cgcs_patch/tests/test_patch_utils.py
+@@ -9,6 +9,7 @@ import socket
+ import testtools
+ import cgcs_patch.constants
++import cgcs_patch.patch_functions
+ import cgcs_patch.utils
+@@ -130,3 +131,16 @@ class CgcsPatchUtilsTestCase(testtools.TestCase):
+         result = cgcs_patch.utils.ip_to_versioned_localhost(ip)
+         self.assertEqual(expected_result, result)
++
++    def test_parse_pkgver(self):
++        versions = {
++            '0:1.2.3-r4': ('0', '1.2.3', 'r4'),
++            '4.3.2-1': (None, '4.3.2', '1'),
++            '8.1.4': (None, '8.1.4', None),
++            '5:7.5.3': ('5', '7.5.3', None),
++            'This is a weird version string': (None, 'This is a weird version string', None),
++        }
++
++        for ver, expected in versions.items():
++            result = cgcs_patch.patch_functions.parse_pkgver(ver)
++            self.assertEqual(result, expected)
+-- 
+2.7.4
+
index 2412e18..a8574f6 100644 (file)
@@ -25,7 +25,10 @@ LICENSE = "Apache-2.0"
 
 LIC_FILES_CHKSUM = "file://LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57"
 
-SRC_URI = "git://opendev.org/starlingx/update.git;protocol=${PROTOCOL};rev=${SRCREV};branch=${BRANCH}"
+SRC_URI = " \
+       git://opendev.org/starlingx/update.git;protocol=${PROTOCOL};rev=${SRCREV};branch=${BRANCH} \
+       file://0001-Remove-use-of-rpmUtils.miscutils-from-cgcs-patch.patch \
+       "
 
 DEPENDS = " \
        python \