Exemplo n.º 1
0
def test_records_readahead(nydus_anchor, nydus_image):
    nydus_image.set_backend(Backend.BACKEND_PROXY).create_image()

    rafs_conf = RafsConf(nydus_anchor, nydus_image)
    rafs_conf.enable_records_readahead(interval=1).set_rafs_backend(
        Backend.LOCALFS, image=nydus_image)

    rafs = RafsMount(nydus_anchor, nydus_image, rafs_conf)
    rafs.mount()

    wg = WorkloadGen(nydus_anchor.mount_point, nydus_image.rootfs())

    # TODO: Run several parallel read workers against the mount_point
    wg.setup_workload_generator()
    wg.torture_read(8, 5)
    wg.finish_torture_read()

    rafs.umount()

    utils.clean_pagecache()

    rafs.mount()

    wg.torture_read(8, 5)
    wg.finish_torture_read()
Exemplo n.º 2
0
def test_basic(
    nydus_anchor,
    nydus_image: RafsImage,
    io_duration,
    backend,
    rafs_conf: RafsConf,
    fs_version,
):
    """
    title: Basic functionality test
    description: Mount rafs with different mount options
    pass_criteria:
      - Rafs can be mounted.
      - Rafs can be unmounted.
    """
    nydus_image.set_backend(backend,
                            blob_dir=()).create_image(fs_version=fs_version)
    rafs_conf.set_rafs_backend(backend)

    rafs = RafsMount(nydus_anchor, nydus_image, rafs_conf)
    rafs.mount()
    assert rafs.is_mounted()

    workload_gen = WorkloadGen(nydus_anchor.mount_point, nydus_image.rootfs())

    workload_gen.setup_workload_generator()
    workload_gen.io_read(io_duration)

    nydus_anchor.check_nydusd_health()
    assert workload_gen.io_error == False
    assert workload_gen.verify_entire_fs()

    assert rafs.is_mounted()
    rafs.umount()
Exemplo n.º 3
0
def test_access_pattern(nydus_anchor, nydus_image, rafs_conf: RafsConf):
    rafs_id = "/"
    rafs_conf.enable_access_pattern().set_rafs_backend(Backend.OSS)
    rafs_conf.dump_rafs_conf()

    nydus_image.set_backend(Backend.OSS).create_image()

    rafs = RafsMount(nydus_anchor, nydus_image, rafs_conf)
    rafs.mount()

    nc = NydusAPIClient(rafs.get_apisock())

    wg = WorkloadGen(nydus_anchor.mount_point, nydus_image.rootfs())
    wg.setup_workload_generator()
    wg.torture_read(4, 8)
    duration = 4
    while duration:
        time.sleep(1)
        duration -= 1
        global_metrics = nc.get_global_metrics()
        global_metrics["access_pattern_enabled"] == True

    patterns = nc.get_access_patterns(rafs_id)
    assert len(patterns) != 0
    patterns = nc.get_access_patterns()
    assert len(patterns) != 0
    nc.get_access_patterns("poison")

    wg.finish_torture_read()
Exemplo n.º 4
0
def test_build_image(nydus_anchor, nydus_scratch_image: RafsImage,
                     rafs_conf: RafsConf):
    """
    title: Build nydus image
    description: Build nydus image from rootfs generating proper bootstrap and
    blob
    pass_criteria:
      - Image can successfully builded and mounted
      - Rafs can be unmounted and do a small account of read io and attr
        operation
      - Try let image builder upload blob itself.
    """

    dist = Distributor(nydus_scratch_image.rootfs(), 80, 1)
    dist.generate_tree()
    dist.put_directories(100)
    dist.put_hardlinks(90)
    dist.put_symlinks(200)
    dist.put_multiple_files(random.randint(20, 28), Size(10, Unit.MB))
    dist.put_multiple_chinese_files(random.randint(20, 28), Size(20, Unit.KB))

    Whiteout().whiteout_one_file(nydus_scratch_image.rootfs(),
                                 "i/am/troublemaker/foo")

    nydus_scratch_image.set_backend(Backend.BACKEND_PROXY).create_image()

    rafs_conf.set_rafs_backend(backend_type=Backend.BACKEND_PROXY)
    rafs_conf.dump_rafs_conf()

    rafs = RafsMount(nydus_anchor, nydus_scratch_image, rafs_conf)
    wg = WorkloadGen(nydus_anchor.mount_point, nydus_scratch_image.rootfs())

    rafs.mount()
    assert wg.verify_entire_fs()
    rafs.umount()
