Blame SOURCES/0006-Remove-sourcepackages-from-install-upgrade-set.patch

5fae5a
From 8f3ce4868ac009976da7323ea39ebcd9a062e32d Mon Sep 17 00:00:00 2001
5fae5a
From: Jaroslav Mracek <jmracek@redhat.com>
5fae5a
Date: Mon, 23 Nov 2020 17:00:01 +0100
5fae5a
Subject: [PATCH 1/3] Remove source packages from install/upgrade set
5fae5a
 (RhBug:1898548)
5fae5a
5fae5a
It prevents Error: Will not install a source rpm package ()
5fae5a
5fae5a
https://bugzilla.redhat.com/show_bug.cgi?id=1898548
5fae5a
---
5fae5a
 dnf/module/module_base.py | 16 ++++++++++------
5fae5a
 1 file changed, 10 insertions(+), 6 deletions(-)
5fae5a
5fae5a
diff --git a/dnf/module/module_base.py b/dnf/module/module_base.py
5fae5a
index 04701b9d..49c871c4 100644
5fae5a
--- a/dnf/module/module_base.py
5fae5a
+++ b/dnf/module/module_base.py
5fae5a
@@ -140,20 +140,21 @@ class ModuleBase(object):
5fae5a
         if fail_safe_repo_used:
5fae5a
             raise dnf.exceptions.Error(_(
5fae5a
                 "Installing module from Fail-Safe repository is not allowed"))
5fae5a
-        install_base_query = self.base.sack.query().filterm(
5fae5a
-            nevra_strict=install_set_artefacts).apply()
5fae5a
+        #  Remove source packages they cannot be installed or upgraded
5fae5a
+        base_no_source_query = self.base.sack.query().filterm(arch__neq=['src', 'nosrc']).apply()
5fae5a
+        install_base_query = base_no_source_query.filter(nevra_strict=install_set_artefacts)
5fae5a
 
5fae5a
         # add hot-fix packages
5fae5a
         hot_fix_repos = [i.id for i in self.base.repos.iter_enabled() if i.module_hotfixes]
5fae5a
-        hotfix_packages = self.base.sack.query().filterm(reponame=hot_fix_repos).filterm(
5fae5a
-            name=install_dict.keys())
5fae5a
+        hotfix_packages = base_no_source_query.filter(
5fae5a
+            reponame=hot_fix_repos, name=install_dict.keys())
5fae5a
         install_base_query = install_base_query.union(hotfix_packages)
5fae5a
 
5fae5a
         for pkg_name, set_specs in install_dict.items():
5fae5a
             query = install_base_query.filter(name=pkg_name)
5fae5a
             if not query:
5fae5a
                 # package can also be non-modular or part of another stream
5fae5a
-                query = self.base.sack.query().filterm(name=pkg_name)
5fae5a
+                query = base_no_source_query.filter(name=pkg_name)
5fae5a
                 if not query:
5fae5a
                     for spec in set_specs:
5fae5a
                         logger.error(_("Unable to resolve argument {}").format(spec))
5fae5a
@@ -182,6 +183,9 @@ class ModuleBase(object):
5fae5a
         fail_safe_repo = hawkey.MODULE_FAIL_SAFE_REPO_NAME
5fae5a
         fail_safe_repo_used = False
5fae5a
 
5fae5a
+        #  Remove source packages they cannot be installed or upgraded
5fae5a
+        base_no_source_query = self.base.sack.query().filterm(arch__neq=['src', 'nosrc']).apply()
5fae5a
+
5fae5a
         for spec in module_specs:
5fae5a
             module_list, nsvcap = self._get_modules(spec)
5fae5a
             if not module_list:
5fae5a
@@ -221,7 +225,7 @@ class ModuleBase(object):
5fae5a
 
5fae5a
             if not upgrade_package_set:
5fae5a
                 logger.error(_("Unable to match profile in argument {}").format(spec))
5fae5a
-            query = self.base.sack.query().filterm(name=upgrade_package_set)
5fae5a
+            query = base_no_source_query.filter(name=upgrade_package_set)
5fae5a
             if query:
5fae5a
                 sltr = dnf.selector.Selector(self.base.sack)
5fae5a
                 sltr.set(pkg=query)
