internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: cobbler/cobbler

Issue:
Bogus `console=ttyS-1,-1` gets inserted in append_line by default for systems (regression from 3.2.x), breaking regular output upon PXE boot
### Describe the bug

If a system is defined in cobbler, `console=ttyS-1,-1` gets added to the kernel_options by default, even though no serial options have been set. This breaks all screen output for PXE-booted installation enviroments.

This is a regression from 3.2.x.

### Steps to reproduce

1. `cobbler system add --name test --mac-address 01:02:03:04:05:06 --netboot-enabled True --profile AlmaLinux-8.6-x86_64` (with AlmaLinux-8.6-x86_64 being an existing profile)
2. `cobbler sync`
3. `cat /var/lib/tftpboot/grub/system/01\:02\:03\:04\:05\:06` now contains the kernel options ending in `console=ttyS-1,-1`
4. `cobbler system report --name test|grep Serial` yields:
    ```
    Serial Baud Rate               : -1
    Serial Device #                : -1
    ```
   on 3.2.x this used to be:
   ```
   Serial Baud Rate               : 
   Serial Device #                : 
   ```

### Expected behavior

Since no Serial options have actually been defined, the kernel options should not contain `console=ttyS-1,-1`

### Cobbler version

<!--- Paste output from `cobbler version` -->
````paste below
Cobbler 3.3.3
  source: 07b1d149, Thu May 12 15:26:31 2022 +0200
  build time: Fri May 13 15:37:22 2022
````

### Operating system

AlmaLinux 8.5


Discussion:

