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>
This commit is contained in:
parent
5d2da5d041
commit
a6912bf7cf
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue