func (s *machineConfigSuite) TestMachineConfig(c *gc.C) { addrs := []instance.Address{instance.NewAddress("1.2.3.4", instance.NetworkUnknown)} hc := instance.MustParseHardware("mem=4G arch=amd64") apiParams := params.AddMachineParams{ Jobs: []params.MachineJob{params.JobHostUnits}, InstanceId: instance.Id("1234"), Nonce: "foo", HardwareCharacteristics: hc, Addrs: addrs, } machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams}) c.Assert(err, gc.IsNil) c.Assert(len(machines), gc.Equals, 1) machineId := machines[0].Machine machineConfig, err := client.MachineConfig(s.State, machineId, apiParams.Nonce, "") c.Assert(err, gc.IsNil) envConfig, err := s.State.EnvironConfig() c.Assert(err, gc.IsNil) env, err := environs.New(envConfig) c.Assert(err, gc.IsNil) stateInfo, apiInfo, err := env.StateInfo() c.Assert(err, gc.IsNil) c.Check(machineConfig.StateInfo.Addrs, gc.DeepEquals, stateInfo.Addrs) c.Check(machineConfig.APIInfo.Addrs, gc.DeepEquals, apiInfo.Addrs) c.Assert(machineConfig.Tools.URL, gc.Not(gc.Equals), "") }
func (s *firewallerSuite) TestInstanceId(c *gc.C) { // Provision 2 machines first. err := s.machines[0].SetProvisioned("i-am", "fake_nonce", nil) c.Assert(err, gc.IsNil) hwChars := instance.MustParseHardware("arch=i386", "mem=4G") err = s.machines[1].SetProvisioned("i-am-not", "fake_nonce", &hwChars) c.Assert(err, gc.IsNil) args := addFakeEntities(params.Entities{Entities: []params.Entity{ {Tag: s.machines[0].Tag()}, {Tag: s.machines[1].Tag()}, {Tag: s.machines[2].Tag()}, {Tag: s.service.Tag()}, {Tag: s.units[2].Tag()}, }}) result, err := s.firewaller.InstanceId(args) c.Assert(err, gc.IsNil) c.Assert(result, jc.DeepEquals, params.StringResults{ Results: []params.StringResult{ {Result: "i-am"}, {Result: "i-am-not"}, {Error: apiservertesting.NotProvisionedError("2")}, {Error: apiservertesting.ErrUnauthorized}, {Error: apiservertesting.ErrUnauthorized}, {Error: apiservertesting.NotFoundError("machine 42")}, {Error: apiservertesting.ErrUnauthorized}, {Error: apiservertesting.ErrUnauthorized}, {Error: apiservertesting.ErrUnauthorized}, {Error: apiservertesting.ErrUnauthorized}, {Error: apiservertesting.ErrUnauthorized}, }, }) }
func (s *BootstrapSuite) TestInitializeEnvironment(c *gc.C) { hw := instance.MustParseHardware("arch=amd64 mem=8G") machConf, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.envcfg, "--instance-id", string(s.instanceId), "--hardware", hw.String()) c.Assert(err, gc.IsNil) err = cmd.Run(nil) c.Assert(err, gc.IsNil) 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) expectInfo, exists := machConf.StateServingInfo() c.Assert(exists, jc.IsTrue) c.Assert(expectInfo.SharedSecret, gc.Equals, "") servingInfo := s.fakeEnsureMongo.info c.Assert(len(servingInfo.SharedSecret), gc.Not(gc.Equals), 0) servingInfo.SharedSecret = "" c.Assert(servingInfo, jc.DeepEquals, expectInfo) 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(&state.Info{ Addrs: []string{testing.MgoServer.Addr()}, CACert: testing.CACert, Password: testPasswordHash(), }, state.DefaultDialOpts(), environs.NewStatePolicy()) c.Assert(err, gc.IsNil) defer st.Close() machines, err := st.AllMachines() c.Assert(err, gc.IsNil) c.Assert(machines, gc.HasLen, 1) instid, err := machines[0].InstanceId() c.Assert(err, gc.IsNil) c.Assert(instid, gc.Equals, instance.Id(string(s.instanceId))) stateHw, err := machines[0].HardwareCharacteristics() c.Assert(err, gc.IsNil) c.Assert(stateHw, gc.NotNil) c.Assert(*stateHw, gc.DeepEquals, hw) cons, err := st.EnvironConstraints() c.Assert(err, gc.IsNil) c.Assert(&cons, jc.Satisfies, constraints.IsEmpty) }
func (s *machineConfigSuite) TestMachineConfigNoTools(c *gc.C) { s.PatchValue(&envtools.DefaultBaseURL, "") addrs := []instance.Address{instance.NewAddress("1.2.3.4", instance.NetworkUnknown)} hc := instance.MustParseHardware("mem=4G arch=amd64") apiParams := params.AddMachineParams{ Series: "quantal", Jobs: []params.MachineJob{params.JobHostUnits}, InstanceId: instance.Id("1234"), Nonce: "foo", HardwareCharacteristics: hc, Addrs: addrs, } machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams}) c.Assert(err, gc.IsNil) _, err = client.MachineConfig(s.State, machines[0].Machine, apiParams.Nonce, "") c.Assert(err, gc.ErrorMatches, coretools.ErrNoMatches.Error()) }
expectedConfig: map[string]interface{}{"name": "banana"}, }, { input: []string{ "--env-config", base64.StdEncoding.EncodeToString([]byte("name: banana\n")), "--instance-id", "anything", "--hardware", "nonsense", }, err: `invalid value "nonsense" for flag --hardware: malformed characteristic "nonsense"`, }, { input: []string{ "--env-config", base64.StdEncoding.EncodeToString([]byte("name: banana\n")), "--instance-id", "anything", "--hardware", "arch=amd64 cpu-cores=4 root-disk=2T", }, expectedInstanceId: "anything", expectedHardware: instance.MustParseHardware("arch=amd64 cpu-cores=4 root-disk=2T"), expectedConfig: map[string]interface{}{"name": "banana"}, }, } func (s *BootstrapSuite) TestBootstrapArgs(c *gc.C) { for i, t := range bootstrapArgTests { c.Logf("test %d", i) var args []string args = append(args, t.input...) _, cmd, err := s.initBootstrapCommand(c, nil, args...) if t.err == "" { c.Assert(cmd, gc.NotNil) c.Assert(err, gc.IsNil) c.Assert(cmd.EnvConfig, gc.DeepEquals, t.expectedConfig) c.Assert(cmd.InstanceId, gc.Equals, t.expectedInstanceId)