Пример #1
0
 def test_in_err(self):
     cmd = ["sh", "-c", "cat >&2; exit 1"]
     p = commands.start(cmd, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
     out, err = commands.communicate(p, b"data")
     assert p.returncode == 1
     assert out is None
     assert err == b"data"
Пример #2
0
 def test_out_err(self):
     cmd = ["sh", "-c", "echo -n 'test out' >&1; echo -n fail >&2; exit 1"]
     p = commands.start(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     out, err = commands.communicate(p)
     assert p.returncode == 1
     assert out == b"test out"
     assert err == b"fail"
Пример #3
0
 def test_int_out(self):
     cmd = ["cat"]
     p = commands.start(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
     out, err = commands.communicate(p, b"data")
     assert p.returncode == 0
     assert out == b"data"
     assert err is None
Пример #4
0
def resize_map(name):
    """
    Invoke multipathd to resize a device
    Must run as root

    Raises Error if multipathd failed to resize the map.
    """
    if os.geteuid() != 0:
        return supervdsm.getProxy().multipath_resize_map(name)

    log.debug("Resizing map %r", name)
    cmd = [_MULTIPATHD.cmd, "resize", "map", name]
    with utils.stopwatch("Resized map %r" % name, log=log):
        p = commands.start(cmd,
                           sudo=True,
                           stdout=subprocess.PIPE,
                           stderr=subprocess.PIPE)
        out, err = commands.communicate(p)

        out = out.decode("utf-8")
        err = err.decode("utf-8")

        # multipathd reports some errors using non-zero exit code and
        # stderr (need to be root), but the command may return 0, and
        # the result is reported using stdout.
        if p.returncode != 0 or out != "ok\n":
            e = cmdutils.Error(cmd, p.returncode, out, err)
            raise Error("Resizing map {!r} failed: {}".format(name, e))
Пример #5
0
def _run_check():
    """
    Check the devices file. As, according to LVM developers, the behavior of
    this functionality is not entirely or strictly well defined yet, we don't
    raise any exception if the check finds issues in devices file, but only
    log a waring with found issues.
    """
    cmd = [constants.EXT_LVM, 'lvmdevices', "--check"]

    p = commands.start(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = commands.communicate(p)

    if p.returncode == 0 and err:
        log.warning("Found following issues in LVM devices file: %s", err)

    if p.returncode != 0:
        raise cmdutils.Error(cmd, p.returncode, out, err)
Пример #6
0
def _run_vgimportdevices(vg):
    """
    Import underlying devices of provided VG into LVM devices file. Import is
    done using vgimportdevices command. vgimportdevices takes into account
    existing lvm filter, so if some devices are excluded by the filter, such
    devices won't be imported. If the filter is wrong, we may miss some
    devices. To avoid such situation, set the filter to enable all the devices.
    """
    cmd = [
        constants.EXT_LVM, 'vgimportdevices', vg, '--config',
        'devices { use_devicesfile = 1 filter = ["a|.*|"] }'
    ]

    p = commands.start(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = commands.communicate(p)

    if p.returncode == 0 and err:
        log.warning("Command %s succeeded with warnings: %s", cmd, err)

    if p.returncode != 0:
        raise cmdutils.Error(cmd, p.returncode, out, err)
Пример #7
0
 def test_out(self):
     p = commands.start(["echo", "-n", "it works"], stdout=subprocess.PIPE)
     out, err = commands.communicate(p)
     assert p.returncode == 0
     assert out == b"it works"
     assert err is None