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

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