コード例 #1
0
def test_apt_unmarshal_invalid_extra_keys():
    test_dict = {
        "architectures": ["amd64", "i386"],
        "components": ["main", "multiverse"],
        "formats": ["deb", "deb-src"],
        "key-id": "A" * 40,
        "key-server": "keyserver.ubuntu.com",
        "name": "test-name",
        "suites": ["xenial", "xenial-updates"],
        "type": "apt",
        "url": "http://archive.ubuntu.com/ubuntu",
        "foo": "bar",
        "foo2": "bar",
    }

    with pytest.raises(errors.PackageRepositoryValidationError) as exc_info:
        PackageRepositoryApt.unmarshal(test_dict)

    assert (
        exc_info.value.brief
        == "Found unsupported package repository properties 'foo', 'foo2'."
    )
    assert exc_info.value.details is None
    assert (
        exc_info.value.resolution
        == "Verify repository configuration and ensure it is correct."
    )
コード例 #2
0
    def test_valid_apt_deb(self):
        repo = PackageRepositoryApt(
            architectures=["amd64", "i386"],
            components=["main", "multiverse"],
            formats=["deb", "deb-src"],
            key_id="test-key-id",
            key_server="keyserver.ubuntu.com",
            name="test-name",
            suites=["xenial", "xenial-updates"],
            url="http://archive.ubuntu.com/ubuntu",
        )

        self.assertThat(
            repo.marshal(),
            Equals({
                "architectures": ["amd64", "i386"],
                "components": ["main", "multiverse"],
                "formats": ["deb", "deb-src"],
                "key-id": "test-key-id",
                "key-server": "keyserver.ubuntu.com",
                "name": "test-name",
                "suites": ["xenial", "xenial-updates"],
                "type": "apt",
                "url": "http://archive.ubuntu.com/ubuntu",
            }),
        )
コード例 #3
0
def test_apt_unmarshal_invalid_data():
    test_dict = "not-a-dict"

    with pytest.raises(errors.PackageRepositoryValidationError) as exc_info:
        PackageRepositoryApt.unmarshal(test_dict)

    assert exc_info.value.brief == "Invalid package repository object 'not-a-dict'."
    assert (exc_info.value.details ==
            "Package repository must be a valid dictionary object.")
    assert (
        exc_info.value.resolution ==
        "Verify repository configuration and ensure that the correct syntax is used."
    )
コード例 #4
0
 def get_required_package_repositories(self) -> List[PackageRepository]:
     return [
         PackageRepositoryApt(
             deb_types=["deb"],
             components=["main"],
             key_id="C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654",
             url="http://packages.ros.org/ros2/ubuntu",
             suites=["$SNAPCRAFT_APT_RELEASE"],
         )
     ]
コード例 #5
0
ファイル: colcon.py プロジェクト: orbit88/snapcraft
 def get_required_package_repositories(cls) -> List[PackageRepository]:
     codename = os_release.OsRelease().version_codename()
     return [
         PackageRepositoryApt(
             formats=["deb"],
             components=["main"],
             key_id="C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654",
             url="http://packages.ros.org/ros2/ubuntu",
             suites=[codename],
         )
     ]
コード例 #6
0
def test_apt_name():
    repo = PackageRepositoryApt(
        architectures=["amd64", "i386"],
        components=["main", "multiverse"],
        formats=["deb", "deb-src"],
        key_id="A" * 40,
        key_server="keyserver.ubuntu.com",
        suites=["xenial", "xenial-updates"],
        url="http://archive.ubuntu.com/ubuntu",
    )

    assert repo.name == "http_archive_ubuntu_com_ubuntu"
コード例 #7
0
def test_apt_invalid_path():
    with pytest.raises(errors.PackageRepositoryValidationError) as exc_info:
        PackageRepositoryApt(
            key_id="A" * 40, path="", url="http://archive.ubuntu.com/ubuntu",
        )

    assert exc_info.value.brief == "Invalid path ''."
    assert exc_info.value.details == "Paths must be non-empty strings."
    assert (
        exc_info.value.resolution
        == "Verify the repository configuration and ensure that 'path' is a non-empty string such as '/'."
    )
