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

chore!(centos): remove CentOS 7 support #1827

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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: 0 additions & 2 deletions charmcraft/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"[email protected]",
"[email protected]",
"[email protected]",
"centos@7",
"almalinux@9",
]
BaseStr = CommonBaseStr
Expand All @@ -76,7 +75,6 @@
BaseName("ubuntu", "23.10"),
BaseName("ubuntu", "24.04"),
BaseName("ubuntu", "devel"),
BaseName("centos", "7"),
BaseName("almalinux", "9"),
)
)
Expand Down
4 changes: 2 additions & 2 deletions charmcraft/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ class CharmProject(CharmcraftProject):
container (that you will then define further in the resources block).
- ``bases`` is a list of bases to be used for resolving a container image,
in descending order of preference. To use it, specify a base name (for
example, ``ubuntu`` or ``centos``), a ``channel`` and an
example, ``ubuntu`` or ``almalinux``), a ``channel`` and an
``architecture``.
- ``mounts`` is a list of mounted storage volumes for this container. To
use it, specify the name of the storage to mount from the charm
Expand Down Expand Up @@ -1009,7 +1009,7 @@ def _check_base_is_legacy(base: charmcraft.BaseDict) -> bool:
and base["channel"] < "24.04" # pyright: ignore[reportTypedDictNotRequiredAccess]
):
return True
return base in ({"name": "centos", "channel": "7"}, {"name": "almalinux", "channel": "9"})
return base in ({"name": "almalinux", "channel": "9"})


def _validate_base(
Expand Down
37 changes: 0 additions & 37 deletions charmcraft/parts/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,26 +186,6 @@ def get_build_packages(self) -> set[str]:
"libyaml-dev",
}
elif platform.is_yum_based():
try:
os_release = os_utils.OsRelease()
if (os_release.id(), os_release.version_id()) in (("centos", "7"), ("rhel", "7")):
# CentOS 7 Python 3.8 from SCL repo
return {
"autoconf",
"automake",
"gcc",
"gcc-c++",
"git",
"make",
"patch",
"rh-python38-python-devel",
"rh-python38-python-pip",
"rh-python38-python-setuptools",
"rh-python38-python-wheel",
}
except (OsReleaseIdError, OsReleaseVersionIdError):
pass

return {
"autoconf",
"automake",
Expand Down Expand Up @@ -233,9 +213,6 @@ def get_build_environment(self) -> dict[str, str]:
# Since we don't need the legacy provider, this works around that bug.
"CRYPTOGRAPHY_OPENSSL_NO_LEGACY": "true"
}
os_special_paths = self._get_os_special_priority_paths()
if os_special_paths:
environment["PATH"] = os_special_paths + ":${PATH}"

return environment

Expand Down Expand Up @@ -324,10 +301,6 @@ def _get_legacy_dependencies_parameters(self) -> list[str]:
base_tools.remove(pkg)

os_release = os_utils.OsRelease()
if (os_release.id(), os_release.version_id()) in (("centos", "7"), ("rhel", "7")):
# CentOS 7 compatibility, bootstrap base tools use binary packages
for pkg in base_tools:
parameters.extend(["-b", pkg])

# build base tools from source
for pkg in base_tools:
Expand All @@ -349,13 +322,3 @@ def _get_legacy_dependencies_parameters(self) -> list[str]:
def post_build_callback(self, step_info):
"""Collect metrics left by charm_builder.py."""
instrum.merge_from(env.get_charm_builder_metrics_path())

def _get_os_special_priority_paths(self) -> str | None:
"""Return a str of PATH for special OS."""
with suppress(OsReleaseIdError, OsReleaseVersionIdError):
os_release = os_utils.OsRelease()
if (os_release.id(), os_release.version_id()) in (("centos", "7"), ("rhel", "7")):
# CentOS 7 Python 3.8 from SCL repo
return "/opt/rh/rh-python38/root/usr/bin"

return None
37 changes: 0 additions & 37 deletions tests/spread/smoketests/basic-centos-7/task.yaml