Exemplo n.º 5
0
def test_limited_mem(nydus_anchor, rafs_conf, nydus_image):
    """
    description: Run nydusd in a memory limited environment.
        - Use `ulimit` to limit virtual memory nydusd can use.
        - Mount rafs
        - Torture rafs
    """

    rafs_conf.enable_rafs_blobcache()
    rafs_conf.dump_rafs_conf()

    rafs = RafsMount(nydus_anchor, nydus_image, rafs_conf)
    rafs.mount(limited_mem=Size(3, Unit.GB))

    wg = WorkloadGen(nydus_anchor.mount_point, nydus_image.rootfs())

    wg.setup_workload_generator()
    wg.torture_read(8, 10)

    nydus_anchor.start_stats_checker()
    wg.finish_torture_read()
    nydus_anchor.stop_stats_checker()

    assert wg.io_error == False
    assert nydus_anchor.check_nydusd_health()
Exemplo n.º 6
0
def test_daemon_info(nydus_anchor, nydus_image, rafs_conf: RafsConf):
    nydus_image.set_backend(Backend.OSS).create_image()
    rafs_conf.set_rafs_backend(Backend.OSS)
    rafs = RafsMount(nydus_anchor, nydus_image, rafs_conf)
    rafs.mount()
    nc = NydusAPIClient(rafs.get_apisock())
    nc.get_wait_daemon()
Exemplo n.º 7
0
def test_blobcache(
    nydus_anchor: NydusAnchor,
    nydus_image: RafsImage,
    rafs_conf: RafsConf,
    compressor,
    backend,
):
    """
    Allocate a file with local test working directory.
    Loop the file so to get a small file system which is easy to get full.
    Change blob cache location the above test blobdir
    """

    blobdir = "/blobdir"

    blob_backend = "blob_backend"
    fd = os.open(blob_backend, os.O_WRONLY | os.O_CREAT | os.O_TRUNC)
    os.posix_fallocate(fd, 0, 1024 * 1024 * 4)
    os.close(fd)

    utils.execute(["mkfs.ext4", "-F", blob_backend])
    utils.execute(["mount", blob_backend, blobdir])

    rafs_conf.enable_rafs_blobcache()
    rafs_conf.set_rafs_backend(backend)
    rafs_conf.dump_rafs_conf()

    cache_file = os.listdir(blobdir)
    assert len(cache_file) == 1

    rafs = RafsMount(nydus_anchor, nydus_image, rafs_conf)
    rafs.mount()
    assert rafs.is_mounted()

    workload_gen = WorkloadGen(nydus_anchor.mount_point,
                               nydus_anchor.source_dir)

    workload_gen.setup_workload_generator()
    workload_gen.torture_read(4, 15)

    nydus_anchor.start_stats_checker()
    workload_gen.finish_torture_read()
    nydus_anchor.stop_stats_checker()

    cache_file = os.listdir(blobdir)
    assert len(cache_file) >= 2

    if workload_gen.io_error:
        warnings.warn(
            UserWarning("Rafs will return EIO if blobcache file is full"))

    rafs.umount()

    ret, _ = utils.execute(["umount", blobdir])
    assert ret

    os.unlink(blob_backend)
Exemplo n.º 8
0
def test_file_tail(nydus_anchor: NydusAnchor, nydus_scratch_image: RafsImage,
                   backend):
    """
    description: Read data from file tail
        - Create several files of different sizes
        - Punch hole to each file of which some should have hole tail
        - Create rafs image from test scratch directory.
        - Mount rafs
        - Do some test.
    """
    file_size_list = [
        Size(1, Unit.KB),
        Size(6, Unit.KB),
        Size(2, Unit.MB),
        Size(10034, Unit.KB),
    ]
    file_list = []

    dist = Distributor(nydus_anchor.scratch_dir, 2, 2)
    dist.generate_tree()

    for f_s in file_size_list:
        f_name = dist.put_single_file(f_s)
        file_list.append(f_name)
        # Punch hole
        with utils.pushd(nydus_anchor.scratch_dir):
            with open(f_name, "a+b") as f:
                fallocate(
                    f,
                    f_s.B - 500,
                    1000,
                    mode=FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
                )

    nydus_scratch_image.set_backend(backend).create_image()

    rafs_conf = RafsConf(nydus_anchor, nydus_scratch_image)
    rafs_conf.set_rafs_backend(backend, image=nydus_scratch_image)

    rafs = RafsMount(nydus_anchor, nydus_scratch_image, rafs_conf)
    rafs.mount()

    with utils.pushd(nydus_anchor.mount_point):
        for name in file_list:
            with open(name, "rb") as f:
                size = os.stat(name).st_size
                f.seek(size - 300)
                buf = f.read(1000)
                assert len(buf) == 300

    wg = WorkloadGen(nydus_anchor.mount_point, nydus_scratch_image.rootfs())
    for f in file_list:
        wg.verify_single_file(os.path.join(nydus_anchor.mount_point, f))

    assert wg.io_error == False
