Please capture/return lxd container error logs within stack traces
greenmoss opened this issue · 1 comments
greenmoss commented
TL;DR
Please clarify the cause of Failed to load config file
errors.
- Cheap/easy: "check your lxd container logs".
- Harder but more friendly: "your config options are b0rked, here's the b0rk message..."
Version info
- pylxd: 2.3.1
- Docker OS: Ubuntu 20.04.6 LTS
- Host OS: Ubuntu 20.04.5 LTS
- LXD version, from snap: 4.0.9
Test case / Detail
from pylxd import Client
client = Client()
c = client.containers.get(name='some-container-you-already-created')
c.config = {'image.architecture': 'x86_64', 'image.description': 'Ubuntu 16.04 LTS server (20180126)', 'image.os': 'ubuntu', 'image.release': 'xenial', 'volatile.apply_template': 'create', 'volatile.base_image': 'f3c173f5595f57c5c8e457f85b20e3a8d62061f49953b38950e928d780d10871', 'volatile.idmap.base': '0', 'volatile.idmap.next': '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":1000000000},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":1000000000}]', 'volatile.last_state.idmap': '[]', 'volatile.uuid': 'e3402349-6dc1-4b19-ae2c-6ec23cb72b46', 'security.privileged': 'false', 'security.nesting': 'true', 'limits.kernel.rtprio': '99', 'limits.cpu': '0-22,24-46', 'limits.memory': '128849018880', 'limits.memory.swap': 'false', 'raw.lxc': 'lxc.loglevel = 0'}
c.config.update(config)
c.save(wait=True)
The result is the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/Env/armory-compute-node/lib/python3.8/site-packages/pylxd/models/_model.py", line 225, in save
self.client.operations.wait_for_operation(response.json()["operation"])
File "/opt/Env/armory-compute-node/lib/python3.8/site-packages/pylxd/models/operation.py", line 57, in wait_for_operation
operation.wait()
File "/opt/Env/armory-compute-node/lib/python3.8/site-packages/pylxd/models/operation.py", line 98, in wait
raise exceptions.LXDAPIException(response)
pylxd.exceptions.LXDAPIException: Failed to load config file "/tmp/lxd_config_1152857147": loading config file for the container failed
What might actually be the cause of this error? Digging around on the system, I find my container logs, which reveal the real problem:
lxc 20230508160111.718 ERROR confile - confile.c:set_config_unsupported_key:153 - Invalid argument - Unsupported config key "lxc.loglevel"
lxc 20230508160111.718 ERROR parse - parse.c:lxc_file_for_each_line_mmap:129 - Failed to parse config file "/tmp/lxd_config_1152857147" at line "lxc.loglevel = 0"
Indeed, once I remove 'raw.lxc': 'lxc.loglevel = 0'
from my config
, c.save
returns.
sirkadirov commented
That would be a great addition! But at first we need to check the output of the LXD REST API in this case - do they give more information about an error 🤔?