This file was deleted.

4 changes: 1 addition & 3 deletions tests/unit/models/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
UBUNTU_JAMMY = Base(name="ubuntu", channel="22.04", architectures=["amd64"])
SIMPLE_BASES = (
UBUNTU_JAMMY,
Base(name="centos", channel="7", architectures=["amd64"]),
Base(name="almalinux", channel="9", architectures=["amd64"]),
)
COMPLEX_BASES = (
Expand Down Expand Up @@ -170,7 +169,7 @@ def test_platform_from_single_base(base):
@pytest.mark.parametrize(
("bases", "expected"),
[
(SIMPLE_BASES, "ubuntu-22.04-amd64_centos-7-amd64_almalinux-9-amd64"),
(SIMPLE_BASES, "ubuntu-22.04-amd64_almalinux-9-amd64"),
(
COMPLEX_BASES,
"ubuntu-devel-amd64-arm64-s390x-riscv64_almalinux-9-amd64-arm64-s390x-ppc64el",
Expand Down Expand Up @@ -941,7 +940,6 @@ def test_read_charm_from_yaml_file_error(filename, errors):
({"name": "ubuntu", "channel": "24.04"}, False),
({"name": "ubuntu", "channel": "24.10"}, False),
({"name": "ubuntu", "channel": "25.04"}, False),
({"name": "centos", "channel": "7"}, True),
({"name": "almalinux", "channel": "9"}, True),
],
)
Expand Down
99 changes: 0 additions & 99 deletions tests/unit/parts/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,6 @@ def test_charmplugin_get_build_package_deb_based(charm_plugin):
}


def test_charmplugin_get_build_package_yum_based(charm_plugin):
with patch("craft_parts.utils.os_utils.OsRelease.id") as mock_id:
mock_id.return_value = "centos"

assert charm_plugin.get_build_packages() == {
"autoconf",
"automake",
"gcc",
"gcc-c++",
"git",
"make",
"patch",
"python3-devel",
"python3-pip",
"python3-setuptools",
"python3-wheel",
}


def test_charmplugin_get_build_package_centos7(charm_plugin):
with patch("craft_parts.utils.os_utils.OsRelease.id") as mock_id:
with patch("craft_parts.utils.os_utils.OsRelease.version_id") as mock_version:
mock_id.return_value = "centos"
mock_version.return_value = "7"

assert charm_plugin.get_build_packages() == {
"autoconf",
"automake",
"gcc",
"gcc-c++",
"git",
"make",
"patch",
"rh-python38-python-devel",
"rh-python38-python-pip",
"rh-python38-python-setuptools",
"rh-python38-python-wheel",
}


def test_charmplugin_get_build_snaps(charm_plugin):
assert charm_plugin.get_build_snaps() == set()

Expand All @@ -93,18 +53,6 @@ def test_charmplugin_get_build_environment_ubuntu(charm_plugin, mocker):
assert charm_plugin.get_build_environment() == {"CRYPTOGRAPHY_OPENSSL_NO_LEGACY": "true"}


def test_charmplugin_get_build_environment_centos_7(charm_plugin, mocker, monkeypatch):
monkeypatch.setenv("PATH", "/some/path")
mock_id = mocker.patch("craft_parts.utils.os_utils.OsRelease.id")
mock_version = mocker.patch("craft_parts.utils.os_utils.OsRelease.version_id")
mock_id.return_value = "centos"
mock_version.return_value = "7"
assert charm_plugin.get_build_environment() == {
"CRYPTOGRAPHY_OPENSSL_NO_LEGACY": "true",
"PATH": "/opt/rh/rh-python38/root/usr/bin:${PATH}",
}


def test_charmplugin_get_build_commands_ubuntu(charm_plugin, tmp_path, mocker, monkeypatch):
monkeypatch.setenv("PATH", "/some/path")
monkeypatch.setenv("SNAP", "snap_value")
Expand Down Expand Up @@ -149,53 +97,6 @@ def test_charmplugin_get_build_commands_ubuntu(charm_plugin, tmp_path, mocker, m
mock_register.assert_called_with(charm_plugin.post_build_callback, step_list=[Step.BUILD])


def test_charmplugin_get_build_commands_centos_7(charm_plugin, tmp_path, mocker, monkeypatch):
monkeypatch.setenv("PATH", "/some/path")
monkeypatch.setenv("SNAP", "snap_value")
monkeypatch.setenv("SNAP_ARCH", "snap_arch_value")
monkeypatch.setenv("SNAP_NAME", "snap_name_value")
monkeypatch.setenv("SNAP_VERSION", "snap_version_value")
monkeypatch.setenv("http_proxy", "http_proxy_value")
monkeypatch.setenv("https_proxy", "https_proxy_value")
monkeypatch.setenv("no_proxy", "no_proxy_value")

mock_id = mocker.patch("craft_parts.utils.os_utils.OsRelease.id")
mock_version = mocker.patch("craft_parts.utils.os_utils.OsRelease.version_id")
mock_register = mocker.patch("craft_parts.callbacks.register_post_step")

mock_id.return_value = "centos"
mock_version.return_value = "7"

assert charm_plugin.get_build_commands() == [
"env -i LANG=C.UTF-8 LC_ALL=C.UTF-8 "
"CRYPTOGRAPHY_OPENSSL_NO_LEGACY=true "
"PATH=/opt/rh/rh-python38/root/usr/bin:/some/path "
"SNAP=snap_value SNAP_ARCH=snap_arch_value SNAP_NAME=snap_name_value "
"SNAP_VERSION=snap_version_value http_proxy=http_proxy_value "
"https_proxy=https_proxy_value no_proxy=no_proxy_value "
f"{sys.executable} -u -I "
f"{charm_builder.__file__} "
f"--builddir {str(tmp_path)}/parts/foo/build "
f"--installdir {str(tmp_path)}/parts/foo/install "
f"--entrypoint {str(tmp_path)}/parts/foo/build/entrypoint "
"-b pip "
"-b setuptools "
"-b wheel "
"-p pip "
"-p setuptools "
"-p wheel "
"-b pkg1 "
"-b pkg2 "
"-p pkg3 "
"-p pkg4 "
"-r reqs1.txt "
"-r reqs2.txt"
]

# check the callback is properly registered for running own method after build
mock_register.assert_called_with(charm_plugin.post_build_callback, step_list=[Step.BUILD])


def test_charmplugin_post_build_metric_collection(charm_plugin):
with patch("charmcraft.instrum.merge_from") as mock_collection:
charm_plugin.post_build_callback("test step info")
Expand Down
11 changes: 0 additions & 11 deletions tests/unit/services/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,8 @@ def test_do_not_overwrite_actions_yaml(
{"name": "ubuntu", "channel": "22.04", "architectures": ["all"]},
],
),
(
[{"name": "centos", "channel": "7"}],
BuildInfo(
platform=util.get_host_architecture(),
build_on=util.get_host_architecture(),
build_for=util.get_host_architecture(),
base=BaseName("centos", "7"),
),
[{"name": "centos", "channel": "7", "architectures": [util.get_host_architecture()]}],
),
pytest.param(
[
{"name": "centos", "channel": "7"},
{
"build-on": [{"name": "ubuntu", "channel": "20.04"}],
"run-on": [{"name": "ubuntu", "channel": "20.04", "architectures": ["all"]}],
Expand Down
10 changes: 0 additions & 10 deletions tests/unit/services/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,6 @@ def provider_service(
bases.BaseName("ubuntu", "22.04"),
bases.BaseName("ubuntu", "24.04"),
bases.BaseName("ubuntu", "devel"),
pytest.param(
bases.BaseName("centos", "7"),
marks=[
pytest.mark.xfail(
raises=AssertionError,
strict=True,
reason="https://github.com/canonical/craft-providers/issues/608",
)
],
),
bases.BaseName("almalinux", "9"),
],
)
Expand Down
Loading