Bug 33932 - Improve Error handling in domains.py _create_disk, "'NoneType' object is unsubscriptable"
Improve Error handling in domains.py _create_disk, "'NoneType' object is unsu...
Status: CLOSED DUPLICATE of bug 39224
Product: UCS
Classification: Unclassified
Component: Virtualization - UVMM
UCS 4.2
Other Linux
: P5 normal (vote)
: ---
Assigned To: UCS maintainers
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2014-01-15 12:41 CET by Erik Damrose
Modified: 2023-06-28 10:46 CEST (History)
3 users (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): Error handling, External feedback
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Erik Damrose univentionstaff 2014-01-15 12:41:22 CET
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:
Comment 1 Philipp Hahn univentionstaff 2014-01-15 13:11:17 CET
(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.
Comment 2 Erik Damrose univentionstaff 2014-01-15 13:28:30 CET
"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.
Comment 3 Philipp Hahn univentionstaff 2018-09-27 10:20:59 CEST

*** This bug has been marked as a duplicate of bug 39224 ***