Exemplo n.º 9
0
def test_blobcache_recovery(
    nydus_anchor: NydusAnchor,
    rafs_conf: RafsConf,
    nydus_scratch_image: RafsImage,
):
    rafs_conf.set_rafs_backend(Backend.BACKEND_PROXY)
    rafs_conf.enable_fs_prefetch()
    rafs_conf.enable_rafs_blobcache()
    rafs_conf.dump_rafs_conf()

    dist = Distributor(nydus_scratch_image.rootfs(), 8, 2)
    dist.generate_tree()
    dirs = dist.put_directories(20)
    dist.put_multiple_files(100, Size(64, Unit.KB))
    dist.put_symlinks(30)
    dist.put_hardlinks(20)
    dist.put_multiple_files(40, Size(64, Unit.KB))
    dist.put_single_file(Size(3, Unit.MB), name="test")

    nydus_scratch_image.set_backend(Backend.BACKEND_PROXY).create_image()

    rafs = RafsMount(nydus_anchor, nydus_scratch_image, rafs_conf)
    rafs.prefetch_files("/").mount()
    wg = WorkloadGen(nydus_anchor.mount_point, nydus_scratch_image.rootfs())

    wg.setup_workload_generator()
    wg.torture_read(4, 4)

    # Hopefully, prefetch can be done in 5 secondes.
    time.sleep(5)

    wg.finish_torture_read()
    rafs.umount()

    rafs2 = RafsMount(nydus_anchor, nydus_scratch_image, rafs_conf)
    rafs2.mount()

    wg.torture_read(4, 4)
    time.sleep(0.5)

    nc = NydusAPIClient(rafs2.get_apisock())

    begin = nc.get_backend_metrics()["read_amount_total"]
    time.sleep(1)
    end = nc.get_backend_metrics()["read_amount_total"]

    assert end == begin == 0

    wg.finish_torture_read()
Exemplo n.º 10
0
def test_prefetch_without_cache(nydus_anchor: NydusAnchor,
                                nydus_scratch_image: RafsImage,
                                rafs_conf: RafsConf):
    """Files prefetch test

    1. relative hinted prefetch files
    2. absolute hinted prefetch files
    3. source rootfs root dir.
    """

    rafs_conf.enable_fs_prefetch().set_rafs_backend(Backend.BACKEND_PROXY)
    rafs_conf.dump_rafs_conf()

    dist = Distributor(nydus_scratch_image.rootfs(), 4, 4)
    dist.generate_tree()
    dist.put_directories(20)
    dist.put_multiple_files(40, Size(8, Unit.KB))
    dist.put_hardlinks(6)
    dist.put_multiple_chinese_files(random.randint(20, 28), Size(20, Unit.KB))

    hint_files = ["/"]
    hint_files.extend(dist.files)
    hint_files.extend(dist.dirs)
    hint_files.extend(dist.symlinks)
    hint_files.extend(dist.hardlinks)

    hint_files = [os.path.join("/", p) for p in hint_files]
    hint_files = "\n".join(hint_files)

    nydus_scratch_image.set_backend(Backend.BACKEND_PROXY).create_image(
        readahead_policy="fs", readahead_files=hint_files.encode())

    rafs = RafsMount(nydus_anchor, nydus_scratch_image, rafs_conf)
    rafs.mount()
    assert rafs.is_mounted()

    workload_gen = WorkloadGen(nydus_anchor.mount_point,
                               nydus_scratch_image.rootfs())

    # TODO: Run several parallel read workers against the mount_point
    workload_gen.setup_workload_generator()
    workload_gen.torture_read(8, 5)
    workload_gen.finish_torture_read()

    assert NydusAnchor.check_nydusd_health()
    assert not workload_gen.io_error

    assert rafs.is_mounted()
    rafs.umount()
