From 58d895624232a2dd37a4d4c2557f19dfada7feeb Mon Sep 17 00:00:00 2001 From: Tomas Tomecek Date: Fri, 8 Jan 2021 10:36:30 +0100 Subject: [PATCH 1/2] simplify packit.yaml Signed-off-by: Tomas Tomecek --- .packit.yaml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.packit.yaml b/.packit.yaml index 8c1fb02..a4894b2 100644 --- a/.packit.yaml +++ b/.packit.yaml @@ -1,8 +1,10 @@ -downstream_package_name: ansible-bender specfile_path: ansible-bender.spec -upstream_package_name: ansible-bender -current_version_command: ["python3", "setup.py", "--version"] -create_tarball_command: ["python3", "setup.py", "sdist", "--dist-dir", "."] +actions: + create-archive: + - "python3 setup.py sdist --dist-dir ." + - "sh -c 'echo ansible-bender-$(python3 setup.py --version).tar.gz'" + get-current-version: + - "python3 setup.py --version" jobs: - job: copr_build metadata: From f63839065a6ae8c8fd52d1a3472d6e28ec014507 Mon Sep 17 00:00:00 2001 From: Tomas Tomecek Date: Fri, 8 Jan 2021 11:34:40 +0100 Subject: [PATCH 2/2] test: check if layers are cached when invoked role fails --- tests/integration/test_api.py | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/integration/test_api.py b/tests/integration/test_api.py index 7876ffa..b0132df 100644 --- a/tests/integration/test_api.py +++ b/tests/integration/test_api.py @@ -4,8 +4,11 @@ import os import shutil import subprocess +from pathlib import Path +import pytest import yaml +from ansible_bender.exceptions import ABBuildUnsuccesful from flexmock import flexmock from ansible_bender.api import Application @@ -256,3 +259,44 @@ def test_pb_with_role(build, application): assert len(build.layers) == 8 finally: run_cmd(["buildah", "rmi", im], ignore_status=True, print_output=True) + + +@pytest.mark.parametrize( + "playbook_content", + ( + "- hosts: all\n" + " roles:\n" + " - train\n", + + "- hosts: all\n" + " tasks:\n" + " - import_role:\n" + " name: train\n", + + "- hosts: all\n" + " tasks:\n" + " - include_role:\n" + " name: train\n" + ) +) +def test_pb_with_role_fail(build, application, tmp_path, playbook_content): + test_roles_path = tmp_path / "roles" + shutil.copytree(roles_dir, test_roles_path) + test_pb_path: Path = tmp_path / Path(role_pb_path).name + test_pb_path.write_text(playbook_content) + im = "image-built-with-role-should-fail" + build.playbook_path = str(test_pb_path) + build.target_image = im + os.environ["ANSIBLE_ROLES_PATH"] = str(test_roles_path) + + # this is the test scenario: make the build fail + os.unlink(test_roles_path / "train" / "files" / "ticket") + + with pytest.raises(ABBuildUnsuccesful): + application.build(build) + + for layer in build.layers: + if layer.base_image_id: + assert not layer.cached # when the task failed, all layers must not be cached + else: + assert layer.cached # the is base image