Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: get assertions for aliased snaps #670

Merged
merged 3 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion craft_providers/actions/snap_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def _get_assertions_file(
"public-key-sha3-384=BWDEoaqyr25nF5SNCvEv2v"
"7QnM9QsfCc0PBMYD_i2NGSQ32EF2d4D0hqUel3m8ul",
],
["snap-declaration", f"snap-name={snap_name}"],
["snap-declaration", f"snap-name={snap_name.partition('_')[0]}"],
["snap-revision", f"snap-revision={snap_revision}", f"snap-id={snap_id}"],
["account", f"account-id={snap_publisher_id}"],
]
Expand Down
5 changes: 5 additions & 0 deletions docs/reference/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Changelog
See the `Releases page`_ on GitHub for a complete list of commits that are
included in each version.

2.0.3 (2024-10-02)
------------------
- Fix a bug where signed aliased snaps couldn't be injected into the build
environment.

2.0.2 (2024-09-26)
------------------
- Improve multipass version parsing
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ docs = [
"sphinx-autobuild==2024.9.19",
"sphinx-lint==1.0.0",
"sphinx-tabs==3.4.5",
"canonical-sphinx~=0.1"
"canonical-sphinx==0.1.0"
]

[build-system]
Expand Down
32 changes: 25 additions & 7 deletions tests/unit/actions/test_snap_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,16 @@ def test_inject_from_host_dangerous(
}


@pytest.mark.parametrize(
("snap_name", "snap_instance_name"),
[
pytest.param("test-name", "test-name", id="non-aliased"),
pytest.param("test-name", "test-name_suffix", id="aliased"),
],
)
def test_inject_from_host_not_dangerous(
snap_instance_name,
snap_name,
config_fixture,
mock_get_host_snap_info,
mock_requests,
Expand All @@ -427,7 +436,7 @@ def test_inject_from_host_not_dangerous(
"snap",
"known",
"snap-declaration",
"snap-name=test-name",
f"snap-name={snap_name}",
]
)
fake_process.register_subprocess(
Expand All @@ -452,28 +461,37 @@ def test_inject_from_host_not_dangerous(
"fake-executor",
"snap",
"ack",
"/tmp/test-name.assert",
f"/tmp/{snap_name}.assert",
]
)
fake_process.register_subprocess(
[
"fake-executor",
"snap",
"install",
"/tmp/test-name.snap",
f"/tmp/{snap_name}.snap",
]
)

snap_installer.inject_from_host(
executor=fake_executor, snap_name="test-name", classic=False
executor=fake_executor, snap_name=snap_instance_name, classic=False
)

mock_requests.get.assert_called_with(
"http+unix://%2Frun%2Fsnapd.socket/v2/snaps/test-name/file"
f"http+unix://%2Frun%2Fsnapd.socket/v2/snaps/{snap_instance_name}/file"
)

assert len(fake_process.calls) == 6
assert Exact("Installing snap 'test-name' from host (classic=False)") in logs.debug
if snap_instance_name == snap_name:
assert (
rf"Installing snap {snap_instance_name!r} from host \(classic=False\)"
in logs.debug
)
else:
assert (
rf"Installing snap {snap_instance_name!r} from host as {snap_name!r} in instance \(classic=False\)\."
in logs.debug
)
assert "Revisions found: host='2', target='1'" in logs.debug

# check saved config
Expand All @@ -484,7 +502,7 @@ def test_inject_from_host_not_dangerous(
)
config = InstanceConfiguration(**yaml.safe_load(saved_config_record["content"]))
assert config.snaps is not None
assert config.snaps["test-name"] == {
assert config.snaps[snap_name] == {
"revision": "2",
"source": snap_installer.SNAP_SRC_HOST,
}
Expand Down
Loading