Skip to content

Commit

Permalink
build,salt: allow to pass a version constraint for packages
Browse files Browse the repository at this point in the history
Instead of passing the exact version, we can now provide
a constraint (<, >, <=, >=) if we don't need a specific
version but we want to exclude some.

Refs: #3387
  • Loading branch information
alexandre-allard committed May 19, 2021
1 parent a6978fe commit 8bfdfc7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
4 changes: 3 additions & 1 deletion buildchain/buildchain/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
SALT_VERSION : str = '3002.6'
CONTAINERD_VERSION : str = '1.4.3'
CONTAINERD_RELEASE : str = '2.el7'
SOS_VERSION : str = '< 4.0'

def load_version_information() -> None:
"""Load version information from `VERSION`."""
Expand Down Expand Up @@ -331,7 +332,8 @@ def deb_full_name(self) -> str:
PackageVersion(name='runc'),
PackageVersion(name='salt-minion', version=SALT_VERSION),
PackageVersion(name='socat'),
PackageVersion(name='sos'), # TODO download built package dependencies
# TODO download built package dependencies
PackageVersion(name='sos', version=SOS_VERSION),
PackageVersion(name='util-linux'),
PackageVersion(name='xfsprogs'),
),
Expand Down
15 changes: 11 additions & 4 deletions salt/_modules/metalk8s_package_manager_yum.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,15 @@ def check_pkg_availability(pkgs_info, exclude=None):
List of package to exclude (e.g.: containerd.io)
'''
for name, info in pkgs_info.items():
pkg_name = name
if info.get('version'):
pkg_name += '-' + str(info['version'])
pkg_version = str(info["version"])
pkg_name = "{}{}{}".format(
name,
"-" if pkg_version[0].isdigit() else " ",
pkg_version
)
else:
pkg_name = name

cmd = [
'yum', 'install', pkg_name,
Expand All @@ -185,8 +191,9 @@ def check_pkg_availability(pkgs_info, exclude=None):

if ret['retcode'] != 0:
raise CommandExecutionError(
'Check availability of package {} failed: {}'.format(
'Check availability of package {} failed:\n{}\n{}'.format(
pkg_name,
ret['stdout']
ret['stdout'],
ret['stderr'],
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,20 @@ check_pkg_availability:
- pkgs_info:
nonexistent_pkg: {}
yum_install_retcode: 1
raise_msg: "Check availability of package nonexistent_pkg failed: Oh ! No ! An ErRoR"
raise_msg: |-
Check availability of package nonexistent_pkg failed:
Some output
Oh ! No ! An ErRoR
# check 1 package not available with version - error when retrieving it
- pkgs_info:
nonexistent_pkg:
version: "3.11.12"
yum_install_retcode: 1
raise_msg: "Check availability of package nonexistent_pkg-3.11.12 failed: Oh ! No ! An ErRoR"
raise_msg: |-
Check availability of package nonexistent_pkg-3.11.12 failed:
Some output
Oh ! No ! An ErRoR
# check 3 package (2 available, 1 not available) - error when retrieving it
- pkgs_info:
Expand All @@ -177,4 +183,12 @@ check_pkg_availability:
version: null
yum_install_retcode:
nonexistent_pkg: 1
raise_msg: "Check availability of package nonexistent_pkg failed: Oh ! No ! An ErRoR"
raise_msg: |-
Check availability of package nonexistent_pkg failed:
Some output
Oh ! No ! An ErRoR
# check 1 package with a version constraint
- pkgs_info:
my_package:
version: "< 3.11.12"
3 changes: 2 additions & 1 deletion salt/tests/unit/modules/test_metalk8s_package_manager_yum.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ def _yum_install_cmd(command):
out_kwargs['retcode'] = yum_install_retcode.get(command[2], 0)

if out_kwargs.get('retcode'):
out_kwargs['stdout'] = 'Oh ! No ! An ErRoR'
out_kwargs['stdout'] = "Some output"
out_kwargs['stderr'] = 'Oh ! No ! An ErRoR'

return utils.cmd_output(**out_kwargs)

Expand Down

0 comments on commit 8bfdfc7

Please sign in to comment.