[NEW PATCH] _delete: fix AttributeError (via gerrit-bot)

Max Benenson mbenenso at redhat.com
Sun Sep 18 06:51:24 UTC 2011


New patch submitted by Max Benenson (mbenenso at redhat.com)

You can review this change at: http://gerrit.usersys.redhat.com/942

commit 79709bc5a43a53f3e4e8b562ddf45aa6af18a770
Author: Max Benenson <mbenenso at redhat.com>
Date:   Thu Sep 15 18:16:29 2011 +0300

    _delete: fix AttributeError
    
    When calling for deleteMutipleVolumes function the AttributeError
    exception is thrown. Fix it by getting an object of the relevant
    module before we actually call for the above function.
    
    CannotRemoveLogicalVolume raised in case the function is not
    found in the relevant module. It's an ugly solution but I want
    to preserve the interface and still log the warning message.
    
    Additional fix: add UUID of the image to the log message.
    
    Change-Id: I9ff76d46707d73ae4de991766841bfc51bf499fa

diff --git a/vdsm/storage/image.py b/vdsm/storage/image.py
index a68f168..d68d55e 100644
--- a/vdsm/storage/image.py
+++ b/vdsm/storage/image.py
@@ -19,6 +19,7 @@
 #
 
 import os
+import sys
 import logging
 import threading
 import uuid
@@ -209,11 +210,16 @@ class Image:
         # If we got here than go ahead and remove all of them without mercy
         if volumes:
             try:
-                #No, this is not a classmethod! No validations here
-                volclass.__module__.deleteMultipleVolumes(sdUUID, volumes, postZero)
+                moduleObj = sys.modules[volclass.__module__]
+                deleteMultipleVolumes = getattr(moduleObj, 'deleteMultipleVolumes', None)
+                if deleteMultipleVolumes is not None and callable(deleteMultipleVolumes):
+                    deleteMultipleVolumes(sdUUID, volumes, postZero)
+                else:
+                    msg = "%s module has no such function %s"
+                    raise se.CannotRemoveLogicalVolume(msg % (volclass.__module__, 'deleteMultipleVolumes'))
             except (se.CannotRemoveLogicalVolume, se.VolumeAccessError):
-                #Any volume deletion failed, but we don't really care at this point
-                self.log.warn("Problems during image %s deletion (%s). Continue...", exc_info=True)
+                # Any volume deletion failed, but we don't really care at this point
+                self.log.warn("Problems during image %s deletion. Continue..." % imgUUID, exc_info=True)
 
         # Now clean the image directory
         removedImage = imageDir = self.getImageDir(sdUUID, imgUUID)




More information about the vdsm-patches mailing list