chantra / rpms / dnf

Forked from rpms/dnf 2 years ago
Clone
Blob Blame History Raw
From 8f3ce4868ac009976da7323ea39ebcd9a062e32d Mon Sep 17 00:00:00 2001
From: Jaroslav Mracek <jmracek@redhat.com>
Date: Mon, 23 Nov 2020 17:00:01 +0100
Subject: [PATCH 1/3] Remove source packages from install/upgrade set
 (RhBug:1898548)

It prevents Error: Will not install a source rpm package ()

https://bugzilla.redhat.com/show_bug.cgi?id=1898548
---
 dnf/module/module_base.py | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/dnf/module/module_base.py b/dnf/module/module_base.py
index 04701b9d..49c871c4 100644
--- a/dnf/module/module_base.py
+++ b/dnf/module/module_base.py
@@ -140,20 +140,21 @@ class ModuleBase(object):
         if fail_safe_repo_used:
             raise dnf.exceptions.Error(_(
                 "Installing module from Fail-Safe repository is not allowed"))
-        install_base_query = self.base.sack.query().filterm(
-            nevra_strict=install_set_artefacts).apply()
+        #  Remove source packages they cannot be installed or upgraded
+        base_no_source_query = self.base.sack.query().filterm(arch__neq=['src', 'nosrc']).apply()
+        install_base_query = base_no_source_query.filter(nevra_strict=install_set_artefacts)
 
         # add hot-fix packages
         hot_fix_repos = [i.id for i in self.base.repos.iter_enabled() if i.module_hotfixes]
-        hotfix_packages = self.base.sack.query().filterm(reponame=hot_fix_repos).filterm(
-            name=install_dict.keys())
+        hotfix_packages = base_no_source_query.filter(
+            reponame=hot_fix_repos, name=install_dict.keys())
         install_base_query = install_base_query.union(hotfix_packages)
 
         for pkg_name, set_specs in install_dict.items():
             query = install_base_query.filter(name=pkg_name)
             if not query:
                 # package can also be non-modular or part of another stream
-                query = self.base.sack.query().filterm(name=pkg_name)
+                query = base_no_source_query.filter(name=pkg_name)
                 if not query:
                     for spec in set_specs:
                         logger.error(_("Unable to resolve argument {}").format(spec))
@@ -182,6 +183,9 @@ class ModuleBase(object):
         fail_safe_repo = hawkey.MODULE_FAIL_SAFE_REPO_NAME
         fail_safe_repo_used = False
 
+        #  Remove source packages they cannot be installed or upgraded
+        base_no_source_query = self.base.sack.query().filterm(arch__neq=['src', 'nosrc']).apply()
+
         for spec in module_specs:
             module_list, nsvcap = self._get_modules(spec)
             if not module_list:
@@ -221,7 +225,7 @@ class ModuleBase(object):
 
             if not upgrade_package_set:
                 logger.error(_("Unable to match profile in argument {}").format(spec))
-            query = self.base.sack.query().filterm(name=upgrade_package_set)
+            query = base_no_source_query.filter(name=upgrade_package_set)
             if query:
                 sltr = dnf.selector.Selector(self.base.sack)
                 sltr.set(pkg=query)
-- 
2.26.2


From c42680b292b2cca38b24fb18f46f06f800c1934f Mon Sep 17 00:00:00 2001
From: Jaroslav Mracek <jmracek@redhat.com>
Date: Mon, 23 Nov 2020 17:04:05 +0100
Subject: [PATCH 2/3] Remove all source packages from query

---
 dnf/base.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/dnf/base.py b/dnf/base.py
index a2955051..a3d9b63f 100644
--- a/dnf/base.py
+++ b/dnf/base.py
@@ -1550,7 +1550,7 @@ class Base(object):
                 if (comps_pkg.basearchonly):
                     query_args.update({'arch': basearch})
                 q = self.sack.query().filterm(**query_args).apply()
-                q.filterm(arch__neq="src")
+                q.filterm(arch__neq=["src", "nosrc"])
                 if not q:
                     package_string = comps_pkg.name
                     if comps_pkg.basearchonly:
-- 
2.26.2


From 1f68fa6dc59fb350e71a24e787135475f3fb5b4c Mon Sep 17 00:00:00 2001
From: Jaroslav Mracek <jmracek@redhat.com>
Date: Mon, 23 Nov 2020 17:29:45 +0100
Subject: [PATCH 3/3] Run tests with sack in tmp directory

---
 tests/api/test_dnf_module_base.py | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/tests/api/test_dnf_module_base.py b/tests/api/test_dnf_module_base.py
index aa47555b..18dd080d 100644
--- a/tests/api/test_dnf_module_base.py
+++ b/tests/api/test_dnf_module_base.py
@@ -7,16 +7,26 @@ from __future__ import unicode_literals
 import dnf
 import dnf.module.module_base
 
+import os
+import shutil
+import tempfile
+
 from .common import TestCase
 
 
 class DnfModuleBaseApiTest(TestCase):
     def setUp(self):
         self.base = dnf.Base(dnf.conf.Conf())
+        self._installroot = tempfile.mkdtemp(prefix="dnf_test_installroot_")
+        self.base.conf.installroot = self._installroot
+        self.base.conf.cachedir = os.path.join(self._installroot, "var/cache/dnf")
+        self.base._sack = dnf.sack._build_sack(self.base)
         self.moduleBase = dnf.module.module_base.ModuleBase(self.base)
 
     def tearDown(self):
         self.base.close()
+        if self._installroot.startswith("/tmp/"):
+            shutil.rmtree(self._installroot)
 
     def test_init(self):
         moduleBase = dnf.module.module_base.ModuleBase(self.base)
@@ -51,12 +61,7 @@ class DnfModuleBaseApiTest(TestCase):
     def test_install(self):
         # ModuleBase.install()
         self.assertHasAttr(self.moduleBase, "install")
-        self.assertRaises(
-            AttributeError,
-            self.moduleBase.install,
-            module_specs=[],
-            strict=False,
-        )
+        self.moduleBase.install(module_specs=[], strict=False)
 
     def test_remove(self):
         # ModuleBase.remove()
-- 
2.26.2