fixed msger.run error when arg is empty str
authorJF Ding <Jian-feng.Ding@intel.com>
Mon, 5 Sep 2011 03:40:04 +0000 (12:40 +0900)
committerJF Ding <Jian-feng.Ding@intel.com>
Mon, 5 Sep 2011 03:40:04 +0000 (12:40 +0900)
mic/msger.py
mic/utils/fs_related.py
mic/utils/partitionedfs.py

index b1d2492..dc7b378 100644 (file)
@@ -190,16 +190,18 @@ def run(cmdln_or_args, q=False):
 
     from subprocess import *
     if isinstance(cmdln_or_args, list):
-        cmdln = ' '.join(cmdln_or_args)
+        args = cmdln_or_args
     else:
-        cmdln = cmdln_or_args
+        import shlex
+        args = shlex.split(cmdln_or_args)
 
-    p = Popen(cmdln, stdout=PIPE, stderr=PIPE, shell=True)
+    p = Popen(args, stdout=PIPE, stderr=PIPE)
     out = p.communicate()[0].strip()
 
     if not q:
-        msg =  'running command: "%s"' % cmdln
+        msg =  'running command: "%s"' % ' '.join(args)
         if out:
+            msg += ', with output::'
             msg += '\n  +----------------'
             for line in out.splitlines():
                 msg += '\n  | %s' % line
index ba8e236..6aab7ee 100644 (file)
@@ -499,7 +499,7 @@ class ExtDiskMount(DiskMount):
             msger.debug("Skip filesystem format.")
             return
 
-        msger.info("Formating %s filesystem on %s" % (self.fstype, self.disk.device))
+        msger.verbose("Formating %s filesystem on %s" % (self.fstype, self.disk.device))
         rc = msger.run([self.mkfscmd,
                         "-F", "-L", self.fslabel,
                         "-m", "1", "-b", str(self.blocksize),
@@ -607,11 +607,13 @@ class VfatDiskMount(DiskMount):
         if self.skipformat:
             msger.debug("Skip filesystem format.")
             return
-        msger.debug("Formating %s filesystem on %s" % (self.fstype, self.disk.device))
+
+        msger.verbose("Formating %s filesystem on %s" % (self.fstype, self.disk.device))
         rc = msger.run([self.mkfscmd, "-n", self.fslabel, "-i", self.uuid, self.disk.device])
         if rc != 0:
             raise MountError("Error creating %s filesystem on disk %s" % (self.fstype,self.disk.device))
-        msger.debug("Tuning filesystem on %s" % self.disk.device)
+
+        msger.verbose("Tuning filesystem on %s" % self.disk.device)
 
     def __resize_filesystem(self, size = None):
         current_size = os.stat(self.disk.lofile)[stat.ST_SIZE]
@@ -710,7 +712,8 @@ class BtrfsDiskMount(DiskMount):
         if self.skipformat:
             msger.debug("Skip filesystem format.")
             return
-        msger.debug("Formating %s filesystem on %s" % (self.fstype, self.disk.device))
+
+        msger.verbose("Formating %s filesystem on %s" % (self.fstype, self.disk.device))
         rc = msger.run([self.mkfscmd, "-L", self.fslabel, self.disk.device])
         if rc != 0:
             raise MountError("Error creating %s filesystem on disk %s" % (self.fstype,self.disk.device))
index 5ac25a4..2367471 100644 (file)
@@ -115,11 +115,13 @@ class PartitionedMount(Mount):
         if fstype:
             part_cmd.extend([fstype])
         part_cmd.extend(["%d" % start, "%d" % end])
+
         msger.debug(part_cmd)
         p1 = subprocess.Popen(part_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
-        (out,err) = p1.communicate()
-        msger.debug(out)
-        return p1
+        out = p1.communicate()[0].strip()
+        if out:
+            msger.debug('"parted" output: %s' % out)
+        return p1.returncode
 
     def __format_disks(self):
         msger.debug("Assigning partitions to disks")
@@ -163,8 +165,9 @@ class PartitionedMount(Mount):
             msger.debug("Initializing partition table for %s" % (d['disk'].device))
             p1 = subprocess.Popen([self.parted, "-s", d['disk'].device, "mklabel", "msdos"],
                                  stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
-            (out,err) = p1.communicate()
-            msger.debug(out)
+            out = p1.communicate()[0].strip()
+            if out:
+                msger.debug('"parted" output: %s' % out)
 
             if p1.returncode != 0:
                 # NOTE: We don't throw exception when return code is not 0, because
@@ -195,11 +198,11 @@ class PartitionedMount(Mount):
                 msger.debug("Substracting one sector from '%s' partition to get even number of sectors for the partition." % (p['mountpoint']))
                 p['size'] -= 1
 
-            p1 = self.__create_part_to_image(d['disk'].device,p['type'],
+            ret = self.__create_part_to_image(d['disk'].device,p['type'],
                                              parted_fs_type, p['start'],
                                              p['size'])
 
-            if p1.returncode != 0:
+            if ret != 0:
                 # NOTE: We don't throw exception when return code is not 0, because
                 # parted always fails to reload part table with loop devices.
                 # This prevents us from distinguishing real errors based on return code.