Problem:UCS@school listing computer objects failed - KeyError: 'ucsschoolRole'

Problem

When listing computers objects in the computers module of School Administration you get a error and empty search.
image001

Internal Server-Error in "schoolwizards/computers/query (schoolwizards/computers)".
Request: schoolwizards/computers/query (schoolwizards/computers)

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/univention/management/console/base.py", line 387, in __error_handling
    six.reraise(etype, exc, etraceback)
  File "/usr/lib/python3/dist-packages/six.py", line 693, in reraise
    raise value
  File "/usr/lib/python3/dist-packages/univention/management/console/base.py", line 285, in execute
    function.__func__(self, request, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/univention/management/console/modules/decorators.py", line 189, in _response
    return function(self, request)
  File "/usr/lib/python3/dist-packages/univention/management/console/modules/schoolwizards/__init__.py", line 241, in _decorated
    ret = func(self, request, *a, **kw)
  File "/usr/lib/python3/dist-packages/ucsschool/lib/school_umc_ldap_connection.py", line 156, in wrapper_func
    return func(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/univention/management/console/modules/schoolwizards/__init__.py", line 555, in get_computers
    computer_class, school, request.options.get("filter"), ldap_user_read, school_prefix=False
  File "/usr/lib/python3/dist-packages/univention/management/console/modules/schoolwizards/__init__.py", line 458, in _get_all
    school_prefix=school_prefix,
  File "/usr/lib/python3/dist-packages/ucsschool/lib/models/base.py", line 940, in get_all
    ret.append(cls.from_udm_obj(udm_obj, school, lo))
  File "/usr/lib/python3/dist-packages/ucsschool/lib/models/computer.py", line 424, in from_udm_obj
    obj = super(SchoolComputer, cls).from_udm_obj(udm_obj, sch/usr/share/ucs-school-import/scripts/fix_ucsschool_roles --dry-runool, lo)
  File "/usr/lib/python3/dist-packages/ucsschool/lib/models/base.py", line 1017, in from_udm_obj
    return klass.from_udm_obj(udm_obj, school, lo)
  File "/usr/lib/python3/dist-packages/ucsschool/lib/models/computer.py", line 424, in from_udm_obj
    obj = super(SchoolComputer, cls).from_udm_obj(udm_obj, school, lo)
  File "/usr/lib/python3/dist-packages/ucsschool/lib/models/base.py", line 1027, in from_udm_obj
    udm_value = udm_obj[attr.udm_name]
  File "/usr/lib/python3/dist-packages/univention/admin/handlers/__init__.py", line 479, in __getitem__
    elif key not in self.__no_default and self.descriptions[key].editable:
KeyError: 'ucsschoolRole'

Hint

If you search for a specific co/usr/share/ucs-school-import/scripts/fix_ucsschool_roles --dry-runmputer, the search will return a suitable result.

Solution

1.
On the primary node, use the following command to check for a failed school server.

/usr/share/ucs-school-import/scripts/fix_ucsschool_roles --dry-run

Changing "ucsschoolRole" of 'cn=srv-ucs,cn=dc,cn=server,cn=computers,ou=ucs,dc=schule,dc=univention,dc=intranet' from [b'dc_slave_edu:school:ucs', b'win_computer:school:ucs'] to [b'dc_slave_edu:school:ucs', b'dc_slave_edu:school:ucs'].
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/univention/admin/uldap.py", line 797, in modify
    return self.lo.modify(dn, changes, serverctrls=serverctrls, response=response, rename_callback=rename_callback)
  File "/usr/lib/python3/dist-packages/univention/uldap.py", line 212, in _decorated
    return func(self, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/univention/uldap.py", line 765, in modify
    self.modify_ext_s(dn, ml, serverctrls=serverctrls, response=response)
  File "/usr/lib/python3/dist-packages/univention/uldap.py", line 212, in _decorated
    return func(self, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/univention/uldap.py", line 824, in modify_ext_s
    rtype, rdata, rmsgid, resp_ctrls = self.lo.modify_ext_s(dn, ml, serverctrls=serverctrls)
  File "/usr/lib/python3/dist-packages/ldap/ldapobject.py", line 1253, in modify_ext_s
    return self._apply_method_s(SimpleLDAPObject.modify_ext_s,*args,**kwargs)
  File "/usr/lib/python3/dist-packages/ldap/ldapobject.py", line 1197, in _apply_method_s
    return func(self,*args,**kwargs)
  File "/usr/lib/python3/dist-packages/ldap/ldapobject.py", line 602, in modify_ext_s
    resp_type, resp_data, resp_msgid, resp_ctrls = self.result3(msgid,all=1,timeout=self.timeout)
  File "/usr/lib/python3/dist-packages/ldap/ldapobject.py", line 749, in result3
    resp_ctrl_classes=resp_ctrl_classes
  File "/usr/lib/python3/dist-packages/ldap/ldapobject.py", line 756, in result4
    ldap_result = self._ldap_call(self._l.result4,msgid,all,timeout,add_ctrls,add_intermediates,add_extop)
  File "/usr/lib/python3/dist-packages/ldap/ldapobject.py", line 329, in _ldap_call
    reraise(exc_type, exc_value, exc_traceback)
  File "/usr/lib/python3/dist-packages/ldap/compat.py", line 44, i /usr/share/ucs-school-import/scripts/fix_ucsschool_slavesn reraise
    raise exc_value
  File "/usr/lib/python3/dist-packages/ldap/ldapobject.py", line 313, in _ldap_call
    result = func(*args,**kwargs)
ldap.TYPE_OR_VALUE_EXISTS: {'desc': 'Type or value exists', 'info': 'ucsschoolRole: value #0 provided more than once'}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/share/ucs-school-import/scripts/fix_ucsschool_roles", line 99, in <module>
    lo.modify(dn, [("ucsschoolRole", old_roles, new_roles)])
  File "/usr/lib/python3/dist-packages/univention/admin/uldap.py", line 808, in modify
    raise univention.admin.uexceptions.ldapError(_err2str(msg), original_exception=msg)
univention.admin.uexceptions.ldapError: LDAP Error: Type or value exists: ucsschoolRole: value #0 provided more than once.

The following output can be used to determine the reason for the presence of a faulty school:

Type or value exists: ucsschoolRole: value #0

2.
To fix this error, we can run the last command without dry-run, this should fix the problem.

/usr/share/ucs-school-import/scripts/fix_ucsschool_roles

3.
Another way to fix the error is to run the following script for ucs@school-slaves.
/usr/share/ucs-school-import/scripts/fix_ucsschool_slaves

Mastodon