Ejemplo n.º 1
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)
}
Ejemplo n.º 2
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()
Ejemplo n.º 3
0
func (s *YumSuite) SetUpSuite(c *gc.C) {
	s.IsolationSuite.SetUpSuite(c)
	s.paccmder = commands.NewYumPackageCommander()
	s.pacman = manager.NewYumPackageManager()
}
Ejemplo n.º 4
0
func (s *ManagerSuite) SetUpSuite(c *gc.C) {
	s.IsolationSuite.SetUpSuite(c)
	s.apt = manager.NewAptPackageManager()
	s.yum = manager.NewYumPackageManager()
}