Bug 51368 - Fix python3 API - transition from ipaddr to ipaddress
Fix python3 API - transition from ipaddr to ipaddress
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: UCR
UCS 4.4
Other Linux
: P5 normal (vote)
: UCS 4.4-4-errata
Assigned To: Philipp Hahn
Florian Best
:
Depends on:
Blocks: 52017
  Show dependency treegraph
 
Reported: 2020-05-28 12:29 CEST by Philipp Hahn
Modified: 2020-09-15 15:30 CEST (History)
1 user (show)

See Also:
What kind of report is it?: Development Internal
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):
Max CVSS v3 score:
hahn: Patch_Available+


Attachments
backup (4.60 KB, patch)
2020-09-15 15:25 CEST, Florian Best
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Philipp Hahn univentionstaff 2020-05-28 12:29:30 CEST
"ipaddr" is the legacy Python 2 module; Python 3 has the native "ipaddress" module in stdlib <https://docs.python.org/3/library/ipaddress.html>.

They are incompatible in details.

UCS-4 based on Debian-9-Stretch
- it contains a backport of "python-ipaddress" <https://packages.debian.org/source/stretch/python-ipaddress>
- it has "python-ipaddr" <https://packages.debian.org/source/stretch/python-ipaddr>
- it has "python3-ipaddr" from Debian-7-Wheezy (!)

UCS-5 based on Debian-10-Buster:
- it still has the backport of "python-ipaddress" <https://packages.debian.org/source/buster/python-ipaddress>
- it has no "python3-ipaddr"
- it has "python-ipaddr" <https://packages.debian.org/source/buster/python-ipaddr>

(Interestingly enough Debian-11-Bullseye drops Python-2 completely, thus no longer has any "python-ipaddr[ess]", but re-introduces "python3-ipaddr" <https://packages.debian.org/source/bullseye/python-ipaddr>)


univention.config_registry.interfaces returns instances of ipaddr, so it is part of the API.
- for Python 2 we must continue using the legacy ipaddr
- for Python 3 we should switch to the stdlib ipaddress


There are also more issues in the Python 3 API.
Comment 1 Philipp Hahn univentionstaff 2020-05-28 18:08:00 CEST
[4.4-4] 31b3d28478 Bug #51368 UCR: Fix Python 3 API
 base/univention-config-registry/debian/changelog   |  6 +++++
 base/univention-config-registry/debian/control     |  1 -
 .../python/univention/config_registry/frontend.py  |  4 ++--
 .../univention/config_registry/interfaces.py       | 27 ++++++++++++----------
 4 files changed, 23 insertions(+), 15 deletions(-)

[4.4-4] a824921d6f Bug #51368 UCR: Fix mixed str | None
 .../python/univention/config_registry/interfaces.py               | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

[4.4-4] cb9706ced9 Bug #51368 UCR: Fix ucr.clear()
 .../python/univention/config_registry/backend.py                  | 8 ++++++++
 1 file changed, 8 insertions(+)

[4.4-4] 09509cefd5 Bug #51368 UCR: Fix unicode repr difference
 .../python/univention/config_registry/misc.py                         | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

[4.4-4] 2cbc4ac4a0 Bug #51368 UCR: Fix basestring
 base/univention-config-registry/python/univention/service_info.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

[4.4-4] e41c354ea8 Bug #51368 UCR: Convert unittest to pytest
 base/univention-config-registry/debian/control     |   3 +-
 base/univention-config-registry/debian/rules       |  10 +-
 .../debian/ucslint.overrides                       |   6 +
 .../python/univention/config_registry/backend.py   |   4 +-
 .../univention/config_registry/interfaces.py       | 385 -------------------
 .../tests/test_backend.py                          | 421 +++++++++------------
 .../tests/test_backend_threading.py                |  30 +-
 base/univention-config-registry/tests/test_cli.py  |  78 ++++
 base/univention-config-registry/tests/test_cli.sh  |  61 ---
 .../tests/test_info_tools.py                       | 232 ++++++------
 ...
 11 files changed, 793 insertions(+), 839 deletions(-)

Package: univention-config-registry
Version: 14.0.0-16A~4.4.0.202005281800
Branch: ucs_4.4-0
Scope: errata4.4-4

[4.4-4] ad3b88d7b7 Bug #51368: univention-config-registry 14.0.0-16A~4.4.0.202005281800
 doc/errata/staging/univention-config-registry.yaml | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Comment 2 Florian Best univentionstaff 2020-05-28 18:40:53 CEST
With the new API we need to differentiate the python version in:

base/univention-base-files/conffiles/etc/network/interfaces.d/10-default:
AttributeError: 'IPv4Interface' object has no attribute 'prefixlen'

services/univention-squid/conffiles/etc/squid/squid.conf:
AttributeError: 'IPv4Interface' object has no attribute 'prefixlen'

→ addr.network.prefixlen

services/univention-printserver/conffiles/etc/cups/cupsd.conf.d/01cupsd-base:
AttributeError: 'IPv4Interface' object has no attribute 'masked'

services/univention-samba4/96univention-samba4.inst:
AttributeError: 'IPv4Interface' object has no attribute 'masked'
Comment 3 Florian Best univentionstaff 2020-06-16 21:55:48 CEST
The fix so far is great.
I am wondering if we can integrate the patch git:506da07bb93043ea17c47b0b2dbe421cceaff6ae now, too? Or should we instead obosolete ipaddr in UCS 5?
I would like to have a reliable interface for Py2+3 somewhere.

One warning, which could also be addressed:
/usr/lib/python3/dist-packages/univention/config_registry/backend.py:39
  /usr/lib/python3/dist-packages/univention/config_registry/backend.py:39: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
    from collections import MutableMapping
Comment 4 Florian Best univentionstaff 2020-06-22 12:22:25 CEST
OK: after the daily we[Sönke,Arvid,me] decided to change the UCR Interfaces API for Python2 and Python 3 in UCS 5.0 and leave this as is.
Comment 5 Erik Damrose univentionstaff 2020-06-24 12:53:12 CEST
<http://errata.software-univention.de/ucs/4.4/638.html>
Comment 6 Florian Best univentionstaff 2020-09-15 15:25:04 CEST
Created attachment 10492 [details]
backup