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

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