[NEW PATCH] BZ#717658 - Simplify recycle function. (via gerrit-bot)

Eduardo Warszawski ewarszaw at redhat.com
Sun Sep 18 07:22:14 UTC 2011


New patch submitted by Eduardo Warszawski (ewarszaw at redhat.com)

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

commit f95164e82a96e052940f35215d451567b93c2936
Author: Eduardo Warszawski <ewarszaw at redhat.com>
Date:   Thu Jun 30 16:18:50 2011 +0300

    BZ#717658 - Simplify recycle function.
    
    Change-Id: I9cf3106f0fb5d5cd067907d48ff02fe50493a66c

diff --git a/vdsm/storage/hsm.py b/vdsm/storage/hsm.py
index b0ee212..84e688a 100644
--- a/vdsm/storage/hsm.py
+++ b/vdsm/storage/hsm.py
@@ -1228,6 +1228,15 @@ class HSM:
         return SDF.produce(sdUUID=sdUUID).validate()
 
 
+    #TODO: Remove this  function when formatStorageDomain() is removed.
+    def _recycle(self, sd):
+        try:
+            SDF.manuallyRemoveDomain(sd.sdUUID)
+        except KeyError:
+            self.log.warn("Storage domain %s doesn't exist in cache. Trying recycle leftovers ...", sd.sdUUID)
+
+        sd.format(sd.sdUUID)
+
     def public_formatStorageDomain(self, sdUUID, autoDetach = False, options = None):
         """
         Formats a detached storage domain.
@@ -1236,6 +1245,7 @@ class HSM:
             This removes all data from the storage domain.
 
         :param sdUUID: The UUID for the storage domain you want to format.
+        :param autoDetach: DEPRECATED
         :type sdUUID: UUID
         :param options: ?
 
@@ -1252,24 +1262,18 @@ class HSM:
                 raise se.CannotFormatStorageDomainInConnectedPool(sdUUID)
 
         # For domains that attached to disconnected pool, format domain if 'autoDetach' flag set
-        if not misc.parseBool(autoDetach):
+        sd = SDF.produce(sdUUID=sdUUID)
+        try:
+            sd.invalidateMetadata()
+            #TODO: autoDetach is True
+            if not misc.parseBool(autoDetach) and sd.getPools():
+                raise se.CannotFormatAttachedStorageDomain(sdUUID)
             # Allow format also for broken domain
-            try:
-                dom = SDF.produce(sdUUID=sdUUID)
-                dom.invalidateMetadata()
-                if len(dom.getPools()) > 0:
-                    raise se.CannotFormatAttachedStorageDomain(sdUUID)
-
-            except (se.StorageDomainMetadataNotFound, se.MetaDataGeneralError, se.MiscFileReadException,
-                    se.MiscBlockReadException, se.MiscBlockReadIncomplete), e:
-                self.log.warn("Domain %s has problem with metadata. Continue formating... (%s)", sdUUID, str(e))
-            except se.CannotFormatAttachedStorageDomain:
-                raise
-            except Exception:
-                self.log.warn("Domain %s can't be formated", sdUUID, exc_info=True)
-                raise se.StorageDomainFormatError(sdUUID)
+        except (se.StorageDomainMetadataNotFound, se.MetaDataGeneralError, se.MiscFileReadException,
+                se.MiscBlockReadException, se.MiscBlockReadIncomplete), e:
+            self.log.warn("Domain %s has problem with metadata. Continue formating... (%s)", sdUUID, str(e))
 
-        SDF.recycle(sdUUID=sdUUID)
+        self._recycle(sd)
 
 
     def public_setStorageDomainDescription(self, sdUUID, description, options = None):
diff --git a/vdsm/storage/sdf.py b/vdsm/storage/sdf.py
index f13c933..c2587d8 100644
--- a/vdsm/storage/sdf.py
+++ b/vdsm/storage/sdf.py
@@ -31,6 +31,9 @@ class StorageDomainFactory:
     storage_repository = config.get('irs', 'repository')
     __sdc = sdc.StorageDomainCache(storage_repository)
 
+    @classmethod
+    def manuallyRemoveDomain(cls, sdUUID):
+        cls.__sdc.manuallyRemoveDomain(sdUUID)
 
     @classmethod
     def produce(cls, sdUUID):
@@ -77,26 +80,6 @@ class StorageDomainFactory:
 
 
     @classmethod
-    def recycle(cls, sdUUID):
-        """
-        Cleanly destroys the domain
-        """
-        import nfsSD
-        import localFsSD
-        import blockSD
-
-        try:
-            cls.__sdc.manuallyRemoveDomain(sdUUID)
-        except Exception:
-            cls.log.warn("Storage domain %s doesn't exist. Trying recycle leftovers ...", sdUUID)
-
-        for domClass in (blockSD.BlockStorageDomain, nfsSD.NfsStorageDomain, localFsSD.LocalFsStorageDomain):
-            return domClass.format(sdUUID)
-
-        raise se.StorageDomainTypeError(sdUUID)
-
-
-    @classmethod
     def getAllUUIDs(cls):
         return cls.__sdc.getUUIDs()
 




More information about the vdsm-patches mailing list