Repository: cobbler/cobbler

Issue:
New systems have two identical interfaces
### Describe the bug

<!--- A clear and concise description of what the bug is. -->

<!--- HINT: You can paste gist.github.com links for long logs or larger files -->

Running `cobbler system add --name new --profile foobar --mac 11:22:33:44:55:66`
creates a system with two identical interfaces:

```
$ cobbler system add --name new --profile foobar --mac 11:22:33:44:55:66
$ cobbler system report --name new | grep -E '^(Interface =====|MAC Address)'
Interface =====                : default
MAC Address                    : 11:22:33:44:55:66
Interface =====                : None
MAC Address                    : 11:22:33:44:55:66
```

### Steps to reproduce

1. Create a new system via `cobbler system add`

### Expected behavior

<!--- A clear and concise description of what you expected to happen. -->

There should be only one interface instead of two.

### Cobbler version

<!--- Paste output from `cobbler version` -->
````paste below
Cobbler 3.2.1
  source: ?, ?
  build time: Tue Jun 22 15:41:34 2021
````

### Operating system

<!--- On which operating system do you use Cobbler? -->
CentOS 8.

### Cobbler log

<!--- Paste (partial) output from `/var/log/cobbler/cobbler.log` -->
````paste below
[Thread-154] 2021-06-22T21:37:57 - INFO | REMOTE get_settings; user(?)
[Thread-155] 2021-06-22T21:37:57 - INFO | REMOTE get_item(system,new); user(?)
[Thread-155] 2021-06-22T21:37:57 - DEBUG | get_item; ['system', 'new']
[Thread-155] 2021-06-22T21:37:57 - DEBUG | done with get_item; ['system', 'new']
[Thread-159] 2021-06-22T21:39:49 - INFO | REMOTE version; user(?)
````



Discussion:
This can in my eyes not happen but since it does anyway, I believe that this is happening somewhere in `xapi_object_edit` in the Lines 1950 and 1966. I will try to debug.

Resolving patch:
diff --git a/cobbler/items/system.py b/cobbler/items/system.py
--- a/cobbler/items/system.py
+++ b/cobbler/items/system.py
@@ -1070,7 +1070,7 @@ def get_mac_address(self, interface: str):
         Get the mac address, which may be implicit in the object name or explicit with --mac-address.
         Use the explicit location first.
 
-        :param interface:
+        :param interface: The name of the interface to get the MAC of.
         """
 
         intf = self.__get_interface(interface)
@@ -1084,7 +1084,7 @@ def get_ip_address(self, interface: str):
         """
         Get the IP address for the given interface.
 
-        :param interface:
+        :param interface: The name of the interface to get the IP address of.
         """
         intf = self.__get_interface(interface)
         if intf.ip_address:
diff --git a/cobbler/remote.py b/cobbler/remote.py
--- a/cobbler/remote.py
+++ b/cobbler/remote.py
@@ -1950,10 +1950,12 @@ def xapi_object_edit(self, object_type: str, object_name: str, edit_type: str, a
                     system_to_edit = self.__get_object(handle)
                     if system_to_edit is None:
                         raise ValueError("No system found with the specified name (name given: \"%s\")!" % object_name)
-                    interface = system_to_edit.interfaces.get(attributes.get("interface"))
-                    if not interface:
-                        interface = system_to_edit.interfaces.get("default")
-                    if not interface:
+                    # If we don't have an explicit interface name use the default interface
+                    interface_name = attributes.get("interface", "default")
+                    self.logger.debug("Interface \"%s\" is being edited.", interface_name)
+                    interface = system_to_edit.interfaces.get(interface_name)
+                    if interface is None:
+                        # If the interface is not existing, create a new one.
                         interface = system.NetworkInterface(self.api)
                     for attribute_key in attributes:
                         if self.__is_interface_field(attribute_key):
@@ -1964,7 +1966,7 @@ def xapi_object_edit(self, object_type: str, object_name: str, edit_type: str, a
                                                     attribute_key)
                         else:
                             self.logger.debug("Field %s was not an interface field.", attribute_key)
-                    system_to_edit.interfaces.update({attributes.get("interface"): interface})
+                    system_to_edit.interfaces.update({interface_name: interface})
                 elif "delete_interface" in attributes:
                     system_to_edit = self.__get_object(handle)
                     system_to_edit.delete_interface(attributes.get("interface"))


Test patch: