Repository: cobbler/cobbler

Issue:
CNAMES silently failing to generate
### Describe the bug

Cobbler is silently failing to generate CNAMES when running `cobbler sync`. It appears as though the interface object used to be a dict but is now an object:

https://github.com/cobbler/cobbler/blob/a9efd94e58cb77bcab38ec35d19720e6e2776e29/cobbler/modules/managers/bind.py#L489

moving that line outside the try/except block reveals the failure:

```
generating /var/named/chroot/etc/secondary.conf
Exception occurred: <class 'AttributeError'>
Exception value: 'NetworkInterface' object has no attribute 'get'
Exception Info:
!!! TASK FAILED !!!
```

Therefore changing that line to:

```
if interface.dns_name != "":
```

Resolves the issue. 

<!--- A clear and concise description of what the bug is. -->

<!--- HINT: You can paste gist.github.com links for long logs or larger files -->

### Steps to reproduce

1. Create a system
```
NAME=testsys
IP=10.10.10.10
MAC=00:11:22:aa:bb:cc
PROFILE=testprofile

cobbler system add --name=${NAME} --dns-name=${NAME} --interface=eth0 --ip-address=${IP} --mac=${MAC} --profile=${PROFILE} --cnames=testcname
```
2. Run `cobbler sync`
3. Run `host testcname` and observe it is not found

### Expected behavior

I expect that `host testcname` would resolve correctly as a cname.

### Cobbler version

````paste below
# cobbler version
Cobbler 3.3.3
  source: ?, ?
  build time: Wed Jul 27 12:05:31 2022
#

````

### Operating system

<!--- On which operating system do you use Cobbler? -->
Rocky Linux 8.6

### Cobbler log

<!--- Paste (partial) output from `/var/log/cobbler/cobbler.log` -->
````paste below
[2022-08-12_044305_sync] 2022-08-12T04:43:17 - INFO | generating /var/named/chroot/etc/secondary.conf
[2022-08-12_044305_sync] 2022-08-12T04:43:17 - INFO | Exception occurred: <class 'AttributeError'>
[2022-08-12_044305_sync] 2022-08-12T04:43:17 - INFO | Exception value: 'NetworkInterface' object has no attribute 'get'
[2022-08-12_044305_sync] 2022-08-12T04:43:17 - INFO | Exception Info:
  File "/usr/lib/python3.6/site-packages/cobbler/remote.py", line 99, in run
    rc = self._run(self)

  File "/usr/lib/python3.6/site-packages/cobbler/remote.py", line 218, in runner
    self.remote.api.sync(self.options.get("verbose", False), what=what)

  File "/usr/lib/python3.6/site-packages/cobbler/api.py", line 1556, in sync
    sync_obj.run()

  File "/usr/lib/python3.6/site-packages/cobbler/actions/sync.py", line 163, in run
    self.dns.write_configs()

  File "/usr/lib/python3.6/site-packages/cobbler/modules/managers/bind.py", line 610, in write_configs
    self.__write_zone_files()

  File "/usr/lib/python3.6/site-packages/cobbler/modules/managers/bind.py", line 571, in __write_zone_files
    metadata['cname_record'] = self.__pretty_print_cname_records(hosts)

  File "/usr/lib/python3.6/site-packages/cobbler/modules/managers/bind.py", line 478, in __pretty_print_cname_records
    foo = interface.get("dns_name", "")

[2022-08-12_044305_sync] 2022-08-12T04:43:17 - ERROR | ### TASK FAILED ###

````

### Screenshots

<!--- If applicable, add screenshots to help explain your problem. -->

### Additional information

<!--- Add any other context about the problem here. -->



Discussion:
@AaronBandt Thanks for the bug report and spot. I will create a PR and fix that on `main` for you. It will take a while though that this will get release because the web-interface is not ready for release yet sadly.

Resolving patch:
diff --git a/cobbler/modules/managers/bind.py b/cobbler/modules/managers/bind.py
--- a/cobbler/modules/managers/bind.py
+++ b/cobbler/modules/managers/bind.py
@@ -486,7 +486,7 @@ def __pretty_print_cname_records(self, hosts, rectype: str = "CNAME"):
                 cnames = interface.cnames
 
                 try:
-                    if interface.get("dns_name", "") != "":
+                    if interface.dns_name != "":
                         dnsname = interface.dns_name.split(".")[0]
                         for cname in cnames:
                             s += "%s  %s  %s;\n" % (
@@ -495,14 +495,17 @@ def __pretty_print_cname_records(self, hosts, rectype: str = "CNAME"):
                                 dnsname,
                             )
                     else:
-                        self.logger.info(
-                            "Warning: dns_name unspecified in the system: %s, Skipped!, while writing "
-                            "cname records",
+                        self.logger.warning(
+                            'CNAME generation for system "%s" was skipped due to a missing dns_name entry while writing'
+                            "records!",
                             system.name,
                         )
                         continue
-                except:
-                    pass
+                except Exception as exception:
+                    self.logger.exception(
+                        "Unspecified error during creation of CNAME for bind9 records!",
+                        exc_info=exception,
+                    )
 
         return s
 


Test patch: