lib/publiccloud/zypper.pm

NAME

publiccloud::zypper - Zypper / transactional-update plumbing for public cloud tests

SYNOPSIS

use publiccloud::zypper qw(pc_pkg_call pc_refresh pc_add_repo);

pc_refresh($instance);
pc_add_repo($instance, 'my-repo', 'http://example.com/repo');
pc_pkg_call($instance, 'in some-package');

DESCRIPTION

Centralises all package-management interactions with remote public cloud instances (and a small helper for local installations). On transactional systems, package-changing operations are transparently routed through transactional-update; refresh and repository management always go through plain zypper.

PUBLIC API

"pc_zypper_call" - plain sudo zypper -n ...
"pc_transactional_call" - plain sudo transactional-update -n ...
"pc_pkg_call" - smart dispatch based on is_transactional()
"pc_refresh" - zypper ref (always plain; poo#195920)
"pc_add_repo" - add a GPG-checked repository
"pc_wait_quit" - wait for zypper/rpm/etc. to finish
"pc_installed_packages" - filter list to installed packages
"pc_available_packages" - filter list to available-but-not-installed
"pc_install_packages_local" - local-SUT install helper

See the per-function sections below for full signatures and options.

pc_zypper_call

pc_zypper_call($instance, $cmd, %opts);
pc_zypper_call($instance, cmd => $cmd, %opts);

Runs sudo zypper -n $cmd on a remote instance. Never wraps the command in transactional-update; use this for repo/refresh/info operations even on transactional systems.

Options (all optional):

timeout => seconds, default 700
retry => number of attempts, default 1
delay => seconds between retries, default 5
exitcode => arrayref of accepted exit codes, default [0]
proceed_on_failure => if true, record the failure but don't die

pc_transactional_call

pc_transactional_call($instance, $cmd, %opts);

Runs sudo transactional-update -n $cmd on a remote instance and triggers a soft reboot on success (unless no_reboot = 1> is passed). The default accepted exit codes are 0, 102, 103.

pc_pkg_call

pc_pkg_call($instance, $cmd, %opts);

Smart dispatch: on transactional systems, translates $cmd into the equivalent transactional-update invocation when possible (for install / remove / update / dup / patch). Anything that transactional-update does not support (refresh, repo management, queries, ...) falls through to plain pc_zypper_call. On non-transactional systems this is identical to pc_zypper_call.

pc_refresh

pc_refresh($instance, %opts);

Refreshes repositories on the remote instance. Always uses plain zypper, even on transactional systems, because transactional-update does not support repo refresh actions (poo#195920).

pc_add_repo

pc_add_repo($instance, $name, $url, [timeout => 600]);

Adds a GPG-checked repository to the remote instance. Uses ssh_assert_script_run directly (i.e. dies on non-zero exit) rather than the full pc_zypper_call retry pipeline, since adding a single repository is a one-shot operation.

pc_wait_quit

pc_wait_quit($instance, [timeout => 20], [delay => 10], [retry => 120]);

Waits until no zypper / packagekit / purge-kernels / rpm processes are running on the remote instance. Defaults give a ~20 minute ceiling.

pc_installed_packages

pc_installed_packages($instance, \@pkgs);

Returns an arrayref of those packages from \@pkgs that are installed on the remote instance, preserving the order from the input list.

pc_available_packages

pc_available_packages($instance, \@pkgs);

Returns an arrayref of packages from \@pkgs that are not yet installed but are available for installation. Uses zypper -x info to query availability.

pc_install_packages_local

pc_install_packages_local(\@pkgs, [timeout => $seconds]);

Installs packages on the local SUT. On transactional systems uses trup_call("pkg install ...") followed by reboot_on_changes; otherwise uses the standard utils::zypper_call("in ...").