tmt.package_managers package

Submodules

tmt.package_managers.apk module

class tmt.package_managers.apk.Apk(*, guest: Guest, logger: Logger)

Bases: PackageManager[ApkEngine]

Initialize name and relation with the parent object

Prepare the workdir for provided id / directory path or generate a new workdir name if workdir=True given. Store command line context and options for future use if context is provided.

NAME: str = 'apk'
check_presence(*installables: Package | FileSystemPath | PackagePath | PackageUrl) dict[Package | FileSystemPath | PackagePath | PackageUrl, bool]

Return a presence status for each given installable

cli_invocation: 'tmt.cli.CliInvocation' | None = None
install_debuginfo(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) CommandOutput
install_local(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) CommandOutput

Install packages stored in a local directory

probe_command: Command = <tmt.utils.Command object>

A command to run to check whether the package manager is available on a guest.

class tmt.package_managers.apk.ApkEngine(*, guest: Guest, logger: Logger)

Bases: PackageManagerEngine

Initialize name and relation with the parent object

Prepare the workdir for provided id / directory path or generate a new workdir name if workdir=True given. Store command line context and options for future use if context is provided.

check_presence(*installables: Package | FileSystemPath | PackagePath | PackageUrl) ShellScript

Return a presence status for each given installable

cli_invocation: 'tmt.cli.CliInvocation' | None = None
disable_repo(*repo_ids: str) ShellScript

Disable specified repositories.

Parameters:

repo_ids – repository IDs to disable.

Returns:

a shell script to disable the repositories.

enable_repo(*repo_ids: str) ShellScript

Enable specified repositories.

Parameters:

repo_ids – repository IDs to enable.

Returns:

a shell script to enable the repositories.

