Пример #1
0
def test_caching_non_ex_image(tmpdir, application, build):
    """
    scenario: we perform a build, we remove an image from cache, we perform the build again, ab should recover
    """
    t = str(tmpdir)
    non_ex_pb_basename = os.path.basename(non_ex_pb)
    p = os.path.join(t, non_ex_pb_basename)

    shutil.copy(non_ex_pb, p)

    with open(p) as fd:
        d = yaml.safe_load(fd)
        d[0]["tasks"][0]["debug"]["msg"] = f"Hello {random_str()}"
    with open(p, "w") as fd:
        yaml.safe_dump(d, fd)

    image_name = random_str(5)
    build.playbook_path = p
    build.target_image = image_name
    application.build(build)
    build = application.db.get_build(build.build_id)

    subprocess.call(["podman", "images", "--all"])
    subprocess.call(["podman", "inspect", build.target_image])

    # FIXME: this command fails in CI, which is super weird
    run_cmd(["buildah", "rmi", build.target_image],
            ignore_status=True,
            print_output=True)
    run_cmd(["buildah", "rmi", build.final_layer_id],
            ignore_status=True,
            print_output=True)
    # now remove all images from the cache
    layers = build.layers[1:]
    layers.reverse()

    for l in layers:
        if l.base_image_id:
            run_cmd(["buildah", "rmi", l.layer_id],
                    ignore_status=True,
                    print_output=True)

    second_build = Build.from_json(build.to_dict())
    second_build.build_id = "33"
    application.build(second_build)
    run_cmd(["buildah", "rmi", build.target_image],
            ignore_status=True,
            print_output=True)
Пример #2
0
 def _load_build(data, build_id, is_latest=False):
     """
     load selected build from database
     :param data: dict
     :param build_id: str or None
     :param is_latest: bool
     :return: build
     """
     try:
         return Build.from_json(data["builds"][build_id])
     except KeyError:
         if is_latest:
             raise RuntimeError(
                 "Latest build with ID %s is no longer available, probably got cleaned."
                 % build_id)
         else:
             raise RuntimeError("There is no such build with ID %s" %
                                build_id)
Пример #3
0
def test_caching_mechanism(application, build):
    """ check that previously executed tasks are being loaded from cache and new ones are computed from scratch """
    small_build = Build.from_json(build.to_dict())
    small_build.target_image += "2"
    small_build.playbook_path = small_basic_playbook_path

    application.build(small_build)
    small_build = application.db.get_build(small_build.build_id)
    assert len(small_build.layers) == 2
    assert small_build.layers[0].cached
    assert not small_build.layers[1].cached

    application.build(build)
    build = application.db.get_build(build.build_id)
    assert len(build.layers) == 5
    assert build.layers[0].cached
    assert build.layers[1].cached
    assert not build.layers[2].cached
    assert not build.layers[3].cached
    assert not build.layers[4].cached
Пример #4
0
 def _load_build(data, build_id):
     try:
         return Build.from_json(data["builds"][build_id])
     except KeyError:
         raise RuntimeError("There is no such build with ID %s" % build_id)