Don't shell out for calling dnf

refactor the dnf call to install packages and groups in
one call. This allows to prevent calling dnf through a
shell. For installing of a package group the group ID
name is expected. This Fixes #1856
This commit is contained in:
Marcus Schäfer 2021-06-21 14:50:59 +02:00
parent 29b6db022e
commit 89b5a6f526
No known key found for this signature in database
GPG Key ID: AD11DD02B44996EF
2 changed files with 15 additions and 35 deletions

View File

@ -64,9 +64,9 @@ class PackageManagerDnf(PackageManagerBase):
"""
Queue a collection request
:param str name: dnf group name
:param str name: dnf group ID name
"""
self.collection_requests.append('"' + name + '"')
self.collection_requests.append(f'@{name}')
def request_product(self, name: str) -> None:
"""
@ -101,22 +101,16 @@ class PackageManagerDnf(PackageManagerBase):
Command.run(
['dnf'] + self.dnf_args + ['makecache']
)
bash_command = [
dnf_command = [
'dnf'
] + self.dnf_args + [
'--installroot', self.root_dir
] + self.custom_args + ['install'] + self.package_requests
if self.collection_requests:
bash_command += [
'&&', 'dnf'
] + self.dnf_args + [
'--installroot', self.root_dir
] + self.custom_args + [
'group', 'install'
] + self.collection_requests
] + self.custom_args + [
'install'
] + self.package_requests + self.collection_requests
self.cleanup_requests()
return Command.call(
['bash', '-c', ' '.join(bash_command)], self.command_env
dnf_command, self.command_env
)
def process_install_requests(self) -> command_call_type:
@ -138,20 +132,14 @@ class PackageManagerDnf(PackageManagerBase):
chroot_dnf_args = Path.move_to_root(
self.root_dir, self.dnf_args
)
bash_command = [
dnf_command = [
'chroot', self.root_dir, 'dnf'
] + chroot_dnf_args + self.custom_args + exclude_args + [
'install'
] + self.package_requests
if self.collection_requests:
bash_command += [
'&&', 'chroot', self.root_dir, 'dnf'
] + chroot_dnf_args + self.custom_args + exclude_args + [
'group', 'install'
] + self.collection_requests
] + self.package_requests + self.collection_requests
self.cleanup_requests()
return Command.call(
['bash', '-c', ' '.join(bash_command)], self.command_env
dnf_command, self.command_env
)
def process_delete_requests(self, force: bool = False) -> command_call_type:

View File

@ -26,7 +26,7 @@ class TestPackageManagerDnf:
def test_request_collection(self):
self.manager.request_collection('name')
assert self.manager.collection_requests == ['"name"']
assert self.manager.collection_requests == ['@name']
def test_request_product(self):
self.manager.request_product('name')
@ -47,12 +47,8 @@ class TestPackageManagerDnf:
)
mock_call.assert_called_once_with(
[
'bash', '-c',
'dnf --config /root-dir/dnf.conf -y '
'--installroot /root-dir install vim && '
'dnf --config /root-dir/dnf.conf -y '
'--installroot /root-dir group install '
'"collection"'
'dnf', '--config', '/root-dir/dnf.conf', '-y',
'--installroot', '/root-dir', 'install', 'vim', '@collection'
], ['env']
)
@ -64,12 +60,8 @@ class TestPackageManagerDnf:
self.manager.process_install_requests()
mock_call.assert_called_once_with(
[
'bash', '-c',
'chroot /root-dir dnf --config /dnf.conf -y '
'--exclude=skipme install vim && '
'chroot /root-dir dnf --config /dnf.conf -y '
'--exclude=skipme group install '
'"collection"'
'chroot', '/root-dir', 'dnf', '--config', '/dnf.conf', '-y',
'--exclude=skipme', 'install', 'vim', '@collection'
], ['env']
)