Skip to content
Open
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
16 changes: 14 additions & 2 deletions craft_application/services/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@
class ProviderService(base.AppService):
"""Manager for craft_providers in an application.

:param app: Metadata about this application.
:param app: Metadata about this application
:param services: Factory class for lazy-loading service classes
:param project: The project model
:param work_dir: The working directory for parts processing
:param build_plan: The filtered build plan of platforms that are valid for
:param provider_name: The provider to use - "lxd" or "multipass"
:param install_snap: Whether to install this app's snap from the host (default True)
:param intercept_mknod: If the host can, tell LXD instance to intercept mknod
"""

managed_mode_env_var = platforms.ENVIRONMENT_CRAFT_MANAGED_MODE
Expand All @@ -72,12 +77,15 @@ def __init__(
work_dir: pathlib.Path,
provider_name: str | None = None,
install_snap: bool = True,
intercept_mknod: bool = True,
) -> None:
super().__init__(app, services)
self._provider: craft_providers.Provider | None = None
self._work_dir = work_dir
self.snaps: list[Snap] = []
self._install_snap = install_snap
self._intercept_mknod = intercept_mknod

self.environment: dict[str, str | None] = {self.managed_mode_env_var: "1"}
self.packages: list[str] = []
# this is a private attribute because it may not reflect the actual
Expand Down Expand Up @@ -343,7 +351,11 @@ def _get_provider_by_name(self, name: str) -> craft_providers.Provider:
def _get_lxd_provider(self) -> LXDProvider:
"""Get the LXD provider for this manager."""
lxd_remote = self._services.config.get("lxd_remote")
return LXDProvider(lxd_project=self._app.name, lxd_remote=lxd_remote)
return LXDProvider(
lxd_project=self._app.name,
lxd_remote=lxd_remote,
intercept_mknod=self._intercept_mknod,
)

def _get_multipass_provider(self) -> MultipassProvider:
"""Get the Multipass provider for this manager."""
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ dependencies = [
"craft-grammar>=2.0.0",
"craft-parts>=2.1.1",
"craft-platforms>=0.6.0",
"craft-providers>=2.1.0",
"craft-providers @ git+https://github.com/canonical/craft-providers.git@main",
#"craft-providers>=2.1.0",
"Jinja2>=3.1.6,<4.0.0",
"snap-helpers>=0.4.2",
"platformdirs>=3.10",
Expand Down Expand Up @@ -144,7 +145,6 @@ explicit = true
[tool.uv.sources]
python-apt = { index = "python-apt-wheels" }


[build-system]
requires = [
"setuptools==75.8.0",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/services/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def test_get_lxd_provider(monkeypatch, provider_service, lxd_remote, check):
check.equal(actual, mock_provider.return_value)
with check:
mock_provider.assert_called_once_with(
lxd_project="testcraft", lxd_remote=lxd_remote
lxd_project="testcraft", lxd_remote=lxd_remote, intercept_mknod=True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you exercise the default value and setting ProviderService(intercept_mknod)?

A quick way to do this would be to instantiate a ProviderService like some of the other tests and add something along the lines of @pytest.param("intercept_mknod", [None, True, False])

)


Expand Down
Loading