Univention Bugzilla – Bug 33932
Improve Error handling in domains.py _create_disk, "'NoneType' object is unsubscriptable"
Last modified: 2023-06-28 10:46:12 CEST
We received the following traceback: Execution of command 'uvmm/domain/put' has failed: Traceback (most recent call last): File "/usr/lib/pymodules/python2.6/univention/management/console/modules/__init__.py", line 204, in execute func( request ) File "/usr/lib/pymodules/python2.6/univention/management/console/modules/uvmm/domains.py", line 533, in domain_add for disk in domain['disks'] File "/usr/lib/pymodules/python2.6/univention/management/console/modules/uvmm/domains.py", line 328, in _create_disk pool_type = pool['type'] TypeError: 'NoneType' object is unsubscriptable The report said that this ocurred while switching the keyboard layout in an existing VM. but i do not see how this relates to the reported error. I could not reproduce the error. Nonetheless, the error handling in _create_disk() domains.py should be improved. The variable pool is not checked in all code paths before it is accessed. Proposed improvement: --- umc/python/uvmm/domains.py +++ umc/python/uvmm/domains.py @@ -304,11 +304,12 @@ else: pool = {} + if not pool: + raise ValueError('Pool "%s" not found' % (pool_name,)) + if disk.get('source', None) is None: # new drive drive.size = disk['size'] - if not pool: - raise ValueError('Pool "%s" not found' % (pool_name,)) drive.source = os.path.join(pool['path'], disk['volumeFilename']) if profile:
(In reply to Erik Damrose from comment #0) > I could not reproduce the error. The pool handling is very tricky, especially since the translations are done in the front-, middle- and backend: - multiple pools can map to the same path, the the reverse-translation is not unique. because of the the full-path-name must be used everywhere and the frontend should display the pool name only for convenience. - there are cases, where the device name is not related to any pool at all, for example for devices like /dev/cdrom. - A pool might not be active, but the volumes in it can still be used, for example /var/lib/libvirt/images/. > Nonetheless, the error handling in > _create_disk() domains.py should be improved. +1 > The variable pool is not > checked in all code paths before it is accessed. Proposed improvement: The patch is wrong! - There are cases where the device is not associated with a pool, for example iSCSI volumes or any device directly entered by the user. - the code must handle both cases, where an existing volume is given or a new volume should be created.
"if not pool:" should be changed to a test if pool is None. Another change would be to fix get_pools() not to return None but throw an exception, but i did not check which other callers would be affected.
*** This bug has been marked as a duplicate of bug 39224 ***