landscape-config: --silent fails with unhelpful twisted error file not found when log_level config value is invalid

Bug #2027521 reported by Chad Smith
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Landscape Client
Fix Committed
Medium
Mitch Burton

Bug Description

Low-priority, but something that hit me during development of cc_landscape module in cloud-init.

Bad landscape/client.conf values for log_level do not result in helpful errors or logs when using landscape-config --silent.

$ cat > ls2.yaml <<EOF
#cloud-config
packages: [landscape-client]
EOF

$ lxc launch ubuntu-daily:mantic ls-m -c cloud-init.user-data="$(cat ls2.yaml)"

$ lxc exec ls-m -- cloud-init status --wait --long
$ lxc exec ls-m -- landscape-config --silent --account-name=your-account --computer-title=mytestvm --data-path=/var/lib/landscape/client --log-level="'info'" --ping-url=http://landscape.canonical.com/ping --url=https://landscape.canonical.com/message-system

Created symlink /etc/systemd/system/multi-user.target.wants/landscape-client.service → /lib/systemd/system/landscape-client.service.
Please wait...
Traceback (most recent call last):
Failure: twisted.internet.error.ConnectError: An error occurred while connecting: 2: No such file or directory.

No longs in /var/log/landscape appear to be emitted as a result of the landscape-config CLI command. So debugging is unhelpful.

To confirm the failure issue one can try to invoke the broker directly which gives a helpful traceback as to what my problem was:

$ sudo -u landscape /usr/bin/python3 /usr/bin/landscape-broker

Traceback (most recent call last):
  File "/usr/bin/landscape-broker", line 8, in <module>
    run(sys.argv)can
  File "/usr/lib/python3/dist-packages/landscape/client/broker/service.py", line 94, in run
    run_landscape_service(BrokerConfiguration, BrokerService, args)
  File "/usr/lib/python3/dist-packages/landscape/client/service.py", line 73, in run_landscape_service
    init_logging(configuration, service_class.service_name)
  File "/usr/lib/python3/dist-packages/landscape/client/deployment.py", line 17, in init_logging
    logging.init_app_logging(configuration.log_dir, configuration.log_level,
  File "/usr/lib/python3/dist-packages/landscape/lib/logging.py", line 32, in init_app_logging
    _init_logging(
  File "/usr/lib/python3/dist-packages/landscape/lib/logging.py", line 45, in _init_logging
    logger.setLevel(level)
  File "/usr/lib/python3.11/logging/__init__.py", line 1464, in setLevel
    self.level = _checkLevel(level)
                 ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/logging/__init__.py", line 207, in _checkLevel
    raise ValueError("Unknown level: %r" % level)
ValueError: Unknown level: "Level 'INFO'"

inv
This can be reproduced outside of calling landscape-config, by introducing the invalid value of log_level: 'info' in /etc/landscape/client.conf.

Chad Smith (chad.smith)
description: updated
Chad Smith (chad.smith)
summary: - landscape-config: --silent fails with unhelpful socket error when
- log_level config value in invalid
+ landscape-config: --silent fails with unhelpful twisted error file not
+ found when log_level config value is invalid
Changed in landscape-client:
assignee: nobody → Mitch Burton (mitchburton)
status: New → Confirmed
importance: Undecided → Medium
Changed in landscape-client:
status: Confirmed → Triaged
Revision history for this message
Juanmi Taboada (juanmitaboada) wrote :

The logging library should provide a better error using "!r" to avoid confusing messages.

I have added a little check to provide a better error from our side, now the error would look like this:
AttributeError: Unknown level "'info'", conversion to logging code was "Level 'INFO'"

The solution has been provided in:
https://github.com/canonical/landscape-client/pull/166

Changed in landscape-client:
status: Triaged → In Progress
Changed in landscape-client:
status: In Progress → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.