Resolving patch:
diff --git a/cobbler/tftpgen.py b/cobbler/tftpgen.py
--- a/cobbler/tftpgen.py
+++ b/cobbler/tftpgen.py
@@ -1138,15 +1138,18 @@ def build_kernel_options(
         # This also is architecture specific. E.g: Some ARM consoles need: console=ttyAMAx,BAUDRATE
         # I guess we need a serial_kernel_dev = param, that can be set to "ttyAMA" if needed.
         if system and arch == Archs.X86_64:
-            if system.serial_device or system.serial_baud_rate:
-                if system.serial_device:
-                    serial_device = system.serial_device
-                else:
+            if (
+                system.serial_device > -1
+                or system.serial_baud_rate != enums.BaudRates.DISABLED
+            ):
+                if system.serial_device == -1:
                     serial_device = 0
-                if system.serial_baud_rate:
-                    serial_baud_rate = system.serial_baud_rate.value
                 else:
+                    serial_device = system.serial_device
+                if system.serial_baud_rate == enums.BaudRates.DISABLED:
                     serial_baud_rate = 115200
+                else:
+                    serial_baud_rate = system.serial_baud_rate.value
 
                 append_line = "%s console=ttyS%s,%s" % (
                     append_line,


Test patch:
Repository: cobbler/cobbler

Issue:
[Backport]  Bogus console=ttyS-1,-1 gets inserted in append_line by default for systems (regression from 3.2.x), breaking regular output upon PXE boot #3102 
### Original feature issue

- Issue: #3102 
- PR: #3103 

### Target release

- [x] release33
- [ ] release32
- [ ] release30

### Reason

Stabilize 3.3.x branch



Discussion:

Resolving patch:
diff --git a/cobbler/tftpgen.py b/cobbler/tftpgen.py
--- a/cobbler/tftpgen.py
+++ b/cobbler/tftpgen.py
@@ -960,15 +960,15 @@ def build_kernel_options(self, system, profile, distro, image, arch: str, autoin
         # This also is architecture specific. E.g: Some ARM consoles need: console=ttyAMAx,BAUDRATE
         # I guess we need a serial_kernel_dev = param, that can be set to "ttyAMA" if needed.
         if system and arch == Archs.X86_64:
-            if system.serial_device or system.serial_baud_rate:
-                if system.serial_device:
-                    serial_device = system.serial_device
-                else:
+            if system.serial_device > -1 or system.serial_baud_rate != enums.BaudRates.DISABLED:
+                if system.serial_device == -1:
                     serial_device = 0
-                if system.serial_baud_rate:
-                    serial_baud_rate = system.serial_baud_rate.value
                 else:
+                    serial_device = system.serial_device
+                if system.serial_baud_rate == enums.BaudRates.DISABLED:
                     serial_baud_rate = 115200
+                else:
+                    serial_baud_rate = system.serial_baud_rate.value
 
                 append_line = "%s console=ttyS%s,%s" % (append_line, serial_device, serial_baud_rate)
 


Test patch:
Repository: cobbler/cobbler

Issue:
`grab_tree` is spamming the log file
### Describe the bug

The log file because unreasonable big because of `grab_tree` messages. They are important but not for normal day-by-day administration.

### Steps to reproduce

1. Look at the logfile
2. See spam

### Expected behavior

The logfile is not exploding.

### Cobbler version

````paste below
[root@nas-1-1 cobbler]# cobbler version
Cobbler 3.3.3
  source: 5c498dbf, Thu Jun 2 18:01:33 2022 +0200
  build time: Tue Jul  5 23:13:40 2022
````

### Operating system

Not relevant

### Cobbler log

See #3169

### Screenshots

None

### Additional information

Splitout of #3169



Discussion:

Resolving patch:
diff --git a/cobbler/items/item.py b/cobbler/items/item.py
--- a/cobbler/items/item.py
+++ b/cobbler/items/item.py
@@ -1010,7 +1010,7 @@ def grab_tree(self) -> list:
             parent = parent.parent
             # FIXME: Now get the object and check its existence
         results.append(self.api.settings())
-        self.logger.info(
+        self.logger.debug(
             "grab_tree found %s children (including settings) of this object",
             len(results),
         )


Test patch:
Repository: cobbler/cobbler

Issue:
[Backport] Kernel not found error message is not precise
### Original feature issue

- Issue: #3193
- PR: #3192

### Target release

- [x] release33
- [ ] release32
- [ ] release30

### Reason

Stabilization of SUSE Manager and Uyuni integration of Cobbler 3.3.3



Discussion:

Resolving patch:
diff --git a/cobbler/items/distro.py b/cobbler/items/distro.py
--- a/cobbler/items/distro.py
+++ b/cobbler/items/distro.py
@@ -164,7 +164,10 @@ def kernel(self, kernel: str):
         if not isinstance(kernel, str):
             raise TypeError("kernel was not of type str")
         if not utils.find_kernel(kernel):
-            raise ValueError("kernel not found: %s" % kernel)
+            raise ValueError(
+                "kernel not found or it does not match with allowed kernel filename pattern [%s]: %s."
+                % (utils._re_kernel.pattern, kernel)
+            )
         self._kernel = kernel
 
     @property
diff --git a/cobbler/utils.py b/cobbler/utils.py
--- a/cobbler/utils.py
+++ b/cobbler/utils.py
@@ -69,8 +69,8 @@
 MODULE_CACHE = {}
 SIGNATURE_CACHE = {}
 
-_re_kernel = re.compile(r'(vmlinu[xz]|(kernel|linux(\.img)?)|pxeboot\.n12|wimboot)')
-_re_initrd = re.compile(r'(initrd(.*)\.img|ramdisk\.image\.gz|boot\.sdi)')
+_re_kernel = re.compile(r'(vmlinu[xz]|(kernel|linux(\.img)?)|pxeboot\.n12|wimboot|mboot\.c32|.+\.kernel)')
+_re_initrd = re.compile(r'(initrd(.*)\.img|ramdisk\.image\.gz|boot\.sdi|imgpayld\.tgz)')
 
 
 class DHCP(enum.Enum):


Test patch:
Repository: cobbler/cobbler

Issue:
Packaging: Provide native packages for Debian & Ubuntu
### Is your feature request related to a problem?

Currently we only provide packages for Debian and Ubuntu via Debbuild. This is good for test installations or users how know the OBS already and are familiar with it.

### The Behaviour you'd like

`apt install cobbler`

### Alternatives you've considered

Well the OBS is nice and all but in the end we will probably have more users when providing Distro-Native packages. Also we will have a simpler specfile.

### Additional context

Current OBS project in my home: https://build.opensuse.org/project/show/home:SchoolGuy:cobbler



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -548,6 +548,7 @@ def run(self):
             "dnspython",
             "file-magic",
             "schema",
+            "gunicorn",
         ],
         extras_require={
             "lint": ["pyflakes", "pycodestyle"],


Test patch:
Repository: cobbler/cobbler

Issue:
Task logs don't end
### Describe the bug

Task logs contain the normal server logs, even though the task has stopped. This leads to duplicated logs in all created files.

### Steps to reproduce

1. `cobbler mkloaders` (or any other task)
2. Repeat step 1
3. See logs being appended to completed tasks

### Expected behavior

The files should only contain the logs for the task.

### Cobbler version

Commit: 2a5c7ce9c1533bbf6f6b9050198d98aca45a06ae

````paste below
Cobbler 3.4.0
  source: ?, ?
  build time: Fri Oct 14 14:17:09 2022
````

### Operating system

```
e62e937a2de9:/var/log/cobbler/tasks # cat /etc/os-release 
NAME="openSUSE Leap"
VERSION="15.3"
ID="opensuse-leap"
ID_LIKE="suse opensuse"
VERSION_ID="15.3"
PRETTY_NAME="openSUSE Leap 15.3"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:leap:15.3"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://www.opensuse.org/"
```

### Cobbler log

Not relevant

### Screenshots

Not relevant

### Additional information

Found by accident during another debugging session



Discussion:

Resolving patch:
diff --git a/cobbler/utils/thread.py b/cobbler/utils/thread.py
--- a/cobbler/utils/thread.py
+++ b/cobbler/utils/thread.py
@@ -41,6 +41,7 @@ def __init__(
         self.event_id = event_id
         self.remote = remote
         self.logger = logging.getLogger()
+        self.__task_log_handler = None
         self.__setup_logger()
         self._run = run
         self.on_done = on_done
@@ -55,13 +56,13 @@ def __setup_logger(self):
         Utility function that will set up the Python logger for the tasks in a special directory.
         """
         filename = pathlib.Path("/var/log/cobbler/tasks") / f"{self.event_id}.log"
-        task_log_handler = logging.FileHandler(str(filename), encoding="utf-8")
+        self.__task_log_handler = logging.FileHandler(str(filename), encoding="utf-8")
         task_log_formatter = logging.Formatter(
             "[%(threadName)s] %(asctime)s - %(levelname)s | %(message)s"
         )
-        task_log_handler.setFormatter(task_log_formatter)
+        self.__task_log_handler.setFormatter(task_log_formatter)
         self.logger.setLevel(logging.INFO)
-        self.logger.addHandler(task_log_handler)
+        self.logger.addHandler(self.__task_log_handler)
 
     def _set_task_state(self, new_state: enums.EventStatus):
         """
@@ -113,3 +114,5 @@ def run(self):
             utils.log_exc()
             self._set_task_state(enums.EventStatus.FAILED)
             return False
+        finally:
+            self.logger.removeHandler(self.__task_log_handler)


Test patch:
Repository: cobbler/cobbler

Issue:
Cobbler modules don't load properly
### Describe the bug

Introduced in https://github.com/cobbler/cobbler/commit/2477c78094af7ba44ecbe350294c775296d96560

### Steps to reproduce

1. Import any Cobbler Module
2. See import error

### Expected behavior

Bug not present

### Cobbler version

````paste below
````

### Operating system

openSUSE Tumbleweed

### Cobbler log

````paste below
````

### Screenshots

None

### Additional information

None



Discussion:

Resolving patch:
diff --git a/cobbler/module_loader.py b/cobbler/module_loader.py
--- a/cobbler/module_loader.py
+++ b/cobbler/module_loader.py
@@ -63,7 +63,7 @@ def load_modules(self):
             basename = filename.replace(self.mod_path, "")
             modname = ""
 
-            if basename in ("__pycache__", "__init__.py"):
+            if "__pycache__" in basename or "__init__.py" in basename:
                 continue
 
             if basename[0] == "/":


Test patch:
Repository: cobbler/cobbler

Issue:
Problem with pxelinux configs
Hi,

I encountered a problem with configs generated in pxelinux.cfg folder, specifically the line below:

        append initrd=/images/debian11-x86_64/initrd.gz  auto-install/enable=true priority=criticalnetcfg/choose_interface=auto url=http://1.1.1.1/cblr/svc/op/autoinstall/system/mydebian hostname=test domain=mydomain.com suite=bullseye

There appears to be an extra space between `initrd.gz` and `auto-install` and no space between `priority=critical` and `netcfg`. I traced the issue to file lib/python3/dist-packages/cobbler/tftpgen.py, specifically line:

        f"{append_line} auto-install/enable=true priority=critical"

If we delete the space between `}` and `auto`, followed by inserting space between `critical` and `"`:

        f"{append_line}auto-install/enable=true priority=critical "

 the config is generated as it should:

        append initrd=/images/debian11-x86_64/initrd.gz auto-install/enable=true priority=critical netcfg/choose_interface=auto url=http://1.1.1.1/cblr/svc/op/autoinstall/system/mydebian hostname=test domain=mydomain.com suite=bullseye


### Steps to reproduce

1. Add system to cobbler with netboot enabled
2. Observe contents of /srv/tftpd/pxelinux.cfg/

### Cobbler version

<!--- Paste output from `cobbler version` -->
````paste below
Cobbler 3.4.0                                                                                                         
  source: fb1a2d97, Tue Feb 14 18:52:39 2023 +0100                                                                    
  build time: Wed Sep 21 07:30:00 2022
````

### Operating system

<!--- On which operating system do you use Cobbler? -->
````paste below
Debian 11.5
````


Thanks,
B



Discussion:
Thanks for filing this bug. If you have found the bug, is it possible for you to also submit the PR?
PR submitted :)
Thanks a lot. Saw it already. :)
Reviewing your PR I noticed that the error might also be present in more places in `tftpgen.py`. However, no test atm is apparently sufficient to detect this. I don't know how much effort you can put into this however if you can put more effort in this I would love it if you could extend our `pytest` tests for `tftpgen.py` in a way that we can have a few cases for all distros that we support covered.

Resolving patch:
diff --git a/cobbler/tftpgen.py b/cobbler/tftpgen.py
--- a/cobbler/tftpgen.py
+++ b/cobbler/tftpgen.py
@@ -1152,7 +1152,7 @@ def build_kernel_options(
                     append_line += f" netdevice={management_mac}"
             elif distro.breed in ("debian", "ubuntu"):
                 append_line = (
-                    f"{append_line} auto-install/enable=true priority=critical"
+                    f"{append_line}auto-install/enable=true priority=critical "
                     f"netcfg/choose_interface=auto url={autoinstall_path}"
                 )
                 if management_interface:


Test patch:
Repository: cobbler/cobbler

Issue:
[Backport] autoinstall_templates are installed into /var/lib/cobbler/templates
### Original feature issue

- PR: #2590

### Target release

- [ ] release33
- [x] release32
- [ ] release30

### Reason

Stabilization of Cobbler 3.2.x in Fedora Ecosystem.



Discussion:

Resolving patch:
diff --git a/cobbler/actions/sync.py b/cobbler/actions/sync.py
--- a/cobbler/actions/sync.py
+++ b/cobbler/actions/sync.py
@@ -179,7 +179,7 @@ def clean_trees(self):
                 if x not in self.settings.webdir_whitelist:
                     # delete directories that shouldn't exist
                     utils.rmtree(path, logger=self.logger)
-                if x in ["autoinstall_templates", "autoinstall_templates_sys", "images", "systems", "distros", "profiles", "repo_profile", "repo_system", "rendered"]:
+                if x in ["templates", "images", "systems", "distros", "profiles", "repo_profile", "repo_system", "rendered"]:
                     # clean out directory contents
                     utils.rmtree_contents(path, logger=self.logger)
         #


Test patch:
diff --git a/tests/test_data/settings_old b/tests/test_data/settings_old
--- a/tests/test_data/settings_old
+++ b/tests/test_data/settings_old
@@ -92,7 +92,7 @@ cheetah_import_whitelist:
 createrepo_flags: "-c cache -s sha"
 
 # if no autoinstall template is specified to profile add, use this template
-default_autoinstall: /var/lib/cobbler/autoinstall_templates/default.ks
+default_autoinstall: /var/lib/cobbler/templates/default.ks
 
 # configure all installed systems to use these nameservers by default
 # unless defined differently in the profile.  For DHCP configurations
@@ -107,7 +107,7 @@ default_ownership:
  - "admin"
 
 # cobbler has various sample automatic installation templates stored
-# in /var/lib/cobbler/autoinstall_templates/.  This controls
+# in /var/lib/cobbler/templates/.  This controls
 # what install (root) password is set up for those
 # systems that reference this variable.  The factory
 # default is "cobbler" and cobbler check will warn if
Repository: cobbler/cobbler

Issue:
[Backport] GHSA-mcg6-h362-cmq5
### Original feature issue

- Advisory: https://github.com/advisories/GHSA-mcg6-h362-cmq5

### Target release

- [ ] release33
- [x] release32
- [ ] release30

### Reason

Stabilization of Cobbler 3.2.x in the Fedora Ecosystem



Discussion:

Resolving patch:
diff --git a/cobbler/modules/authentication/pam.py b/cobbler/modules/authentication/pam.py
--- a/cobbler/modules/authentication/pam.py
+++ b/cobbler/modules/authentication/pam.py
@@ -114,6 +114,10 @@ class PamConv(Structure):
 PAM_AUTHENTICATE.restype = c_int
 PAM_AUTHENTICATE.argtypes = [PamHandle, c_int]
 
+PAM_ACCT_MGMT = LIBPAM.pam_acct_mgmt
+PAM_ACCT_MGMT.restype = c_int
+PAM_ACCT_MGMT.argtypes = [PamHandle, c_int]
+
 
 def authenticate(api_handle, username: str, password: str) -> bool:
     """
@@ -155,4 +159,8 @@ def my_conv(n_messages, messages, p_response, app_data):
         return False
 
     retval = PAM_AUTHENTICATE(handle, 0)
+
+    if retval == 0:
+        retval = PAM_ACCT_MGMT(handle, 0)
+
     return retval == 0


Test patch:
Repository: cobbler/cobbler

Issue:
`cobbler buildiso` mixes given arguments
### Describe the bug

`cobbler buildiso` is switching the `--profile` and `--system`` arguments.

### Steps to reproduce

1. `cobbler buildiso --tempdir=/var/cache/cobbler/buildiso --iso /var/cache/cobbler/orchid.iso --distro=buildisodistro`
2. See error

### Expected behavior

`cobbler buildiso` works as expected and doesn't raise an error.

### Cobbler version

````paste below
---
````

### Operating system

<!--- On which operating system do you use Cobbler? -->

### Cobbler log

````paste below
# cobbler buildiso --tempdir=/var/cache/cobbler/buildiso --iso /var/cache/cobbler/orchid.iso --distro=buildisodistro --profile=orchid'
task started: 2023-04-24_143158_buildiso
task started (id=Build Iso, time=Mon Apr 24 14:31:58 2023)
"orchid" is not a valid profile or system
Exception occurred: <class 'ValueError'>
Exception value: No valid systems or profiles were specified.
Exception Info:
!!! TASK FAILED !!!
````

### Screenshots

None

### Additional information

Upstream report of: https://github.com/SUSE/spacewalk/issues/21269



Discussion:

Resolving patch:
diff --git a/cobbler/actions/buildiso/netboot.py b/cobbler/actions/buildiso/netboot.py
--- a/cobbler/actions/buildiso/netboot.py
+++ b/cobbler/actions/buildiso/netboot.py
@@ -684,7 +684,7 @@ def run(
         system_names = input_converters.input_string_or_list_no_inherit(systems)
         profile_names = input_converters.input_string_or_list_no_inherit(profiles)
         loader_config_parts = self._generate_boot_loader_configs(
-            system_names, profile_names, exclude_dns
+            profile_names, system_names, exclude_dns
         )
 
         buildisodir = self._prepare_buildisodir(buildisodir)


Test patch:
Repository: cobbler/cobbler

Issue:
Reduce time to make a new release
### Is your feature request related to a problem?

At the moment writing the changelog for a new release takes ages. It would be cool if we could automate that process.

### Provide a detailed description of the proposed feature

I would like to utilize https://github.com/release-drafter/release-drafter to draft the next release.

### Alternatives you've considered

- Manual work: Not scalable in the long-term.
- Ping me for alternatives. They should be compatible to GitHub Releases.

### Additional information

@nodeg was so nice to send me this as an idea.



Discussion:
Another option is to use https://github.com/twisted/towncrier. This is used by Saltstack and thus I have experience with it already. Towncrier would also enable us to publish a classical release file.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -612,6 +612,9 @@ def run(self):
                 "pytest-benchmark",
             ],
             "docs": ["sphinx", "sphinx-rtd-theme", "sphinxcontrib-apidoc"],
+            # We require the current version to properly detect duplicate issues
+            # See: https://github.com/twisted/towncrier/releases/tag/22.8.0
+            "changelog": ["towncrier>=22.8.0"],
         },
         packages=find_packages(exclude=["*tests*"]),
         scripts=[


Test patch:
Repository: cobbler/cobbler

Issue:
Notify to "systemd" when "cobblerd" startup has finished
### Is your feature request related to a problem?

As a sysadmin or developer,
I want to make "cobblerd" to notify "systemd" about cobblerd service startup has finished
so that I can have other dependand systemd services waiting until "cobblerd" is really ready to accept requests.

### Provide a detailed description of the proposed feature

By using `Type=notify` at systemd service definition for "cobblerd", this makes systemd to wait until "cobblerd" notifies the startup is finished. This makes "systemd" to not consider the "cobblerd" service as "active" until it receives the notification from "cobblerd".


### Alternatives you've considered

None

### Additional information

None



Discussion:

Resolving patch:
diff --git a/cobbler/cobblerd.py b/cobbler/cobblerd.py
--- a/cobbler/cobblerd.py
+++ b/cobbler/cobblerd.py
@@ -13,6 +13,8 @@
 import pwd
 import time
 
+import systemd.daemon  # type: ignore
+
 from cobbler import remote, utils
 from cobbler.api import CobblerAPI
 
@@ -81,6 +83,7 @@ def do_xmlrpc_rw(cobbler_api: CobblerAPI, port: int) -> None:
         # This is not critical, but debug only - just install python3-psutil
         pass
 
+    systemd.daemon.notify("READY=1")  # type: ignore
     while True:
         try:
             logger.info("Cobbler startup completed %s", start_time)
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -583,6 +583,7 @@ def run(self):
             "dnspython",
             "file-magic",
             "schema",
+            "systemd-python",
             "gunicorn",
         ],
         extras_require={


Test patch:
Repository: cobbler/cobbler

Issue:
cobbler check points to non-existent wiki page
### Describe the bug

cobbler check reports:
```
4: SELinux is enabled. Please review the following wiki page for details on ensuring Cobbler works correctly in your SELinux environment:
    https://github.com/cobbler/cobbler/wiki/Selinux
```
That wiki page does not exist.

### Cobbler version

<!--- Paste output from `cobbler version` -->
````paste below
Cobbler 3.4.0
  source: ?, ?
  build time: Mon Nov 27 00:21:47 2023
````


Discussion:

Resolving patch:
diff --git a/cobbler/actions/check.py b/cobbler/actions/check.py
--- a/cobbler/actions/check.py
+++ b/cobbler/actions/check.py
@@ -295,7 +295,7 @@ def check_selinux(self, status: List[str]) -> None:
             status.append(
                 "SELinux is enabled. Please review the following wiki page for details on ensuring Cobbler "
                 "works correctly in your SELinux environment:\n    "
-                "https://github.com/cobbler/cobbler/wiki/Selinux"
+                "https://cobbler.readthedocs.io/en/latest/user-guide/selinux.html"
             )
 
     def check_for_default_password(self, status: List[str]) -> None:


Test patch: