Bug 56051 - fix(udm-rest-server): pass debug level from CLI to child processes
fix(udm-rest-server): pass debug level from CLI to child processes
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: UDM - REST API
UCS 5.0
Other Linux
: P5 normal (vote)
: UCS 5.0-3-errata
Assigned To: Per Macha (ext)
Florian Best
https://git.knut.univention.de/univen...
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2023-05-10 21:05 CEST by Florian Best
Modified: 2023-05-24 15:43 CEST (History)
1 user (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): bitesize
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Best univentionstaff 2023-05-10 21:05:18 CEST
When starting the UDM REST server and explicitly setting the debug level on the cli (e.g. `-d 2`),
the debug level is not passed on to the subprocesses.
Instead, the child processes attempt to read the value from the UCR and use this instead.

We encountered this issue when running the containerized UDM REST server,
which had explicitly set the `-d` flag on startup,
but it was missing the UCR entry.
In this case the subprocesses would try to set the log level to `None` (but were expecting an `int`) and failed to start.
 
# Steps to reproduce

1. Stop the UDM REST server if it is running.
2. Unset `directory/manager/rest/debug/level` in UCR.
3. Start the server again:

   `python3 -m univention.admin.rest.server -d 4 -p 9979 -i 0.0.0.0 -c 0`

# What is the current bug behavior?

The child processes will not start:

   ```
   09.05.23 14:30:17        INFO      (       88) : Started child 29
   09.05.23 14:30:18.563  DEBUG_INIT
   Traceback (most recent call last):
     File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
       "__main__", mod_spec)
     File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
       exec(code, run_globals)
     File "/usr/lib/python3/dist-packages/univention/admin/rest/__main__.py", line 219, in <module>
       Server.main()
     File "/usr/lib/python3/dist-packages/univention/admin/rest/__main__.py", line 215, in main
       server.run(args)
     File "/usr/lib/python3/dist-packages/univention/admin/rest/__main__.py", line 77, in run
       log_init('/dev/stdout', args.debug, args.processes != 1)
     File "/usr/lib/python3/dist-packages/univention/management/console/log.py", line 87, in log_init
       log_set_level(log_level)
     File "/usr/lib/python3/dist-packages/univention/management/console/log.py", line 104, in log_set_level
       ud.set_level(component, level)
   TypeError: an integer is required (got type NoneType)
   ```

# What is the expected correct behavior?

Server starts with no error messages.
Comment 1 Florian Best univentionstaff 2023-05-10 21:22:42 CEST
Merged the MR from Thomas:

univention-directory-manager-rest.yaml
2567453591d8 | chore(univention-directory-manager-rest): update advisory
f6a8f1fd7b16 | fix(udm-rest-server): pass debug level from CLI to child processes

univention-directory-manager-rest (10.0.6-3)
f6a8f1fd7b16 | fix(udm-rest-server): pass debug level from CLI to child processes
Comment 2 Florian Best univentionstaff 2023-05-16 16:52:09 CEST
REOPEN: the fix breaks UDM REST API completely:

16.05.23 16:42:37        INFO      (    30137) : stopping children: []
16.05.23 16:42:37        INFO      (    30137) : stopping subprocesses: []
Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3/dist-packages/univention/admin/rest/server/__main__.py", line 41, in <module>
    Gateway.main()
  File "/usr/lib/python3/dist-packages/univention/admin/rest/server/__init__.py", line 217, in main
    cls.start_processes(args.processes, args.port, args.debug)
  File "/usr/lib/python3/dist-packages/univention/admin/rest/server/__init__.py", line 292, in start_processes
    cls.PROCESSES[language] = subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr)
  File "/usr/lib/python3.7/subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.7/subprocess.py", line 1453, in _execute_child
    restore_signals, start_new_session, preexec_fn)
TypeError: expected str, bytes or os.PathLike object, not int
Comment 3 Florian Best univentionstaff 2023-05-24 11:04:59 CEST
univention-directory-manager-rest (10.0.6-3)
0a6260bbc98e | fixup! fix(udm-rest-server): pass debug level from CLI to child processes
Comment 4 Florian Best univentionstaff 2023-05-24 11:05:47 CEST
OK: YAML
OK: changes