Exemplo n.º 11
0
def test_syscalls(
    nydus_anchor: NydusAnchor,
    nydus_scratch_image: RafsImage,
    rafs_conf: RafsConf,
):

    syscall_helper = "framework/test_syscalls"
    ret, _ = utils.execute(
        ["gcc", "framework/test_syscalls.c", "-o", syscall_helper],
        shell=False,
        print_output=True,
    )
    assert ret

    dist = Distributor(nydus_scratch_image.rootfs(), 2, 2)
    dist.generate_tree()
    dist.put_single_file(Size(8, Unit.KB),
                         pos=nydus_scratch_image.rootfs(),
                         name="xattr_no_kv")
    dist.put_single_file_with_xattr(
        Size(8, Unit.KB),
        ("trusted.nydus.key", ""),
        pos=nydus_scratch_image.rootfs(),
        name="xattr_empty_value",
    )
    dist.put_single_file_with_xattr(
        Size(8, Unit.KB),
        ("trusted.nydus.key", "1234567890"),
        pos=nydus_scratch_image.rootfs(),
        name="xattr_insufficient_buffer",
    )

    nydus_scratch_image.set_backend(Backend.BACKEND_PROXY).create_image()

    rafs_conf.enable_xattr().set_rafs_backend(Backend.BACKEND_PROXY)
    rafs_conf.dump_rafs_conf()

    rafs = RafsMount(nydus_anchor, nydus_scratch_image, rafs_conf)
    rafs.mount()

    for no in [58]:
        ret, _ = utils.execute(
            [syscall_helper, nydus_anchor.mount_point,
             str(no)],
            shell=False,
            print_output=True,
        )
        assert ret
Exemplo n.º 12
0
def test_build_image_param_blobid(nydus_anchor, nydus_image: RafsImage,
                                  rafs_conf: RafsConf):
    """
    description:
        Test if nydus-image argument `--blob-id` works properly
    """
    # More strict id check?
    nydus_image.set_backend(Backend.BACKEND_PROXY).set_param(
        "blob-id", uuid.uuid4()).create_image()
    rafs_conf.set_rafs_backend(Backend.BACKEND_PROXY)
    rafs = RafsMount(nydus_anchor, nydus_image, rafs_conf)
    rafs.mount()

    wg = WorkloadGen(nydus_anchor.mount_point, nydus_image.rootfs())
    wg.setup_workload_generator()
    wg.torture_read(5, 5)
    wg.finish_torture_read()
Exemplo n.º 13
0
def test_digest_validate(nydus_anchor, rafs_conf: RafsConf,
                         nydus_image: RafsImage, compressor):

    rafs_conf.set_rafs_backend(Backend.LOCALFS)
    rafs_conf.enable_validation()
    rafs_conf.enable_rafs_blobcache()

    nydus_image.set_backend(Backend.LOCALFS,
                            blob_dir=()).create_image(compressor=compressor)

    rafs = RafsMount(nydus_anchor, nydus_image, rafs_conf)
    rafs.mount()

    wg = WorkloadGen(nydus_anchor.mount_point, nydus_image.rootfs())
    wg.setup_workload_generator()
    wg.torture_read(5, 5, verify=True)
    wg.finish_torture_read()
Exemplo n.º 14
0
def test_iostats(nydus_anchor: NydusAnchor, nydus_image: RafsImage,
                 rafs_conf: RafsConf):
    rafs_id = "/"
    rafs_conf.enable_files_iostats().enable_latest_read_files(
    ).set_rafs_backend(Backend.OSS)
    nydus_image.set_backend(Backend.OSS).create_image()
    rafs = RafsMount(nydus_anchor, nydus_image, rafs_conf)

    rafs.mount()
    assert rafs.is_mounted()

    nc = NydusAPIClient(rafs.get_apisock())

    duration = 5

    wg = WorkloadGen(nydus_anchor.mount_point, nydus_image.rootfs())
    wg.setup_workload_generator()
    wg.torture_read(4, duration)

    while duration:
        time.sleep(1)
        duration -= 1
        nc.get_global_metrics()
        nc.get_files_metrics(rafs_id)
        nc.get_backend_metrics(rafs_id)

    wg.finish_torture_read()

    duration = 7
    wg.torture_read(4, duration)
    # Disable it firstly and then enable it.
    # TODO: files metrics can't be toggled dynamically now. Try to implement it.
    # nc.disable_files_metrics(rafs_id)
    # nc.enable_files_metrics(rafs_id)

    r = nc.get_latest_files_metrics(rafs_id)
    print(r)

    while duration:
        time.sleep(1)
        duration -= 1
        nc.get_files_metrics(rafs_id)

    wg.finish_torture_read()
    rafs.umount()