install(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript
install_command = <tmt.utils.Command object>
install_debuginfo(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript
path_to_package(path: FileSystemPath) Package

Find a package providing given filesystem path.

This is not easily possible in Alpine. There is apk-file utility available but it seems unrealiable. Support only a fixed set of mappings until a better solution is available.

prepare_command() tuple[Command, Command]

Prepare installation command for apk

refresh_metadata() ShellScript
reinstall(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript

tmt.package_managers.apt module

class tmt.package_managers.apt.Apt(*, guest: Guest, logger: Logger)

Bases: PackageManager[AptEngine]

Initialize name and relation with the parent object

Prepare the workdir for provided id / directory path or generate a new workdir name if workdir=True given. Store command line context and options for future use if context is provided.

NAME: str = 'apt'
check_presence(*installables: Package | FileSystemPath | PackagePath | PackageUrl) dict[Package | FileSystemPath | PackagePath | PackageUrl, bool]

Return a presence status for each given installable

cli_invocation: 'tmt.cli.CliInvocation' | None = None
install_debuginfo(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) CommandOutput
install_local(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) CommandOutput

Install packages stored in a local directory

probe_command: Command = <tmt.utils.Command object>

A command to run to check whether the package manager is available on a guest.

class tmt.package_managers.apt.AptEngine(*, guest: Guest, logger: Logger)

Bases: PackageManagerEngine

Initialize name and relation with the parent object

Prepare the workdir for provided id / directory path or generate a new workdir name if workdir=True given. Store command line context and options for future use if context is provided.

check_presence(*installables: Package | FileSystemPath | PackagePath | PackageUrl) ShellScript

Return a presence status for each given installable

cli_invocation: 'tmt.cli.CliInvocation' | None = None
disable_repo(*repo_ids: str) ShellScript

Disable specified repositories.

Parameters:

repo_ids – repository IDs to disable.

Returns:

a shell script to disable the repositories.

enable_repo(*repo_ids: str) ShellScript

Enable specified repositories.

Parameters:

repo_ids – repository IDs to enable.

Returns:

a shell script to enable the repositories.

install(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript
install_command = <tmt.utils.Command object>
install_debuginfo(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript
prepare_command() tuple[Command, Command]

Prepare installation command for apt

refresh_metadata() ShellScript
reinstall(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript

tmt.package_managers.bootc module

class tmt.package_managers.bootc.BootEntry(*, image: ImageStatus | None = None, **extra_data: Any)

Bases: BootcMetadataContainer

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

image: ImageStatus | None
model_config: ClassVar[ConfigDict] = {'alias_generator': <function key_to_option>, 'extra': 'allow', 'validate_assignment': True, 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class tmt.package_managers.bootc.Bootc(*, guest: Guest, logger: Logger)

Bases: PackageManager[BootcEngine]

Initialize name and relation with the parent object

Prepare the workdir for provided id / directory path or generate a new workdir name if workdir=True given. Store command line context and options for future use if context is provided.

NAME: str = 'bootc'
assert_config_manager() None

Make sure the config-manager plugin for repository management is installed.

build_container() CommandOutput | None
check_presence(*installables: Package | FileSystemPath | PackagePath | PackageUrl) dict[Package | FileSystemPath | PackagePath | PackageUrl, bool]

Return a presence status for each given installable

cli_invocation: 'tmt.cli.CliInvocation' | None = None
disable_repo(*repo_ids: str) None

Disable specified repositories.

Parameters:

repo_ids – repository IDs to disable.

enable_repo(*repo_ids: str) None

Enable specified repositories.

Parameters:

repo_ids – repository IDs to enable.

extract_package_name_from_package_manager_output(output: str) Iterator[str]

Extract failed package names from package manager error output.

Parameters:

output – Error output (stdout or stderr) from the package manager.

Returns:

An iterator of package names that failed to install.

finalize_installation() CommandOutput

Coordinate installation process through containerfile building and switching

install(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) CommandOutput
install_debuginfo(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) CommandOutput
install_local(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) CommandOutput

Install packages stored in a local directory

probe_command: Command = <tmt.utils.Command object>

A command to run to check whether the package manager is available on a guest.

probe_priority: int = 130

Package managers with higher value would be preferred when more one package manager is detected on guest. For most of the time, the default is sufficient, but some families of package managers (looking at you, yum, dnf, dnf5, rpm-ostree!) may be installed togethers, and therefore a priority is needed.

refresh_metadata() CommandOutput
reinstall(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) CommandOutput
class tmt.package_managers.bootc.BootcEngine(*args: Any, **kwargs: Any)

Bases: PackageManagerEngine

Initialize bootc engine for package management

check_presence(*installables: Package | FileSystemPath | PackagePath | PackageUrl) ShellScript

Return a presence status for each given installable

cli_invocation: 'tmt.cli.CliInvocation' | None = None
containerfile_directives: list[str]
disable_repo(*repo_ids: str) ShellScript

Disable specified repositories.

Parameters:

repo_ids – repository IDs to disable.

Returns:

a shell script to disable the repositories.

enable_repo(*repo_ids: str) ShellScript

Enable specified repositories.

Parameters:

repo_ids – repository IDs to enable.

Returns:

a shell script to enable the repositories.

flush_containerfile_directives() None
install(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript
install_debuginfo(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript
open_containerfile_directives() None

Initialize containerfile directives

prepare_command() tuple[Command, Command]

Prepare installation command for bootc

refresh_metadata() ShellScript
reinstall(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript
class tmt.package_managers.bootc.BootcHost(*, status: HostStatus | None = None, **extra_data: Any)

Bases: BootcMetadataContainer

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_config: ClassVar[ConfigDict] = {'alias_generator': <function key_to_option>, 'extra': 'allow', 'validate_assignment': True, 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

status: HostStatus | None
class tmt.package_managers.bootc.BootcMetadataContainer(**extra_data: Any)

Bases: MetadataContainer

Metadata container for bootc images. References the official bootc host v1 JSON schema(https://bootc-dev.github.io/bootc/host-v1.schema.json). This is a minimal version only including relevant fields for tmt.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_config: ClassVar[ConfigDict] = {'alias_generator': <function key_to_option>, 'extra': 'allow', 'validate_assignment': True, 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class tmt.package_managers.bootc.HostStatus(*, booted: BootEntry | None = None, **extra_data: Any)

Bases: BootcMetadataContainer

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

booted: BootEntry | None
model_config: ClassVar[ConfigDict] = {'alias_generator': <function key_to_option>, 'extra': 'allow', 'validate_assignment': True, 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class tmt.package_managers.bootc.ImageReference(*, image: str, **extra_data: Any)

Bases: BootcMetadataContainer

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

image: str
model_config: ClassVar[ConfigDict] = {'alias_generator': <function key_to_option>, 'extra': 'allow', 'validate_assignment': True, 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class tmt.package_managers.bootc.ImageStatus(*, image: ImageReference, **extra_data: Any)

Bases: BootcMetadataContainer

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

image: ImageReference
model_config: ClassVar[ConfigDict] = {'alias_generator': <function key_to_option>, 'extra': 'allow', 'validate_assignment': True, 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

tmt.package_managers.dnf module

class tmt.package_managers.dnf.Dnf(*, guest: Guest, logger: Logger)

Bases: PackageManager[DnfEngine]

Initialize name and relation with the parent object

Prepare the workdir for provided id / directory path or generate a new workdir name if workdir=True given. Store command line context and options for future use if context is provided.

NAME: str = 'dnf'
assert_config_manager() None

Make sure the config-manager plugin for repository management is installed.

bootc_builder: bool = True

If set, this package manager can be used for building derived images under the hood of the bootc package manager.

check_presence(*installables: Package | FileSystemPath | PackagePath | PackageUrl) dict[Package | FileSystemPath | PackagePath | PackageUrl, bool]

Return a presence status for each given installable

cli_invocation: 'tmt.cli.CliInvocation' | None = None
config_manager_plugin: ClassVar[str] = 'dnf-command(config-manager)'

Package name of the config-manager plugin for this package manager.

copr_plugin: ClassVar[str] = 'dnf-plugins-core'

Package name of the COPR plugin for this package manager.

enable_copr(*repositories: str) None

Enable requested copr repositories

install_debuginfo(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) CommandOutput
install_local(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) CommandOutput

Install packages stored in a local directory

list_packages(repository: Repository) list[Version]

List packages available in the specified repository.

Parameters:

repository – The repository to query.

Returns:

A list of versions available in the repository.

probe_command: Command = <tmt.utils.Command object>

A command to run to check whether the package manager is available on a guest.

probe_priority: int = 50

Package managers with higher value would be preferred when more one package manager is detected on guest. For most of the time, the default is sufficient, but some families of package managers (looking at you, yum, dnf, dnf5, rpm-ostree!) may be installed togethers, and therefore a priority is needed.

class tmt.package_managers.dnf.Dnf5(*, guest: Guest, logger: Logger)

Bases: Dnf

Initialize name and relation with the parent object

Prepare the workdir for provided id / directory path or generate a new workdir name if workdir=True given. Store command line context and options for future use if context is provided.

NAME: str = 'dnf5'
cli_invocation: 'tmt.cli.CliInvocation' | None = None
config_manager_plugin: ClassVar[str] = 'dnf5-command(config-manager)'

Package name of the config-manager plugin for this package manager.

copr_plugin: ClassVar[str] = 'dnf5-command(copr)'

Package name of the COPR plugin for this package manager.

probe_command: Command = <tmt.utils.Command object>

A command to run to check whether the package manager is available on a guest.

probe_priority: int = 60

Package managers with higher value would be preferred when more one package manager is detected on guest. For most of the time, the default is sufficient, but some families of package managers (looking at you, yum, dnf, dnf5, rpm-ostree!) may be installed togethers, and therefore a priority is needed.

class tmt.package_managers.dnf.Dnf5Engine(*, guest: Guest, logger: Logger)

Bases: DnfEngine

Initialize name and relation with the parent object

Prepare the workdir for provided id / directory path or generate a new workdir name if workdir=True given. Store command line context and options for future use if context is provided.

cli_invocation: 'tmt.cli.CliInvocation' | None = None
skip_missing_debuginfo_option = '--skip-unavailable'
skip_missing_packages_option = '--skip-unavailable'
class tmt.package_managers.dnf.DnfEngine(*, guest: Guest, logger: Logger)

Bases: PackageManagerEngine

Initialize name and relation with the parent object

Prepare the workdir for provided id / directory path or generate a new workdir name if workdir=True given. Store command line context and options for future use if context is provided.

check_presence(*installables: Package | FileSystemPath | PackagePath | PackageUrl) ShellScript

Return a presence status for each given installable

cli_invocation: 'tmt.cli.CliInvocation' | None = None
create_repository(directory: Path) ShellScript

Create repository metadata for package files in the given directory.

Parameters:

directory – The path to the directory containing RPM packages.

Returns:

A shell script to create repository metadata.

disable_repo(*repo_ids: str) ShellScript

Disable specified repositories.

Parameters:

repo_ids – repository IDs to disable.

Returns:

a shell script to disable the repositories.

enable_repo(*repo_ids: str) ShellScript

Enable specified repositories.

Parameters:

repo_ids – repository IDs to enable.

Returns:

a shell script to enable the repositories.

get_package_origin(packages: Iterable[str]) ShellScript

List source repositories for each installed package.

The script must emit one line per package in the format:

<name> <origin>

Empty lines are allowed and will be ignored by the caller. If the origin field is omitted the package is treated as having an unknown source repository (equivalent to SpecialPackageOrigin.UNKNOWN). Packages whose name does not appear in the output at all are treated as not installed (equivalent to SpecialPackageOrigin.NOT_INSTALLED).

Parameters:

packages – Package names to query.

Returns:

A shell script to list source repositories for the given packages.

Raises:

NotImplementedError – If the package manager does not support this query.

install(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript
install_debuginfo(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript
install_repository(repository: Repository) ShellScript

Install a repository by placing its configuration in /etc/yum.repos.d/.

Parameters:

repository – The repository to install.

Returns:

A shell script to install the repository.

list_packages(repository: Repository) ShellScript

List packages available in the specified repository.

Parameters:

repository – The repository to query.

Returns:

A shell script to list packages in the repository.

Raises:

NotImplementedError – If the package manager does not support listing packages.

prepare_command() tuple[Command, Command]

Prepare installation command and subcommand options

refresh_metadata() ShellScript
reinstall(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript
resolve_provides(provides: Sequence[str], repo_ids: Iterable[str] = ()) ShellScript

Resolves each provide to the NEVRAs of packages that provide it.

The script must emit YAML mapping each provide string to a list of mappings with nevra and repo_id keys, or an empty value when nothing provides it, e.g.

'/usr/bin/cmake':
    - nevra: 'cmake-0:3.31.6-4.fc43.x86_64'
      repo_id: 'updates'
'/usr/bin/non-existent-provides':
'make':
    - nevra: 'make-1:4.4.1-8.fc43.x86_64'
      repo_id: 'fedora'
Parameters:
  • provides – Provides to resolve.

  • repo_ids – Restrict the query to these repository IDs; searches all enabled repositories when not provided.

Returns:

A shell script emitting the YAML mapping described above.

Raises:

PrepareError – If the package manager does not support this query.

skip_missing_debuginfo_option = '--skip-broken'
skip_missing_packages_option = '--skip-broken'
class tmt.package_managers.dnf.Yum(*, guest: Guest, logger: Logger)

Bases: Dnf

Initialize name and relation with the parent object

Prepare the workdir for provided id / directory path or generate a new workdir name if workdir=True given. Store command line context and options for future use if context is provided.

NAME: str = 'yum'
bootc_builder: bool = False

If set, this package manager can be used for building derived images under the hood of the bootc package manager.

cli_invocation: 'tmt.cli.CliInvocation' | None = None
config_manager_plugin: ClassVar[str] = 'yum-utils'

Package name of the config-manager plugin for this package manager.

copr_plugin: ClassVar[str] = 'yum-plugin-copr'

Package name of the COPR plugin for this package manager.

probe_command: Command = <tmt.utils.Command object>

A command to run to check whether the package manager is available on a guest.

probe_priority: int = 40

Package managers with higher value would be preferred when more one package manager is detected on guest. For most of the time, the default is sufficient, but some families of package managers (looking at you, yum, dnf, dnf5, rpm-ostree!) may be installed togethers, and therefore a priority is needed.

class tmt.package_managers.dnf.YumEngine(*, guest: Guest, logger: Logger)

Bases: DnfEngine

Initialize name and relation with the parent object

Prepare the workdir for provided id / directory path or generate a new workdir name if workdir=True given. Store command line context and options for future use if context is provided.

cli_invocation: 'tmt.cli.CliInvocation' | None = None
disable_repo(*repo_ids: str) ShellScript

Disable specified repositories.

Parameters:

repo_ids – repository IDs to disable.

Returns:

a shell script to disable the repositories.

enable_repo(*repo_ids: str) ShellScript

Enable specified repositories.

Parameters:

repo_ids – repository IDs to enable.

Returns:

a shell script to enable the repositories.

get_package_origin(packages: Iterable[str]) ShellScript

List source repositories for each installed package.

The script must emit one line per package in the format:

<name> <origin>

Empty lines are allowed and will be ignored by the caller. If the origin field is omitted the package is treated as having an unknown source repository (equivalent to SpecialPackageOrigin.UNKNOWN). Packages whose name does not appear in the output at all are treated as not installed (equivalent to SpecialPackageOrigin.NOT_INSTALLED).

Parameters:

packages – Package names to query.

Returns:

A shell script to list source repositories for the given packages.

Raises:

NotImplementedError – If the package manager does not support this query.

install(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript
refresh_metadata() ShellScript
reinstall(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript
resolve_provides(provides: Sequence[str], repo_ids: Iterable[str] = ()) ShellScript

Resolves each provide to the NEVRAs of packages that provide it.

The script must emit YAML mapping each provide string to a list of mappings with nevra and repo_id keys, or an empty value when nothing provides it, e.g.

'/usr/bin/cmake':
    - nevra: 'cmake-0:3.31.6-4.fc43.x86_64'
      repo_id: 'updates'
'/usr/bin/non-existent-provides':
'make':
    - nevra: 'make-1:4.4.1-8.fc43.x86_64'
      repo_id: 'fedora'
Parameters:
  • provides – Provides to resolve.

  • repo_ids – Restrict the query to these repository IDs; searches all enabled repositories when not provided.

Returns:

A shell script emitting the YAML mapping described above.

Raises:

PrepareError – If the package manager does not support this query.

tmt.package_managers.mock module

class tmt.package_managers.mock.MockDnf(*, guest: Guest, logger: Logger)

Bases: _MockPackageManager

Initialize name and relation with the parent object

Prepare the workdir for provided id / directory path or generate a new workdir name if workdir=True given. Store command line context and options for future use if context is provided.

NAME: str = 'mock-dnf'
cli_invocation: 'tmt.cli.CliInvocation' | None = None
class tmt.package_managers.mock.MockDnf5(*, guest: Guest, logger: Logger)

Bases: _MockPackageManager

Initialize name and relation with the parent object

Prepare the workdir for provided id / directory path or generate a new workdir name if workdir=True given. Store command line context and options for future use if context is provided.

NAME: str = 'mock-dnf5'
cli_invocation: 'tmt.cli.CliInvocation' | None = None
class tmt.package_managers.mock.MockEngine(*, guest: Guest, logger: Logger)

Bases: PackageManagerEngine

We use mock –pm-cmd … to execute the package manager commands inside the mock. Such scripts need to be executed locally and not inside the mock shell.

Initialize name and relation with the parent object

Prepare the workdir for provided id / directory path or generate a new workdir name if workdir=True given. Store command line context and options for future use if context is provided.

check_presence(*installables: Package | FileSystemPath | PackagePath | PackageUrl) ShellScript

Return a presence status for each given installable

cli_invocation: 'tmt.cli.CliInvocation' | None = None
disable_repo(*repo_ids: str) ShellScript

Disable specified repositories.

Parameters:

repo_ids – repository IDs to disable.

Returns:

a shell script to disable the repositories.

enable_repo(*repo_ids: str) ShellScript

Enable specified repositories.

Parameters:

repo_ids – repository IDs to enable.

Returns:

a shell script to enable the repositories.

install(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript
install_debuginfo(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript
prepare_command() tuple[Command, Command]

Prepare installation command and subcommand options

refresh_metadata() ShellScript
reinstall(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript
class tmt.package_managers.mock.MockYum(*, guest: Guest, logger: Logger)

Bases: _MockPackageManager

Initialize name and relation with the parent object

Prepare the workdir for provided id / directory path or generate a new workdir name if workdir=True given. Store command line context and options for future use if context is provided.

NAME: str = 'mock-yum'
cli_invocation: 'tmt.cli.CliInvocation' | None = None

tmt.package_managers.rpm_ostree module

class tmt.package_managers.rpm_ostree.RpmOstree(*, guest: Guest, logger: Logger)

Bases: PackageManager[RpmOstreeEngine]

Initialize name and relation with the parent object

Prepare the workdir for provided id / directory path or generate a new workdir name if workdir=True given. Store command line context and options for future use if context is provided.

NAME: str = 'rpm-ostree'
check_presence(*installables: Package | FileSystemPath | PackagePath | PackageUrl) dict[Package | FileSystemPath | PackagePath | PackageUrl, bool]

Return a presence status for each given installable

cli_invocation: 'tmt.cli.CliInvocation' | None = None
enable_copr(*repositories: str) None

Enable COPR repositories by delegating to a Dnf5 package manager instance.

install(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) CommandOutput
install_debuginfo(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) CommandOutput
install_local(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) CommandOutput

Install packages stored in a local directory

probe_command: Command = <tmt.utils.Command object>

A command to run to check whether the package manager is available on a guest.

probe_priority: int = 100

Package managers with higher value would be preferred when more one package manager is detected on guest. For most of the time, the default is sufficient, but some families of package managers (looking at you, yum, dnf, dnf5, rpm-ostree!) may be installed togethers, and therefore a priority is needed.

refresh_metadata() CommandOutput
reinstall(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) CommandOutput
sort_packages(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options) tuple[list[Package | FileSystemPath | PackagePath | PackageUrl], list[Package | FileSystemPath | PackagePath | PackageUrl]]

Sort packages into required and recommended based on presence and skip_missing.

class tmt.package_managers.rpm_ostree.RpmOstreeEngine(*, guest: Guest, logger: Logger)

Bases: PackageManagerEngine

Initialize name and relation with the parent object

Prepare the workdir for provided id / directory path or generate a new workdir name if workdir=True given. Store command line context and options for future use if context is provided.

check_presence(*installables: Package | FileSystemPath | PackagePath | PackageUrl) ShellScript

Return a presence status for each given installable

cli_invocation: 'tmt.cli.CliInvocation' | None = None
disable_repo(*repo_ids: str) ShellScript

Disable specified repositories.

Parameters:

repo_ids – repository IDs to disable.

Returns:

a shell script to disable the repositories.

enable_repo(*repo_ids: str) ShellScript

Enable specified repositories.

Parameters:

repo_ids – repository IDs to enable.

Returns:

a shell script to enable the repositories.

install(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript
install_debuginfo(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript
prepare_command() tuple[Command, Command]

Prepare installation command for rpm-ostree

refresh_metadata() ShellScript
reinstall(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript

Module contents

class tmt.package_managers.FileSystemPath(*args, **kwargs)

Bases: Path

A filesystem path provided by a package

Construct a PurePath from one or several strings and or existing PurePath objects. The strings and path objects are combined so as to yield a canonicalized path, which is incorporated into the new PurePath object.

tmt.package_managers.Installable = tmt.package_managers.Package | tmt.package_managers.FileSystemPath | tmt.package_managers.PackagePath | tmt.package_managers.PackageUrl

All installable objects.

class tmt.package_managers.Options(excluded_packages: list[tmt.package_managers.Package] = <factory>, skip_missing: bool = False, check_first: bool = True, install_root: tmt._compat.pathlib.Path | None = None, release_version: str | None = None, allow_untrusted: bool = False)

Bases: object

allow_untrusted: bool = False

If set, instruct package manager to install from untrusted sources.

check_first: bool = True

If set, check whether the package is already installed, and do not attempt to install it if it is already present.

excluded_packages: list[Package]

A list of packages to exclude from installation.

install_root: Path | None = None

If set, install packages under this path instead of the usual system root.

release_version: str | None = None

If set, instruct package manager to behave as if the distribution release was release_version.

skip_missing: bool = False

If set, a failure to install a given package would not cause an error.

class tmt.package_managers.Package

Bases: str

A package name

class tmt.package_managers.PackageManager(*, guest: Guest, logger: Logger)

Bases: Common, Generic[PackageManagerEngineT]

A base class for package manager plugins

Initialize name and relation with the parent object

Prepare the workdir for provided id / directory path or generate a new workdir name if workdir=True given. Store command line context and options for future use if context is provided.

NAME: str
assert_config_manager() None

Make sure the config-manager plugin for repository management is installed.

bootc_builder: bool = False

If set, this package manager can be used for building derived images under the hood of the bootc package manager.

abstractmethod check_presence(*installables: Package | FileSystemPath | PackagePath | PackageUrl) dict[Package | FileSystemPath | PackagePath | PackageUrl, bool]

Return a presence status for each given installable

cli_invocation: 'tmt.cli.CliInvocation' | None = None
create_repository(directory: Path) CommandOutput

Wrapper of PackageManagerEngine.create_repository().

disable_repo(*repo_ids: str) None

Disable specified repositories.

Parameters:

repo_ids – repository IDs to disable.

enable_copr(*repositories: str) None

Enable requested copr repositories

enable_repo(*repo_ids: str) None

Enable specified repositories.

Parameters:

repo_ids – repository IDs to enable.

engine: PackageManagerEngineT
extract_package_name_from_package_manager_output(output: str) Iterator[str]

Extract failed package names from package manager error output.

Parameters:

output – Error output (stdout or stderr) from the package manager.

Returns:

An iterator of package names that failed to install.

finalize_installation() CommandOutput

Perform any post-installation steps.

get_package_origin(packages: Iterable[str]) dict[str, PackageOrigin]

Get the repository each package was installed from.

Parameters:

packages – Package names to query.

Returns:

A mapping of package names to source repository names. Packages not installed are mapped to SpecialPackageOrigin.NOT_INSTALLED. Packages whose source repository is unknown are mapped to SpecialPackageOrigin.UNKNOWN.

install(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) CommandOutput
install_debuginfo(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) CommandOutput
install_local(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) CommandOutput

Install packages stored in a local directory

install_repository(repository: Repository) CommandOutput

Install a repository by placing its configuration in /etc/yum.repos.d/ and refresh the package manager cache.

Parameters:

repository – The repository to install.

Returns:

The output of the command execution.

list_packages(repository: Repository) list[Version]

List packages available in the specified repository.

Parameters:

repository – The repository to query.

Returns:

A list of versions available in the repository.

probe_command: Command

A command to run to check whether the package manager is available on a guest.

probe_priority: int = 0

Package managers with higher value would be preferred when more one package manager is detected on guest. For most of the time, the default is sufficient, but some families of package managers (looking at you, yum, dnf, dnf5, rpm-ostree!) may be installed togethers, and therefore a priority is needed.

refresh_metadata() CommandOutput
reinstall(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) CommandOutput
resolve_provides(provides: Sequence[str], repo_ids: Iterable[str] = ()) dict[str, list[RpmVersion]]

Map each provide to the RpmVersion objects of packages that provide it.

Parameters:
  • provides – Provides to resolve.

  • repo_ids – Restrict the query to these repository IDs; searches all enabled repositories when not provided.

Returns:

Mapping from each provide to a list of RpmVersion objects, each carrying the NEVRA and source repository. Every requested provide appears as a key; provides with no match map to an empty list.

class tmt.package_managers.PackageManagerEngine(*, guest: Guest, logger: Logger)

Bases: Common

Initialize name and relation with the parent object

Prepare the workdir for provided id / directory path or generate a new workdir name if workdir=True given. Store command line context and options for future use if context is provided.

abstractmethod check_presence(*installables: Package | FileSystemPath | PackagePath | PackageUrl) ShellScript

Return a presence status for each given installable

cli_invocation: 'tmt.cli.CliInvocation' | None = None
command: Command
create_repository(directory: Path) ShellScript

Create repository metadata for package files in the given directory.

Parameters:

directory – The path to the directory containing packages.

Returns:

A shell script to create repository metadata.

Raises:

PrepareError – If this package manager does not support creating repositories.

abstractmethod disable_repo(*repo_ids: str) ShellScript

Disable specified repositories.

Parameters:

repo_ids – repository IDs to disable.

Returns:

a shell script to disable the repositories.

abstractmethod enable_repo(*repo_ids: str) ShellScript

Enable specified repositories.

Parameters:

repo_ids – repository IDs to enable.

Returns:

a shell script to enable the repositories.

get_package_origin(packages: Iterable[str]) ShellScript

List source repositories for each installed package.

The script must emit one line per package in the format:

<name> <origin>

Empty lines are allowed and will be ignored by the caller. If the origin field is omitted the package is treated as having an unknown source repository (equivalent to SpecialPackageOrigin.UNKNOWN). Packages whose name does not appear in the output at all are treated as not installed (equivalent to SpecialPackageOrigin.NOT_INSTALLED).

Parameters:

packages – Package names to query.

Returns:

A shell script to list source repositories for the given packages.

Raises:

NotImplementedError – If the package manager does not support this query.

abstractmethod install(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript
abstractmethod install_debuginfo(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript
install_repository(repository: Repository) ShellScript

Install a repository by placing its configuration in /etc/yum.repos.d/.

Parameters:

repository – The repository to install.

Returns:

A shell script to install the repository.

list_packages(repository: Repository) ShellScript

List packages available in the specified repository.

Parameters:

repository – The repository to query.

Returns:

A shell script to list packages in the repository.

Raises:

NotImplementedError – If the package manager does not support listing packages.

options: Command
abstractmethod prepare_command() tuple[Command, Command]

Prepare installation command and subcommand options

abstractmethod refresh_metadata() ShellScript
abstractmethod reinstall(*installables: Package | FileSystemPath | PackagePath | PackageUrl, options: Options | None = None) ShellScript
resolve_provides(provides: Sequence[str], repo_ids: Iterable[str] = ()) ShellScript

Resolves each provide to the NEVRAs of packages that provide it.

The script must emit YAML mapping each provide string to a list of mappings with nevra and repo_id keys, or an empty value when nothing provides it, e.g.

'/usr/bin/cmake':
    - nevra: 'cmake-0:3.31.6-4.fc43.x86_64'
      repo_id: 'updates'
'/usr/bin/non-existent-provides':
'make':
    - nevra: 'make-1:4.4.1-8.fc43.x86_64'
      repo_id: 'fedora'
Parameters:
  • provides – Provides to resolve.

  • repo_ids – Restrict the query to these repository IDs; searches all enabled repositories when not provided.

Returns:

A shell script emitting the YAML mapping described above.

Raises:

PrepareError – If the package manager does not support this query.

class tmt.package_managers.PackagePath(*args, **kwargs)

Bases: Path

A path to a package file

Construct a PurePath from one or several strings and or existing PurePath objects. The strings and path objects are combined so as to yield a canonicalized path, which is incorporated into the new PurePath object.

class tmt.package_managers.PackageUrl

Bases: str

A URL of a package file

class tmt.package_managers.Repository(content: str, name: str, repo_ids: list[str] = <factory>)

Bases: object

Thin wrapper/holder for .repo file content

content: str

Content of the repository

property filename: str

The name of the .repo file (e.g., ‘my-repo.repo’).

classmethod from_content(content: str, name: str, logger: Logger) Repository

Create a Repository instance directly from provided content string.

Parameters:
  • content – The string content of the repository.

  • name – The name for the repository (required when using content).

  • logger – Logger to use for the operation.

Returns:

A Repository instance.

Raises:

GeneralError – If the name is empty.

classmethod from_file_path(file_path: Path, logger: Logger, name: str | None = None) Repository

Create a Repository instance by reading content from a local file path.

Parameters:
  • file_path – The local path to the repository file.

  • logger – Logger to use for the operation.

  • name – Optional name for the repository. If not provided, derived from the file path.

Returns:

A Repository instance.

Raises:

GeneralError – If reading the file fails.

classmethod from_url(url: str, logger: Logger, name: str | None = None) Repository

Create a Repository instance by fetching content from a URL.

Parameters:
  • url – The URL to fetch the repository content from.

  • logger – Logger to use for the operation.

  • name – Optional name for the repository. If not provided, derived from the URL.

Returns:

A Repository instance.

Raises:

GeneralError – If fetching or parsing fails.

name: str

Uniquely identifiable name

repo_ids: list[str]

repository_ids present in the .repo file

class tmt.package_managers.SpecialPackageOrigin(*values)

Bases: str, Enum

Sentinel values used in place of an actual repository name to convey special package states returned by PackageManager.get_package_origin().

NOT_INSTALLED = '<not-installed>'

Package is not installed on the guest.

UNKNOWN = '<unknown>'

Package is installed but its source repository cannot be determined (e.g. pre-installed in a container image).

class tmt.package_managers.Version(name: str, version: str, release: str, arch: str, epoch: int = 0)

Bases: object

Version information for artifacts.

arch: str
epoch: int = 0
name: str
property nevra: str
property nvra: str
release: str
version: str
tmt.package_managers.YUM_REPOS_DIR = Path('/etc/yum.repos.d')

Directory where DNF/YUM repository files are stored.

tmt.package_managers.escape_installables(*installables: Package | FileSystemPath | PackagePath | PackageUrl) Iterator[str]
tmt.package_managers.find_package_manager(name: GuestPackageManager) PackageManagerClass[PackageManagerEngine]

Find a package manager by its name.

Raises:

GeneralError – when the plugin does not exist.