Example #1
0
def test_parts_lifecycle_run_parts_error(new_dir):
    lifecycle = PartsLifecycle(
        {"p1": {
            "plugin": "dump",
            "source": "foo"
        }},
        work_dir=new_dir,
        assets_dir=new_dir,
        base="core22",
        parallel_build_count=8,
        part_names=[],
        package_repositories=[],
        adopt_info=None,
        project_name="test-project",
        parse_info={},
        project_vars={
            "version": "1",
            "grade": "stable"
        },
        target_arch="amd64",
    )
    with pytest.raises(errors.PartsLifecycleError) as raised:
        lifecycle.run("prime")
    assert str(raised.value) == (
        "Failed to pull source: unable to determine source type of 'foo'.")
Example #2
0
def test_parts_lifecycle_run(mocker, parts_data, step_name, new_dir, emitter):
    mocker.patch("craft_parts.executor.executor.Executor._install_build_snaps")
    lcm_spy = mocker.spy(craft_parts, "LifecycleManager")
    lifecycle = PartsLifecycle(
        parts_data,
        work_dir=new_dir,
        assets_dir=new_dir,
        base="core22",
        parallel_build_count=8,
        part_names=[],
        package_repositories=[],
        adopt_info=None,
        project_name="test-project",
        parse_info={},
        project_vars={
            "version": "1",
            "grade": "stable"
        },
        extra_build_snaps=["core22"],
        target_arch="amd64",
    )
    lifecycle.run(step_name)
    assert lifecycle.prime_dir == Path(new_dir, "prime")
    assert lifecycle.prime_dir.is_dir()
    assert lcm_spy.mock_calls == [
        call(
            {"parts": {
                "p1": {
                    "plugin": "nil"
                }
            }},
            application_name="snapcraft",
            work_dir=ANY,
            cache_dir=ANY,
            arch="x86_64",
            base="core22",
            ignore_local_sources=["*.snap"],
            extra_build_snaps=["core22"],
            parallel_build_count=8,
            project_name="test-project",
            project_vars_part_name=None,
            project_vars={
                "version": "1",
                "grade": "stable"
            },
        )
    ]
    emitter.assert_progress(f"Executing parts lifecycle: {step_name} p1")
Example #3
0
def test_parts_lifecycle_run_with_all_architecture(mocker, parts_data,
                                                   new_dir):
    """`target_arch=all` should use the host architecture."""

    mocker.patch("craft_parts.executor.executor.Executor._install_build_snaps")
    lcm_spy = mocker.spy(craft_parts, "LifecycleManager")
    lifecycle = PartsLifecycle(
        parts_data,
        work_dir=new_dir,
        assets_dir=new_dir,
        base="core22",
        parallel_build_count=8,
        part_names=[],
        package_repositories=[],
        adopt_info=None,
        parse_info={},
        project_name="test-project",
        project_vars={
            "version": "1",
            "grade": "stable"
        },
        target_arch="amd64",
    )
    lifecycle.run("prime")

    assert lcm_spy.mock_calls == [
        call(
            {"parts": {
                "p1": {
                    "plugin": "nil"
                }
            }},
            application_name="snapcraft",
            work_dir=ANY,
            cache_dir=ANY,
            arch="x86_64",
            base="core22",
            ignore_local_sources=["*.snap"],
            extra_build_snaps=None,
            parallel_build_count=8,
            project_name="test-project",
            project_vars_part_name=None,
            project_vars={
                "version": "1",
                "grade": "stable"
            },
        )
    ]
Example #4
0
def test_parts_lifecycle_initialize_with_package_repositories_deps_not_installed(
    mocker,
    parts_data,
    new_dir,
):
    mocker.patch("craft_parts.packages.Repository.is_package_installed",
                 return_value=False)
    install_packages_mock = mocker.patch(
        "craft_parts.packages.Repository.install_packages")
    mocker.patch(
        "snapcraft.repo.apt_key_manager.AptKeyManager.install_package_repository_key",
        return_value=True,
    )
    mocker.patch(
        "snapcraft.repo.apt_sources_manager.AptSourcesManager.install_package_repository_sources"
    )
    mocker.patch("craft_parts.packages.Repository.refresh_packages_list")

    parts_lifecycle = PartsLifecycle(
        parts_data,
        work_dir=new_dir,
        assets_dir=new_dir,
        base="core22",
        parallel_build_count=8,
        part_names=[],
        package_repositories=[
            {
                "type": "apt",
                "ppa": "test/somerepo",
            },
        ],
        adopt_info=None,
        project_name="test-project",
        parse_info={},
        project_vars={
            "version": "1",
            "grade": "stable"
        },
        extra_build_snaps=["core22"],
        target_arch="amd64",
    )

    parts_lifecycle._install_package_repositories()

    assert install_packages_mock.mock_calls == [
        call(["gnupg", "dirmngr"], refresh_package_cache=True)
    ]
Example #5
0
def test_parts_lifecycle_clean_parts(parts_data, new_dir, emitter):
    lifecycle = PartsLifecycle(
        parts_data,
        work_dir=new_dir,
        assets_dir=new_dir,
        base="core22",
        parallel_build_count=8,
        part_names=[],
        package_repositories=[],
        adopt_info=None,
        project_name="test-project",
        parse_info={},
        project_vars={
            "version": "1",
            "grade": "stable"
        },
    )
    lifecycle.clean(part_names=["p1"])
    emitter.assert_progress("Cleaning parts: p1")
Example #6
0
def test_parts_lifecycle_run_bad_step(parts_data, new_dir):
    lifecycle = PartsLifecycle(
        parts_data,
        work_dir=new_dir,
        assets_dir=new_dir,
        base="core22",
        parallel_build_count=8,
        part_names=[],
        package_repositories=[],
        adopt_info=None,
        parse_info={},
        project_name="test-project",
        project_vars={
            "version": "1",
            "grade": "stable"
        },
    )
    with pytest.raises(RuntimeError) as raised:
        lifecycle.run("invalid")
    assert str(raised.value) == "Invalid target step 'invalid'"
Example #7
0
def test_parts_lifecycle_run_internal_error(parts_data, new_dir, mocker):
    lifecycle = PartsLifecycle(
        parts_data,
        work_dir=new_dir,
        assets_dir=new_dir,
        base="core22",
        parallel_build_count=8,
        part_names=[],
        package_repositories=[],
        adopt_info=None,
        project_name="test-project",
        parse_info={},
        project_vars={
            "version": "1",
            "grade": "stable"
        },
    )
    mocker.patch("craft_parts.LifecycleManager.plan",
                 side_effect=RuntimeError("crash"))
    with pytest.raises(RuntimeError) as raised:
        lifecycle.run("prime")
    assert str(raised.value) == "Parts processing internal error: crash"
Example #8
0
def test_parts_lifecycle_bad_architecture(parts_data, new_dir):
    with pytest.raises(errors.InvalidArchitecture) as raised:
        PartsLifecycle(
            parts_data,
            work_dir=new_dir,
            assets_dir=new_dir,
            base="core22",
            parallel_build_count=8,
            part_names=[],
            package_repositories=[],
            adopt_info=None,
            parse_info={},
            project_name="test-project",
            project_vars={
                "version": "1",
                "grade": "stable"
            },
            target_arch="bad-arch",
        )

    assert str(raised.value) == "Architecture 'bad-arch' is not supported."