Exemplo n.º 15
0
def test_global_metrics(nydus_anchor, nydus_image: RafsImage,
                        rafs_conf: RafsConf):
    rafs_id = "/"

    rafs_conf.enable_files_iostats().set_rafs_backend(Backend.OSS)
    nydus_image.set_backend(Backend.OSS).create_image()

    rafs = RafsMount(nydus_anchor, nydus_image, rafs_conf)
    rafs.mount()

    nc = NydusAPIClient(rafs.get_apisock())

    gm = nc.get_global_metrics()
    assert gm["files_account_enabled"] == True
    assert gm["measure_latency"] == True

    file_counters = nc.get_files_metrics(rafs_id)
    assert len(file_counters)

    logging.info("There are %d file counters created.", len(file_counters))

    wg = WorkloadGen(nydus_anchor.mount_point, nydus_image.rootfs())
    wg.setup_workload_generator()

    wg.io_read(4)

    file_counters = nc.get_files_metrics(rafs_id)
    assert file_counters is not None and len(file_counters)
    logging.info("There are %d file counters created after some read.",
                 len(file_counters))

    if len(file_counters):
        k = random.choice(list(file_counters))
        logging.info("ino: %s, stats: %s", k, file_counters[k])

    gm_old = nc.get_global_metrics()

    wg.io_read(4)

    gm_new = nc.get_global_metrics()
    assert gm_new["data_read"] > gm_old["data_read"]
    assert (gm_new["fop_hits"][nydusd_client.Fop.Read.get_value()] >
            gm_old["fop_hits"][nydusd_client.Fop.Read.get_value()])

    rafs.umount()
Exemplo n.º 16
0
def test_deep_directory(nydus_anchor, rafs_conf: RafsConf,
                        nydus_scratch_image: RafsImage):

    dist = Distributor(nydus_anchor.scratch_dir, 100, 1)
    dist.generate_tree()

    nydus_scratch_image.set_backend(Backend.BACKEND_PROXY).create_image()

    rafs_conf.set_rafs_backend(Backend.BACKEND_PROXY)
    rafs_conf.dump_rafs_conf()

    rafs = RafsMount(nydus_anchor, nydus_scratch_image, rafs_conf)
    rafs.mount()

    wg = WorkloadGen(nydus_anchor.mount_point, nydus_scratch_image.rootfs())

    wg.setup_workload_generator()
    wg.torture_read(8, 5)

    wg.finish_torture_read()
    assert wg.verify_entire_fs()
Exemplo n.º 17
0
def test_various_file_types(nydus_anchor: NydusAnchor, rafs_conf: RafsConf,
                            nydus_scratch_image: RafsImage):
    """
    description: Put various types of files into rootfs.
        - Regular, dir, char, block, fifo, sock, symlink
    """

    with utils.pushd(nydus_scratch_image.rootfs()):
        fd = os.open("regular", os.O_CREAT | os.O_RDWR)
        os.close(fd)

        os.mkfifo("fifo")
        os.mknod("blk", 0o600 | stat.S_IFBLK, device=random.randint(0, 2 ^ 64))
        os.mknod("char",
                 0o600 | stat.S_IFCHR,
                 device=random.randint(0, 2 ^ 64))
        os.mknod("sock",
                 0o600 | stat.S_IFSOCK,
                 device=random.randint(0, 2 ^ 64))
        os.symlink("regular", "symlink")

    nydus_scratch_image.set_backend(Backend.BACKEND_PROXY).create_image()
    rafs_conf.set_rafs_backend(Backend.BACKEND_PROXY)

    rafs = RafsMount(nydus_anchor, nydus_scratch_image, rafs_conf)
    rafs.mount()

    with utils.pushd(nydus_anchor.mount_point):
        assert os.path.exists("fifo")
        assert os.path.exists("blk")
        assert os.path.exists("char")
        assert os.path.exists("sock")
        assert os.path.exists("symlink")

    wg = WorkloadGen(nydus_anchor.mount_point, nydus_scratch_image.rootfs())
    wg.setup_workload_generator()
    assert wg.verify_entire_fs()

    wg.torture_read(2, 4)
    wg.finish_torture_read()
