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

Changes for 1.20.3 #549

Merged
merged 3 commits into from
Apr 11, 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
7 changes: 5 additions & 2 deletions craft_providers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Base(ABC):
_timeout_unpredictable: Optional[float] = TIMEOUT_UNPREDICTABLE
_cache_path: Optional[pathlib.Path] = None
alias: Enum
compatibility_tag: str = "base-v4"
compatibility_tag: str = "base-v8"

@abstractmethod
def __init__(
Expand Down Expand Up @@ -979,6 +979,7 @@ def setup(
*,
executor: Executor,
timeout: Optional[float] = TIMEOUT_UNPREDICTABLE,
mount_cache: bool = True,
) -> None:
"""Prepare base instance for use by the application.

Expand All @@ -994,6 +995,7 @@ def setup(

:param executor: Executor for target container.
:param timeout: Timeout in seconds.
:param mount_cache: If true, mount the cache directories.

:raises BaseCompatibilityError: if instance is incompatible.
:raises BaseConfigurationError: on other unexpected error.
Expand All @@ -1015,7 +1017,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
10 changes: 8 additions & 2 deletions craft_providers/lxd/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,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 Expand Up @@ -220,7 +223,10 @@ def _create_instance(
instance.restart()
else:
instance.start()
base_configuration.wait_until_ready(executor=instance)
# Warmup the instance to ensure we have everything set up.
# There are cases where setup won't do everything to the base instance that
# warmup does to the final instance (such as mounting cache directories).
base_configuration.warmup(executor=instance)


def _ensure_project_exists(
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Changelog
See the `Releases page`_ on GitHub for a complete list of commits that are
included in each version.

1.20.3 (2024-04-11)

- Do not mount cache directories in LXD base instances.
- Update base compatibility tag from ``base-v4`` to ``base-v8``

1.20.2 (2024-03-15)
-------------------
- Parse LXD versions with "LTS" suffix
Expand Down
19 changes: 13 additions & 6 deletions tests/integration/lxd/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_base_instance():
def _base_instance(
image_name: str = "22.04",
image_remote: str = "ubuntu",
compatibility_tag: str = "buildd-base-v4",
compatibility_tag: str = "buildd-base-v8",
project: str = "default",
):
"""Get the base instance."""
Expand All @@ -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,10 @@ 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 +275,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 Expand Up @@ -302,7 +309,7 @@ def test_launch_create_base_instance_with_correct_image_description(

assert (
lxc_result[0]["expanded_config"]["image.description"]
== "base-instance-buildd-base-v4-ubuntu-22.04"
== "base-instance-buildd-base-v8-ubuntu-22.04"
)


Expand Down Expand Up @@ -704,7 +711,7 @@ def test_launch_instance_config_incompatible_without_auto_clean(

assert exc_info.value.brief == (
"Incompatible base detected:"
" Expected image compatibility tag 'buildd-base-v4', found 'invalid'."
" Expected image compatibility tag 'buildd-base-v8', found 'invalid'."
)


Expand Down Expand Up @@ -737,7 +744,7 @@ def test_launch_instance_not_setup_without_auto_clean(
"""Raise an error if an existing instance is not setup and auto_clean is False."""
core22_instance.push_file_io(
destination=base_configuration._instance_config_path,
content=io.BytesIO(b"compatibility_tag: buildd-base-v4\nsetup: false\n"),
content=io.BytesIO(b"compatibility_tag: buildd-base-v8\nsetup: false\n"),
file_mode="0644",
)

Expand All @@ -758,7 +765,7 @@ def test_launch_instance_not_setup_with_auto_clean(base_configuration, core22_in
"""Clean the instance if it is not setup and auto_clean is True."""
core22_instance.push_file_io(
destination=base_configuration._instance_config_path,
content=io.BytesIO(b"compatibility_tag: buildd-base-v4\nsetup: false\n"),
content=io.BytesIO(b"compatibility_tag: buildd-base-v8\nsetup: false\n"),
file_mode="0644",
)

Expand Down
6 changes: 3 additions & 3 deletions tests/integration/multipass/test_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def test_launch_instance_config_incompatible_instance(core22_instance):

assert exc_info.value.brief == (
"Incompatible base detected:"
" Expected image compatibility tag 'buildd-base-v4', found 'invalid'."
" Expected image compatibility tag 'buildd-base-v8', found 'invalid'."
)

# Retry with auto_clean=True.
Expand All @@ -178,7 +178,7 @@ def test_launch_instance_not_setup_without_auto_clean(core22_instance):

core22_instance.push_file_io(
destination=base_configuration._instance_config_path,
content=io.BytesIO(b"compatibility_tag: buildd-base-v4\nsetup: false\n"),
content=io.BytesIO(b"compatibility_tag: buildd-base-v8\nsetup: false\n"),
file_mode="0644",
)

Expand All @@ -200,7 +200,7 @@ def test_launch_instance_not_setup_with_auto_clean(core22_instance):

core22_instance.push_file_io(
destination=base_configuration._instance_config_path,
content=io.BytesIO(b"compatibility_tag: buildd-base-v4\nsetup: false\n"),
content=io.BytesIO(b"compatibility_tag: buildd-base-v8\nsetup: false\n"),
file_mode="0644",
)

Expand Down
20 changes: 10 additions & 10 deletions tests/unit/bases/test_almalinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
def mock_load(mocker):
return mocker.patch(
"craft_providers.instance_config.InstanceConfiguration.load",
return_value=InstanceConfiguration(compatibility_tag="almalinux-base-v4"),
return_value=InstanceConfiguration(compatibility_tag="almalinux-base-v8"),
)


Expand Down Expand Up @@ -149,7 +149,7 @@ def mock_get_os_release(mocker):
],
)
@pytest.mark.parametrize(
("tag", "expected_tag"), [(None, "almalinux-base-v4"), ("test-tag", "test-tag")]
("tag", "expected_tag"), [(None, "almalinux-base-v8"), ("test-tag", "test-tag")]
)
def test_setup(
fake_process,
Expand Down Expand Up @@ -653,7 +653,7 @@ def test_ensure_image_version_compatible_failure(fake_executor, monkeypatch):
base_config._ensure_instance_config_compatible(executor=fake_executor)

assert exc_info.value == BaseCompatibilityError(
"Expected image compatibility tag 'almalinux-base-v4', found 'invalid-tag'"
"Expected image compatibility tag 'almalinux-base-v8', found 'invalid-tag'"
)


Expand Down Expand Up @@ -1056,7 +1056,7 @@ def test_update_setup_status(fake_executor, mock_load, status):
assert fake_executor.records_of_push_file_io == [
{
"content": (
"compatibility_tag: almalinux-base-v4\n"
"compatibility_tag: almalinux-base-v8\n"
f"setup: {str(status).lower()}\n".encode()
),
"destination": "/etc/craft-instance.conf",
Expand Down Expand Up @@ -1165,7 +1165,7 @@ def test_warmup_overall(
environment, fake_process, fake_executor, mock_load, mocker, cache_path
):
mock_load.return_value = InstanceConfiguration(
compatibility_tag="almalinux-base-v4", setup=True
compatibility_tag="almalinux-base-v8", setup=True
)
alias = almalinux.AlmaLinuxBaseAlias.NINE

Expand Down Expand Up @@ -1220,7 +1220,7 @@ def test_warmup_overall(

def test_warmup_bad_os(fake_process, fake_executor, mock_load):
mock_load.return_value = InstanceConfiguration(
compatibility_tag="almalinux-base-v4", setup=True
compatibility_tag="almalinux-base-v8", setup=True
)
base_config = almalinux.AlmaLinuxBase(
alias=almalinux.AlmaLinuxBaseAlias.NINE,
Expand All @@ -1245,7 +1245,7 @@ def test_warmup_bad_os(fake_process, fake_executor, mock_load):

def test_warmup_bad_instance_config(fake_process, fake_executor, mock_load):
mock_load.return_value = InstanceConfiguration(
compatibility_tag="almalinux-base-v4", setup=True
compatibility_tag="almalinux-base-v8", setup=True
)
alias = almalinux.AlmaLinuxBaseAlias.NINE
base_config = almalinux.AlmaLinuxBase(
Expand Down Expand Up @@ -1274,7 +1274,7 @@ def test_warmup_bad_instance_config(fake_process, fake_executor, mock_load):
def test_warmup_not_setup(setup, fake_process, fake_executor, mock_load):
"""Raise a BaseConfigurationError if the instance is not setup."""
mock_load.return_value = InstanceConfiguration(
compatibility_tag="almalinux-base-v4", setup=setup
compatibility_tag="almalinux-base-v8", setup=setup
)
alias = almalinux.AlmaLinuxBaseAlias.NINE
base_config = almalinux.AlmaLinuxBase(
Expand Down Expand Up @@ -1302,7 +1302,7 @@ def test_warmup_not_setup(setup, fake_process, fake_executor, mock_load):

def test_warmup_never_ready(fake_process, fake_executor, mock_load):
mock_load.return_value = InstanceConfiguration(
compatibility_tag="almalinux-base-v4", setup=True
compatibility_tag="almalinux-base-v8", setup=True
)
alias = almalinux.AlmaLinuxBaseAlias.NINE
base_config = almalinux.AlmaLinuxBase(
Expand Down Expand Up @@ -1335,7 +1335,7 @@ def test_warmup_never_ready(fake_process, fake_executor, mock_load):

def test_warmup_never_network(fake_process, fake_executor, mock_load):
mock_load.return_value = InstanceConfiguration(
compatibility_tag="almalinux-base-v4", setup=True
compatibility_tag="almalinux-base-v8", setup=True
)
alias = almalinux.AlmaLinuxBaseAlias.NINE
base_config = almalinux.AlmaLinuxBase(
Expand Down
20 changes: 10 additions & 10 deletions tests/unit/bases/test_centos_7.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
def mock_load(mocker):
return mocker.patch(
"craft_providers.instance_config.InstanceConfiguration.load",
return_value=InstanceConfiguration(compatibility_tag="centos-base-v4"),
return_value=InstanceConfiguration(compatibility_tag="centos-base-v8"),
)


Expand Down Expand Up @@ -150,7 +150,7 @@ def mock_get_os_release(mocker):
],
)
@pytest.mark.parametrize(
("tag", "expected_tag"), [(None, "centos-base-v4"), ("test-tag", "test-tag")]
("tag", "expected_tag"), [(None, "centos-base-v8"), ("test-tag", "test-tag")]
)
def test_setup(
fake_process,
Expand Down Expand Up @@ -603,7 +603,7 @@ def test_ensure_image_version_compatible_failure(fake_executor, monkeypatch):
base_config._ensure_instance_config_compatible(executor=fake_executor)

assert exc_info.value == BaseCompatibilityError(
"Expected image compatibility tag 'centos-base-v4', found 'invalid-tag'"
"Expected image compatibility tag 'centos-base-v8', found 'invalid-tag'"
)


Expand Down Expand Up @@ -1003,7 +1003,7 @@ def test_update_setup_status(fake_executor, mock_load, status):
assert fake_executor.records_of_push_file_io == [
{
"content": (
"compatibility_tag: centos-base-v4\n"
"compatibility_tag: centos-base-v8\n"
f"setup: {str(status).lower()}\n".encode()
),
"destination": "/etc/craft-instance.conf",
Expand Down Expand Up @@ -1112,7 +1112,7 @@ def test_warmup_overall(
environment, fake_process, fake_executor, mock_load, mocker, cache_path
):
mock_load.return_value = InstanceConfiguration(
compatibility_tag="centos-base-v4", setup=True
compatibility_tag="centos-base-v8", setup=True
)
alias = centos.CentOSBaseAlias.SEVEN

Expand Down Expand Up @@ -1164,7 +1164,7 @@ def test_warmup_overall(

def test_warmup_bad_os(fake_process, fake_executor, mock_load):
mock_load.return_value = InstanceConfiguration(
compatibility_tag="centos-base-v4", setup=True
compatibility_tag="centos-base-v8", setup=True
)
base_config = centos.CentOSBase(
alias=centos.CentOSBaseAlias.SEVEN,
Expand All @@ -1189,7 +1189,7 @@ def test_warmup_bad_os(fake_process, fake_executor, mock_load):

def test_warmup_bad_instance_config(fake_process, fake_executor, mock_load):
mock_load.return_value = InstanceConfiguration(
compatibility_tag="centos-base-v4", setup=True
compatibility_tag="centos-base-v8", setup=True
)
alias = centos.CentOSBaseAlias.SEVEN
base_config = centos.CentOSBase(
Expand Down Expand Up @@ -1218,7 +1218,7 @@ def test_warmup_bad_instance_config(fake_process, fake_executor, mock_load):
def test_warmup_not_setup(setup, fake_process, fake_executor, mock_load):
"""Raise a BaseConfigurationError if the instance is not setup."""
mock_load.return_value = InstanceConfiguration(
compatibility_tag="centos-base-v4", setup=setup
compatibility_tag="centos-base-v8", setup=setup
)
alias = centos.CentOSBaseAlias.SEVEN
base_config = centos.CentOSBase(
Expand Down Expand Up @@ -1246,7 +1246,7 @@ def test_warmup_not_setup(setup, fake_process, fake_executor, mock_load):

def test_warmup_never_ready(fake_process, fake_executor, mock_load):
mock_load.return_value = InstanceConfiguration(
compatibility_tag="centos-base-v4", setup=True
compatibility_tag="centos-base-v8", setup=True
)
alias = centos.CentOSBaseAlias.SEVEN
base_config = centos.CentOSBase(
Expand Down Expand Up @@ -1279,7 +1279,7 @@ def test_warmup_never_ready(fake_process, fake_executor, mock_load):

def test_warmup_never_network(fake_process, fake_executor, mock_load):
mock_load.return_value = InstanceConfiguration(
compatibility_tag="centos-base-v4", setup=True
compatibility_tag="centos-base-v8", setup=True
)
alias = centos.CentOSBaseAlias.SEVEN
base_config = centos.CentOSBase(
Expand Down
Loading
Loading