stx-update: backport a patch to remove dependency on yum

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.

Signed-off-by: Jackie Huang <jackie.huang@windriver.com>
Signed-off-by: Babak Sarashki <Babak.SarAshki@windriver.com>
This commit is contained in:
Jackie Huang 2020-05-04 17:20:01 +08:00 committed by Babak Sarashki
parent 6e9c410435
commit 4fb62a827a
2 changed files with 174 additions and 0 deletions

View File

@ -9,6 +9,7 @@ S = "${S_DIR}/cgcs-patch/cgcs-patch"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57"
SRC_URI += "file://0001-Remove-use-of-rpmUtils.miscutils-from-cgcs-patch.patch;striplevel=3"
RDEPENDS_${PN}_append = " \
bash \

View File

@ -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