~rogpeppe/juju-core/themue-058-debug-log-api

« back to all changes in this revision

Viewing changes to cmd/jujud/machine_test.go

  • Committer: Frank Mueller
  • Date: 2014-01-21 08:46:24 UTC
  • mfrom: (2152.1.76 juju-core)
  • Revision ID: frank.mueller@canonical.com-20140121084624-rv32dv6ufzul9h1b
debugger: merged trunk and added access to debugger API facade

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
        "launchpad.net/juju-core/state/api"
27
27
        apideployer "launchpad.net/juju-core/state/api/deployer"
28
28
        "launchpad.net/juju-core/state/api/params"
 
29
        charmtesting "launchpad.net/juju-core/state/apiserver/charmrevisionupdater/testing"
29
30
        statetesting "launchpad.net/juju-core/state/testing"
30
31
        "launchpad.net/juju-core/state/watcher"
31
32
        coretesting "launchpad.net/juju-core/testing"
693
694
        _, err = os.Stat(ac.DataDir())
694
695
        c.Assert(err, jc.Satisfies, os.IsNotExist)
695
696
}
 
697
 
 
698
// MachineWithCharmsSuite provides infrastructure for tests which need to
 
699
// work with charms.
 
700
type MachineWithCharmsSuite struct {
 
701
        charmtesting.CharmSuite
 
702
 
 
703
        machine *state.Machine
 
704
}
 
705
 
 
706
var _ = gc.Suite(&MachineWithCharmsSuite{})
 
707
 
 
708
func (s *MachineWithCharmsSuite) SetUpTest(c *gc.C) {
 
709
        s.CharmSuite.SetUpTest(c)
 
710
 
 
711
        // Create a state server machine.
 
712
        var err error
 
713
        s.machine, err = s.State.AddOneMachine(state.MachineTemplate{
 
714
                Series:     "quantal",
 
715
                InstanceId: "ardbeg-0",
 
716
                Nonce:      state.BootstrapNonce,
 
717
                Jobs:       []state.MachineJob{state.JobManageState},
 
718
        })
 
719
        c.Assert(err, gc.IsNil)
 
720
        err = s.machine.SetPassword(initialMachinePassword)
 
721
        c.Assert(err, gc.IsNil)
 
722
        tag := names.MachineTag(s.machine.Id())
 
723
        err = s.machine.SetMongoPassword(initialMachinePassword)
 
724
        c.Assert(err, gc.IsNil)
 
725
 
 
726
        // Set up the agent configuration.
 
727
        stateInfo := s.StateInfo(c)
 
728
        writeStateAgentConfig(c, stateInfo, s.DataDir(), tag, initialMachinePassword)
 
729
}
 
730
 
 
731
func (s *MachineWithCharmsSuite) TestManageStateRunsCharmRevisionUpdater(c *gc.C) {
 
732
        s.SetupScenario(c)
 
733
 
 
734
        // Start the machine agent.
 
735
        a := &MachineAgent{}
 
736
        args := []string{"--data-dir", s.DataDir(), "--machine-id", s.machine.Id()}
 
737
        err := coretesting.InitCommand(a, args)
 
738
        c.Assert(err, gc.IsNil)
 
739
 
 
740
        go func() {
 
741
                c.Check(a.Run(nil), gc.IsNil)
 
742
        }()
 
743
        defer func() { c.Check(a.Stop(), gc.IsNil) }()
 
744
 
 
745
        checkRevision := func() bool {
 
746
                curl := charm.MustParseURL("cs:quantal/mysql")
 
747
                placeholder, err := s.State.LatestPlaceholderCharm(curl)
 
748
                return err == nil && placeholder.String() == curl.WithRevision(23).String()
 
749
        }
 
750
        success := false
 
751
        for attempt := coretesting.LongAttempt.Start(); attempt.Next(); {
 
752
                if success = checkRevision(); success {
 
753
                        break
 
754
                }
 
755
        }
 
756
        c.Assert(success, gc.Equals, true)
 
757
}