more compatible way to pass ext options
authorGui Chen <gui.chen@intel.com>
Sun, 9 Dec 2012 07:13:33 +0000 (15:13 +0800)
committerGui Chen <gui.chen@intel.com>
Wed, 12 Dec 2012 11:33:44 +0000 (19:33 +0800)
and also catch mkfs error

Signed-off-by: Gui Chen <gui.chen@intel.com>
mic/utils/fs_related.py

index f582cd2..da1ffeb 100644 (file)
@@ -444,22 +444,23 @@ class ExtDiskMount(DiskMount):
             return
 
         msger.verbose("Formating %s filesystem on %s" % (self.fstype, self.disk.device))
-        if self.extopts is None:
-            self.extopts = ""
-        cmdline = "%s -F -L %s -m 1 -b %s %s %s"  % (self.mkfscmd,
-                                                     self.fslabel,
-                                                     self.blocksize,
-                                                     self.extopts,
-                                                     self.disk.device)
-        rc = runner.show(cmdline.split())
+        cmdlist = [self.mkfscmd, "-F", "-L", self.fslabel, "-m", "1", "-b",
+                   str(self.blocksize)]
+        if self.extopts:
+            cmdlist.extend(self.extopts.split())
+        cmdlist.extend([self.disk.device])
+
+        rc, errout = runner.runtool(cmdlist, catch=2)
         if rc != 0:
-            raise MountError("Error creating %s filesystem on disk %s" % (self.fstype, self.disk.device))
+            raise MountError("Error creating %s filesystem on disk %s:\n%s" %
+                             (self.fstype, self.disk.device, errout))
 
-        rc, out = runner.runtool([self.dumpe2fs, '-h', self.disk.device])
+        if not self.extopts:
+            msger.debug("Tuning filesystem on %s" % self.disk.device)
+            runner.show([self.tune2fs, "-c0", "-i0", "-Odir_index", "-ouser_xattr,acl", self.disk.device])
 
+        rc, out = runner.runtool([self.dumpe2fs, '-h', self.disk.device])
         self.uuid = self.__parse_field(out, "Filesystem UUID")
-        msger.debug("Tuning filesystem on %s" % self.disk.device)
-        runner.show([self.tune2fs, "-c0", "-i0", "-Odir_index", "-ouser_xattr,acl", self.disk.device])
 
     def __resize_filesystem(self, size = None):
         current_size = os.stat(self.disk.lofile)[stat.ST_SIZE]