예제 #1
0
파일: systemctl_test.py 프로젝트: nirs/vdsm
def test_single_unit():
    unit = "test-sleep-{}.service".format(uuid.uuid4())
    properties = ("Names", "LoadState", "ActiveState")

    systemd.run(["sleep", "5"], unit=unit)
    try:

        r = systemctl.show(unit, properties=properties)
        assert r == [{
            "ActiveState": "active",
            "LoadState": "loaded",
            "Names": unit,
        }]

        r = systemctl.show(unit)
        assert len(r) == 1
        assert r[0]["ActiveState"] == "active"
        assert r[0]["LoadState"] == "loaded"
        assert r[0]["Names"] == unit

    finally:
        systemctl.stop(unit)

    r = systemctl.show(unit, properties=properties)
    assert r == [{
        "ActiveState": "inactive",
        "LoadState": "not-found",
        "Names": unit,
    }]
예제 #2
0
def test_single_unit():
    unit = "test-sleep-{}.service".format(uuid.uuid4())
    properties = ("Names", "LoadState", "ActiveState")

    systemd.run(["sleep", "5"], unit=unit)
    try:

        r = systemctl.show(unit, properties=properties)
        assert r == [{
            "ActiveState": "active",
            "LoadState": "loaded",
            "Names": unit,
        }]

        r = systemctl.show(unit)
        assert len(r) == 1
        assert r[0]["ActiveState"] == "active"
        assert r[0]["LoadState"] == "loaded"
        assert r[0]["Names"] == unit

    finally:
        systemctl.stop(unit)

    r = systemctl.show(unit, properties=properties)
    assert r == [{
        "ActiveState": "inactive",
        "LoadState": "not-found",
        "Names": unit,
    }]
예제 #3
0
def start_transient_service(server_id, config):
    if os.geteuid() != 0:
        return supervdsm.getProxy().nbd_start_transient_service(
            server_id, config)

    _verify_path(config.path)

    cmd = [
        QEMU_NBD,
        "--socket", _socket_path(server_id),
        "--format", config.format,
        "--persistent",

        # Use empty export name for nicer url: "nbd:unix:/path" instead of
        # "nbd:unix:/path:exportname=name".
        "--export-name=",

        "--cache=none",
        "--aio=native",
    ]

    if config.readonly:
        cmd.append("--read-only")
    elif config.discard:
        cmd.append("--discard=unmap")

    cmd.append(config.path)

    systemd.run(
        cmd,
        unit=_service_name(server_id),
        uid=fileUtils.resolveUid(constants.VDSM_USER),
        gid=fileUtils.resolveGid(constants.VDSM_GROUP))
예제 #4
0
파일: nbd.py 프로젝트: dong-df/vdsm
def start_transient_service(server_id, config):
    if os.geteuid() != 0:
        return supervdsm.getProxy().nbd_start_transient_service(
            server_id, config)

    _verify_path(config.path)

    cmd = [
        str(QEMU_NBD),
        "--socket",
        _socket_path(server_id),
        "--persistent",

        # Allow up to 8 clients to share the device. Safe for readers, but for
        # now, consistency is not guaranteed between multiple writers.  Eric
        # Blake says it should be safe if clients write to distinct areas.
        # https://patchwork.kernel.org/patch/11096321/
        "--shared=8",

        # Use empty export name for nicer url: "nbd:unix:/path" instead of
        # "nbd:unix:/path:exportname=name".
        "--export-name=",
        "--cache=none",
        "--aio=native",
    ]

    if config.format != "raw":
        # Enable detection of unallocated extents in qcow2 images. Required for
        # downloading single volume with backing_chain=False. Always enable it
        # so NBD client can inspect image allocation.
        # For raw images allocation depth is not useful, and also triggers a
        # bug in qemu-nbd 6.2 breaking extents reporting in some cases.
        # See https://bugzilla.redhat.com/2041480.
        cmd.append("--allocation-depth")

    if config.readonly:
        cmd.append("--read-only")
    else:
        if config.discard:
            cmd.append("--discard=unmap")

        if config.detect_zeroes:
            # "on" convert zero write to fallocate(WRITE_ZEROES).
            # "unmap" convert zero write to fallocate(PUNCH_HOLE).
            detect_mode = "unmap" if config.discard else "on"
            cmd.append("--detect-zeroes={}".format(detect_mode))

    if config.bitmap:
        cmd.append("--bitmap={}".format(config.bitmap))

    cmd.append(json_uri(config))

    systemd.run(cmd,
                unit=_service_name(server_id),
                uid=fileUtils.resolveUid(constants.VDSM_USER),
                gid=fileUtils.resolveGid(constants.VDSM_GROUP))
