Documentation ¶
Overview ¶
The manager package defines an interface which can carry out numerous package-management related operations on the local system and the respective implementations on apt and yum-based systems.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( AttemptStrategy = utils.AttemptStrategy{ Delay: 10 * time.Second, Min: 30, } )
var CommandOutput = (*exec.Cmd).CombinedOutput
CommandOutput is cmd.Output. It was aliased for testing purposes.
var ProcessStateSys = (*os.ProcessState).Sys
processStateSys is ps.Sys. It was aliased for testing purposes.
var RunCommand = utils.RunCommand
RunCommand is utils.RunCommand. It was aliased for testing purposes.
var RunCommandWithRetry = func(cmd string) (output string, code int, err error) { var out []byte args := strings.Fields(cmd) if len(args) <= 1 { return "", 1, errors.New(fmt.Sprintf("too few arguments: expected at least 2, got %d", len(args))) } logger.Infof("Running: %s", cmd) for a := AttemptStrategy.Start(); a.Next(); { cmd := exec.Command(args[0], args[1:]...) out, err = CommandOutput(cmd) if err == nil { return string(out), 0, nil } exitError, ok := err.(*exec.ExitError) if !ok { err = errors.Annotatef(err, "unexpected error type %T", err) break } waitStatus, ok := ProcessStateSys(exitError.ProcessState).(exitStatuser) if !ok { err = errors.Annotatef(err, "unexpected process state type %T", exitError.ProcessState.Sys()) break } code = waitStatus.ExitStatus() if code != 100 { break } logger.Infof("Retrying: %s", cmd) } if err != nil { logger.Errorf("packaging command failed: %v; cmd: %q; output: %s", err, cmd, string(out)) return "", code, errors.Errorf("packaging command failed: %v", err) } return string(out), 0, nil }
RunCommandWithRetry is a helper function which tries to execute the given command. It tries to do so for 30 times with a 10 second sleep between commands. It returns the output of the command, the exit code, and an error, if one occurs, logging along the way. It was aliased for testing purposes.
Functions ¶
This section is empty.
Types ¶
type PackageManager ¶
type PackageManager interface { // InstallPrerequisite runs the command which installs the prerequisite // package which provides repository management functionalityes. InstallPrerequisite() error // Update runs the command to update the local package list. Update() error // Upgrade runs the command which issues an upgrade on all packages // with available newer versions. Upgrade() error // Install runs a *single* command that installs the given package(s). Install(packs ...string) error // Remove runs a *single* command that removes the given package(s). Remove(packs ...string) error // Purge runs the command that removes the given package(s) along // with any associated config files. Purge(packs ...string) error // Search runs the command that determines whether the given package is // available for installation from the currently configured repositories. Search(pack string) (bool, error) // IsInstalled runs the command which determines whether or not the // given package is currently installed on the system. IsInstalled(pack string) bool // AddRepository runs the command that adds a repository to the // list of available repositories. // NOTE: requires the prerequisite package whose installation command // is done by running InstallPrerequisite(). AddRepository(repo string) error // RemoveRepository runs the command that removes a given // repository from the list of available repositories. // NOTE: requires the prerequisite package whose installation command // is done by running InstallPrerequisite(). RemoveRepository(repo string) error // Cleanup runs the command that cleans up all orphaned packages, // left-over files and previously-cached packages. Cleanup() error // GetProxySettings returns the curretly-configured package manager proxy. GetProxySettings() (proxy.Settings, error) // SetProxy runs the commands to set the given proxy parameters for the // package management system. SetProxy(settings proxy.Settings) error }
PackageManager is the interface which carries out various package-management related work.
func NewAptPackageManager ¶
func NewAptPackageManager() PackageManager
NewAptPackageManager returns a PackageManager for apt-based systems.
func NewPackageManager ¶
func NewPackageManager(series string) (PackageManager, error)
NewPackageManager returns the appropriate PackageManager implementation based on the provided series.
func NewYumPackageManager ¶
func NewYumPackageManager() PackageManager
NewYumPackageManager returns a PackageManager for yum-based systems.
Directories ¶
Path | Synopsis |
---|---|
This package contains a mock implementation of the manager.PackageManager interface which always returns positive outcomes and a nil error.
|
This package contains a mock implementation of the manager.PackageManager interface which always returns positive outcomes and a nil error. |