示例#1
0
def test_search_image_file_ova(tmpdir):

    os.makedirs(str(tmpdir / "QEMU" / "a.ova"))
    with open(str(tmpdir / "QEMU" / "a.ova" / "a.vmdk"),
              "w+",
              encoding="utf-8") as f:
        f.write("ALPHA")
    with open(str(tmpdir / "QEMU" / "a.ova.md5sum"), "w+") as f:
        f.write("36b84f8e3fba5bf993e3ba352d62d146")

    os.makedirs(str(tmpdir / "QEMU" / "b.ova"))
    with open(str(tmpdir / "QEMU" / "b.ova" / "b.vmdk"),
              "w+",
              encoding="utf-8") as f:
        f.write("BETA")
    with open(str(tmpdir / "QEMU" / "b.ova.md5sum"), "w+") as f:
        f.write("36b84f8e3fba5bf993e3ba352d62d122")

    registry = Registry(set([str(tmpdir / "QEMU")]))
    image = registry.search_image_file("a.ova/a.vmdk",
                                       "36b84f8e3fba5bf993e3ba352d62d146", 5)
    assert image.path == str(tmpdir / "QEMU" / "a.ova" / "a.vmdk")

    image = registry.search_image_file("b.ova/b.vmdk", None, None)
    assert image.path == str(tmpdir / "QEMU" / "b.ova" / "b.vmdk")
示例#2
0
def test_search_image_file(tmpdir):

    os.makedirs(str(tmpdir / "QEMU"))
    with open(str(tmpdir / "QEMU" / "a"), "w+", encoding="utf-8") as f:
        f.write("ALPHA")
    with open(str(tmpdir / "QEMU" / "b"), "w+", encoding="utf-8") as f:
        f.write("BETA")
    with open(str(tmpdir / "QEMU" / "c"), "w+", encoding="utf-8") as f:
        f.write("CHARLIE")
    with open(str(tmpdir / "QEMU" / "c.md5sum"), "w+", encoding="utf-8") as f:
        f.write("42b84f8e3fba5bf993e3ba352d62d146")

    registry = Registry(set([str(tmpdir / "QEMU")]))
    image = registry.search_image_file("b", "36b84f8e3fba5bf993e3ba352d62d146",
                                       5)
    assert image.path == str(tmpdir / "QEMU" / "b")

    # Search by name
    image = registry.search_image_file("b", None, None)
    assert image.path == str(tmpdir / "QEMU" / "b")

    # Test using md5sum cache file
    image = registry.search_image_file("c", "42b84f8e3fba5bf993e3ba352d62d146",
                                       5)
    assert image.path == str(tmpdir / "QEMU" / "c")

    # If size doesn't match ignore the file
    registry = Registry(set([str(tmpdir / "QEMU")]))
    image = registry.search_image_file("b", "36b84f8e3fba5bf993e3ba352d62d146",
                                       1000)
    assert image is None

    # md5sum doesn't exists
    assert registry.search_image_file("x", "00000000000000000000000000000000",
                                      5) is None
示例#3
0
def test_search_image_file_ova(tmpdir):

    os.makedirs(str(tmpdir / "QEMU" / "a.ova"))
    with open(str(tmpdir / "QEMU" / "a.ova" / "a.vmdk"), "w+", encoding="utf-8") as f:
        f.write("ALPHA")
    with open(str(tmpdir / "QEMU" / "a.ova.md5sum"), "w+") as f:
        f.write("36b84f8e3fba5bf993e3ba352d62d146")

    registry = Registry(set([str(tmpdir / "QEMU")]))
    image = registry.search_image_file("a.ova/a.vmdk", "36b84f8e3fba5bf993e3ba352d62d146", 5)
    assert image == str(tmpdir / "QEMU" / "a.ova" / "a.vmdk")
示例#4
0
def test_search_image_file(tmpdir):

    os.makedirs(str(tmpdir / "QEMU"))
    with open(str(tmpdir / "QEMU" / "a"), "w+", encoding="utf-8") as f:
        f.write("ALPHA")
    with open(str(tmpdir / "QEMU" / "b"), "w+", encoding="utf-8") as f:
        f.write("BETA")
    with open(str(tmpdir / "QEMU" / "c"), "w+", encoding="utf-8") as f:
        f.write("CHARLIE")
    with open(str(tmpdir / "QEMU" / "c.md5sum"), "w+", encoding="utf-8") as f:
        f.write("42b84f8e3fba5bf993e3ba352d62d146")

    registry = Registry(set([str(tmpdir / "QEMU")]))
    image = registry.search_image_file("b", "36b84f8e3fba5bf993e3ba352d62d146", 5)
    assert image.path == str(tmpdir / "QEMU" / "b")

    # Search by name
    image = registry.search_image_file("b", None, None)
    assert image.path == str(tmpdir / "QEMU" / "b")

    # Test using md5sum cache file
    image = registry.search_image_file("c", "42b84f8e3fba5bf993e3ba352d62d146", 5)
    assert image.path == str(tmpdir / "QEMU" / "c")

    # If size doesn't match ignore the file
    registry = Registry(set([str(tmpdir / "QEMU")]))
    image = registry.search_image_file("b", "36b84f8e3fba5bf993e3ba352d62d146", 1000)
    assert image is None

    # md5sum doesn't exists
    assert registry.search_image_file("x", "00000000000000000000000000000000", 5) is None
示例#5
0
def registry(images_dir):
    return Registry([os.path.join(images_dir, "QEMU")])