Skip to content

Commit

Permalink
Merge branch 'main' into work/fix-bogus-lxd-profile
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-cal authored Jul 24, 2024
2 parents 09bb92f + 282913b commit 0d4f284
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 40 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
echo "Installing snaps in the background while running apt and pip..."
sudo snap install --no-wait --classic pyright
sudo snap install --no-wait shellcheck
sudo snap install --no-wait ruff
echo "::endgroup::"
echo "::group::pip install"
python -m pip install 'tox>=4'
Expand Down
4 changes: 2 additions & 2 deletions HACKING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ you with tox, but you'll need to install:
``snap install --classic pyright``)
- ShellCheck_ (also available via snap: ``snap install shellcheck``)
- pre-commit_
- ruff_ (also available via snap: ``snap install ruff``)

Once you have all of those installed, you can install the necessary virtual
environments for this repository using tox.
Expand All @@ -35,7 +36,6 @@ Some other tools we use for code quality include:

- Black_ for code formatting
- pytest_ for testing
- ruff_ for linting (and some additional formatting)

A complete list is kept in our pyproject.toml_ file in dev dependencies.

Expand Down Expand Up @@ -130,7 +130,7 @@ Please follow these guidelines when committing code for this project:
.. _pyproject.toml: ./pyproject.toml
.. _Pyright: https://github.com/microsoft/pyright
.. _pytest: https://pytest.org
.. _ruff: https://github.com/charliermarsh/ruff
.. _ruff: https://github.com/astral-sh/ruff
.. _ShellCheck: https://www.shellcheck.net/
.. _`SSH access is limited`: https://github.com/marketplace/actions/debugging-with-tmate#use-registered-public-ssh-keys
.. _`SSH key on GitHub`: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account
Expand Down
1 change: 0 additions & 1 deletion craft_providers/bases/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class BaseName(NamedTuple):
BaseName("ubuntu", "18.04"): ubuntu.BuilddBaseAlias.BIONIC,
BaseName("ubuntu", "20.04"): ubuntu.BuilddBaseAlias.FOCAL,
BaseName("ubuntu", "22.04"): ubuntu.BuilddBaseAlias.JAMMY,
BaseName("ubuntu", "23.10"): ubuntu.BuilddBaseAlias.MANTIC,
BaseName("ubuntu", "24.04"): ubuntu.BuilddBaseAlias.NOBLE,
BaseName("ubuntu", "24.10"): ubuntu.BuilddBaseAlias.ORACULAR,
BaseName("ubuntu", "devel"): ubuntu.BuilddBaseAlias.DEVEL,
Expand Down
1 change: 0 additions & 1 deletion craft_providers/bases/ubuntu.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class BuilddBaseAlias(enum.Enum):
BIONIC = "18.04"
FOCAL = "20.04"
JAMMY = "22.04"
MANTIC = "23.10"
NOBLE = "24.04"
ORACULAR = "24.10"
DEVEL = "devel"
Expand Down
3 changes: 2 additions & 1 deletion craft_providers/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ def __init__(self) -> None:
brief = "A network related operation failed in a context of no network access."
# XXX Facundo 2022-12-13: need to improve the URL here once
# we have the online docs updated
url = "https://canonical-craft-providers.readthedocs-hosted.com/en/latest/explanation/"
resolution = (
"Verify that the environment has internet connectivity; "
"see https://craft-providers.readthedocs.io/ for further reference."
f"see {url} for further reference."
)
super().__init__(brief=brief, resolution=resolution)
8 changes: 0 additions & 8 deletions craft_providers/lxd/remotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,6 @@ def add_remote(self, lxc: LXC) -> None:
remote_address=BUILDD_DAILY_REMOTE_ADDRESS,
remote_protocol=ProtocolType.SIMPLESTREAMS,
),
# mantic buildd daily blocked by
# https://bugs.launchpad.net/cloud-images/+bug/2007419
ubuntu.BuilddBaseAlias.MANTIC: RemoteImage(
image_name="mantic",
remote_name=DAILY_REMOTE_NAME,
remote_address=DAILY_REMOTE_ADDRESS,
remote_protocol=ProtocolType.SIMPLESTREAMS,
),
ubuntu.BuilddBaseAlias.ORACULAR: RemoteImage(
image_name="oracular",
remote_name=BUILDD_DAILY_REMOTE_NAME,
Expand Down
6 changes: 1 addition & 5 deletions craft_providers/multipass/multipass_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,8 @@ def name(self) -> str:
ubuntu.BuilddBaseAlias.JAMMY: RemoteImage(
remote=Remote.SNAPCRAFT, image_name="22.04"
),
ubuntu.BuilddBaseAlias.MANTIC: RemoteImage(
remote=Remote.RELEASE, image_name="mantic"
),
# this should use `image_name="24.04"` once noble is released (#511)
ubuntu.BuilddBaseAlias.NOBLE: RemoteImage(
remote=Remote.SNAPCRAFT, image_name="devel"
remote=Remote.SNAPCRAFT, image_name="24.04"
),
ubuntu.BuilddBaseAlias.ORACULAR: RemoteImage(
remote=Remote.DAILY, image_name="oracular"
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.24.1 (2024-02-07)
-------------------
- Improve detection of installed LXD
- Update the link to the network troubleshooting docs

1.24.0 (2024-06-18)
-------------------
- Add support for Ubuntu 24.10 (Oracular)
Expand Down
2 changes: 2 additions & 0 deletions docs/explanation/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Explanation
.. toctree::
:maxdepth: 1

.. _network-error:

Failure to properly execute commands that depend on network access
==================================================================

Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ dev = [
lint = [
"black==24.4.2",
"codespell[toml]==2.2.6",
"ruff==0.4.8",
"yamllint==1.35.1",
]
types = [
Expand All @@ -72,7 +71,7 @@ docs = [

[build-system]
requires = [
"setuptools==70.0.0",
"setuptools==71.1.0",
"setuptools_scm[toml]>=7.1"
]
build-backend = "setuptools.build_meta"
Expand Down
22 changes: 21 additions & 1 deletion tests/integration/lxd/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021-2023 Canonical Ltd.
# Copyright 2021-2024 Canonical Ltd.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand All @@ -25,11 +25,31 @@
from typing import Any, Dict, Optional

import pytest
from craft_providers.bases import ubuntu
from craft_providers.lxd import LXC
from craft_providers.lxd import project as lxc_project
from craft_providers.lxd.lxd_instance import LXDInstance
from craft_providers.lxd.lxd_provider import LXDProvider

_xfail_bases = {
ubuntu.BuilddBaseAlias.XENIAL: "Fails to setup snapd (#582)",
ubuntu.BuilddBaseAlias.ORACULAR: "24.10 fails setup (#598)",
ubuntu.BuilddBaseAlias.DEVEL: "24.10 fails setup (#598)",
}
"""List of bases that are expected to fail and a reason why."""

UBUNTU_BASES_PARAM = [
(
pytest.param(
base, marks=pytest.mark.xfail(reason=_xfail_bases[base], strict=True)
)
if base in _xfail_bases
else base
)
for base in ubuntu.BuilddBaseAlias
]
"""List of testable Ubuntu bases."""


@pytest.fixture(autouse=True, scope="module")
def installed_lxd_required(installed_lxd):
Expand Down
12 changes: 5 additions & 7 deletions tests/integration/lxd/test_lxd_provider.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright 2022-2023 Canonical Ltd.
# Copyright 2022-2024 Canonical Ltd.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand All @@ -17,9 +17,11 @@
#

import pytest
from craft_providers.bases import almalinux, get_base_from_alias, ubuntu
from craft_providers.bases import almalinux, get_base_from_alias
from craft_providers.lxd import LXDProvider, is_installed

from .conftest import UBUNTU_BASES_PARAM


def test_ensure_provider_is_available_not_installed(uninstalled_lxd):
"""Verify lxd is installed and configured."""
Expand All @@ -42,11 +44,7 @@ def test_create_environment(installed_lxd, instance_name):


@pytest.mark.parametrize(
"alias",
[
*set(ubuntu.BuilddBaseAlias) - {ubuntu.BuilddBaseAlias.XENIAL},
almalinux.AlmaLinuxBaseAlias.NINE,
],
"alias", [*UBUNTU_BASES_PARAM, almalinux.AlmaLinuxBaseAlias.NINE]
)
def test_launched_environment(
alias, installed_lxd, instance_name, tmp_path, session_provider
Expand Down
9 changes: 4 additions & 5 deletions tests/integration/lxd/test_remotes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2021-2023 Canonical Ltd.
# Copyright 2021-2024 Canonical Ltd.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand All @@ -21,17 +21,16 @@
from craft_providers import lxd
from craft_providers.bases import ubuntu

from .conftest import UBUNTU_BASES_PARAM

# The LXD tests can be flaky, erroring out with a BaseCompatibilityError:
# "Clean incompatible instance and retry the requested operation."
# This is due to an upstream LXD bug that appears to still be present in LXD 5.14:
# https://github.com/lxc/lxd/issues/11422
pytestmark = pytest.mark.flaky(reruns=3, reruns_delay=2)


# exclude XENIAL because it is not supported for LXD
@pytest.mark.parametrize(
"alias", set(ubuntu.BuilddBaseAlias) - {ubuntu.BuilddBaseAlias.XENIAL}
)
@pytest.mark.parametrize("alias", UBUNTU_BASES_PARAM)
def test_configure_and_launch_remote(instance_name, alias):
"""Verify remotes are configured and images can be launched."""
base_configuration = ubuntu.BuilddBase(alias=alias)
Expand Down
3 changes: 0 additions & 3 deletions tests/integration/multipass/test_multipass_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ def test_launched_environment(alias, installed_multipass, instance_name, tmp_pat
if sys.platform == "darwin" and alias == BuilddBaseAlias.NOBLE:
pytest.skip(reason="Noble on MacOS are not available")

if sys.platform == "darwin" and alias == BuilddBaseAlias.MANTIC:
pytest.skip(reason="Mantic on MacOS are not available")

if sys.platform == "darwin" and alias == BuilddBaseAlias.DEVEL:
pytest.skip(reason="snapcraft:devel is not working on MacOS (LP #2007419)")

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/lxd/test_remotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def test_add_remote_race_condition_error(fake_remote_image, mock_lxc, logs):
(ubuntu.BuilddBaseAlias.BIONIC, "core18"),
(ubuntu.BuilddBaseAlias.FOCAL, "core20"),
(ubuntu.BuilddBaseAlias.JAMMY, "core22"),
(ubuntu.BuilddBaseAlias.MANTIC, "mantic"),
(ubuntu.BuilddBaseAlias.NOBLE, "core24"),
(ubuntu.BuilddBaseAlias.ORACULAR, "oracular"),
(ubuntu.BuilddBaseAlias.DEVEL, "devel"),
],
)
Expand All @@ -164,8 +164,8 @@ def test_get_image_remote(provider_base_alias, image_name):
(ubuntu.BuilddBaseAlias.BIONIC, "core18"),
(ubuntu.BuilddBaseAlias.FOCAL, "core20"),
(ubuntu.BuilddBaseAlias.JAMMY, "core22"),
(ubuntu.BuilddBaseAlias.MANTIC, "mantic"),
(ubuntu.BuilddBaseAlias.NOBLE, "core24"),
(ubuntu.BuilddBaseAlias.ORACULAR, "oracular"),
(ubuntu.BuilddBaseAlias.DEVEL, "devel"),
],
)
Expand Down
7 changes: 5 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ requires =
# renovate: datasource=pypi
tox-ignore-env-name-mismatch>=0.2.0.post2
# renovate: datasource=pypi
tox-gh==1.3.1
tox-gh==1.3.2
# Allow tox to access the user's $TMPDIR environment variable if set.
# This workaround is required to avoid circular dependencies for TMPDIR,
# since tox will otherwise attempt to use the environment's TMPDIR variable.
Expand Down Expand Up @@ -93,6 +93,7 @@ base = testenv, lint
labels = lint
allowlist_externals =
shellcheck: bash, xargs
ruff: ruff
commands_pre =
shellcheck: bash -c '{[shellcheck]find} | {[shellcheck]filter} > {env_tmp_dir}/shellcheck_files'
commands =
Expand Down Expand Up @@ -120,9 +121,11 @@ commands =
description = Automatically format source code
base = testenv, lint
labels = format
allowlist_externals =
ruff: ruff
commands =
black: black {tty:--color} {posargs} .
ruff: ruff --fix --respect-gitignore {posargs} .
ruff: ruff check --fix --respect-gitignore {posargs} .
codespell: codespell --toml {tox_root}/pyproject.toml --write-changes {posargs}

[testenv:pre-commit]
Expand Down

0 comments on commit 0d4f284

Please sign in to comment.