Bug 25163 - Automatische Zuweisung von IP-Adressen anpassen
Automatische Zuweisung von IP-Adressen anpassen
Status: REOPENED
Product: UCS
Classification: Unclassified
Component: UMC - Computers
UCS 5.0
Other Linux
: P5 normal (vote)
: ---
Assigned To: UMC maintainers
:
: 25204 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-12-05 13:35 CET by Alexander Kläser
Modified: 2023-06-23 12:21 CEST (History)
4 users (show)

See Also:
What kind of report is it?: ---
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional): Cleanup
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Kläser univentionstaff 2011-12-05 13:35:01 CET
Derzeit gibt wurde eine Workaround in dem UMC-UDM-Modul eingebaut, um den unten beschriebenen Fehler zu umgehen. Das sollte noch korrekt angepasst werden. Der Workaround befindet sich in der folgenden Datei:

  univention-management-console-module-udm/umc/python/udm/udm_ldap.py

Hier die Fehlerbeschreibung aus Bug 24077, Comment 6:

> (In reply to comment #3)
> > Mit folgendem Netzwerk wurde mir nach dem Hinzufügen eines Rechners beim
> > hinzufügen eines weiteren Rechners wieder die gleiche (.11) Adresse
> > vorgeschlagen.
> > 
> > DN: cn=bereich,cn=networks,dc=erster,dc=tag
> > ARG: None
> >   dnsEntryZoneReverse: None
> >   netmask: 24
> >   dhcpEntryZone: None
> >   name: bereich
> >   dnsEntryZoneForward: None
> >   ipRange: 2.3.4.1 2.3.4.254
> >   nextIp: 2.3.4.11
> >   network: 2.3.4.0
> 
> Das scheint an folgendem Problem zu liegen: die Logik, ob der interne Zähler
> für die nächste freie IP-Adress hochgezählt wird oder nicht, wird in
> simpleComputer.__setitem__() durchgeführt, wenn das Netzwerk verändert wird. Im
> alten UDM-Frontend wurde das Netzwerk durch die Reihenfolge der Reiter
> wahrscheinlich immer vor der IP-Adresse gesetzt. Das ist jetzt nicht mehr der
> Fall, das alle Werte auf einmal an das Backend übermittelt werden. Dort ist
> dann die Reihenfolge der zu setzenden Werte unterschiedlich. Für einen
> IP-Managed-Client wird zuerst die IP-Adresse, dann das Netzwerk und für einen
> Windows-Client umgekehrt gesetzt.
> 
> Hier die Reihenfolge der Werte, die gesetzt werden, für einen Windows-Client:
> 
> ====================
> 05.12.11 12:42:55.738  MODULE      ( INFO    ) : Setting property shell to
> /bin/false
> 05.12.11 12:42:55.738  MODULE      ( INFO    ) : Setting property network to
> cn=default,cn=networks,cn=umc,cn=univention,cn=dev
> 05.12.11 12:42:55.850  MODULE      ( INFO    ) : Setting property ip to
> ['10.200.26.60']
> 05.12.11 12:42:55.850  MODULE      ( INFO    ) : Setting of property ignored
> (is empty)
> 05.12.11 12:42:55.867  MODULE      ( INFO    ) : Setting property unixhome to
> /dev/null
> 05.12.11 12:42:55.867  MODULE      ( INFO    ) : Setting property
> dnsEntryZoneReverse to
> [['zoneName=26.200.10.in-addr.arpa,cn=dns,cn=umc,cn=univention,cn=dev',
> '10.200.26.60']]
> 05.12.11 12:42:55.867  MODULE      ( INFO    ) : Setting of property ignored
> (is empty)
> 05.12.11 12:42:55.868  MODULE      ( INFO    ) : Setting property primaryGroup
> to cn=Windows Hosts,cn=groups,cn=umc,cn=univention,cn=dev
> 05.12.11 12:42:55.868  MODULE      ( INFO    ) : Setting property
> dnsEntryZoneForward to
> [['zoneName=umc.univention.dev,cn=dns,cn=umc,cn=univention,cn=dev',
> '10.200.26.60']]
> 05.12.11 12:42:55.868  MODULE      ( INFO    ) : Setting of property ignored
> (is empty)
> 05.12.11 12:42:55.868  MODULE      ( INFO    ) : Setting property name to
> newwin1
> ====================
> 
> Und hier die Reihenfolge eines IP-Managed-Clients:
> 
> ====================
> 05.12.11 12:44:09.272  MODULE      ( INFO    ) : Setting property name to
> newipmanaged1
> 05.12.11 12:44:09.273  MODULE      ( INFO    ) : Setting property ip to
> ['10.200.26.61']
> 05.12.11 12:44:09.273  MODULE      ( INFO    ) : Setting of property ignored
> (is empty)
> 05.12.11 12:44:09.273  MODULE      ( INFO    ) : Setting property
> dnsEntryZoneReverse to
> [['zoneName=26.200.10.in-addr.arpa,cn=dns,cn=umc,cn=univention,cn=dev',
> '10.200.26.61']]
> 05.12.11 12:44:09.273  MODULE      ( INFO    ) : Setting of property ignored
> (is empty)
> 05.12.11 12:44:09.273  MODULE      ( INFO    ) : Setting property
> dnsEntryZoneForward to
> [['zoneName=umc.univention.dev,cn=dns,cn=umc,cn=univention,cn=dev',
> '10.200.26.61']]
> 05.12.11 12:44:09.273  MODULE      ( INFO    ) : Setting of property ignored
> (is empty)
> 05.12.11 12:44:09.273  MODULE      ( INFO    ) : Setting property network to
> cn=default,cn=networks,cn=umc,cn=univention,cn=dev
> ====================
Comment 1 Alexander Kläser univentionstaff 2011-12-06 09:46:40 CET
*** Bug 25204 has been marked as a duplicate of this bug. ***
Comment 2 Alexander Kläser univentionstaff 2011-12-06 09:47:08 CET
(In reply to comment #1)
> *** Bug 25204 has been marked as a duplicate of this bug. ***

Aus Bug 25204:

> 2. Der erste Rechner im neuen Netz wurde mit  10.200.2.1 angelegt, dann
> folgte 10.200.2.3, dann 10.200.2.4, dann 10.200.2.5, d.h. 10.200.2.2 wurde
> ausgelassen.
Comment 3 Alexander Kläser univentionstaff 2012-07-06 16:20:05 CEST
Idealerweise würde man sich wünschen, dass es eine Funktion gibt, die die nächste freie IP-Adresse zurückgibt. Diese Funktion kann auf eine intern vermerkte nächste freie IP-Adresse zurückgreifen (prinzipiell, aber nicht zwingenderweise) und diese hochzählen, wenn die Adresse bereits vergeben ist. Diese Funktion sollte dann auch eine Excpeption werfen, wenn keine IP-Adressen aus dem Pool mehr frei sind.

Derzeit ist es problematisch, dass das Hochzählen des internen IP-Adresse-Zählers aus simpleComputer initiiert wird beim Setzen des Netzwerk-Objektes an einem Computer.

Da der beschriebene Bug unschön ist, aber kein unmittelbares Problem auslöst, wird der Bug im Zuge einer Cleanup-Aktion später angegangen.
Comment 4 Stefan Gohmann univentionstaff 2017-06-16 20:36:19 CEST
This issue has been filed against UCS 3. UCS 3 is out of the normal maintenance and many UCS components have vastly changed in UCS 4.

If this issue is still valid, please change the version to a newer UCS version otherwise this issue will be automatically closed in the next weeks.
Comment 5 Stefan Gohmann univentionstaff 2017-08-08 07:07:26 CEST
This issue has been filed against UCS 3.0.

UCS 3.0 is out of maintenance and many UCS components have vastly changed in later releases. Thus, this issue is now being closed.

If this issue still occurs in newer UCS versions, please use "Clone this bug" or reopen this issue. In this case please provide detailed information on how this issue is affecting you.
Comment 6 Johannes Lohmer univentionstaff 2022-06-29 16:08:18 CEST
# Introduction
- this bug still occurs:
    - The existing workaround is implemented for the UMC and UDM-REST-API but not for the UDM-CLI
    - The workaround only fixes one of at least two cases.
- This bug still occuurs and now also affects the UDM CLI.

A dhcp network entry is not created due to wrong/a conflict LDAP entry creation order of `network` and `mac`
​
While migrating 66_udm-computers/31_all_roles_creation_set_network.py to pytest, a bug in UDM was discovered:
When a computer is created without assigning a ip address but with assigning a network (which assigns the next free IP address) the creation of the DHCP service for that computer object fails.
​
Creating a network requires a mac-address but the entry creation order does not enforce this.
​
# Reproduce the bug:
- execute the python test
- execute the test manually:
​
## setup:
### create DNS zones:
udm dns/forward_zone create --position cn=dns,dc=jojo-31,dc=intranet --set zone=cqq4n83jxm.z8iyqevhzy --set nameserver=eytdgvfchqx
udm dns/reverse_zone create --position cn=dns,dc=jojo-31,dc=intranet --set subnet=10.20.30 --set nameserver=huuwycaloj
### create Network:
udm networks/network create --set name=nt1lvegbmc --set network=10.20.30.0 --set netmask=24 --set dnsEntryZoneForward=zoneNgame=cqq4n83jxm.z8iyqevhzy,cn=dns,dc=jojo-31,dc=intranet --set dnsEntryZoneReverse=zoneName=30.20.10.in-addr.arpa,cn=dns,dc=jojo-31,dc=intranet --set dhcpEntryZone=cn=dytwico7ym,dc=jojo-31,dc=intranet --set 'ipRange=10.20.30.2 10.20.30.254'
​
## test:
/usr/sbin/udm-test computers/windows create --set network=cn=nt1lvegbmc,dc=jojo-31,dc=intranet --set mac=01:23:45:67:89:ab --set name=sle7oyv7xx2
​
## verify:
univention-ldapsearch -LLL -b 'cn=sle7oyv7xx2,cn=dytwico7ym,dc=jojo-31,dc=intranet' dn
​
## outcome:
the ldapsearch can't find the dhcp/host because it was not created.
​
# Notes on a solution:
​
the behaviour of `management/univention-directory-manager-modules/modules/univention/admin/handlers/__init__.py` depends on the LDAP entry creation order, the order of the modification list.
​
This order needs to be intelligently sorted:
1. the `network` entry must be set before the `ip` entry
    if a static ip address is specified, it must overwrite the automatic dhcp ip, not the other way around.
2. the `mac` entry must be set before the `network` entry
    no network object is created if the mac entry does not exist already.
There may be more requirements

## TODO:
- check for other requirements
either: Fix behaviour in UDM itself
or:​ Fix in **all** UDM implementations:
    - extend the workaround in the UDM-REST-API and UMC
    - implement the workaround in the UDM-CLI

## POC for the UDM-CLI:
​
```
--- management/univention-directory-manager-modules/modules/univention/admincli/admin.py
+++ management/univention-directory-manager-modules/modules/univention/admincli/admin.py
@@ -245,10 +245,18 @@ def module_information(module, identifies_only=0):
        return information
​
​
+def _tmp_cmp(i):
+       if i[0] == 'mac':
+               return ("\x00", i[1])
+       if i[0] == 'network':
+               return ("\x01", i[1])
+       return i
+
+
 def object_input(module, object, input, append=None, remove=None):
        out = []
        if append:
-               for key, values in append.items():
+               for key, values in sorted(append.items(), key=_tmp_cmp):
                        if key in object and not object.has_property(key):
                                opts = module.property_descriptions[key].options
                                if len(opts) == 1:
@@ -313,7 +321,7 @@ def object_input(module, object, input, append=None, remove=None):
                        object[key] = current_values
​
        if input:
-               for key, value in input.items():
+               for key, value in sorted(input.items(), key=_tmp_cmp):
                        if key in object and not object.has_property(key):
                                opts = module.property_descriptions[key].options
                                if len(opts) == 1:
```