Blame SOURCES/0011-comps-Make-the-install_or_skip-method-not-catch-Comp.patch

149d5d
From f0f037db8219b1e74be4ed86f5eea53b63ca1d88 Mon Sep 17 00:00:00 2001
70e049
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= <lhrazky@redhat.com>
149d5d
Date: Tue, 20 Jul 2021 15:29:59 +0200
70e049
Subject: [PATCH] comps: Make the install_or_skip() method not catch CompsError
70e049
 anymore
149d5d
149d5d
According to its docstring, the original intention of the method was to
149d5d
not fail on installing an already installed group/environment.
149d5d
149d5d
However, the CompsError is no longer thrown when attempting to install
149d5d
an already installed group or environment. It was changed to logging a
149d5d
warning directly in 5210b9dc and then the check was removed completely
149d5d
in 217ca0fa.
149d5d
149d5d
For the other case for which an instance of CompsError can be thrown
149d5d
from the install_group() and install_environment() methods, which is
149d5d
when a group or environment is not found, we certainly want to throw an
149d5d
error (see the linked bugs), therefore there's no reason to catch the
149d5d
exception anymore.
149d5d
149d5d
The install_or_skip() method is preserved as part of the API so as not
149d5d
to break compatibility any more than necessary.
149d5d
149d5d
msg: API: Raise CompsError when group/env not found in install_group and install_environment
149d5d
type: bugfix
149d5d
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1947958
149d5d
related: https://bugzilla.redhat.com/show_bug.cgi?id=1943206
149d5d
---
149d5d
 dnf/base.py               |  8 ++------
149d5d
 dnf/cli/commands/group.py |  4 ++--
149d5d
 dnf/comps.py              | 20 ++++++++++----------
149d5d
 doc/api_base.rst          |  4 ++--
149d5d
 4 files changed, 16 insertions(+), 20 deletions(-)
149d5d
149d5d
diff --git a/dnf/base.py b/dnf/base.py
70e049
index c258a5a7..babca31d 100644
149d5d
--- a/dnf/base.py
149d5d
+++ b/dnf/base.py
149d5d
@@ -1668,9 +1668,7 @@ class Base(object):
149d5d
         if not isinstance(types, int):
149d5d
             types = libdnf.transaction.listToCompsPackageType(types)
149d5d
 
149d5d
-        trans = dnf.comps.install_or_skip(solver._environment_install,
149d5d
-                                          env_id, types, exclude or set(),
149d5d
-                                          strict, exclude_groups)
149d5d
+        trans = solver._environment_install(env_id, types, exclude or set(), strict, exclude_groups)
149d5d
         if not trans:
149d5d
             return 0
149d5d
         return self._add_comps_trans(trans)
149d5d
@@ -1713,9 +1711,7 @@ class Base(object):
149d5d
         if not isinstance(pkg_types, int):
149d5d
             pkg_types = libdnf.transaction.listToCompsPackageType(pkg_types)
149d5d
 
149d5d
-        trans = dnf.comps.install_or_skip(solver._group_install,
149d5d
-                                          grp_id, pkg_types, exclude_pkgnames,
149d5d
-                                          strict)
149d5d
+        trans = solver._group_install(grp_id, pkg_types, exclude_pkgnames, strict)
149d5d
         if not trans:
149d5d
             return 0
149d5d
         if strict:
149d5d
diff --git a/dnf/cli/commands/group.py b/dnf/cli/commands/group.py
70e049
index cf542799..fd723c48 100644
149d5d
--- a/dnf/cli/commands/group.py
149d5d
+++ b/dnf/cli/commands/group.py
149d5d
@@ -244,9 +244,9 @@ class GroupCommand(commands.Command):
149d5d
             types = tuple(self.base.conf.group_package_types)
149d5d
         pkg_types = libdnf.transaction.listToCompsPackageType(types)
149d5d
         for env_id in res.environments:
149d5d
-            dnf.comps.install_or_skip(solver._environment_install, env_id, pkg_types)
149d5d
+            solver._environment_install(env_id, pkg_types)
149d5d
         for group_id in res.groups:
149d5d
-            dnf.comps.install_or_skip(solver._group_install, group_id, pkg_types)
149d5d
+            solver._group_install(group_id, pkg_types)
149d5d
 
149d5d
     def _mark_remove(self, patterns):
