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 dnf.subject
import hawkey import hawkey
import requests import requests
import rpm
import yaml import yaml
from createrepo_c import Package
from dataclasses import dataclass from dataclasses import dataclass
@ -235,6 +237,20 @@ class PackagesGenerator:
os.remove(repomd_record_file_path) os.remove(repomd_record_file_path)
return list(modules_data) 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( def generate_packages_json(
self self
) -> Dict[AnyStr, Dict[AnyStr, Dict[AnyStr, List[AnyStr]]]]: ) -> Dict[AnyStr, Dict[AnyStr, Dict[AnyStr, List[AnyStr]]]]:
@ -248,6 +264,7 @@ class PackagesGenerator:
) )
) )
) )
all_packages = defaultdict(dict)
for repo_info in self.repos: for repo_info in self.repos:
packages = {} # type: Dict[AnyStr, cr.Package] packages = {} # type: Dict[AnyStr, cr.Package]
repomd_records = self._get_repomd_records( repomd_records = self._get_repomd_records(
@ -259,31 +276,50 @@ class PackagesGenerator:
packages=packages, packages=packages,
) )
for package in packages.values(): for package in packages.values():
package_name = package.name package_key = f'{package.name}.{package.arch}'
package_arch = package.arch
if 'module' in package.release: if 'module' in package.release:
continue continue
if any(re.search(excluded_package, package_name) if package_key not in all_packages:
for excluded_package in self.excluded_packages): all_packages[package_key]['variant'] = repo_info.name
continue all_packages[package_key]['arch'] = repo_info.arch
src_package_name = dnf.subject.Subject( all_packages[package_key]['package'] = package
package.rpm_sourcerpm, elif self.compare_pkgs_version(
).get_nevra_possibilities( package,
forms=hawkey.FORM_NEVRA, 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:
continue
if any(re.search(excluded_package, package_name)
for excluded_package in self.excluded_packages):
continue
src_package_name = dnf.subject.Subject(
package.rpm_sourcerpm,
).get_nevra_possibilities(
forms=hawkey.FORM_NEVRA,
)
if len(src_package_name) > 1:
# We should stop utility if we can't get exact name of srpm
raise ValueError(
'We can\'t get exact name of srpm '
f'by its NEVRA "{package.rpm_sourcerpm}"'
) )
if len(src_package_name) > 1: else:
# We should stop utility if we can't get exact name of srpm src_package_name = src_package_name[0].name
raise ValueError( pkgs_list = packages_json[repo_name][
'We can\'t get exact name of srpm ' repo_arch][src_package_name]
f'by its NEVRA "{package.rpm_sourcerpm}"' added_pkg = f'{package_name}.{package_arch}'
) if added_pkg not in pkgs_list:
else: pkgs_list.append(added_pkg)
src_package_name = src_package_name[0].name
pkgs_list = packages_json[repo_info.name][
repo_info.arch][src_package_name]
added_pkg = f'{package_name}.{package_arch}'
if added_pkg not in pkgs_list:
pkgs_list.append(added_pkg)
return packages_json return packages_json

View File

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