Bug 53642 - Changing computer name: TypeError: replace() argument 1 must be str, not bytes
Changing computer name: TypeError: replace() argument 1 must be str, not bytes
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: UDM (Generic)
UCS 5.0
Other Linux
: P5 normal (vote)
: UCS 5.0-0-errata
Assigned To: Florian Best
Dirk Wiesenthal
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2021-08-11 08:39 CEST by Florian Best
Modified: 2021-08-20 14:07 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: 2021081121000118, 2021080921000631, 2021080921000641
Bug group (optional): External feedback
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 2021-08-11 08:39:37 CEST
I cannot reproduce this, but a fix is easy.
I tested all standard computer roles, maybe it's some extension role.

Version: 5.0-0 errata65

Remark: Change Computer Name 

Error: 
Internal server error during "udm/put (computers/computer)".
Request: udm/put (computers/computer)

  File "%PY3%/notifier/threads.py", line 80, in _run
    result = self._function()
  File "%PY3%/notifier/__init__.py", line 105, in __call__
    return self._function(*tmp, **self._kwargs)
  File "%PY3%/univention/management/console/modules/udm/__init__.py", line 442, in _thread
    module.modify(properties)
  File "%PY3%/univention/management/console/modules/udm/udm_ldap.py", line 649, in modify
    obj.modify()
  File "%PY3%/univention/admin/handlers/__init__.py", line 636, in modify
    dn = self._modify(modify_childs, ignore_license=ignore_license, response=response)
  File "%PY3%/univention/admin/handlers/__init__.py", line 1360, in _modify
    self._ldap_post_modify()
  File "%PY3%/univention/admin/handlers/computers/__base.py", line 206, in _ldap_post_modify
    univention.admin.handlers.simpleComputer._ldap_post_modify(self)
  File "%PY3%/univention/admin/handlers/__init__.py", line 2776, in _ldap_post_modify
    self.__rename_dhcp_object(old_name=self.__changes['name'][0], new_name=self.__changes['name'][1])
  File "%PY3%/univention/admin/handlers/__init__.py", line 2220, in __rename_dhcp_object
    object['host'] = object['host'].replace(old_name, new_name)
TypeError: replace() argument 1 must be str, not bytes
Comment 1 Florian Best univentionstaff 2021-08-11 08:39:52 CEST
diff --git management/univention-directory-manager-modules/modules/univention/admin/handlers/__init__.py management/univention-directory-manager-modules/modules/univention/admin/handlers/__init__.py
index f61ac8a576..a3a9cf3164 100644
--- management/univention-directory-manager-modules/modules/univention/admin/handlers/__init__.py
+++ management/univention-directory-manager-modules/modules/univention/admin/handlers/__init__.py
@@ -2848,7 +2848,7 @@ class simpleComputer(simpleLdap):
 
                if self.hasChanged('name'):
                        ml.append(('sn', self.oldattr.get('sn', [None])[0], self['name'].encode('UTF-8')))
-                       self.__changes['name'] = (self.oldattr.get('sn', [None])[0], self['name'])
+                       self.__changes['name'] = (self.oldattr.get('sn', [None])[0].decode("UTF-8"), self['name'])
 
                if self.hasChanged('ip') or self.hasChanged('mac'):
                        dhcp = [self.__split_dhcp_line(entry) for entry in self.info.get('dhcpEntryZone', [])]
Comment 2 Florian Best univentionstaff 2021-08-11 08:41:32 CEST
#!/usr/share/ucs-test/runner pytest-3 -s -l -v
## desc: Rename object for all computer roles
## tags: [udm-computers]
## roles: [domaincontroller_master]
## exposure: careful
## packages:
##   - univention-config
##   - univention-directory-manager-tools

import univention.testing.udm as udm_test
import univention.testing.strings as uts
import univention.testing.utils as utils

import pytest


@pytest.mark.parametrize('role', udm_test.UCSTestUDM.COMPUTER_MODULES)
def test_all_roles_rename(role, udm):
        computer = udm.create_object(role, name=uts.random_string())
        udm.modify_object(role, dn=computer, name=uts.random_string())
        # TODO: verify ldap object
Comment 3 Florian Best univentionstaff 2021-08-11 08:56:39 CEST
univention-directory-manager-modules.yaml
97f762317912 | Bug #53642: fix changing computer name

univention-directory-manager-modules (15.0.11-14)
97f762317912 | Bug #53642: fix changing computer name
Comment 4 Dirk Wiesenthal univentionstaff 2021-08-11 13:25:11 CEST
This does not work:

Interner Server-Fehler in "udm/add (computers/computer)".
Request: udm/add (computers/computer)

  File "/usr/lib/python3/dist-packages/notifier/threads.py", line 80, in _run
    result = self._function()
  File "/usr/lib/python3/dist-packages/notifier/__init__.py", line 105, in __call__
    return self._function(*tmp, **self._kwargs)
  File "/usr/lib/python3/dist-packages/univention/management/console/modules/udm/__init__.py", line 404, in _thread
    dn = module.create(properties, container=options.get('container'), superordinate=options.get('superordinate'))
  File "/usr/lib/python3/dist-packages/univention/management/console/modules/udm/udm_ldap.py", line 570, in create
    obj.create()
  File "/usr/lib/python3/dist-packages/univention/admin/handlers/__init__.py", line 543, in create
    dn = self._create(response=response, serverctrls=serverctrls)
  File "/usr/lib/python3/dist-packages/univention/admin/handlers/__init__.py", line 1255, in _create
    al.extend(self._ldap_modlist())
  File "/usr/lib/python3/dist-packages/univention/admin/handlers/computers/__base.py", line 223, in _ldap_modlist
    ml = univention.admin.handlers.simpleComputer._ldap_modlist(self)
  File "/usr/lib/python3/dist-packages/univention/admin/handlers/__init__.py", line 2851, in _ldap_modlist
    self.__changes['name'] = (self.oldattr.get('sn', [None])[0].decode("UTF-8"), self['name'])
AttributeError: 'NoneType' object has no attribute 'decode'
Comment 5 Florian Best univentionstaff 2021-08-11 13:27:55 CEST
Oups, sorry.
Fixed in:

univention-directory-manager-modules (15.0.11-14)
cb269dd4db40 | fixup! Bug #53642: fix changing computer name
Comment 6 Dirk Wiesenthal univentionstaff 2021-08-11 13:53:20 CEST
Manual renaming a computer with and without DHCP service: OK
Codechange: OK
YAML: OK
Comment 7 Philipp Hahn univentionstaff 2021-08-11 16:37:29 CEST
<https://errata.software-univention.de/#/?erratum=5.0x67>