コード例 #8
0
def test_apt_invalid_url():
    with pytest.raises(errors.PackageRepositoryValidationError) as exc_info:
        PackageRepositoryApt(
            key_id="A" * 40, url="",
        )

    assert exc_info.value.brief == "Invalid URL ''."
    assert exc_info.value.details == "URLs must be non-empty strings."
    assert (
        exc_info.value.resolution
        == "Verify the repository configuration and ensure that 'url' is correctly specified."
    )
コード例 #9
0
def test_apt_unmarshal_invalid_type():
    test_dict = {
        "architectures": ["amd64", "i386"],
        "components": ["main", "multiverse"],
        "formats": ["deb", "deb-src"],
        "key-id": "A" * 40,
        "key-server": "keyserver.ubuntu.com",
        "name": "test-name",
        "suites": ["xenial", "xenial-updates"],
        "type": "aptx",
        "url": "http://archive.ubuntu.com/ubuntu",
    }

    with pytest.raises(errors.PackageRepositoryValidationError) as exc_info:
        PackageRepositoryApt.unmarshal(test_dict)

    assert exc_info.value.brief == "Unsupported type 'aptx'."
    assert exc_info.value.details == "The only currently supported type is 'apt'."
    assert (
        exc_info.value.resolution ==
        "Verify repository configuration and ensure that 'type' is correctly specified."
    )
コード例 #10
0
def test_apt_marshal():
    repo = PackageRepositoryApt(
        architectures=["amd64", "i386"],
        components=["main", "multiverse"],
        formats=["deb", "deb-src"],
        key_id="A" * 40,
        key_server="xkeyserver.ubuntu.com",
        name="test-name",
        suites=["xenial", "xenial-updates"],
        url="http://archive.ubuntu.com/ubuntu",
    )

    assert repo.marshal() == {
        "architectures": ["amd64", "i386"],
        "components": ["main", "multiverse"],
        "formats": ["deb", "deb-src"],
        "key-id": "A" * 40,
        "key-server": "xkeyserver.ubuntu.com",
        "name": "test-name",
        "suites": ["xenial", "xenial-updates"],
        "type": "apt",
        "url": "http://archive.ubuntu.com/ubuntu",
    }
コード例 #11
0
def test_apt_invalid_suites_as_path():
    with pytest.raises(errors.PackageRepositoryValidationError) as exc_info:
        PackageRepositoryApt(
            key_id="A" * 40,
            suites=["my-suite/"],
            url="http://archive.ubuntu.com/ubuntu",
        )

    assert exc_info.value.brief == "Invalid suite 'my-suite/'."
    assert exc_info.value.details == "Suites must not end with a '/'."
    assert (
        exc_info.value.resolution ==
        "Verify the repository configuration and remove the trailing '/ from suites or use the 'path' property to define a path."
    )
コード例 #12
0
def test_apt_invalid_missing_suites():
    with pytest.raises(errors.PackageRepositoryValidationError) as exc_info:
        PackageRepositoryApt(
            key_id="A" * 40,
            components=["main"],
            url="http://archive.ubuntu.com/ubuntu",
        )

    assert exc_info.value.brief == "No suites specified."
    assert exc_info.value.details == "Suites are required when using components."
    assert (
        exc_info.value.resolution ==
        "Verify the repository configuration and ensure that 'suites' is correctly specified."
    )
コード例 #13
0
def test_apt_invalid_path_with_components():
    with pytest.raises(errors.PackageRepositoryValidationError) as exc_info:
        PackageRepositoryApt(
            key_id="A" * 40,
            path="/",
            components=["main"],
            url="http://archive.ubuntu.com/ubuntu",
        )

    assert (exc_info.value.brief ==
            "Components ['main'] cannot be combined with path '/'.")
    assert exc_info.value.details == "Path and components are incomptiable options."
    assert (
        exc_info.value.resolution ==
        "Verify the repository configuration and remove 'path' or 'components'."
    )
コード例 #14
0
def test_apt_invalid_path_with_suites():
    with pytest.raises(errors.PackageRepositoryValidationError) as exc_info:
        PackageRepositoryApt(
            key_id="A" * 40,
            path="/",
            suites=["xenial", "xenial-updates"],
            url="http://archive.ubuntu.com/ubuntu",
        )

    assert (
        exc_info.value.brief ==
        "Suites ['xenial', 'xenial-updates'] cannot be combined with path '/'."
    )
    assert exc_info.value.details == "Path and suites are incomptiable options."
    assert (
        exc_info.value.resolution ==
        "Verify the repository configuration and remove 'path' or 'suites'.")
