Blame SOURCES/0007-Report-missing-default-profile-as-an-error-RhBug16695271724564.patch

1f580a
From 4662a3d342de4be584812267c5b59ed9c1f9c44e Mon Sep 17 00:00:00 2001
1f580a
From: Jaroslav Mracek <jmracek@redhat.com>
1f580a
Date: Tue, 25 Jun 2019 18:54:54 +0200
1f580a
Subject: [PATCH] Report missing default profile as an error (RhBug:1669527,1724564)
1f580a
1f580a
The behavior where module install command doesn't install any package
1f580a
when there are no default profiles was recognized by users as an
1f580a
unexpected behavior.
1f580a
1f580a
The patch allows DNF to fail when no default profile is available.
1f580a
1f580a
https://bugzilla.redhat.com/show_bug.cgi?id=1669527
1f580a
https://bugzilla.redhat.com/show_bug.cgi?id=1724564
1f580a
---
1f580a
 dnf/module/module_base.py | 27 +++++++++++++++++++++++----
1f580a
 tests/test_modules.py     | 12 ++----------
1f580a
 2 files changed, 25 insertions(+), 14 deletions(-)
1f580a
1f580a
diff --git a/dnf/module/module_base.py b/dnf/module/module_base.py
1f580a
index 83e5e4a..ea56ad0 100644
1f580a
--- a/dnf/module/module_base.py
1f580a
+++ b/dnf/module/module_base.py
1f580a
@@ -83,21 +83,40 @@ class ModuleBase(object):
1f580a
                     if nsvcap.profile:
1f580a
                         profiles.extend(latest_module.getProfiles(nsvcap.profile))
1f580a
                         if not profiles:
1f580a
-                            logger.error(_("Unable to match profile in argument {}").format(spec))
1f580a
+                            available_profiles = latest_module.getProfiles()
1f580a
+                            if available_profiles:
1f580a
+                                profile_names = ", ".join(
1f580a
+                                    [profile.getName() for profile in available_profiles])
1f580a
+                                msg = _("Unable to match profile for argument {}. Available "
1f580a
+                                        "profiles for '{}:{}': {}").format(
1f580a
+                                    spec, name, stream, profile_names)
1f580a
+                            else:
1f580a
+                                msg = _("Unable to match profile for argument {}").format(spec)
1f580a
+                            logger.error(msg)
1f580a
                             no_match_specs.append(spec)
1f580a
                             continue
1f580a
                     else:
1f580a
                         profiles_strings = self.base._moduleContainer.getDefaultProfiles(
1f580a
                             name, stream)
1f580a
                         if not profiles_strings:
1f580a
-                            logger.error(_("No default profiles for module {}:{}").format(
1f580a
-                                name, stream))
1f580a
+                            available_profiles = latest_module.getProfiles()
1f580a
+                            if available_profiles:
1f580a
+                                profile_names = ", ".join(
1f580a
+                                    [profile.getName() for profile in available_profiles])
1f580a
+                                msg = _("No default profiles for module {}:{}. Available profiles"
1f580a
+                                        ": {}").format(
1f580a
+                                    name, stream, profile_names)
1f580a
+                            else:
1f580a
+                                msg = _("No default profiles for module {}:{}").format(name, stream)
1f580a
+                            logger.error(msg)
1f580a
+                            no_match_specs.append(spec)
1f580a
                         for profile in set(profiles_strings):
1f580a
                             module_profiles = latest_module.getProfiles(profile)
1f580a
                             if not module_profiles:
1f580a
                                 logger.error(
1f580a
-                                    _("Profile {} not matched for module {}:{}").format(
1f580a
+                                    _("Default profile {} not available in module {}:{}").format(
1f580a
                                         profile, name, stream))
1f580a
+                                no_match_specs.append(spec)
1f580a
 
1f580a
                             profiles.extend(module_profiles)
1f580a
                     for profile in profiles:
1f580a
diff --git a/tests/test_modules.py b/tests/test_modules.py
1f580a
index d5fde4f..49e7718 100644
1f580a
--- a/tests/test_modules.py
1f580a
+++ b/tests/test_modules.py
1f580a
@@ -274,16 +274,8 @@ class ModuleTest(unittest.TestCase):
1f580a
 
1f580a
     def test_install_implicit_empty_default_profile(self):
1f580a
         # install module without a 'default' profile
1f580a
-        # -> no packages should be installed, just module enablement
1f580a
-        self.module_base.install(["m4:1.4.18"])
1f580a
-
1f580a
-        self.assertEqual(self.base._moduleContainer.getModuleState("m4"),
1f580a
-                         libdnf.module.ModulePackageContainer.ModuleState_ENABLED)
1f580a
-        self.assertEqual(self.base._moduleContainer.getEnabledStream("m4"), "1.4.18")
1f580a
-        self.assertEqual(list(self.base._moduleContainer.getInstalledProfiles("m4")), [])
1f580a
-
1f580a
-        self.base.resolve()
1f580a
-        self.assertInstalls([])
1f580a
+        # -> It should raise an error
1f580a
+        self.assertRaises(dnf.exceptions.MarkingErrors, self.module_base.install, ["m4:1.4.18"])
1f580a
 
1f580a
     # dnf module upgrade / dnf upgrade @
1f580a
 
1f580a
--
1f580a
libgit2 0.28.2
1f580a