Blob Blame History Raw
From 25d7c0129c7a5490f2c735cd927555c043e04ff6 Mon Sep 17 00:00:00 2001
From: Jaroslav Mracek <jmracek@redhat.com>
Date: Wed, 13 Feb 2019 16:27:39 +0100
Subject: [PATCH] Not allow direct module switch (RhBug:1669491)

---
 dnf/cli/commands/module.py | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/dnf/cli/commands/module.py b/dnf/cli/commands/module.py
index edb3dfd..6d23bd2 100644
--- a/dnf/cli/commands/module.py
+++ b/dnf/cli/commands/module.py
@@ -31,6 +31,14 @@ import libdnf
 import dnf.module.module_base
 import dnf.exceptions
 
+
+def report_module_switch(switchedModules):
+    msg1 = _("The operation would result in switching of module '{0}' stream '{1}' to "
+             "stream '{2}'")
+    for moduleName, streams in switchedModules.items():
+        logger.warning(msg1.format(moduleName, streams[0], streams[1]))
+
+
 class ModuleCommand(commands.Command):
     class SubCommand(commands.Command):
 
@@ -115,6 +123,14 @@ class ModuleCommand(commands.Command):
                             libdnf.module.ModulePackageContainer.ModuleErrorType_ERROR_IN_DEFAULTS:
                         raise e
                 logger.error(str(e))
+            switchedModules = dict(self.base._moduleContainer.getSwitchedStreams())
+            if switchedModules:
+                report_module_switch(switchedModules)
+                msg = _("It is not possible to switch enabled streams of a module.\n"
+                        "It is recommended to remove all installed content from the module, and "
+                        "reset the module using 'dnf module reset <module_name>' command. After "
+                        "you reset the module, you can enable the other stream.")
+                raise dnf.exceptions.Error(msg)
 
     class DisableSubCommand(SubCommand):
 
@@ -178,6 +194,14 @@ class ModuleCommand(commands.Command):
                     if e.no_match_group_specs or e.error_group_specs:
                         raise e
                 logger.error(str(e))
+            switchedModules = dict(self.base._moduleContainer.getSwitchedStreams())
+            if switchedModules:
+                report_module_switch(switchedModules)
+                msg = _("It is not possible to switch enabled streams of a module.\n"
+                        "It is recommended to remove all installed content from the module, and "
+                        "reset the module using 'dnf module reset <module_name>' command. After "
+                        "you reset the module, you can install the other stream.")
+                raise dnf.exceptions.Error(msg)
 
     class UpdateSubCommand(SubCommand):
 
--
libgit2 0.27.7