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

Support Alpine Linux apk package manager #2788

Merged
merged 1 commit into from
Mar 27, 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
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# Prepare variables
TMP = $(CURDIR)/tmp
UNIT_TESTS_IMAGE_TAG = tmt-unit-tests

# Define special targets
.DEFAULT_GOAL := help
Expand Down Expand Up @@ -82,6 +83,11 @@ images: ## Build tmt images for podman/docker
podman build -t tmt --squash -f ./containers/Containerfile.mini .
podman build -t tmt-all --squash -f ./containers/Containerfile.full .

images-unit-tests: image-alpine ## Build images for unit tests

image-alpine: ## Build local alpine image for unit tests
podman build -t alpine:$(UNIT_TESTS_IMAGE_TAG) -f ./containers/Containerfile.alpine .

##
## Development
##
Expand Down
4 changes: 4 additions & 0 deletions containers/Containerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM docker.io/library/alpine:latest

# tmt requires `bash` to be installed
RUN apk add --no-cache bash
5 changes: 3 additions & 2 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ Internal implementation of basic package manager actions has been
refactored. tmt now supports package implementations to be shipped as
plugins, therefore allowing for tmt to work natively with distributions
beyond the ecosystem of rpm-based distributions. As a preview, ``apt``,
the package manager used by Debian and Ubuntu, has been included in this
release.
the package manager used by Debian and Ubuntu, ``rpm-ostree``, the
package manager used by ``rpm-ostree``-based Linux systems and ``apk``,
the package manager of Alpine Linux have been included in this release.

New environment variable ``TMT_TEST_ITERATION_ID`` has been added to
:ref:`test-variables`. This variable is a combination of a unique
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ lint = ["autopep8 {args:.}", "ruff --fix {args:.}"]
type = ["mypy {args:tmt}"]
check = ["lint", "type"]

