Bug 54325 - Allow subclassing Kelvin plugin of ID Connector
Summary: Allow subclassing Kelvin plugin of ID Connector
Status: CLOSED FIXED
Alias: None
Product: UCS@school
Classification: Unclassified
Component: ucsschool-id-connector
Version: UCS@school 5.0
Hardware: Other Linux
: P5 normal
Target Milestone: ---
Assignee: Daniel Tröder
QA Contact: Tobias Wenzel
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-01-12 09:24 CET by Daniel Tröder
Modified: 2023-06-12 16:27 CEST (History)
1 user (show)

See Also:
What kind of report is it?: Feature Request
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):
Customer ID:
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Tröder univentionstaff 2022-01-12 09:24:26 CET
When a customer wants to adapt the Kelvin plugin to its needs (like in bug 54307), importing of the Kelvin plugin fails, because the Plugin registration happens on the module level and the module is executed multiple times by the import code:

---------------------------------------------------------------------
2022-01-11 18:09:14 ERROR [IDConnectorService.runner:498] Plugin already registered: kelvin=<plugins.plugins.kelvin_handlers.KelvinHandler object at 0x7f9c23786b80>
Traceback (most recent call last):
...
  File "/var/lib/univention-appcenter/apps/ucsschool-id-connector/conf/plugins/plugins/bb-kelvin.py", line 3, in <module>
    from plugins.plugins.kelvin_handlers import KelvinHandler
  File "/ucsschool-id-connector/src/plugins/plugins/kelvin_handlers.py", line 90, in <module>
    plugin_manager.register(KelvinHandler(), KelvinHandler.plugin_name)
---------------------------------------------------------------------

Wrap the plugin registration in try-except, so that other plugins can load the module.
Comment 1 Daniel Tröder univentionstaff 2022-01-12 10:26:33 CET
The repeated import of the Kelvin plugin is now possible:

[master] 9b9cae0 Bug #54325: allow other plugins to import from the Kelvin plugin module

Unrelated formatting fixes:

[master] 57bac08 Bug #54325: fix code formatting

To test, install the following file at /var/lib/univention-appcenter/apps/ucsschool-id-connector/conf/plugins/plugins and "/etc/init.d/ucsschool-id-connector restart":

-----------------------------------------------------------------------------
from plugins.plugins.kelvin_handlers import KelvinHandler
from ucsschool_id_connector.plugins import plugin_manager

class bbKelvinHandler(KelvinHandler):
    plugin_name = "bb-kelvin"

plugin_manager.register(bbKelvinHandler(), bbKelvinHandler.plugin_name)
-----------------------------------------------------------------------------

It will fail with the old version and succeed with the new one.

A new Docker image for version 2.2.0 has been built (image hash: dba834d88edd).
Comment 2 Tobias Wenzel univentionstaff 2022-01-12 14:03:52 CET
QA

OK code
OK changelogs
OK manual test (in 4.4/5.0 envs)


before fix

    raise ValueError(
ValueError: Plugin already registered: kelvin=<plugins.plugins.kelvin_handlers.KelvinHandler o
bject at 0x7f1c12e6a940>


after fix

-> no errors
Comment 3 Tobias Wenzel univentionstaff 2022-01-12 14:03:59 CET
QA

OK code
OK changelogs
OK manual test (in 4.4/5.0 envs)


before fix

    raise ValueError(
ValueError: Plugin already registered: kelvin=<plugins.plugins.kelvin_handlers.KelvinHandler o
bject at 0x7f1c12e6a940>


after fix

-> no errors
Comment 4 Daniel Tröder univentionstaff 2023-06-12 16:27:43 CEST
Has been released with v2.2.0 (2021-01-04).