コード例 #15
0
def test_install_package_repository_key_already_installed(
    mock_is_key_installed,
    is_installed,
    apt_gpg,
):
    mock_is_key_installed.return_value = is_installed
    package_repo = PackageRepositoryApt(
        components=["main", "multiverse"],
        key_id="8" * 40,
        key_server="xkeyserver.com",
        suites=["xenial"],
        url="http://archive.ubuntu.com/ubuntu",
    )

    updated = apt_gpg.install_package_repository_key(package_repo=package_repo)

    assert updated is not is_installed
コード例 #16
0
def test_apt_install_implied_path(mock_repo, tmp_path):
    repo = PackageRepositoryApt(
        key_id="A" * 40, url="http://archive.ubuntu.com/ubuntu",
    )

    repo.install()

    assert mock_repo.mock_calls == [
        mock.call.install_sources(
            architectures=None,
            components=None,
            formats=None,
            name="http_archive_ubuntu_com_ubuntu",
            suites=["/"],
            url="http://archive.ubuntu.com/ubuntu",
        ),
    ]
コード例 #17
0
def test_install_package_repository_key_from_asset(
    mock_install_key,
    mock_is_key_installed,
    apt_gpg,
    key_assets,
):
    key_id = "8" * 40
    expected_key_path = key_assets / ("8" * 8 + ".asc")
    expected_key_path.write_text("key-data")

    package_repo = PackageRepositoryApt(
        components=["main", "multiverse"],
        key_id=key_id,
        suites=["xenial"],
        url="http://archive.ubuntu.com/ubuntu",
    )

    updated = apt_gpg.install_package_repository_key(package_repo=package_repo)

    assert updated is True
    assert mock_install_key.mock_calls == [call(key="key-data")]
コード例 #18
0
def test_install_package_repository_key_apt_from_keyserver(
    mock_install_key_from_keyserver,
    mock_is_key_installed,
    apt_gpg,
):
    key_id = "8" * 40

    package_repo = PackageRepositoryApt(
        components=["main", "multiverse"],
        key_id=key_id,
        key_server="key.server",
        suites=["xenial"],
        url="http://archive.ubuntu.com/ubuntu",
    )

    updated = apt_gpg.install_package_repository_key(package_repo=package_repo)

    assert updated is True
    assert mock_install_key_from_keyserver.mock_calls == [
        call(key_id=key_id, key_server="key.server")
    ]
コード例 #19
0
def test_apt_install(mock_repo, tmp_path):
    repo = PackageRepositoryApt(
        architectures=["amd64", "i386"],
        components=["main", "multiverse"],
        formats=["deb", "deb-src"],
        key_id="A" * 40,
        key_server="xkeyserver.ubuntu.com",
        name="some-name",
        suites=["xenial", "xenial-updates"],
        url="http://archive.ubuntu.com/ubuntu",
    )

    repo.install()

    assert mock_repo.mock_calls == [
        mock.call.install_sources(
            architectures=["amd64", "i386"],
            components=["main", "multiverse"],
            formats=["deb", "deb-src"],
            name="some-name",
            suites=["xenial", "xenial-updates"],
            url="http://archive.ubuntu.com/ubuntu",
        ),
    ]
コード例 #20
0
def test_apt_valid_architectures(arch):
    package_repo = PackageRepositoryApt(key_id="A" * 40,
                                        url="http://test",
                                        architectures=[arch])

    assert package_repo.architectures == [arch]
コード例 #21
0
        apt_sources_manager._sudo_write_file(dst_path="/foo/bar",
                                             content=b"some-content")

    assert (str(error.value).startswith(
        "Failed to install repository config with: ['sudo', 'install'") is
            True)


@pytest.mark.parametrize(
    "package_repo,name,content",
    [
        (
            PackageRepositoryApt(
                architectures=["amd64", "arm64"],
                components=["test-component"],
                formats=["deb", "deb-src"],
                key_id="A" * 40,
                suites=["test-suite1", "test-suite2"],
                url="http://test.url/ubuntu",
            ),
            "snapcraft-http_test_url_ubuntu.sources",
            dedent("""\
                Types: deb deb-src
                URIs: http://test.url/ubuntu
                Suites: test-suite1 test-suite2
                Components: test-component
                Architectures: amd64 arm64
                """).encode(),
        ),
        (
            PackageRepositoryApt(
                architectures=["amd64", "arm64"],