def test_snapshotter(
    nydus_anchor: NydusAnchor,
    rafs_conf: RafsConf,
    image_url,
    nydus_snapshotter,
    local_registry,
):
    snapshotter = Snapshotter(nydus_anchor)
    containerd = Containerd(nydus_anchor, snapshotter).gen_config()
    snapshotter.set_root(containerd.root)

    nydus_anchor.put_dustbin(snapshotter)
    nydus_anchor.put_dustbin(containerd)

    converter = Nydusify(nydus_anchor)
    converter.docker_v2().convert(image_url)

    rafs_conf.set_rafs_backend(Backend.REGISTRY, repo=converter.original_repo)
    rafs_conf.enable_xattr()
    rafs_conf.dump_rafs_conf()

    snapshotter.run(rafs_conf.path())
    time.sleep(1)
    containerd.run()

    cri = Cri(containerd.address, containerd.address)
    container_name = str(uuid.uuid4())
    cri.run_container(converter.converted_image, container_name)
    id, status = cri.check_container_status(container_name, timeout=30)
    assert id is not None
    assert status
    cri.stop_rm_container(id)
    cri.remove_image(converter.converted_image)
    containerd.remove_image_sync(converter.converted_image)
Exemple #2
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
def test_snapshotter_converted_images(
    nydus_anchor: NydusAnchor,
    rafs_conf: RafsConf,
    converted_images,
    nydus_snapshotter,
):
    # snapshotter = Snapshotter(nydus_anchor).enable_nydus_overlayfs()
    snapshotter = Snapshotter(nydus_anchor)
    containerd = Containerd(nydus_anchor, snapshotter).gen_config()
    snapshotter.set_root(containerd.root)

    nydus_anchor.put_dustbin(snapshotter)
    nydus_anchor.put_dustbin(containerd)

    # We can safely pass the step provide repo configured into the rafs configuration file.
    rafs_conf.set_rafs_backend(Backend.REGISTRY, scheme="https")
    rafs_conf.enable_xattr()
    rafs_conf.dump_rafs_conf()

    snapshotter.run(rafs_conf.path())
    time.sleep(1)
    containerd.run()
    cri = Cri(containerd.address, containerd.address)

    id_set = []
    for ref in converted_images:
        container_name = str(uuid.uuid4())
        cri.run_container(ref, container_name)
        id, status = cri.check_container_status(container_name, timeout=30)
        assert id is not None
        assert status
        id_set.append((id, ref))
        time.sleep(2)

    for id, ref in id_set:
        cri.stop_rm_container(id)
        cri.remove_image(ref)
        containerd.remove_image_sync(ref)

    # TODO: Rafs won't be unmounted and and nydusd still be alive even image is removed locally
    # So kill all nydusd here to make following test verification pass. Is this a bug?

    # Ensure nydusd must have been stopped here
    time.sleep(3)
def test_snapshotter_restart(
    nydus_anchor: NydusAnchor,
    rafs_conf: RafsConf,
    converted_images,
    nydus_snapshotter,
):
    snapshotter = Snapshotter(nydus_anchor)
    containerd = Containerd(nydus_anchor, snapshotter).gen_config()
    snapshotter.set_root(containerd.root)

    nydus_anchor.put_dustbin(containerd)

    # We can safely pass the step provide repo configured into the rafs configuration file.
    rafs_conf.set_rafs_backend(Backend.REGISTRY, scheme="https")
    rafs_conf.enable_xattr().enable_fs_prefetch().enable_rafs_blobcache(
        work_dir=snapshotter.cache_dir())
    rafs_conf.enable_xattr().dump_rafs_conf()
    rafs_conf.dump_rafs_conf()

    snapshotter.run(rafs_conf.path())
    time.sleep(1)
    containerd.run()
    cri = Cri(containerd.address, containerd.address)

    id_set = []
    for ref in converted_images:
        container_name = str(uuid.uuid4())
        cri.run_container(ref, container_name)
        id, status = cri.check_container_status(container_name, timeout=30)
        assert id is not None
        assert status
        id_set.append((id, ref))
        time.sleep(2)

    snapshotter.shutdown()
    snapshotter = Snapshotter(nydus_anchor)
    snapshotter.set_root(containerd.root)
    nydus_anchor.put_dustbin(snapshotter)
    snapshotter.run(rafs_conf.path())

    for id, ref in id_set:
        cri.stop_rm_container(id)
        cri.remove_image(ref)
        containerd.remove_image_sync(ref)