def binary_container_build(task_args: dict): """Run a binary container build. :param task_args: CLI arguments for a binary-container-build task """ params = BinaryBuildTaskParams.from_cli_args(task_args) task = BinaryBuildTask(params) return task.run()
def test_platform_is_not_enabled(self, aarch64_task_params, caplog): mock_workflow_data(enabled_platforms=["x86_64"]) flexmock(PodmanRemote).should_receive("build_container").never() task = BinaryBuildTask(aarch64_task_params) task.execute() assert "Platform aarch64 is not enabled for this build" in caplog.text
def test_acquire_remote_resource_fails(self, x86_task_params): pool = remote_host.RemoteHostsPool([X86_REMOTE_HOST]) # also test that the method passes params to the remote_host module correctly (flexmock(remote_host.RemoteHostsPool).should_receive( "from_config").with_args(REMOTE_HOST_CONFIG, "x86_64").once().and_return(pool)) (flexmock(pool).should_receive("lock_resource").with_args( PIPELINE_RUN_NAME).once().and_return(None)) task = BinaryBuildTask(x86_task_params) err_msg = "Failed to acquire a build slot on any remote host!" with pytest.raises(BuildTaskError, match=err_msg): task.acquire_remote_resource(REMOTE_HOST_CONFIG)
def test_run_exit_steps_on_failure(self, x86_task_params, x86_build_dir, mock_podman_remote, mock_locked_resource, caplog): mock_workflow_data(enabled_platforms=["x86_64"]) mock_config(REGISTRY_CONFIG, REMOTE_HOST_CONFIG) x86_build_dir.dockerfile_path.write_text(DOCKERFILE_CONTENT) (flexmock(mock_podman_remote).should_receive( "build_container").and_raise( BuildProcessError("something went wrong"))) # test that the LockedResource is unlocked on failure flexmock(mock_locked_resource).should_receive("unlock").once() task = BinaryBuildTask(x86_task_params) with pytest.raises(BuildProcessError): task.execute() # test that the Dockerfile is printed on failure assert DOCKERFILE_CONTENT in caplog.text
def test_run_build(self, x86_task_params, x86_build_dir, mock_podman_remote, mock_locked_resource, caplog, fail_image_size_check, is_flatpak): mock_workflow_data(enabled_platforms=["x86_64"]) if fail_image_size_check: mock_config(REGISTRY_CONFIG, REMOTE_HOST_CONFIG, image_size_limit=1233) else: mock_config(REGISTRY_CONFIG, REMOTE_HOST_CONFIG, image_size_limit=1234) x86_build_dir.dockerfile_path.write_text(DOCKERFILE_CONTENT) def mock_build_container(*, build_dir, build_args, dest_tag, squash_all): assert build_dir.path == x86_build_dir.path assert build_dir.platform == "x86_64" assert build_args == BUILD_ARGS assert dest_tag == X86_UNIQUE_IMAGE assert squash_all == is_flatpak yield from ["output line 1\n", "output line 2\n"] (flexmock(mock_podman_remote).should_receive( "build_container").once().replace_with(mock_build_container)) (flexmock(mock_podman_remote).should_receive( "push_container").with_args( X86_UNIQUE_IMAGE, insecure=REGISTRY_CONFIG[0] ["insecure"]).times(0 if fail_image_size_check else 1)) (flexmock(mock_podman_remote).should_receive("get_image_size"). with_args(X86_UNIQUE_IMAGE).and_return(1234).once()) flexmock(mock_locked_resource).should_receive("unlock").once() x86_task_params.user_params['flatpak'] = is_flatpak task = BinaryBuildTask(x86_task_params) if fail_image_size_check: err_msg = 'The size 1234 of image registry.example.org/osbs/spam:v1.0-x86_64 exceeds ' \ 'the limitation 1233 configured in reactor config.' with pytest.raises(ExceedsImageSizeError, match=err_msg): task.execute() else: task.execute() assert ( f"Building for the x86_64 platform from {x86_build_dir.dockerfile_path}" in caplog.text) assert "output line 1" in caplog.text assert "output line 2" in caplog.text assert DOCKERFILE_CONTENT in caplog.text build_log_file = Path(x86_task_params.context_dir, 'x86_64-build.log') assert build_log_file.exists() build_logs = build_log_file.read_text().splitlines() assert ["output line 1", "output line 2"] == build_logs