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: don't mount cache directories in lxd base instances #473

Merged
merged 3 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion craft_providers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,7 @@ def setup(
*,
executor: Executor,
timeout: Optional[float] = TIMEOUT_UNPREDICTABLE,
mount_cache: bool = True,
lengau marked this conversation as resolved.
Show resolved Hide resolved
) -> None:
"""Prepare base instance for use by the application.

Expand Down Expand Up @@ -1015,7 +1016,8 @@ def setup(

self._update_compatibility_tag(executor=executor)

self._mount_shared_cache_dirs(executor=executor)
if mount_cache:
self._mount_shared_cache_dirs(executor=executor)

self._pre_setup_os(executor=executor)
self._setup_os(executor=executor)
Expand Down
5 changes: 4 additions & 1 deletion craft_providers/lxd/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ def _create_instance(
)
config_timer = InstanceTimer(base_instance)
config_timer.start()
base_configuration.setup(executor=base_instance)

# The base configuration shouldn't mount cache directories because if
# they get deleted, copying the base instance will fail.
base_configuration.setup(executor=base_instance, mount_cache=False)
_set_timezone(
base_instance,
base_instance.project,
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/lxd/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ def _base_instance(


@pytest.fixture()
def base_configuration():
def base_configuration(tmp_path):
"""Returns a simple base configuration."""
return ubuntu.BuilddBase(
alias=ubuntu.BuilddBaseAlias.JAMMY,
hostname="test-hostname",
cache_path=tmp_path / "cache"
)


Expand Down Expand Up @@ -224,6 +225,7 @@ def test_launch_use_base_instance(
# fingerprint the base instance
base_instance.start()
base_instance.execute_run(["touch", "/base-instance"])
assert base_instance.execute_run(["ls", "/root/.cache/pip/"], check=False).returncode == 2
base_instance.stop()

# delete the instance so a new instance is created from the base instance
Expand Down Expand Up @@ -270,6 +272,8 @@ def test_launch_use_base_instance(

assert instance_hostname == instance.instance_name

instance.execute_run(["ls", "/root/.cache/pip/"], check=True)


def test_launch_create_base_instance_with_correct_image_description(
base_configuration, get_base_instance, instance_name
Expand Down
Loading