Problem: ucsschool-api is not properly starting up

Problem:

ucsschool-apis is not properly starting up.

# telnet 127.0.0.1 40001
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Connection closed by foreign host. 

Investigation:

Check /var/log/univention/ucsschool-apis/http.log

univention-app shell ucsschool-apis
uvicorn --reload ucsschool.apis.main:app --host 0.0.0.0 --port 8080 --log-level debug

If you see something like that:

INFO: Will watch for changes in these directories: [’/app’]
INFO: Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit)
INFO: Started reloader process [124] using statreload
INFO: Started server process [126]
INFO: Waiting for application startup.
2022-12-19 11:32:16 INFO main.initialize:137 [126][None] App settings:
{‘enabled_plugins’: [‘auth’, ‘bildungslogin’], ‘auth’: {‘idps’: {‘bildungslogin’: {‘strategy’: ‘local_secret’, ‘settings’: {}}}, ‘tag_idp_mapping’: {‘bildungslogin’: [‘bi
ldungslogin’]}}}
2022-12-19 11:32:16 INFO main.activate_auth_strategy:122 [126][None] Activating authentication strategy ‘basic_auth’.
2022-12-19 11:32:16 INFO main.activate_auth_strategy:122 [126][None] Activating authentication strategy ‘local_secret’.
2022-12-19 11:32:16 INFO main.activate_auth_strategy:122 [126][None] Activating authentication strategy ‘oauth2’.
2022-12-19 11:32:16 INFO main.initialize:155 [126][None] Loading plugins…
2022-12-19 11:32:16 INFO main.initialize:156 [126][None] Plugins enabled in settings: [‘auth’, ‘bildungslogin’]
2022-12-19 11:32:16 INFO main.activate_plugin:111 [126][None] Activating plugin ‘bildungslogin’ version 1.0.0.
2022-12-19 11:32:16 INFO plugin.setup:32 [126][None] Setup of ‘bildungslogin’ with version ‘1.0.0’…
ERROR: Traceback (most recent call last):
File “/usr/local/lib/python3.9/site-packages/udm_rest_client/base_http.py”, line 77, in
import openapi_client_udm
ModuleNotFoundError: No module named ‘openapi_client_udm’

The above exception was the direct cause of the following exception:

Traceback (most recent call last):   
  File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 635, in lifespan
    async with self.lifespan_context(app):
  File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 530, in __aenter__
    await self._router.startup()
  File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 614, in startup
    handler()
  File "/app/./ucsschool/apis/main.py", line 168, in initialize
    activate_plugin(plugin)
  File "/app/./ucsschool/apis/main.py", line 112, in activate_plugin
    plugin.setup_func()
  File "/usr/local/lib/python3.9/site-packages/bildungslogin_plugin/plugin.py", line 33, in setup
    backend = create_db_backend()
  File "/usr/local/lib/python3.9/site-packages/bildungslogin_plugin/plugin.py", line 39, in create_db_backend
    from .backend_udm_rest_api import UdmRestApiBackend
  File "/usr/local/lib/python3.9/site-packages/bildungslogin_plugin/backend_udm_rest_api.py", line 14, in <module>
    from udm_rest_client.udm import UDM, UdmObject
  File "/usr/local/lib/python3.9/site-packages/udm_rest_client/__init__.py", line 8, in <module>
    from .base_http import UdmModule, UdmObject
  File "/usr/local/lib/python3.9/site-packages/udm_rest_client/base_http.py", line 80, in <module>
    raise ImportError(
ImportError: Please run 'update_openapi_client' to install the OpenAPI client library package 'openapi-client-udm'.
2022-12-19 11:32:16 ERROR on.send:119 [126][None] Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/udm_rest_client/base_http.py", line 77, in <module>
    import openapi_client_udm
ModuleNotFoundError: No module named 'openapi_client_udm'

Solution:

univention-run-join-scripts --run-scripts --force 69bildungslogin-plugin-openapi-client.inst


Another case with another traceback

Again we check inside from the ucsschool-api App with:

uvicorn --reload ucsschool.apis.main:app --host 0.0.0.0 --port 8080 --log-level debug

and got the following Traceback:

2024-02-16 15:04:14 INFO  plugin.setup:32 [181][None] Setup of 'bildungslogin' with version '1.0.0'...
ERROR:    Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 677, in lifespan
    async with self.lifespan_context(app) as maybe_state:
  File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 566, in __aenter__
    await self._router.startup()
  File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 656, in startup
    handler()
  File "/app/./ucsschool/apis/main.py", line 180, in initialize
    activate_plugin(plugin)
  File "/app/./ucsschool/apis/main.py", line 124, in activate_plugin
    plugin.setup_func()
  File "/usr/local/lib/python3.9/site-packages/bildungslogin_plugin/plugin.py", line 33, in setup
    backend = create_db_backend()
  File "/usr/local/lib/python3.9/site-packages/bildungslogin_plugin/plugin.py", line 45, in create_db_backend
    return UdmRestApiBackend(
  File "/usr/local/lib/python3.9/site-packages/bildungslogin_plugin/backend_udm_rest_api.py", line 234, in __init__
    self.assignment_mod = self.udm.get("bildungslogin/assignment")
  File "/usr/local/lib/python3.9/site-packages/udm_rest_client/udm.py", line 191, in get
    return UdmModule(name, self.session)
  File "/usr/local/lib/python3.9/site-packages/udm_rest_client/base_http.py", line 1086, in __init__
    raise UnknownModuleType(f"Unknown module: {name!r}.", module_name=name)
udm_rest_client.exceptions.UnknownModuleType: Unknown module: 'bildungslogin/assignment'.

The module bildungslogin/assignment is unknown.
We fixed this by re-running the bildungslogin join scripts and restarting the corresponding services and finally the ucsschool-apis App itself:

univention-run-join-scripts --run-scripts --force 68udm-bildungslogin.inst
univention-run-join-scripts --run-scripts --force 69bildungslogin-plugin-openapi-client.inst
univention-run-join-scripts --run-scripts --force 70bildungslogin-plugin.inst                          
service ucs-school-import-http-api restart                                                    
service ucs-school-import-celery-worker restart                                                         
univention-app restart ucsschool-apis                                                                  

One other thing to try is rebuilding the OpenAPI client for the udm_rest_client. This can sometimes be a reason for an “Unknown module” error.

2 Likes
Mastodon