unit = "pytest -vvv -ra --showlocals -n 0 tests/unit"
unit = "make images-unit-tests && pytest -vvv -ra --showlocals -n 0 tests/unit"
smoke = "pytest -vvv -ra --showlocals -n 0 tests/unit/test_cli.py"
cov = [
"coverage run --source=tmt -m pytest -vvv -ra --showlocals -n 0 tests",
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ rlJournalStart

rlLogInfo "pip is $(which pip), $(pip --version)"
rlLogInfo "hatch is $(which hatch), $(hatch --version)"

rlRun "make -C $TMT_TREE images-unit-tests"
rlPhaseEnd

if [ "$WITH_SYSTEM_PACKAGES" = "yes" ]; then
Expand Down
88 changes: 86 additions & 2 deletions tests/unit/test_package_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@
CONTAINER_CENTOS_7 = Container(url='quay.io/centos/centos:7')
CONTAINER_UBUNTU_2204 = Container(url='docker.io/library/ubuntu:22.04')
CONTAINER_FEDORA_COREOS = Container(url='quay.io/fedora/fedora-coreos:stable')
# Local image created via `make image-alpine`, reference to local registry
CONTAINER_ALPINE = Container(url='containers-storage:localhost/alpine:tmt-unit-tests')
thrix marked this conversation as resolved.
Show resolved Hide resolved

PACKAGE_MANAGER_DNF5 = tmt.package_managers._PACKAGE_MANAGER_PLUGIN_REGISTRY.get_plugin('dnf5')
PACKAGE_MANAGER_DNF = tmt.package_managers._PACKAGE_MANAGER_PLUGIN_REGISTRY.get_plugin('dnf')
PACKAGE_MANAGER_YUM = tmt.package_managers._PACKAGE_MANAGER_PLUGIN_REGISTRY.get_plugin('yum')
PACKAGE_MANAGER_APT = tmt.package_managers._PACKAGE_MANAGER_PLUGIN_REGISTRY.get_plugin('apt')
PACKAGE_MANAGER_RPMOSTREE = tmt.package_managers._PACKAGE_MANAGER_PLUGIN_REGISTRY \
.get_plugin('rpm-ostree')
PACKAGE_MANAGER_APK = tmt.package_managers._PACKAGE_MANAGER_PLUGIN_REGISTRY.get_plugin('apk')


CONTAINER_BASE_MATRIX = [
Expand All @@ -73,6 +76,9 @@

# Fedora CoreOS
(CONTAINER_FEDORA_COREOS, PACKAGE_MANAGER_RPMOSTREE),

# Alpine
(CONTAINER_ALPINE, PACKAGE_MANAGER_APK),
]

CONTAINER_MATRIX_IDS = [
Expand Down Expand Up @@ -181,6 +187,13 @@ def _parametrize_test_install() -> \
'Installing: tree', \
None # noqa: E501

elif package_manager_class is tmt.package_managers.apk.Apk:
yield container, \
package_manager_class, \
r"apk info -e tree \|\| apk add tree", \
'Installing tree', \
None

else:
pytest.fail(f"Unhandled package manager class '{package_manager_class}'.")

Expand Down Expand Up @@ -277,6 +290,13 @@ def _parametrize_test_install_nonexistent() -> \
'no package provides tree-but-spelled-wrong', \
'error: Packages not found: tree-but-spelled-wrong' # noqa: E501

elif package_manager_class is tmt.package_managers.apk.Apk:
yield container, \
package_manager_class, \
r"apk info -e tree-but-spelled-wrong \|\| apk add tree-but-spelled-wrong", \
None, \
'ERROR: unable to select packages:\n tree-but-spelled-wrong (no such package):\n required by: world[tree-but-spelled-wrong]' # noqa: E501

else:
pytest.fail(f"Unhandled package manager class '{package_manager_class}'.")

Expand Down Expand Up @@ -373,6 +393,13 @@ def _parametrize_test_install_nonexistent_skip() -> \
'no package provides tree-but-spelled-wrong', \
'error: Packages not found: tree-but-spelled-wrong' # noqa: E501

elif package_manager_class is tmt.package_managers.apk.Apk:
yield container, \
package_manager_class, \
r"apk info -e tree-but-spelled-wrong \|\| apk add tree-but-spelled-wrong \|\| /bin/true", \
None, \
'ERROR: unable to select packages:\n tree-but-spelled-wrong (no such package):\n required by: world[tree-but-spelled-wrong]' # noqa: E501

else:
pytest.fail(f"Unhandled package manager class '{package_manager_class}'.")

Expand Down Expand Up @@ -453,6 +480,13 @@ def _parametrize_test_install_dont_check_first() -> \
'Installing: tree', \
None

elif package_manager_class is tmt.package_managers.apk.Apk:
yield container, \
package_manager_class, \
r"apk add tree", \
'Installing tree', \
None

else:
pytest.fail(f"Unhandled package manager class '{package_manager_class}'.")

Expand Down Expand Up @@ -506,6 +540,7 @@ def _parametrize_test_reinstall() -> Iterator[tuple[
if 'centos:7' in container.url:
yield container, \
package_manager_class, \
Package('tar'), \
True, \
r"rpm -q --whatprovides tar && yum reinstall -y tar && rpm -q --whatprovides tar", \
'Reinstalling:\n tar', \
Expand All @@ -514,6 +549,7 @@ def _parametrize_test_reinstall() -> Iterator[tuple[
else:
yield container, \
package_manager_class, \
Package('tar'), \
True, \
r"rpm -q --whatprovides tar && yum reinstall -y tar && rpm -q --whatprovides tar", \
'Reinstalled:\n tar', \
Expand All @@ -522,6 +558,7 @@ def _parametrize_test_reinstall() -> Iterator[tuple[
elif package_manager_class is tmt.package_managers.dnf.Dnf:
yield container, \
package_manager_class, \
Package('tar'), \
True, \
r"rpm -q --whatprovides tar && dnf reinstall -y tar", \
'Reinstalled:\n tar', \
Expand All @@ -530,6 +567,7 @@ def _parametrize_test_reinstall() -> Iterator[tuple[
elif package_manager_class is tmt.package_managers.dnf.Dnf5:
yield container, \
package_manager_class, \
Package('tar'), \
True, \
r"rpm -q --whatprovides tar && dnf5 reinstall -y tar", \
'Reinstalling tar', \
Expand All @@ -538,6 +576,7 @@ def _parametrize_test_reinstall() -> Iterator[tuple[
elif package_manager_class is tmt.package_managers.apt.Apt:
yield container, \
package_manager_class, \
Package('tar'), \
True, \
r"export DEBIAN_FRONTEND=noninteractive; dpkg-query --show tar && apt reinstall -y tar", \
'Setting up tar', \
Expand All @@ -546,18 +585,29 @@ def _parametrize_test_reinstall() -> Iterator[tuple[
elif package_manager_class is tmt.package_managers.rpm_ostree.RpmOstree:
yield container, \
package_manager_class, \
Package('tar'), \
False, \
None, \
None, \
None

elif package_manager_class is tmt.package_managers.apk.Apk:
yield container, \
package_manager_class, \
Package('bash'), \
True, \
r"apk info -e bash && apk fix bash", \
'Reinstalling bash', \
None

else:
pytest.fail(f"Unhandled package manager class '{package_manager_class}'.")


@pytest.mark.containers()
@pytest.mark.parametrize(('container_per_test',
'package_manager_class',
'package',
'supported',
'expected_command',
'expected_stdout',
Expand All @@ -569,6 +619,7 @@ def test_reinstall(
container_per_test: ContainerData,
guest_per_test: GuestContainer,
package_manager_class: PackageManagerClass,
package: Package,
supported: bool,
expected_command: Optional[str],
expected_stdout: Optional[str],
Expand All @@ -584,14 +635,14 @@ def test_reinstall(
if supported:
assert expected_command is not None

output = package_manager.reinstall(Package('tar'))
output = package_manager.reinstall(package)

assert_log(caplog, message=MATCH(
rf"Run command: podman exec .+? /bin/bash -c '{expected_command}'"))

else:
with pytest.raises(tmt.utils.GeneralError) as excinfo:
package_manager.reinstall(Package('tar'))
package_manager.reinstall(package)

assert excinfo.value.message \
== "rpm-ostree does not support reinstall operation."
Expand Down Expand Up @@ -666,6 +717,14 @@ def _generate_test_reinstall_nonexistent_matrix() -> Iterator[tuple[
None, \
None

elif package_manager_class is tmt.package_managers.apk.Apk:
yield container, \
package_manager_class, \
True, \
r"apk info -e tree-but-spelled-wrong && apk fix tree-but-spelled-wrong", \
None, \
''

else:
pytest.fail(f"Unhandled package manager class '{package_manager_class}'.")

Expand Down Expand Up @@ -951,6 +1010,31 @@ def _generate_test_check_presence() -> Iterator[
r'\s+out:\s+util-linux-core', \
None

elif package_manager_class is tmt.package_managers.apk.Apk:
yield container, \
package_manager_class, \
Package('busybox'), \
True, \
r"apk info -e busybox", \
r'\s+out:\s+busybox', \
None

yield container, \
package_manager_class, \
Package('tree-but-spelled-wrong'), \
False, \
r"apk info -e tree-but-spelled-wrong", \
None, \
''

yield container, \
package_manager_class, \
FileSystemPath('/usr/bin/arch'), \
True, \
r"apk info -e busybox", \
r'\s+out:\s+busybox', \
None

else:
pytest.fail(f"Unhandled package manager class '{package_manager_class}'.")

Expand Down
Loading
Loading