예제 #1
0
파일: lvm.py 프로젝트: rollandf/vdsm
def _systemctl(*args):
    cmd = [_SYSTEMCTL.cmd]
    cmd.extend(args)
    rc, out, err = commands.execCmd(cmd, raw=True)
    if rc != 0:
        raise cmdutils.Error(cmd=cmd, rc=rc, out=out, err=err)
    return out
예제 #2
0
파일: blkdiscard.py 프로젝트: akashihi/vdsm
def blkdiscard(device):
    cmd = [_blkdiscard.cmd]
    cmd.append(device)

    rc, out, err = commands.execCmd(cmd)

    if rc != 0:
        raise cmdutils.Error(cmd, rc, out, err)
예제 #3
0
파일: numa.py 프로젝트: rexhsu/vdsm
def _run_command(args):
    cmd = [_SYSCTL.cmd]
    cmd.extend(args)
    rc, out, err = commands.execCmd(cmd, raw=True)
    if rc != 0:
        raise cmdutils.Error(cmd, rc, out, err)

    return out
예제 #4
0
파일: loopback.py 프로젝트: rollandf/vdsm
 def attach(self):
     if self._path is not None:
         raise AssertionError("Device is attached: %s" % self)
     cmd = ["losetup", "--find", "--show", self._backing_file]
     rc, out, err = commands.execCmd(cmd, raw=True)
     if rc != 0:
         raise cmdutils.Error(cmd, rc, out, err)
     self._path = out.strip().decode("ascii")
예제 #5
0
def blkdiscard(device):
    cmd = [_blkdiscard.cmd]
    cmd.append(device)

    rc, out, err = commands.execCmd(cmd, deathSignal=signal.SIGKILL)

    if rc != 0:
        raise cmdutils.Error(cmd, rc, out, err)
예제 #6
0
def qemu_pattern_verify(path, format, offset=512, len=1024, pattern=5):
    read_cmd = 'read -P %d -s 0 -l %d %d %d' % (pattern, len, offset, len)
    cmd = ['qemu-io', '-f', format, '-c', read_cmd, path]
    rc, out, err = commands.execCmd(cmd, raw=True)
    if rc != 0:
        raise cmdutils.Error(cmd, rc, out, err)
    if "Pattern verification failed" in out:
        raise ChainVerificationError("Verification of volume %s failed. "
                                     "Pattern 0x%x not found at offset %s" %
                                     (path, pattern, offset))
예제 #7
0
def discard(device):
    """
    Discards a block device.

    Arguments:
        device (str): The path to the block device to discard.

    Raises:
        cmdutils.Error if an error has occurred in blkdiscard.
    """
    cmd = [_blkdiscard.cmd]
    cmd.append(device)

    rc, out, err = commands.execCmd(cmd)

    if rc != 0:
        raise cmdutils.Error(cmd, rc, out, err)
예제 #8
0
    def _finalize(self, out, err):
        """
        Update operation state after underlying process has terminated.

        Raises:
            `exception.ActionStopped` if the command was aborted
            `cmdutils.Error` if the command failed
            `RuntimeError` if operation state is invalid
        """
        rc = self._proc.returncode
        log.debug(common_cmdutils.retcode_log_line(rc, err))
        with self._lock:
            self._proc = None
            if self._state == ABORTING:
                self._state = ABORTED
                raise exception.ActionStopped
            elif self._state == RUNNING:
                self._state = TERMINATED
                if rc != 0:
                    raise cmdutils.Error(self._cmd, rc, out, err)
            else:
                raise RuntimeError("Invalid state: %s" % self)
예제 #9
0
파일: loopback.py 프로젝트: rollandf/vdsm
 def detach(self):
     if self._path is None:
         raise AssertionError("Device is detached: %s" % self)
     cmd = ["losetup", "--detach", self._path]
     rc, out, err = commands.execCmd(cmd, raw=True)
     if rc != 0:
         raise cmdutils.Error(cmd, rc, out, err)
     self._path = None
     # After deactivating lvs backed by loop device, we get tons of udev
     # events. We must wait for the events or we may get stale lvs that
     # would fail the next tests.
     #
     # $ udevadm monitor -u
     # ...
     # UDEV  [314195.642497] remove   /devices/virtual/block/dm-4 (block)
     # UDEV  [314195.643032] remove   /devices/virtual/block/dm-4 (block)
     # UDEV  [314195.653214] remove   /devices/virtual/bdi/253:4 (bdi)
     # UDEV  [314195.664478] remove   /devices/virtual/block/dm-5 (block)
     # UDEV  [314195.664863] remove   /devices/virtual/block/dm-5 (block)
     # UDEV  [314195.674426] remove   /devices/virtual/bdi/253:5 (bdi)
     # UDEV  [314195.807277] change   /devices/virtual/block/loop0 (block)
     udevadm.settle(5)
예제 #10
0
def qemu_pattern_write(path, format, offset=512, len=1024, pattern=5):
    write_cmd = 'write -P %d %d %d' % (pattern, offset, len)
    cmd = ['qemu-io', '-f', format, '-c', write_cmd, path]
    rc, out, err = commands.execCmd(cmd, raw=True)
    if rc != 0:
        raise cmdutils.Error(cmd, rc, out, err)
예제 #11
0
def _run_cmd(cmd, cwd=None):
    rc, out, err = commands.execCmd(cmd, raw=True, cwd=cwd)
    if rc != 0:
        raise cmdutils.Error(cmd, rc, out, err)
    return out
예제 #12
0
 def test_format(self):
     # Should not raise
     str(cmdutils.Error(["cmd"], 1, "out\n", "err\n"))
예제 #13
0
def failure(*args, **kwargs):
    raise cmdutils.Error("code", "out", "err", "Fail amend")