149d5d
         q = CompsQuery(self.base.comps, self.base.history,
149d5d
diff --git a/dnf/comps.py b/dnf/comps.py
70e049
index 89765337..461eb274 100644
149d5d
--- a/dnf/comps.py
149d5d
+++ b/dnf/comps.py
149d5d
@@ -93,15 +93,15 @@ def _fn_display_order(group):
149d5d
 
149d5d
 def install_or_skip(install_fnc, grp_or_env_id, types, exclude=None,
149d5d
                     strict=True, exclude_groups=None):
149d5d
-    """Either mark in persistor as installed given `grp_or_env` (group
149d5d
-       or environment) or skip it (if it's already installed).
149d5d
-       `install_fnc` has to be Solver._group_install
149d5d
-       or Solver._environment_install.
149d5d
-       """
149d5d
-    try:
149d5d
-        return install_fnc(grp_or_env_id, types, exclude, strict, exclude_groups)
149d5d
-    except dnf.comps.CompsError as e:
149d5d
-        logger.warning("%s, %s", ucd(e)[:-1], _("skipping."))
149d5d
+    """
149d5d
+    Installs a group or an environment identified by grp_or_env_id.
149d5d
+    This method is preserved for API compatibility. It used to catch an
149d5d
+    exception thrown when a gorup or env was already installed, which is no
149d5d
+    longer thrown.
149d5d
+    `install_fnc` has to be Solver._group_install or
149d5d
+    Solver._environment_install.
149d5d
+    """
149d5d
+    return install_fnc(grp_or_env_id, types, exclude, strict, exclude_groups)
149d5d
 
149d5d
 
149d5d
 class _Langs(object):
149d5d
@@ -592,7 +592,7 @@ class Solver(object):
149d5d
         assert dnf.util.is_string_type(group_id)
149d5d
         return self.history.env.is_removable_group(group_id)
149d5d
 
149d5d
-    def _environment_install(self, env_id, pkg_types, exclude, strict=True, exclude_groups=None):
149d5d
+    def _environment_install(self, env_id, pkg_types, exclude=None, strict=True, exclude_groups=None):
149d5d
         assert dnf.util.is_string_type(env_id)
149d5d
         comps_env = self.comps._environment_by_id(env_id)
149d5d
         if not comps_env:
149d5d
diff --git a/doc/api_base.rst b/doc/api_base.rst
70e049
index 20d7945e..03396b69 100644
149d5d
--- a/doc/api_base.rst
149d5d
+++ b/doc/api_base.rst
149d5d
@@ -179,7 +179,7 @@
149d5d
 
149d5d
   .. method:: group_install(group_id, pkg_types, exclude=None, strict=True)
149d5d
 
149d5d
-    Mark group with corresponding `group_id` installed and mark the packages in the group for installation. Return the number of packages that the operation has marked for installation. `pkg_types` is a sequence of strings determining the kinds of packages to be installed, where the respective groups can be selected by including ``"mandatory"``, ``"default"`` or ``"optional"`` in it. If `exclude` is given, it has to be an iterable of package name glob patterns: :meth:`.group_install` will then not mark the respective packages for installation whenever possible. Parameter `strict` is a boolean indicating whether group packages that exist but are non-installable due to e.g. dependency issues should be skipped (False) or cause transaction to fail to resolve (True).
149d5d
+    Mark group with corresponding `group_id` installed and mark the packages in the group for installation. Return the number of packages that the operation has marked for installation. `pkg_types` is a sequence of strings determining the kinds of packages to be installed, where the respective groups can be selected by including ``"mandatory"``, ``"default"`` or ``"optional"`` in it. If `exclude` is given, it has to be an iterable of package name glob patterns: :meth:`.group_install` will then not mark the respective packages for installation whenever possible. Parameter `strict` is a boolean indicating whether group packages that exist but are non-installable due to e.g. dependency issues should be skipped (False) or cause transaction to fail to resolve (True).  Raises :exc:`dnf.exceptions.CompsError` in case the group doesn't exist.
149d5d
 
149d5d
   .. method:: group_remove(group_id)
149d5d
 
149d5d
@@ -191,7 +191,7 @@
149d5d
 
149d5d
   .. method:: environment_install(env_id, types, exclude=None, strict=True, exclude_groups=None)
149d5d
 
149d5d
-    Similar to :meth:`.group_install` but operates on environmental groups. `exclude_groups` is an iterable of group IDs that will not be marked as installed.
149d5d
+    Similar to :meth:`.group_install` but operates on environmental groups. `exclude_groups` is an iterable of group IDs that will not be marked as installed.  Raises :exc:`dnf.exceptions.CompsError` in case the group doesn't exist.
149d5d
 
149d5d
   .. method:: environment_remove(env_id)
149d5d
 
70e049
-- 
70e049
2.35.1
149d5d