Univention Bugzilla – Bug 30127
Inconsistent API for UCR modules - changes different depending on register or update
Last modified: 2021-10-03 22:12:26 CEST
If one or more UCR variables get changed, the handler() function of UCR modules will be called. This function gets two arguments: - a ConfigRegistry() object - a dictionary containing the changes → each key of that represents a UCR variable name → for each key a tuple consisting of old and new UCR value is stored handler(ucr, changes) → ucr: { 'cron/autostart': 'yes', 'update/secure_apt': 'yes', … } → changes: { 'changedUCRVariable1': ( 'oldValue', 'newValue' ), 'changedUCRVariable2': ( 'oldValue', 'newValue' ), 'newVariable': ( None, 'newValue' ), 'removedVariable': ( 'oldValue', '' ), 'VariableToEmptyString': ( 'oldValue', '' ), } During UCR module registration ("ucr register packagename") the second positional argument ("changes") contains no tuple but a simple string or None. Each variable that is specified in the .info-File ("Variables: ldap/hostdn") will be looked up for its current value that is stored in the dictionary. If regular expressions are used or the variable is unset, the value None is stored instead of a string. ---[foo.info]--- Type: module Module: foo.py Variables: foo/.* Variables: unknown/variable Variables: ldap/hostdn Variables: hostname --- Values passed as "changes" to handler() during "ucr register": {'hostname': 'master', 'unknown/variable': None, 'foo/.*': None, 'ldap/hostdn': 'cn=master,cn=dc,cn=computers,dc=nstx,dc=ucsschool' } There are some inconsistencies that should be fixed in future: - during registration: - all variables matching a given regexp should be expanded - a tuple of two values should be passed for each variable to the freshly registered module to be consistend with later API: { 'hostname': (None, 'master'), 'unknown/variable': (None, None), 'foo/bar': (None, 'test'), 'foo/baz': (None, 'test2'), 'ldap/hostdn': (None, 'cn=master,cn=dc,cn=computers,dc=example,dc=com') } - after registration when variables change: - when variables get removed, the old value and None should be stored in the "changes" dictionary, to be able to distinct variables that have been removed and variables that have been set to empty string.
*** Bug 39444 has been marked as a duplicate of this bug. ***
The suggestions from comment #0 have been implemented: * pass (None, ucr[variable]) * evaluate regex-patterns and provide all variables matching it univention-config-registry (15.0.0-4) Bug #30127: fix arguments of UCR register API changelog-5.0-0.xml Bug #30127: add changelog entry
I created a test case for this: ucs-test (10.0.0-43) 6315fa441a7b | Bug #30127: add test case
OK: API change OK: test OK: changelog
UCS 5.0 has been released: https://docs.software-univention.de/release-notes-5.0-0-en.html https://docs.software-univention.de/release-notes-5.0-0-de.html If this error occurs again, please use "Clone This Bug".