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 Alpine Linux support #2828

Merged
merged 8 commits into from
May 1, 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
3 changes: 2 additions & 1 deletion plans/main.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ provision:
how: local

prepare+:
# Install jq and yq for cleaner tests
# Install jq and yq for cleaner tests, and required make
- how: install
package:
- jq
- make
- python3-pip

- how: shell
Expand Down
10 changes: 10 additions & 0 deletions tests/provision/container/alpine/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
summary: Test Alpine Linux container
description:
Make sure that Alpine Linux container works as expected.
The vanilla alpine linux does not contain `bash` package,
so make sure a reasonable error is returned to the user.
Run a simple successful check against the Alpine Linux
tests image.
tag+:
- provision-only
- provision-container
34 changes: 34 additions & 0 deletions tests/provision/container/alpine/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
. /usr/share/beakerlib/beakerlib.sh || exit 1

USER="tester"

rlJournalStart
rlPhaseStartSetup
rlRun "make -C ../../../../ image-unit-tests-alpine"

# Directories
rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory"
rlRun "run=\$(mktemp -d)" 0 "Create run directory"
rlRun "pushd $tmp"
rlPhaseEnd

rlPhaseStartTest "Test vanilla alpine without bash"
rlRun -s "tmt run --all --id $run --verbose --scratch \
provision --how container --image docker.io/alpine \
execute --how tmt --script whoami" 2
rlAssertGrep "fail: /bin/bash is required on the guest." $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "Test alpine with bash"
rlRun -s "tmt run -vv --all --id $run --verbose --scratch \
provision --how container --image localhost/alpine:tmt-unit-tests \
execute --how tmt --script whoami" 0
rlAssertGrep "out: root" $rlRun_LOG
rlPhaseEnd
happz marked this conversation as resolved.
Show resolved Hide resolved

rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $tmp $run" 0 "Remove tmp and run directory"
rlPhaseEnd
rlJournalEnd
3 changes: 3 additions & 0 deletions tmt/package_managers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ class Options:
#: was ``release_version``.
release_version: Optional[str] = None

#: If set, instruct package manager to install from untrusted sources.
allow_untrusted: bool = False


class PackageManager(tmt.utils.Common):
""" A base class for package manager plugins """
Expand Down
1 change: 1 addition & 0 deletions tmt/package_managers/apk.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def install(

script = ShellScript(
f'{self.command.to_script()} {self.install_command.to_script()} '
f'{"--allow-untrusted " if options.allow_untrusted else ""}'
f'{" ".join(escape_installables(*packages))}')

if options.check_first:
Expand Down
56 changes: 56 additions & 0 deletions tmt/steps/prepare/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,53 @@ def install_debuginfo(self) -> None:
*[Package(f'{package}-debuginfo') for package in self.debuginfo_packages])


class InstallApk(InstallBase):
""" Install packages using apk """

def install_local(self) -> None:
""" Install packages stored in a local directory """

filelist = [PackagePath(self.package_directory / filename)
for filename in self.local_packages]

self.guest.package_manager.install(
*self.list_installables('local packages', *filelist),
options=Options(
excluded_packages=self.exclude,
skip_missing=self.skip_missing,
allow_untrusted=True
)
)

summary = fmf.utils.listed([str(path) for path in self.local_packages], 'local package')
self.info('total', f"{summary} installed", 'green')

def install_from_url(self) -> None:
""" Install packages stored on a remote URL """

raise tmt.utils.PrepareError(
f'Package manager "{self.guest.facts.package_manager}" '
'does not support installing from a remote URL.')

def install_from_repository(self) -> None:
""" Install packages from a repository """

self.guest.package_manager.install(
*self.list_installables("package", *self.packages),
options=Options(
excluded_packages=self.exclude,
skip_missing=self.skip_missing
)
)

def install_debuginfo(self) -> None:
""" Install debuginfo packages """

raise tmt.utils.PrepareError(
f'Package manager "{self.guest.facts.package_manager}" does not support '
'installing debuginfo packages.')


@dataclasses.dataclass
class PrepareInstallData(tmt.steps.prepare.PrepareStepData):
package: list[tmt.base.DependencySimple] = field(
Expand Down Expand Up @@ -614,6 +661,15 @@ def go(
exclude=self.data.exclude,
guest=guest)

elif guest.facts.package_manager == 'apk':
installer = InstallApk(
logger=logger,
parent=self,
dependencies=self.data.package,
directories=self.data.directory,
exclude=self.data.exclude,
guest=guest)

else:
raise tmt.utils.PrepareError(
f'Package manager "{guest.facts.package_manager}" is not supported.')
Expand Down
4 changes: 4 additions & 0 deletions tmt/steps/provision/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ def _execute(
except tmt.utils.RunError as exc:
if exc.stdout and 'Please login as the user' in exc.stdout:
raise tmt.utils.GeneralError(f'Login to the guest failed.\n{exc.stdout}') from exc
if exc.stderr and \
f'executable file `{tmt.utils.DEFAULT_SHELL}` not found' in exc.stderr:
raise tmt.utils.GeneralError(
f'{tmt.utils.DEFAULT_SHELL.capitalize()} is required on the guest.') from exc
happz marked this conversation as resolved.
Show resolved Hide resolved

return None

Expand Down
Loading