示例#1
0
func updateDistroInfo() error {
	pm := manager.NewAptPackageManager()
	if err := pm.Update(); err != nil {
		return errors.Annotate(err, "updating package list")
	}
	if err := pm.Install("distro-info"); err != nil {
		return errors.Annotate(err, "updating distro-info package")
	}
	return series.UpdateSeriesVersions()
}
示例#2
0
func (s *UtilsSuite) TestRunCommandWithRetryStopsWithFatalError(c *gc.C) {
	const minRetries = 3
	var calls int
	state := os.ProcessState{}
	cmdError := &exec.ExitError{ProcessState: &state}
	s.PatchValue(&manager.AttemptStrategy, utils.AttemptStrategy{Min: minRetries})
	s.PatchValue(&manager.ProcessStateSys, func(*os.ProcessState) interface{} {
		return mockExitStatuser(100) // retry each time.
	})
	s.PatchValue(&manager.CommandOutput, func(cmd *exec.Cmd) ([]byte, error) {
		calls++
		cmdOutput := fmt.Sprintf("Reading state information...\nE: Unable to locate package %s",

			testedPackageName)
		return []byte(cmdOutput), cmdError
	})

	apt := manager.NewAptPackageManager()
	err := apt.Install(testedPackageName)
	c.Check(err, gc.ErrorMatches, "packaging command failed: encountered fatal error: unable to locate package")
	c.Check(calls, gc.Equals, 1)
}
示例#3
0
func (s *UtilsSuite) TestRunCommandWithRetryDoesNotCallCombinedOutputTwice(c *gc.C) {
	const minRetries = 3
	var calls int
	state := os.ProcessState{}
	cmdError := &exec.ExitError{ProcessState: &state}
	s.PatchValue(&manager.AttemptStrategy, utils.AttemptStrategy{Min: minRetries})
	s.PatchValue(&manager.ProcessStateSys, func(*os.ProcessState) interface{} {
		return mockExitStatuser(100) // retry each time.
	})
	s.PatchValue(&manager.CommandOutput, func(cmd *exec.Cmd) ([]byte, error) {
		calls++
		// Replace the command path and args so it's a no-op.
		cmd.Path = ""
		cmd.Args = []string{"version"}
		// Call the real cmd.CombinedOutput to simulate better what
		// happens in production. See also http://pad.lv/1394524.
		output, err := cmd.CombinedOutput()
		if _, ok := err.(*exec.Error); err != nil && !ok {
			c.Check(err, gc.ErrorMatches, "exec: Stdout already set")
			c.Fatalf("CommandOutput called twice unexpectedly")
		}
		return output, cmdError
	})

	apt := manager.NewAptPackageManager()

	err := apt.Install(testedPackageName)
	c.Check(err, gc.ErrorMatches, "packaging command failed: exit status.*")
	c.Check(calls, gc.Equals, minRetries)

	// reset calls and re-test for Yum calls:
	calls = 0
	yum := manager.NewYumPackageManager()
	err = yum.Install(testedPackageName)
	c.Check(err, gc.ErrorMatches, "packaging command failed: exit status.*")
	c.Check(calls, gc.Equals, minRetries)
}
示例#4
0
文件: apt_test.go 项目: juju/utils
func (s *AptSuite) SetUpSuite(c *gc.C) {
	s.IsolationSuite.SetUpSuite(c)
	s.paccmder = commands.NewAptPackageCommander()
	s.pacman = manager.NewAptPackageManager()
}
示例#5
0
// Copyright 2015 Canonical Ltd.
// Copyright 2015 Cloudbase Solutions SRL
// Licensed under the LGPLv3, see LICENCE file for details.

package manager_test

import (
	"github.com/juju/utils/packaging/manager"
)

var _ manager.PackageManager = manager.NewAptPackageManager()
var _ manager.PackageManager = manager.NewYumPackageManager()
示例#6
0
func (s *ManagerSuite) SetUpSuite(c *gc.C) {
	s.IsolationSuite.SetUpSuite(c)
	s.apt = manager.NewAptPackageManager()
	s.yum = manager.NewYumPackageManager()
}