func (s *dblogSuite) runUnitAgentTest(c *gc.C) bool { // Lease setup stuff, only needed when running a uniter. m, err := lease.NewLeaseManager(s.State) c.Assert(err, jc.ErrorIsNil) s.AddCleanup(func(c *gc.C) { m.Kill() c.Assert(m.Wait(), jc.ErrorIsNil) }) // Create a unit and an agent for it. u, password := s.Factory.MakeUnitReturningPassword(c, nil) s.PrimeAgent(c, u.Tag(), password, version.Current) logsCh, err := logsender.InstallBufferedLogWriter(1000) c.Assert(err, jc.ErrorIsNil) a := agentcmd.NewUnitAgent(nil, logsCh) s.InitAgent(c, a, "--unit-name", u.Name(), "--log-to-stderr=true") // Ensure there's no logs to begin with. c.Assert(s.getLogCount(c, u.Tag()), gc.Equals, 0) // Start the agent. go func() { c.Assert(a.Run(nil), jc.ErrorIsNil) }() defer a.Stop() return s.waitForLogs(c, u.Tag()) }
func (s *serviceSuite) SetUpTest(c *gc.C) { s.uniterSuite.SetUpTest(c) var err error s.apiService, err = s.uniter.Service(s.wordpressService.Tag().(names.ServiceTag)) c.Assert(err, jc.ErrorIsNil) m, err := lease.NewLeaseManager(s.State) c.Assert(err, jc.ErrorIsNil) s.AddCleanup(func(c *gc.C) { m.Kill() c.Assert(m.Wait(), jc.ErrorIsNil) }) }
func (ctx *context) run(c *gc.C, steps []stepper) { // We need this lest leadership calls block forever. lease, err := lease.NewLeaseManager(ctx.st) c.Assert(err, jc.ErrorIsNil) defer func() { lease.Kill() c.Assert(lease.Wait(), jc.ErrorIsNil) }() defer func() { if ctx.uniter != nil { err := ctx.uniter.Stop() c.Assert(err, jc.ErrorIsNil) } }() for i, s := range steps { c.Logf("step %d:\n", i) step(c, ctx, s) } }
func (s *leadershipSuite) SetUpTest(c *gc.C) { s.AgentSuite.SetUpTest(c) leaseManager, err := lease.NewLeaseManager(s.State) c.Assert(err, jc.ErrorIsNil) s.AddCleanup(func(c *gc.C) { leaseManager.Kill() c.Assert(leaseManager.Wait(), jc.ErrorIsNil) }) file, _ := ioutil.TempFile("", "juju-run") defer file.Close() s.AgentSuite.PatchValue(&agentcmd.JujuRun, file.Name()) agenttesting.InstallFakeEnsureMongo(s) s.PatchValue(&agentcmd.ProductionMongoWriteConcern, false) // Create a machine to manage the environment. stateServer, password := s.Factory.MakeMachineReturningPassword(c, &factory.MachineParams{ InstanceId: "id-1", Nonce: agent.BootstrapNonce, Jobs: []state.MachineJob{state.JobManageEnviron}, }) c.Assert(stateServer.PasswordValid(password), gc.Equals, true) c.Assert(stateServer.SetMongoPassword(password), jc.ErrorIsNil) // Create a machine to host some units. unitHostMachine := s.Factory.MakeMachine(c, &factory.MachineParams{ Nonce: agent.BootstrapNonce, Password: password, }) // Create a service and an instance of that service so that we can // create a client. service := s.Factory.MakeService(c, &factory.ServiceParams{}) s.serviceId = service.Tag().Id() unit := s.Factory.MakeUnit(c, &factory.UnitParams{Machine: unitHostMachine, Service: service}) s.unitId = unit.UnitTag().Id() c.Assert(unit.SetPassword(password), jc.ErrorIsNil) s.apiState = s.OpenAPIAs(c, unit.Tag(), password) // Tweak and write out the config file for the state server. writeStateAgentConfig( c, s.MongoInfo(c), s.DataDir(), stateServer.Tag(), s.State.EnvironTag(), password, version.Current, ) // Create & start a machine agent so the tests have something to call into. agentConf := agentcmd.NewAgentConf(s.DataDir()) machineAgentFactory := agentcmd.MachineAgentFactoryFn(agentConf, agentConf, nil, nil) s.machineAgent = machineAgentFactory(stateServer.Id()) // See comment in createMockJujudExecutable if runtime.GOOS == "windows" { dirToRemove := createMockJujudExecutable(c, s.DataDir(), s.machineAgent.Tag().String()) s.AddCleanup(func(*gc.C) { os.RemoveAll(dirToRemove) }) } c.Log("Starting machine agent...") go func() { err := s.machineAgent.Run(coretesting.Context(c)) c.Assert(err, jc.ErrorIsNil) }() }