Skip to content

Commit 96ab5de

Browse files
build,salt: allow to pass a version constraint for packages
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
1 parent a6978fe commit 96ab5de

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

buildchain/buildchain/versions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
SALT_VERSION : str = '3002.6'
2323
CONTAINERD_VERSION : str = '1.4.3'
2424
CONTAINERD_RELEASE : str = '2.el7'
25+
SOS_VERSION : str = '<4.0'
2526

2627
def load_version_information() -> None:
2728
"""Load version information from `VERSION`."""
@@ -331,7 +332,8 @@ def deb_full_name(self) -> str:
331332
PackageVersion(name='runc'),
332333
PackageVersion(name='salt-minion', version=SALT_VERSION),
333334
PackageVersion(name='socat'),
334-
PackageVersion(name='sos'), # TODO download built package dependencies
335+
# TODO download built package dependencies
336+
PackageVersion(name='sos', version=SOS_VERSION),
335337
PackageVersion(name='util-linux'),
336338
PackageVersion(name='xfsprogs'),
337339
),

salt/_modules/metalk8s_package_manager_yum.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,15 @@ def check_pkg_availability(pkgs_info, exclude=None):
167167
List of package to exclude (e.g.: containerd.io)
168168
'''
169169
for name, info in pkgs_info.items():
170-
pkg_name = name
171170
if info.get('version'):
172-
pkg_name += '-' + str(info['version'])
171+
pkg_version = str(info["version"])
172+
pkg_name = "{}{}{}".format(
173+
name,
174+
"-" if pkg_version[0].isdigit() else " ",
175+
pkg_version
176+
)
177+
else:
178+
pkg_name = name
173179

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

186192
if ret['retcode'] != 0:
187193
raise CommandExecutionError(
188-
'Check availability of package {} failed: {}'.format(
194+
'Check availability of package {} failed:\n{}\n{}'.format(
189195
pkg_name,
190-
ret['stdout']
196+
ret['stdout'],
197+
ret['stderr'],
191198
)
192199
)

salt/tests/unit/modules/files/test_metalk8s_package_manager_yum.yaml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,20 @@ check_pkg_availability:
159159
- pkgs_info:
160160
nonexistent_pkg: {}
161161
yum_install_retcode: 1
162-
raise_msg: "Check availability of package nonexistent_pkg failed: Oh ! No ! An ErRoR"
162+
raise_msg: |-
163+
Check availability of package nonexistent_pkg failed:
164+
Some output
165+
Oh ! No ! An ErRoR
163166
164167
# check 1 package not available with version - error when retrieving it
165168
- pkgs_info:
166169
nonexistent_pkg:
167170
version: "3.11.12"
168171
yum_install_retcode: 1
169-
raise_msg: "Check availability of package nonexistent_pkg-3.11.12 failed: Oh ! No ! An ErRoR"
172+
raise_msg: |-
173+
Check availability of package nonexistent_pkg-3.11.12 failed:
174+
Some output
175+
Oh ! No ! An ErRoR
170176
171177
# check 3 package (2 available, 1 not available) - error when retrieving it
172178
- pkgs_info:
@@ -177,4 +183,12 @@ check_pkg_availability:
177183
version: null
178184
yum_install_retcode:
179185
nonexistent_pkg: 1
180-
raise_msg: "Check availability of package nonexistent_pkg failed: Oh ! No ! An ErRoR"
186+
raise_msg: |-
187+
Check availability of package nonexistent_pkg failed:
188+
Some output
189+
Oh ! No ! An ErRoR
190+
191+
# check 1 package with a version constraint
192+
- pkgs_info:
193+
my_package:
194+
version: "<3.11.12"

salt/tests/unit/modules/test_metalk8s_package_manager_yum.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ def _yum_install_cmd(command):
153153
out_kwargs['retcode'] = yum_install_retcode.get(command[2], 0)
154154

155155
if out_kwargs.get('retcode'):
156-
out_kwargs['stdout'] = 'Oh ! No ! An ErRoR'
156+
out_kwargs['stdout'] = "Some output"
157+
out_kwargs['stderr'] = 'Oh ! No ! An ErRoR'
157158

158159
return utils.cmd_output(**out_kwargs)
159160

0 commit comments

Comments
 (0)