// TODO(mjs) - the following should maybe be part of AgentSuite func (s *upgradeSuite) configureMachine(c *gc.C, machineId string, vers version.Binary) ( machine *state.Machine, agentConfig agent.ConfigSetterWriter, tools *tools.Tools, ) { m, err := s.State.Machine(machineId) c.Assert(err, jc.ErrorIsNil) // Provision the machine if it isn't already if _, err := m.InstanceId(); err != nil { inst, md := jujutesting.AssertStartInstance(c, s.Environ, s.ControllerConfig.ControllerUUID(), machineId) c.Assert(m.SetProvisioned(inst.Id(), agent.BootstrapNonce, md), jc.ErrorIsNil) } // Make the machine live pinger, err := m.SetAgentPresence() c.Assert(err, jc.ErrorIsNil) s.AddCleanup(func(c *gc.C) { pinger.Stop() }) // Set up the new machine. err = m.SetAgentVersion(vers) c.Assert(err, jc.ErrorIsNil) err = m.SetPassword(initialMachinePassword) c.Assert(err, jc.ErrorIsNil) tag := m.Tag() if m.IsManager() { err = m.SetMongoPassword(initialMachinePassword) c.Assert(err, jc.ErrorIsNil) agentConfig, tools = s.PrimeStateAgentVersion(c, tag, initialMachinePassword, vers) info, ok := agentConfig.StateServingInfo() c.Assert(ok, jc.IsTrue) ssi := cmdutil.ParamsStateServingInfoToStateStateServingInfo(info) err = s.State.SetStateServingInfo(ssi) c.Assert(err, jc.ErrorIsNil) } else { agentConfig, tools = s.PrimeAgentVersion(c, tag, initialMachinePassword, vers) } err = agentConfig.Write() c.Assert(err, jc.ErrorIsNil) return m, agentConfig, tools }
func (s *commonMachineSuite) configureMachine(c *gc.C, machineId string, vers version.Binary) ( machine *state.Machine, agentConfig agent.ConfigSetterWriter, tools *tools.Tools, ) { m, err := s.State.Machine(machineId) c.Assert(err, jc.ErrorIsNil) // Add a machine and ensure it is provisioned. inst, md := jujutesting.AssertStartInstance(c, s.Environ, s.ControllerConfig.ControllerUUID(), machineId) c.Assert(m.SetProvisioned(inst.Id(), agent.BootstrapNonce, md), jc.ErrorIsNil) // Add an address for the tests in case the initiateMongoServer // codepath is exercised. s.setFakeMachineAddresses(c, m) // Set up the new machine. err = m.SetAgentVersion(vers) c.Assert(err, jc.ErrorIsNil) err = m.SetPassword(initialMachinePassword) c.Assert(err, jc.ErrorIsNil) tag := m.Tag() if m.IsManager() { err = m.SetMongoPassword(initialMachinePassword) c.Assert(err, jc.ErrorIsNil) agentConfig, tools = s.PrimeStateAgentVersion(c, tag, initialMachinePassword, vers) info, ok := agentConfig.StateServingInfo() c.Assert(ok, jc.IsTrue) ssi := cmdutil.ParamsStateServingInfoToStateStateServingInfo(info) err = s.State.SetStateServingInfo(ssi) c.Assert(err, jc.ErrorIsNil) } else { agentConfig, tools = s.PrimeAgentVersion(c, tag, initialMachinePassword, vers) } err = agentConfig.Write() c.Assert(err, jc.ErrorIsNil) return m, agentConfig, tools }
func (s *BootstrapSuite) TestInitializeEnvironment(c *gc.C) { hw := instance.MustParseHardware("arch=amd64 mem=8G") machConf, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.b64yamlEnvcfg, "--instance-id", string(s.instanceId), "--hardware", hw.String()) c.Assert(err, jc.ErrorIsNil) err = cmd.Run(nil) c.Assert(err, jc.ErrorIsNil) c.Assert(s.fakeEnsureMongo.DataDir, gc.Equals, s.dataDir) c.Assert(s.fakeEnsureMongo.InitiateCount, gc.Equals, 1) c.Assert(s.fakeEnsureMongo.EnsureCount, gc.Equals, 1) c.Assert(s.fakeEnsureMongo.DataDir, gc.Equals, s.dataDir) c.Assert(s.fakeEnsureMongo.OplogSize, gc.Equals, 1234) expectInfo, exists := machConf.StateServingInfo() c.Assert(exists, jc.IsTrue) c.Assert(expectInfo.SharedSecret, gc.Equals, "") c.Assert(expectInfo.SystemIdentity, gc.Equals, "") servingInfo := s.fakeEnsureMongo.Info c.Assert(len(servingInfo.SharedSecret), gc.Not(gc.Equals), 0) c.Assert(len(servingInfo.SystemIdentity), gc.Not(gc.Equals), 0) servingInfo.SharedSecret = "" servingInfo.SystemIdentity = "" expect := cmdutil.ParamsStateServingInfoToStateStateServingInfo(expectInfo) c.Assert(servingInfo, jc.DeepEquals, expect) expectDialAddrs := []string{fmt.Sprintf("127.0.0.1:%d", expectInfo.StatePort)} gotDialAddrs := s.fakeEnsureMongo.InitiateParams.DialInfo.Addrs c.Assert(gotDialAddrs, gc.DeepEquals, expectDialAddrs) memberHost := fmt.Sprintf("%s:%d", s.bootstrapName, expectInfo.StatePort) c.Assert(s.fakeEnsureMongo.InitiateParams.MemberHostPort, gc.Equals, memberHost) c.Assert(s.fakeEnsureMongo.InitiateParams.User, gc.Equals, "") c.Assert(s.fakeEnsureMongo.InitiateParams.Password, gc.Equals, "") st, err := state.Open(testing.EnvironmentTag, &mongo.MongoInfo{ Info: mongo.Info{ Addrs: []string{gitjujutesting.MgoServer.Addr()}, CACert: testing.CACert, }, Password: testPasswordHash(), }, mongo.DefaultDialOpts(), environs.NewStatePolicy()) c.Assert(err, jc.ErrorIsNil) defer st.Close() machines, err := st.AllMachines() c.Assert(err, jc.ErrorIsNil) c.Assert(machines, gc.HasLen, 1) instid, err := machines[0].InstanceId() c.Assert(err, jc.ErrorIsNil) c.Assert(instid, gc.Equals, instance.Id(string(s.instanceId))) stateHw, err := machines[0].HardwareCharacteristics() c.Assert(err, jc.ErrorIsNil) c.Assert(stateHw, gc.NotNil) c.Assert(*stateHw, gc.DeepEquals, hw) cons, err := st.EnvironConstraints() c.Assert(err, jc.ErrorIsNil) c.Assert(&cons, jc.Satisfies, constraints.IsEmpty) cfg, err := st.EnvironConfig() c.Assert(err, jc.ErrorIsNil) c.Assert(cfg.AuthorizedKeys(), gc.Equals, s.envcfg.AuthorizedKeys()+"\npublic-key") }