Exemplo n.º 18
0
def test_hardlink(nydus_anchor: NydusAnchor, nydus_scratch_image,
                  rafs_conf: RafsConf):
    dist = Distributor(nydus_scratch_image.rootfs(), 8, 6)
    dist.generate_tree()

    hardlink_verifier = verifier.HardlinkVerifier(nydus_scratch_image.rootfs(),
                                                  dist)
    hardlink_verifier.scratch()

    nydus_scratch_image.set_backend(Backend.BACKEND_PROXY).create_image()
    rafs_conf.set_rafs_backend(Backend.BACKEND_PROXY)
    rafs = RafsMount(nydus_anchor, nydus_scratch_image, rafs_conf)
    rafs.mount()

    wg = WorkloadGen(nydus_anchor.mount_point, nydus_scratch_image.rootfs())

    hardlink_verifier.verify(nydus_anchor.mount_point,
                             nydus_scratch_image.rootfs())

    wg.setup_workload_generator()
    wg.io_read(3)
    nydus_anchor.check_nydusd_health()

    assert wg.io_error == False
Exemplo n.º 19
0
def test_signal_handling(nydus_anchor: NydusAnchor,
                         nydus_scratch_image: RafsImage, rafs_conf: RafsConf,
                         sig):

    dist = Distributor(nydus_scratch_image.rootfs(), 2, 2)
    dist.generate_tree()
    dist.put_multiple_files(5, Size(2, Unit.KB))

    nydus_scratch_image.set_backend(Backend.BACKEND_PROXY).create_image()

    victim = os.path.join(nydus_anchor.mount_point, dist.files[-1])

    rafs_conf.set_rafs_backend(Backend.BACKEND_PROXY)

    rafs = RafsMount(nydus_anchor, nydus_scratch_image, rafs_conf)
    rafs.mount()
    fd = os.open(victim, os.O_RDONLY)
    assert rafs.is_mounted()
    os.kill(rafs.p.pid, sig)
    time.sleep(3)

    assert not os.path.ismount(nydus_anchor.mount_point)

    rafs.p.wait()
Exemplo n.º 20
0
def test_stargz(
    nydus_anchor: NydusAnchor,
    rafs_conf: RafsConf,
    nydus_scratch_image: RafsImage,
):
    """
    Example command:
        stargzify file:`pwd`/foo.tar.gz foo.stargz

    """
    intermediator = "tmp.tar.gz"
    stargz_image = "tmp.stargz"

    dist = Distributor(nydus_scratch_image.rootfs(), 4, 4)
    dist.generate_tree()
    dirs = dist.put_directories(20)
    dist.put_multiple_files(100, Size(64, Unit.KB))
    dist.put_symlinks(30)
    dist.put_multiple_files(10, Size(4, Unit.MB))
    dist.put_hardlinks(20)
    dist.put_single_file(Size(3, Unit.MB), name="test")
    try:
        shutil.rmtree("origin")
    except Exception:
        pass
    shutil.copytree(nydus_scratch_image.rootfs(), "origin", symlinks=True)
    utils.write_tar_gz(nydus_scratch_image.rootfs(), intermediator)

    cmd = ["framework/bin/stargzify", f"file:{intermediator}", stargz_image]
    utils.execute(cmd)

    toc = utils.parse_stargz(stargz_image)
    image = RafsImage(
        nydus_anchor,
        toc,
        "bootstrap_scratched",
        "blob_scratched",
        clear_from_oss=True,
    )

    # This is a trick since blob name is usually a temp file created when RafsImage instantiated.
    # framework will upload stargz to oss.
    image.blob_abs_path = stargz_image
    image.set_backend(Backend.OSS).set_param(
        "blob-id", uuid.uuid4()).create_image(from_stargz=True)

    rafs_conf.set_rafs_backend(Backend.OSS)
    rafs_conf.enable_rafs_blobcache(is_compressed=True)

    rafs = RafsMount(nydus_anchor, image, rafs_conf)
    rafs.mount()

    wg = WorkloadGen(nydus_anchor.mount_point, "origin")

    wg.verify_entire_fs()

    wg.setup_workload_generator()
    wg.torture_read(4, 4)

    wg.finish_torture_read()
    assert not wg.io_error