예제 #5
0
def start_server(server_id, config):
    cfg = ServerConfig(config)
    dom = sdCache.produce_manifest(cfg.sd_id)
    vol = dom.produceVolume(cfg.img_id, cfg.vol_id)

    if vol.isShared() and not cfg.readonly:
        raise se.SharedVolumeNonWritable(vol)

    cmd = [QEMU_NBD]

    sock = _socket_path(server_id)
    service = _service_name(server_id)

    cmd.append("--socket")
    cmd.append(sock)

    cmd.append("--format")
    cmd.append(sc.fmt2str(vol.getFormat()))

    cmd.append("--persistent")

    # Use empty export name for nicer url: "nbd:unix:/path" instead of
    # "nbd:unix:/path:exportname=name".
    cmd.append("--export-name=")

    cmd.append("--cache=none")
    cmd.append("--aio=native")

    if cfg.readonly:
        cmd.append("--read-only")
    elif cfg.discard:
        cmd.append("--discard=unmap")

    cmd.append(vol.getVolumePath())

    _create_rundir()

    log.info("Starting transient service %s, serving volume %s/%s via unix "
             "socket %s",
             service, cfg.sd_id, cfg.vol_id, sock)

    systemd.run(cmd, unit=service, uid=os.getuid(), gid=os.getgid())

    if not _wait_for_socket(sock, 1.0):
        raise Timeout("Timeout starting NBD server {}: {}"
                      .format(server_id, config))

    return "nbd:unix:" + sock
예제 #6
0
def test_multiple_units():
    unit1 = "test-sleep-{}.service".format(uuid.uuid4())
    unit2 = "test-sleep-{}.service".format(uuid.uuid4())
    pattern = "test-sleep-*.service"
    properties = ("Names", "LoadState", "ActiveState")

    systemd.run(["sleep", "5"], unit=unit1)
    try:

        r = systemctl.show(pattern, properties=properties)
        assert r == [
            {
                "ActiveState": "active",
                "LoadState": "loaded",
                "Names": unit1,
            },
        ]

        systemd.run(["sleep", "5"], unit=unit2)

        r = systemctl.show(pattern, properties=properties)
        assert r == [
            {
                "ActiveState": "active",
                "LoadState": "loaded",
                "Names": unit1,
            },
            {
                "ActiveState": "active",
                "LoadState": "loaded",
                "Names": unit2,
            },
        ]

        r = systemctl.show(pattern)
        assert len(r) == 2
        assert r[0]["LoadState"] == "loaded"
        assert r[0]["Names"] == unit1
        assert r[1]["LoadState"] == "loaded"
        assert r[1]["Names"] == unit2

    finally:
        systemctl.stop(pattern)

    r = systemctl.show(pattern, properties=properties)
    assert r == []
예제 #7
0
파일: systemctl_test.py 프로젝트: nirs/vdsm
def test_multiple_units():
    unit1 = "test-sleep-{}.service".format(uuid.uuid4())
    unit2 = "test-sleep-{}.service".format(uuid.uuid4())
    pattern = "test-sleep-*.service"
    properties = ("Names", "LoadState", "ActiveState")

    systemd.run(["sleep", "5"], unit=unit1)
    try:

        r = systemctl.show(pattern, properties=properties)
        assert r == [
            {
                "ActiveState": "active",
                "LoadState": "loaded",
                "Names": unit1,
            },
        ]

        systemd.run(["sleep", "5"], unit=unit2)

        r = systemctl.show(pattern, properties=properties)
        assert r == [
            {
                "ActiveState": "active",
                "LoadState": "loaded",
                "Names": unit1,
            },
            {
                "ActiveState": "active",
                "LoadState": "loaded",
                "Names": unit2,
            },
        ]

        r = systemctl.show(pattern)
        assert len(r) == 2
        assert r[0]["LoadState"] == "loaded"
        assert r[0]["Names"] == unit1
        assert r[1]["LoadState"] == "loaded"
        assert r[1]["Names"] == unit2

    finally:
        systemctl.stop(pattern)

    r = systemctl.show(pattern, properties=properties)
    assert r == []
예제 #8
0
파일: nbd.py 프로젝트: guozhonghua216/vdsm
def start_transient_service(server_id, config):
    if os.geteuid() != 0:
        return supervdsm.getProxy().nbd_start_transient_service(
            server_id, config)

    _verify_path(config.path)

    cmd = [
        str(QEMU_NBD),
        "--socket",
        _socket_path(server_id),
        "--persistent",

        # Allow up to 8 clients to share the device. Safe for readers, but for
        # now, consistency is not guaranteed between multiple writers.  Eric
        # Blake says it should be safe if clients write to distinct areas.
        # https://patchwork.kernel.org/patch/11096321/
        "--shared=8",

        # Use empty export name for nicer url: "nbd:unix:/path" instead of
        # "nbd:unix:/path:exportname=name".
        "--export-name=",
        "--cache=none",
        "--aio=native",
    ]

    if config.readonly:
        cmd.append("--read-only")
    elif config.discard:
        cmd.append("--discard=unmap")

    if config.bitmap:
        cmd.append("--bitmap={}".format(config.bitmap))

    cmd.append(json_uri(config))

    systemd.run(cmd,
                unit=_service_name(server_id),
                uid=fileUtils.resolveUid(constants.VDSM_USER),
                gid=fileUtils.resolveGid(constants.VDSM_GROUP))
예제 #9
0
파일: systemd.py 프로젝트: chipmap/vdsm
def systemd_run(cmd,
                scope=False,
                unit=None,
                slice=None,
                uid=None,
                gid=None,
                accounting=None):
    return systemd.run(cmd,
                       scope=scope,
                       unit=unit,
                       slice=slice,
                       uid=uid,
                       gid=gid,
                       accounting=accounting)