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
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),
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]
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))
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")
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
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.