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() }
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) }
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) }
func (s *AptSuite) SetUpSuite(c *gc.C) { s.IsolationSuite.SetUpSuite(c) s.paccmder = commands.NewAptPackageCommander() s.pacman = manager.NewAptPackageManager() }
// 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()
func (s *ManagerSuite) SetUpSuite(c *gc.C) { s.IsolationSuite.SetUpSuite(c) s.apt = manager.NewAptPackageManager() s.yum = manager.NewYumPackageManager() }