github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/cmd/jujud/agent/machine_charms_test.go (about) 1 // Copyright 2012-2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package agent 5 6 import ( 7 jc "github.com/juju/testing/checkers" 8 gc "gopkg.in/check.v1" 9 "gopkg.in/juju/charm.v6" 10 11 charmtesting "github.com/juju/juju/apiserver/facades/controller/charmrevisionupdater/testing" 12 "github.com/juju/juju/controller" 13 "github.com/juju/juju/state" 14 coretesting "github.com/juju/juju/testing" 15 ) 16 17 // MachineWithCharmsSuite provides infrastructure for tests which need to 18 // work with charms. 19 type MachineWithCharmsSuite struct { 20 commonMachineSuite 21 charmtesting.CharmSuite 22 23 machine *state.Machine 24 } 25 26 var _ = gc.Suite(&MachineWithCharmsSuite{}) 27 28 func (s *MachineWithCharmsSuite) SetUpSuite(c *gc.C) { 29 s.commonMachineSuite.SetUpSuite(c) 30 s.CharmSuite.SetUpSuite(c, &s.commonMachineSuite.JujuConnSuite) 31 } 32 33 func (s *MachineWithCharmsSuite) TearDownSuite(c *gc.C) { 34 s.CharmSuite.TearDownSuite(c) 35 s.commonMachineSuite.TearDownSuite(c) 36 } 37 38 func (s *MachineWithCharmsSuite) SetUpTest(c *gc.C) { 39 s.ControllerConfigAttrs = map[string]interface{}{ 40 // TODO(raftlease): setting this temporarily until the startup 41 // issue is resolved. 42 controller.Features: []interface{}{"legacy-leases"}, 43 } 44 s.commonMachineSuite.SetUpTest(c) 45 s.CharmSuite.SetUpTest(c) 46 } 47 48 func (s *MachineWithCharmsSuite) TearDownTest(c *gc.C) { 49 s.CharmSuite.TearDownTest(c) 50 s.commonMachineSuite.TearDownTest(c) 51 } 52 53 func (s *MachineWithCharmsSuite) TestManageModelRunsCharmRevisionUpdater(c *gc.C) { 54 m, _, _ := s.primeAgent(c, state.JobManageModel) 55 56 s.SetupScenario(c) 57 58 a := s.newAgent(c, m) 59 go func() { 60 c.Check(a.Run(nil), jc.ErrorIsNil) 61 }() 62 defer func() { c.Check(a.Stop(), jc.ErrorIsNil) }() 63 64 checkRevision := func() bool { 65 curl := charm.MustParseURL("cs:quantal/mysql") 66 placeholder, err := s.State.LatestPlaceholderCharm(curl) 67 return err == nil && placeholder.String() == curl.WithRevision(23).String() 68 } 69 success := false 70 for attempt := coretesting.LongAttempt.Start(); attempt.Next(); { 71 if success = checkRevision(); success { 72 break 73 } 74 } 75 c.Assert(success, jc.IsTrue) 76 }