Bug 30127 - Inconsistent API for UCR modules - changes different depending on register or update
Inconsistent API for UCR modules - changes different depending on register or...
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: UCR
UCS 5.0
Other Linux
: P5 normal (vote)
: UCS 5.0
Assigned To: Florian Best
Philipp Hahn
:
: 39444 (view as bug list)
Depends on:
Blocks: 30128 53424
  Show dependency treegraph
 
Reported: 2013-01-23 14:02 CET by Sönke Schwardt-Krummrich
Modified: 2021-10-03 22:12 CEST (History)
2 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): API change, Cleanup
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sönke Schwardt-Krummrich univentionstaff 2013-01-23 14:02:51 CET
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.
Comment 1 Florian Best univentionstaff 2020-07-06 15:38:12 CEST
*** Bug 39444 has been marked as a duplicate of this bug. ***
Comment 2 Florian Best univentionstaff 2020-07-08 02:21:03 CEST
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
Comment 3 Florian Best univentionstaff 2020-07-14 15:57:59 CEST
I created a test case for this:

ucs-test (10.0.0-43)
6315fa441a7b | Bug #30127: add test case
Comment 4 Philipp Hahn univentionstaff 2020-07-29 18:52:00 CEST
OK: API change
OK: test
OK: changelog
Comment 5 Florian Best univentionstaff 2021-05-25 15:57:34 CEST
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".