5fae5a
-- 
5fae5a
2.26.2
5fae5a
5fae5a
5fae5a
From c42680b292b2cca38b24fb18f46f06f800c1934f Mon Sep 17 00:00:00 2001
5fae5a
From: Jaroslav Mracek <jmracek@redhat.com>
5fae5a
Date: Mon, 23 Nov 2020 17:04:05 +0100
5fae5a
Subject: [PATCH 2/3] Remove all source packages from query
5fae5a
5fae5a
---
5fae5a
 dnf/base.py | 2 +-
5fae5a
 1 file changed, 1 insertion(+), 1 deletion(-)
5fae5a
5fae5a
diff --git a/dnf/base.py b/dnf/base.py
5fae5a
index a2955051..a3d9b63f 100644
5fae5a
--- a/dnf/base.py
5fae5a
+++ b/dnf/base.py
5fae5a
@@ -1550,7 +1550,7 @@ class Base(object):
5fae5a
                 if (comps_pkg.basearchonly):
5fae5a
                     query_args.update({'arch': basearch})
5fae5a
                 q = self.sack.query().filterm(**query_args).apply()
5fae5a
-                q.filterm(arch__neq="src")
5fae5a
+                q.filterm(arch__neq=["src", "nosrc"])
5fae5a
                 if not q:
5fae5a
                     package_string = comps_pkg.name
5fae5a
                     if comps_pkg.basearchonly:
5fae5a
-- 
5fae5a
2.26.2
5fae5a
5fae5a
5fae5a
From 1f68fa6dc59fb350e71a24e787135475f3fb5b4c Mon Sep 17 00:00:00 2001
5fae5a
From: Jaroslav Mracek <jmracek@redhat.com>
5fae5a
Date: Mon, 23 Nov 2020 17:29:45 +0100
5fae5a
Subject: [PATCH 3/3] Run tests with sack in tmp directory
5fae5a
5fae5a
---
5fae5a
 tests/api/test_dnf_module_base.py | 17 +++++++++++------
5fae5a
 1 file changed, 11 insertions(+), 6 deletions(-)
5fae5a
5fae5a
diff --git a/tests/api/test_dnf_module_base.py b/tests/api/test_dnf_module_base.py
5fae5a
index aa47555b..18dd080d 100644
5fae5a
--- a/tests/api/test_dnf_module_base.py
5fae5a
+++ b/tests/api/test_dnf_module_base.py
5fae5a
@@ -7,16 +7,26 @@ from __future__ import unicode_literals
5fae5a
 import dnf
5fae5a
 import dnf.module.module_base
5fae5a
 
5fae5a
+import os
5fae5a
+import shutil
5fae5a
+import tempfile
5fae5a
+
5fae5a
 from .common import TestCase
5fae5a
 
5fae5a
 
5fae5a
 class DnfModuleBaseApiTest(TestCase):
5fae5a
     def setUp(self):
5fae5a
         self.base = dnf.Base(dnf.conf.Conf())
5fae5a
+        self._installroot = tempfile.mkdtemp(prefix="dnf_test_installroot_")
5fae5a
+        self.base.conf.installroot = self._installroot
5fae5a
+        self.base.conf.cachedir = os.path.join(self._installroot, "var/cache/dnf")
5fae5a
+        self.base._sack = dnf.sack._build_sack(self.base)
5fae5a
         self.moduleBase = dnf.module.module_base.ModuleBase(self.base)
5fae5a
 
5fae5a
     def tearDown(self):
5fae5a
         self.base.close()
5fae5a
+        if self._installroot.startswith("/tmp/"):
5fae5a
+            shutil.rmtree(self._installroot)
5fae5a
 
5fae5a
     def test_init(self):
5fae5a
         moduleBase = dnf.module.module_base.ModuleBase(self.base)
5fae5a
@@ -51,12 +61,7 @@ class DnfModuleBaseApiTest(TestCase):
5fae5a
     def test_install(self):
5fae5a
         # ModuleBase.install()
5fae5a
         self.assertHasAttr(self.moduleBase, "install")
5fae5a
-        self.assertRaises(
5fae5a
-            AttributeError,
5fae5a
-            self.moduleBase.install,
5fae5a
-            module_specs=[],
5fae5a
-            strict=False,
5fae5a
-        )
5fae5a
+        self.moduleBase.install(module_specs=[], strict=False)
5fae5a
 
5fae5a
     def test_remove(self):
5fae5a
         # ModuleBase.remove()
5fae5a
-- 
5fae5a
2.26.2
5fae5a