func (s *provisionerSuite) TestProvisioningScript(c *gc.C) { const series = "precise" const arch = "amd64" defer fakeSSH{ Series: series, Arch: arch, InitUbuntuUser: true, }.install(c).Restore() machineId, err := manual.ProvisionMachine(s.getArgs(c)) c.Assert(err, gc.IsNil) mcfg, err := client.MachineConfig(s.State, machineId, state.BootstrapNonce, "/var/lib/juju") c.Assert(err, gc.IsNil) script, err := manual.ProvisioningScript(mcfg) c.Assert(err, gc.IsNil) cloudcfg := coreCloudinit.New() err = cloudinit.ConfigureJuju(mcfg, cloudcfg) c.Assert(err, gc.IsNil) cloudcfg.SetAptUpgrade(false) sshinitScript, err := sshinit.ConfigureScript(cloudcfg) c.Assert(err, gc.IsNil) removeLogFile := "rm -f '/var/log/cloud-init-output.log'\n" expectedScript := removeLogFile + shell.DumpFileOnErrorScript("/var/log/cloud-init-output.log") + sshinitScript c.Assert(script, gc.Equals, expectedScript) }
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 *machineConfigSuite) TestMachineConfigNoArch(c *gc.C) { apiParams := params.AddMachineParams{ Jobs: []params.MachineJob{params.JobHostUnits}, InstanceId: instance.Id("1234"), Nonce: "foo", } machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams}) c.Assert(err, gc.IsNil) c.Assert(len(machines), gc.Equals, 1) _, err = client.MachineConfig(s.State, machines[0].Machine, apiParams.Nonce, "") c.Assert(err, gc.ErrorMatches, fmt.Sprintf("arch is not set for %q", "machine-"+machines[0].Machine)) }
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()) }
func (s *provisionerSuite) TestFinishMachineConfig(c *gc.C) { const series = "precise" const arch = "amd64" defer fakeSSH{ Series: series, Arch: arch, InitUbuntuUser: true, }.install(c).Restore() machineId, err := manual.ProvisionMachine(s.getArgs(c)) c.Assert(err, gc.IsNil) // Now check what we would've configured it with. mcfg, err := client.MachineConfig(s.State, machineId, state.BootstrapNonce, "/var/lib/juju") c.Assert(err, gc.IsNil) c.Check(mcfg, gc.NotNil) c.Check(mcfg.APIInfo, gc.NotNil) c.Check(mcfg.StateInfo, gc.NotNil) stateInfo, apiInfo, err := s.APIConn.Environ.StateInfo() c.Assert(err, gc.IsNil) c.Check(mcfg.APIInfo.Addrs, gc.DeepEquals, apiInfo.Addrs) c.Check(mcfg.StateInfo.Addrs, gc.DeepEquals, stateInfo.Addrs) }