func (t *localServerSuite) testStartInstanceAvailZoneOneConstrained(c *gc.C, runInstancesError *amzec2.Error) { env := t.Prepare(c) err := bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{}) c.Assert(err, jc.ErrorIsNil) mock := mockAvailabilityZoneAllocations{ result: []common.AvailabilityZoneInstances{ {ZoneName: "az1"}, {ZoneName: "az2"}, }, } t.PatchValue(ec2.AvailabilityZoneAllocations, mock.AvailabilityZoneAllocations) // The first call to RunInstances fails with an error indicating the AZ // is constrained. The second attempt succeeds, and so allocates to az2. var azArgs []string realRunInstances := *ec2.RunInstances t.PatchValue(ec2.RunInstances, func(e *amzec2.EC2, ri *amzec2.RunInstances) (*amzec2.RunInstancesResp, error) { azArgs = append(azArgs, ri.AvailZone) if len(azArgs) == 1 { return nil, runInstancesError } return realRunInstances(e, ri) }) inst, hwc := testing.AssertStartInstance(c, env, "1") c.Assert(azArgs, gc.DeepEquals, []string{"az1", "az2"}) c.Assert(ec2.InstanceEC2(inst).AvailZone, gc.Equals, "az2") c.Check(*hwc.AvailabilityZone, gc.Equals, "az2") }
func (t *localServerSuite) TestStartInstanceDistribution(c *gc.C) { env := t.Prepare(c) err := bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{}) c.Assert(err, jc.ErrorIsNil) // test-available is the only available AZ, so AvailabilityZoneAllocations // is guaranteed to return that. inst, _ := testing.AssertStartInstance(c, env, "1") c.Assert(ec2.InstanceEC2(inst).AvailZone, gc.Equals, "test-available") }
func (t *localServerSuite) TestStartInstanceDistribution(c *gc.C) { env := t.Prepare(c) envtesting.UploadFakeTools(c, env.Storage()) err := bootstrap.Bootstrap(coretesting.Context(c), env, environs.BootstrapParams{}) c.Assert(err, gc.IsNil) // test-available is the only available AZ, so BestAvailabilityZoneAllocations // is guaranteed to return that. inst, _ := testing.AssertStartInstance(c, env, "1") c.Assert(ec2.InstanceEC2(inst).AvailZone, gc.Equals, "test-available") }
func (t *LiveTests) TestStartInstanceConstraints(c *gc.C) { cons := constraints.MustParse("mem=2G") inst, hc := testing.AssertStartInstanceWithConstraints(c, t.Env, "30", cons) defer t.Env.StopInstances(inst.Id()) ec2inst := ec2.InstanceEC2(inst) c.Assert(ec2inst.InstanceType, gc.Equals, "m1.medium") c.Assert(*hc.Arch, gc.Equals, "amd64") c.Assert(*hc.Mem, gc.Equals, uint64(3840)) c.Assert(*hc.RootDisk, gc.Equals, uint64(8192)) c.Assert(*hc.CpuCores, gc.Equals, uint64(1)) c.Assert(*hc.CpuPower, gc.Equals, uint64(200)) }
func (t *LiveTests) TestStartInstanceConstraints(c *gc.C) { t.PrepareOnce(c) cons := constraints.MustParse("mem=4G") inst, hc := testing.AssertStartInstanceWithConstraints(c, t.Env, t.ControllerUUID, "30", cons) defer t.Env.StopInstances(inst.Id()) ec2inst := ec2.InstanceEC2(inst) c.Assert(ec2inst.InstanceType, gc.Equals, "m4.large") c.Assert(*hc.Arch, gc.Equals, "amd64") c.Assert(*hc.Mem, gc.Equals, uint64(8*1024)) c.Assert(*hc.RootDisk, gc.Equals, uint64(8*1024)) c.Assert(*hc.CpuCores, gc.Equals, uint64(2)) }
func (t *localServerSuite) TestInstanceTags(c *gc.C) { env := t.Prepare(c) err := bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{}) c.Assert(err, jc.ErrorIsNil) instances, err := env.AllInstances() c.Assert(err, jc.ErrorIsNil) c.Assert(instances, gc.HasLen, 1) ec2Inst := ec2.InstanceEC2(instances[0]) c.Assert(ec2Inst.Tags, jc.SameContents, []amzec2.Tag{ {"Name", "juju-sample-machine-0"}, {"juju-env-uuid", coretesting.EnvironmentTag.Id()}, {"juju-is-state", "true"}, }) }
func (t *LiveTests) TestInstanceAttributes(c *gc.C) { inst, hc := testing.AssertStartInstance(c, t.Env, "30") defer t.Env.StopInstances(inst.Id()) // Sanity check for hardware characteristics. c.Assert(hc.Arch, gc.NotNil) c.Assert(hc.Mem, gc.NotNil) c.Assert(hc.RootDisk, gc.NotNil) c.Assert(hc.CpuCores, gc.NotNil) c.Assert(hc.CpuPower, gc.NotNil) addresses, err := jujutesting.WaitInstanceAddresses(t.Env, inst.Id()) // TODO(niemeyer): This assert sometimes fails with "no instances found" c.Assert(err, gc.IsNil) c.Assert(addresses, gc.Not(gc.HasLen), 0) insts, err := t.Env.Instances([]instance.Id{inst.Id()}) c.Assert(err, gc.IsNil) c.Assert(len(insts), gc.Equals, 1) ec2inst := ec2.InstanceEC2(insts[0]) c.Assert(ec2inst.DNSName, gc.Equals, addresses[0].Value) c.Assert(ec2inst.InstanceType, gc.Equals, "m1.small") }
func (t *localServerSuite) TestStartInstanceAvailZone(c *gc.C) { inst, err := t.testStartInstanceAvailZone(c, "test-available") c.Assert(err, jc.ErrorIsNil) c.Assert(ec2.InstanceEC2(inst).AvailZone, gc.Equals, "test-available") }