Exemplo n.º 21
0
def test_pseudo_fs(nydus_anchor, nydus_image, rafs_conf: RafsConf):
    nydus_image.set_backend(Backend.BACKEND_PROXY).create_image()

    rafs_conf.set_rafs_backend(Backend.BACKEND_PROXY)

    rafs = RafsMount(nydus_anchor, None, rafs_conf)
    rafs.mount()
    time.sleep(1)
    nc = NydusAPIClient(rafs.get_apisock())

    try:
        shutil.rmtree("pseudo_fs_scratch")
    except FileNotFoundError:
        pass

    scratch_rootfs = shutil.copytree(nydus_image.rootfs(),
                                     "pseudo_fs_scratch",
                                     symlinks=True)
    dist = Distributor(scratch_rootfs, 5, 5)
    dist.generate_tree()
    dist.put_multiple_files(20, Size(8, Unit.KB))

    ###
    suffix = "1"
    image = RafsImage(
        nydus_anchor,
        scratch_rootfs,
        "bs" + suffix,
        "blob" + suffix,
    )
    conf = RafsConf(nydus_anchor)
    conf.enable_fs_prefetch()
    conf.enable_validation()
    conf.set_rafs_backend(Backend.BACKEND_PROXY)
    conf.dump_rafs_conf()

    image.set_backend(Backend.BACKEND_PROXY).create_image()
    nc.pseudo_fs_mount(image.bootstrap_path, f"/pseudo{suffix}", conf.path(),
                       None)
    ###
    suffix = "2"
    image = RafsImage(
        nydus_anchor,
        scratch_rootfs,
        "bs" + suffix,
        "blob" + suffix,
    )
    conf = RafsConf(nydus_anchor)
    conf.enable_rafs_blobcache()
    conf.enable_validation()
    conf.enable_records_readahead()
    conf.set_rafs_backend(Backend.BACKEND_PROXY)
    conf.dump_rafs_conf()

    dist.put_multiple_files(20, Size(8, Unit.KB))

    image.set_backend(Backend.BACKEND_PROXY).create_image()
    nc.pseudo_fs_mount(image.bootstrap_path, f"/pseudo{suffix}", conf.path(),
                       None)
    ###
    suffix = "3"
    image = RafsImage(
        nydus_anchor,
        scratch_rootfs,
        "bs" + suffix,
        "blob" + suffix,
    )
    conf = RafsConf(nydus_anchor)
    conf.enable_rafs_blobcache()
    conf.enable_records_readahead()
    conf.set_rafs_backend(Backend.BACKEND_PROXY)
    conf.dump_rafs_conf()

    dist.put_multiple_files(20, Size(8, Unit.KB))

    image.set_backend(Backend.BACKEND_PROXY).create_image()
    nc.pseudo_fs_mount(image.bootstrap_path, f"/pseudo{suffix}", conf.path(),
                       None)

    wg1 = WorkloadGen(os.path.join(nydus_anchor.mount_point, "pseudo1"),
                      scratch_rootfs)
    wg2 = WorkloadGen(os.path.join(nydus_anchor.mount_point, "pseudo2"),
                      scratch_rootfs)
    wg3 = WorkloadGen(os.path.join(nydus_anchor.mount_point, "pseudo3"),
                      scratch_rootfs)

    time.sleep(2)
    wg1.setup_workload_generator()
    wg2.setup_workload_generator()
    wg3.setup_workload_generator()

    wg1.torture_read(4, 8)
    wg2.torture_read(4, 8)
    wg3.torture_read(4, 8)

    wg1.finish_torture_read()
    wg2.finish_torture_read()
    wg3.finish_torture_read()

    # TODO: Temporarily disable the verification as hard to select `verify dir`
    # assert wg1.verify_entire_fs()
    # assert wg2.verify_entire_fs()
    # assert wg3.verify_entire_fs()

    nc.umount_rafs("/pseudo1")
    nc.umount_rafs("/pseudo2")
    nc.umount_rafs("/pseudo3")