LNX-318: Modify build scripts for building CloudLinux OS 8.4

- [Fixed] The script `create_packages_json` selects a first
          comer package from variant, but it should select the
          higher by version of package

@BS-NOBUILD
@BS-TARGET-CL8

Change-Id: I36268f2a493897fc11e787c040066d2d501a1c81
This commit is contained in:
stepan_oksanichenko 2021-06-04 12:36:03 +03:00
parent aaeee7132d
commit 941d6b064a
2 changed files with 71 additions and 23 deletions

View File

@ -19,7 +19,9 @@ import createrepo_c as cr
import dnf.subject
import hawkey
import requests
import rpm
import yaml
from createrepo_c import Package
from dataclasses import dataclass
@ -235,6 +237,20 @@ class PackagesGenerator:
os.remove(repomd_record_file_path)
return list(modules_data)
@staticmethod
def compare_pkgs_version(package_1: Package, package_2: Package) -> int:
version_tuple_1 = (
package_1.epoch,
package_1.version,
package_1.release,
)
version_tuple_2 = (
package_2.epoch,
package_2.version,
package_2.release,
)
return rpm.labelCompare(version_tuple_1, version_tuple_2)
def generate_packages_json(
self
) -> Dict[AnyStr, Dict[AnyStr, Dict[AnyStr, List[AnyStr]]]]:
@ -248,6 +264,7 @@ class PackagesGenerator:
)
)
)
all_packages = defaultdict(dict)
for repo_info in self.repos:
packages = {} # type: Dict[AnyStr, cr.Package]
repomd_records = self._get_repomd_records(
@ -259,6 +276,25 @@ class PackagesGenerator:
packages=packages,
)
for package in packages.values():
package_key = f'{package.name}.{package.arch}'
if 'module' in package.release:
continue
if package_key not in all_packages:
all_packages[package_key]['variant'] = repo_info.name
all_packages[package_key]['arch'] = repo_info.arch
all_packages[package_key]['package'] = package
elif self.compare_pkgs_version(
package,
all_packages[package_key]['package']
) > 0:
all_packages[package_key]['variant'] = repo_info.name
all_packages[package_key]['arch'] = repo_info.arch
all_packages[package_key]['package'] = package
for package_dict in all_packages.values():
repo_name = package_dict['variant']
repo_arch = package_dict['arch']
package = package_dict['package']
package_name = package.name
package_arch = package.arch
if 'module' in package.release:
@ -279,8 +315,8 @@ class PackagesGenerator:
)
else:
src_package_name = src_package_name[0].name
pkgs_list = packages_json[repo_info.name][
repo_info.arch][src_package_name]
pkgs_list = packages_json[repo_name][
repo_arch][src_package_name]
added_pkg = f'{package_name}.{package_arch}'
if added_pkg not in pkgs_list:
pkgs_list.append(added_pkg)

View File

@ -21,6 +21,14 @@ test_repo_info = RepoInfo(
is_remote=False,
)
test_repo_info_2 = RepoInfo(
path=FOLDER_WITH_TEST_DATA,
folder='test_repo_2',
name='TestRepo2',
arch='x86_64',
is_remote=False,
)
class TestPackagesJson(TestCase):
def test_01__get_remote_file_content(self):
@ -53,6 +61,7 @@ class TestPackagesJson(TestCase):
pg = PackagesGenerator(
repos=[
test_repo_info,
test_repo_info_2,
],
excluded_packages=['zziplib-utils'],
)
@ -65,9 +74,12 @@ class TestPackagesJson(TestCase):
)
test_packages['TestRepo']['x86_64']['zziplib'] = \
[
'zziplib.i686',
'zziplib.x86_64',
]
test_packages['TestRepo2']['x86_64']['zziplib'] = \
[
'zziplib.i686',
]
result = pg.generate_packages_json()
self.assertEqual(
test_packages,