Bug 51156 - fix python 3 compatibility of UCR interfaces
fix python 3 compatibility of UCR interfaces
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: UCR
UCS 4.4
All Linux
: P5 normal (vote)
: UCS 4.4-4-errata
Assigned To: Florian Best
Dirk Wiesenthal
:
Depends on: 49129
Blocks:
  Show dependency treegraph
 
Reported: 2020-04-23 11:57 CEST by Florian Best
Modified: 2020-04-29 12:32 CEST (History)
3 users (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:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Best univentionstaff 2020-04-23 11:57:19 CEST
We introduced in git:85c443999f96ddab1b36548bbe6f428afcf1ac2e a different use of ipaddress vs ipaddr module for the public API of univention.config_registry.interfaces:

> if six.PY3:
>         from ipaddress import IPv4Address, IPv4Network, IPv6Address, IPv6Network
> else:
>        from ipaddr import IPv4Address, IPv4Network, IPv6Address, IPv6Network

For Code using this (like univention-printserver, univention-squid, etc.) this is an non compatible API change, e.g. when using:
> list(univention.config_registry.interfaces.Interfaces(configRegistry).ipv4_interfaces)[0][1].ipv4_address().masked()
resulting in:
> AttributeError: 'IPv4Network' object has no attribute 'masked'

For now, we should use `ipaddr` and change this maybe in UCS 5.0.

Another detail, which is not yet python3 compatible is the encoding of stdin in univention.config_registry.handler.run_script().

$ python3 /usr/sbin/ucr --debug commit /etc/cups/cupsd.conf
Multifile: /etc/cups/cupsd.conf
Traceback (most recent call last):
  File "<stdin>", line 16, in <module>
AttributeError: 'bool' object has no attribute 'masked'
Traceback (most recent call last):
  File "<stdin>", line 16, in <module>
AttributeError: 'bool' object has no attribute 'masked'
Traceback (most recent call last):
  File "/usr/sbin/ucr", line 69, in <module>
    ub.main(convertToUtf8(sys.argv[1:]))
  File "/usr/lib/python3/dist-packages/univention/config_registry/frontend.py", line 777, in main
    result = handler_func(args, cmd_opts)
  File "/usr/lib/python3/dist-packages/univention/config_registry/frontend.py", line 287, in handler_commit
    handlers.commit(ucr, args)
  File "/usr/lib/python3/dist-packages/univention/config_registry/handler.py", line 1128, in commit
    self.call_handler(ucr, handler)
  File "/usr/lib/python3/dist-packages/univention/config_registry/handler.py", line 1147, in call_handler
    handler((ucr, values))
  File "/usr/lib/python3/dist-packages/univention/config_registry/handler.py", line 451, in __call__
    run_script(script_file, 'postinst', changed)
  File "/usr/lib/python3/dist-packages/univention/config_registry/handler.py", line 167, in run_script
    proc.communicate(''.join(diff))
  File "/usr/lib/python3.5/subprocess.py", line 786, in communicate
    self._stdin_write(input)
  File "/usr/lib/python3.5/subprocess.py", line 741, in _stdin_write
    self.stdin.write(input)
TypeError: a bytes-like object is required, not 'str

+++ This bug was initially created as a clone of Bug #49129 +++
Comment 1 Florian Best univentionstaff 2020-04-23 12:10:30 CEST
Both points addressed in:

univention-config-registry.yaml
5ea3b72bfb3c | YAML Bug #51156

univention-config-registry (14.0.0-15)
d5ad607e65f5 | Bug #51156: fix python3 compatibility in interfaces.py
4d2a5f2fb6af | Bug #51156: ucr: Fix python3 compatibility in handler.run_script()
Comment 2 Dirk Wiesenthal univentionstaff 2020-04-27 21:59:14 CEST
/etc/cups/cupsd.conf compiles again.

Code: OK
YAML: OK
Comment 3 Erik Damrose univentionstaff 2020-04-29 12:32:16 CEST
<http://errata.software-univention.de/ucs/4.4/557.html>