func (s *UnitSuite) TestChangeConfig(c *gc.C) { config := FakeAgentConfig{} configChanged := voyeur.NewValue(true) a := UnitAgent{ AgentConf: config, configChangedVal: configChanged, } var mutateCalled bool mutate := func(config agent.ConfigSetter) error { mutateCalled = true return nil } configChangedCh := make(chan bool) watcher := configChanged.Watch() watcher.Next() // consume initial event go func() { configChangedCh <- watcher.Next() }() err := a.ChangeConfig(mutate) c.Assert(err, jc.ErrorIsNil) c.Check(mutateCalled, jc.IsTrue) select { case result := <-configChangedCh: c.Check(result, jc.IsTrue) case <-time.After(coretesting.LongWait): c.Fatal("timed out waiting for config changed signal") } }
// NewUnitAgent creates a new UnitAgent value properly initialized. func NewUnitAgent(ctx *cmd.Context, bufferedLogs logsender.LogRecordCh) *UnitAgent { return &UnitAgent{ AgentConf: NewAgentConf(""), configChangedVal: voyeur.NewValue(true), ctx: ctx, initialUpgradeCheckComplete: make(chan struct{}), bufferedLogs: bufferedLogs, } }
func (s *ManifoldSuite) SetUpTest(c *gc.C) { s.IsolationSuite.SetUpTest(c) s.agent = new(mockAgent) s.context = dt.StubContext(nil, map[string]interface{}{ "agent": s.agent, }) s.agentConfigChanged = voyeur.NewValue(0) s.manifold = apiconfigwatcher.Manifold(apiconfigwatcher.ManifoldConfig{ AgentName: "agent", AgentConfigChanged: s.agentConfigChanged, }) }
func (s *ManifoldSuite) SetUpTest(c *gc.C) { s.IsolationSuite.SetUpTest(c) s.agent = new(mockAgent) s.agent.conf.setStateServingInfo(true) s.agent.conf.tag = names.NewMachineTag("99") s.goodContext = dt.StubContext(nil, map[string]interface{}{ "agent": s.agent, }) s.agentConfigChanged = voyeur.NewValue(0) s.manifold = stateconfigwatcher.Manifold(stateconfigwatcher.ManifoldConfig{ AgentName: "agent", AgentConfigChanged: s.agentConfigChanged, }) }
func (s *ManifoldSuite) SetUpTest(c *gc.C) { s.IsolationSuite.SetUpTest(c) s.agent = new(mockAgent) s.agent.conf.setStateServingInfo(true) s.agent.conf.tag = names.NewMachineTag("99") s.goodGetResource = dt.StubGetResource(dt.StubResources{ "agent": dt.StubResource{Output: s.agent}, }) s.agentConfigChanged = voyeur.NewValue(0) s.manifold = stateconfigwatcher.Manifold(stateconfigwatcher.ManifoldConfig{ AgentName: "agent", AgentConfigChanged: s.agentConfigChanged, }) }
// NewMachineAgent instantiates a new MachineAgent. func NewMachineAgent( machineId string, agentConfWriter AgentConfigWriter, bufferedLogs logsender.LogRecordCh, runner worker.Runner, loopDeviceManager looputil.LoopDeviceManager, rootDir string, ) *MachineAgent { return &MachineAgent{ machineId: machineId, AgentConfigWriter: agentConfWriter, configChangedVal: voyeur.NewValue(true), bufferedLogs: bufferedLogs, workersStarted: make(chan struct{}), runner: runner, rootDir: rootDir, initialUpgradeCheckComplete: gate.NewLock(), loopDeviceManager: loopDeviceManager, } }