Bug 51280 - Write active S4-Connector mapping to log file
Write active S4-Connector mapping to log file
Status: NEW
Product: UCS
Classification: Unclassified
Component: S4 Connector
UCS 4.4
Other Linux
: P5 enhancement (vote)
: ---
Assigned To: Samba maintainers
Samba maintainers
:
Depends on: 48410
Blocks:
  Show dependency treegraph
 
Reported: 2020-05-12 12:29 CEST by Arvid Requate
Modified: 2020-06-25 16:23 CEST (History)
4 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: 2020050421000415
Bug group (optional):
Max CVSS v3 score:


Attachments
print_mapping.diff (731 bytes, patch)
2020-05-12 12:29 CEST, Arvid Requate
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Arvid Requate univentionstaff 2020-05-12 12:29:15 CEST
Since Commit 4795bb08ed for Bug #48410 the committed mapping.py file doesn't show the active mapping any longer. E.g. the mapping_table generated from UCR connector/s4/mapping/group/table/ is not shown any more. This makes it hard for supporters to see what the S4-Connector is configured to do.
Comment 1 Arvid Requate univentionstaff 2020-05-12 12:29:59 CEST
Created attachment 10360 [details]
print_mapping.diff

Something like this.
Comment 2 Florian Best univentionstaff 2020-05-12 13:00:18 CEST
There is already logging in:

services/univention-s4-connector/modules/univention/s4connector/s4/__init__.py:
729 »   »   ud.debug(ud.LDAP, ud.ALL, 'Mapping is: %s' % (pprint.pformat(property, indent=4, width=250)))
Comment 3 Florian Best univentionstaff 2020-05-12 13:06:03 CEST
Plus you can also do:

python -i /etc/univention/connector/s4/mapping.py
>>> print(s4_mapping)
Comment 4 Arvid Requate univentionstaff 2020-05-12 17:26:09 CEST
Re: Comment 2: Ok two things:

* we should at least lower the minimal debug level to INFO,
  ALL (4) is a bit much.

* we should find a different place for this, because at
  that point in the mapping gets logged every time
  somebody runs univention-s4connector-list-rejected.
  Or we should adjust something about the logging.
Comment 5 Florian Best univentionstaff 2020-05-12 17:28:04 CEST
OK. Let's always print it to the status logfile when starting the S4-connector and remove it from regular logging.
Comment 7 Arvid Requate univentionstaff 2020-06-17 15:17:20 CEST
The current logging is insufficient (example taken from ADC):

17.06.2020 15:16:09.284 LDAP        (ALL  ): Mapping is: {   'container': <univention.connector.property instance at 0x7f1794e14d88>,
    'group': <univention.connector.property instance at 0x7f1794e14b00>,
    'ou': <univention.connector.property instance at 0x7f1794e14e60>,
    'user': <univention.connector.property instance at 0x7f1794e148c0>,
    'windowscomputer': <univention.connector.property instance at 0x7f1794e14cb0>}
Comment 8 Arvid Requate univentionstaff 2020-06-18 23:18:49 CEST
Gosh, this pprint/__repr__ technique results in proper uglyness:

=======================
17.06.2020 22:58:18.485 LDAP        (INFO   ): Mapping:
{   'container': univention.connector.property(**{   'attributes': {   'cn': univention.connector.attribute(**{   'compare_function': <function compare_lowercase at 0x7f3751cac7d0>,
    'con_attribute': 'cn',
    'con_other_attribute': '',
    'con_value_merge_function': '',
    'ldap_attribute': 'cn',
    'required': 1,
    [...]
=======================

Why on earth doesn't pprint print a newline after the opening brackets/braces/parentheses? Is this even PEP8?
Comment 9 Florian Best univentionstaff 2020-06-18 23:31:25 CEST
(In reply to Arvid Requate from comment #8)
> Gosh, this pprint/__repr__ technique results in proper uglyness:
Yes, the alternative would be: `json.dumps(foo, indent=4, sort_keys=True)`
Comment 10 Arvid Requate univentionstaff 2020-06-19 13:43:00 CEST
Problem with that is: 

TypeError: <function compare_lowercase at 0x7f5b878c17d0> is not JSON serializable

So we'd either have to subclass JSONEncoder (resulted in even more uglyness in my attempts, but that surely could work). or convert the functions to callable classes, which is too intrusive for my taste, just to print the mapping. For now I'll stick to my ugly code producing less ugly output in the ADC.
Comment 11 Arvid Requate univentionstaff 2020-06-25 16:23:54 CEST
Felix also requested, that this should rather be written into a separate file.
Like /usr/sbin/univention-s4-connector does "cat mapping | ucr filter > mapping.py",
but then with the final mapping.