From 0a05872328f9d3f419a7f74d967b3aaeb3a65825 Mon Sep 17 00:00:00 2001
From: Jochen Breuer <jbreuer@suse.de>
Date: Fri, 9 Nov 2018 10:27:06 +0100
Subject: [PATCH 1/3] Yast uses textmode instead of text

In order to use textmode with SUSE distributions text has to be
replaced with textmode=1 and text has to be removed from the
kernel options.
---
 cobbler/action_buildiso.py | 21 +++++++++++++++++++--
 cobbler/pxegen.py          |  9 +++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/cobbler/action_buildiso.py b/cobbler/action_buildiso.py
index 749f5cbba..63d1e530b 100644
--- a/cobbler/action_buildiso.py
+++ b/cobbler/action_buildiso.py
@@ -115,7 +115,7 @@ def sort_name(self,a,b):
        """
        return cmp(a.name,b.name)
 
-  
+
     def generate_netboot_iso(self,imagesdir,isolinuxdir,profiles=None,systems=None,exclude_dns=None):
        """
        Create bootable CD image to be used for network installations
@@ -155,6 +155,15 @@ def generate_netboot_iso(self,imagesdir,isolinuxdir,profiles=None,systems=None,e
              cfg.write("  kernel %s.krn\n" % distname)
 
              data = utils.blender(self.api, False, profile)
+
+             # SUSE is not using 'text'. Instead 'textmode' is used as kernel option
+             if dist.breed == "suse":
+                 if 'textmode' in data['kernel_options'].keys():
+                     data['kernel_options'].pop('text', None)
+                 elif 'text' in data['kernel_options'].keys():
+                     data['kernel_options'].pop('text', None)
+                     data['kernel_options']['textmode'] = ['1']
+
              if data["kickstart"].startswith("/"):
                  data["kickstart"] = "http://%s:%s/cblr/svc/op/ks/profile/%s" % (
                      data["server"], self.api.settings().http_port, profile.name
@@ -357,7 +366,7 @@ def generate_netboot_iso(self,imagesdir,isolinuxdir,profiles=None,systems=None,e
              if my_dns is None:
                 if data.has_key("name_servers") and data["name_servers"] != "":
                    my_dns = data["name_servers"]
-             
+
              # add information to the append_line
              if my_int is not None:
                  if dist.breed == "suse":
@@ -457,6 +466,14 @@ def generate_standalone_iso(self,imagesdir,isolinuxdir,distname,filesource):
         for descendant in descendants:
             data = utils.blender(self.api, False, descendant)
 
+            # SUSE is not using 'text'. Instead 'textmode' is used as kernel option
+            if distro.breed == "suse":
+                if 'textmode' in data['kernel_options'].keys():
+                    data['kernel_options'].pop('text', None)
+                elif 'text' in data['kernel_options'].keys():
+                    data['kernel_options'].pop('text', None)
+                    data['kernel_options']['textmode'] = ['1']
+
             cfg.write("\n")
             cfg.write("LABEL %s\n" % descendant.name)
             cfg.write("  MENU LABEL %s\n" % descendant.name)
diff --git a/cobbler/pxegen.py b/cobbler/pxegen.py
index 288c5a726..fc873d9b6 100644
--- a/cobbler/pxegen.py
+++ b/cobbler/pxegen.py
@@ -775,6 +775,15 @@ def build_kernel_options(self, system, profile, distro, image, arch,
 
         append_line = ""
         kopts = blended.get("kernel_options", dict())
+
+        # SUSE is not using 'text'. Instead 'textmode' is used as kernel option
+        if distro.breed == "suse":
+            if 'textmode' in kopts.keys():
+                kopts.pop('text', None)
+            elif 'text' in kopts.keys():
+                kopts.pop('text', None)
+                kopts['textmode'] = ['1']
+
         # support additional initrd= entries in kernel options.
         if "initrd" in kopts:
             append_line = ",%s" % kopts.pop("initrd")

From babcd86176a933c594a6c21cf0e4b2f8c28474e9 Mon Sep 17 00:00:00 2001
From: Jochen Breuer <jbreuer@suse.de>
Date: Tue, 13 Nov 2018 16:31:07 +0100
Subject: [PATCH 3/3] Deduplicates suse-textmode code and moves it to utils

---
 cobbler/action_buildiso.py | 20 ++++----------------
 cobbler/pxegen.py          |  7 +------
 cobbler/utils.py           |  9 +++++++++
 3 files changed, 14 insertions(+), 22 deletions(-)

diff --git a/cobbler/action_buildiso.py b/cobbler/action_buildiso.py
index 50d720f92..41048b3e4 100644
--- a/cobbler/action_buildiso.py
+++ b/cobbler/action_buildiso.py
@@ -155,14 +155,8 @@ def generate_netboot_iso(self,imagesdir,isolinuxdir,profiles=None,systems=None,e
              cfg.write("  kernel %s.krn\n" % distname)
 
              data = utils.blender(self.api, False, profile)
-
-             # SUSE is not using 'text'. Instead 'textmode' is used as kernel option
-             if dist.breed == "suse":
-                 if 'textmode' in data['kernel_options'].keys():
-                     data['kernel_options'].pop('text', None)
-                 elif 'text' in data['kernel_options'].keys():
-                     data['kernel_options'].pop('text', None)
-                     data['kernel_options']['textmode'] = ['1']
+             # SUSE is not using 'text'. Instead 'textmode' is used as kernel option.
+             utils.suse_kopts_textmode_overwrite(dist.breed, data['kernel_options'])
 
              if data["kickstart"].startswith("/"):
                  data["kickstart"] = "http://%s:%s/cblr/svc/op/ks/profile/%s" % (
@@ -465,14 +459,8 @@ def generate_standalone_iso(self,imagesdir,isolinuxdir,distname,filesource):
 
         for descendant in descendants:
             data = utils.blender(self.api, False, descendant)
-
-            # SUSE is not using 'text'. Instead 'textmode' is used as kernel option
-            if distro.breed == "suse":
-                if 'textmode' in data['kernel_options'].keys():
-                    data['kernel_options'].pop('text', None)
-                elif 'text' in data['kernel_options'].keys():
-                    data['kernel_options'].pop('text', None)
-                    data['kernel_options']['textmode'] = ['1']
+            # SUSE is not using 'text'. Instead 'textmode' is used as kernel option.
+            utils.suse_kopts_textmode_overwrite(distro.breed, data['kernel_options'])
 
             cfg.write("\n")
             cfg.write("LABEL %s\n" % descendant.name)
diff --git a/cobbler/pxegen.py b/cobbler/pxegen.py
index fc873d9b6..0ca1397a6 100644
--- a/cobbler/pxegen.py
+++ b/cobbler/pxegen.py
@@ -777,12 +777,7 @@ def build_kernel_options(self, system, profile, distro, image, arch,
         kopts = blended.get("kernel_options", dict())
 
         # SUSE is not using 'text'. Instead 'textmode' is used as kernel option
-        if distro.breed == "suse":
-            if 'textmode' in kopts.keys():
-                kopts.pop('text', None)
-            elif 'text' in kopts.keys():
-                kopts.pop('text', None)
-                kopts['textmode'] = ['1']
+        utils.suse_kopts_textmode_overwrite(distro.breed, kopts)
 
         # support additional initrd= entries in kernel options.
         if "initrd" in kopts:
diff --git a/cobbler/utils.py b/cobbler/utils.py
index 9cf997779..1dbf95c61 100644
--- a/cobbler/utils.py
+++ b/cobbler/utils.py
@@ -2304,6 +2304,15 @@ def find_distro_path(settings, distro):
     # directory in which the given distro's kernel is
     return os.path.dirname(distro.kernel)
 
+def suse_kopts_textmode_overwrite(distro_breed, kopts):
+    """SUSE is not using 'text'. Instead 'textmode' is used as kernel option."""
+    if distro_breed == "suse":
+        if 'textmode' in kopts.keys():
+            kopts.pop('text', None)
+        elif 'text' in kopts.keys():
+            kopts.pop('text', None)
+            kopts['textmode'] = ['1']
+
 if __name__ == "__main__":
     print os_release() # returns 2, not 3
 
