// TestStartStop is similar to Tests.TestStartStop except // that it does not assume a pristine environment. func (t *LiveTests) TestStartStop(c *gc.C) { t.PrepareOnce(c) t.UploadFakeTools(c, t.Env.Storage()) inst, _ := testing.AssertStartInstance(c, t.Env, "0") c.Assert(inst, gc.NotNil) id0 := inst.Id() insts, err := t.Env.Instances([]instance.Id{id0, id0}) c.Assert(err, gc.IsNil) c.Assert(insts, gc.HasLen, 2) c.Assert(insts[0].Id(), gc.Equals, id0) c.Assert(insts[1].Id(), gc.Equals, id0) // Asserting on the return of AllInstances makes the test fragile, // as even comparing the before and after start values can be thrown // off if other instances have been created or destroyed in the same // time frame. Instead, just check the instance we created exists. insts, err = t.Env.AllInstances() c.Assert(err, gc.IsNil) found := false for _, inst := range insts { if inst.Id() == id0 { c.Assert(found, gc.Equals, false, gc.Commentf("%v", insts)) found = true } } c.Assert(found, gc.Equals, true, gc.Commentf("expected %v in %v", inst, insts)) addresses, err := jujutesting.WaitInstanceAddresses(t.Env, inst.Id()) c.Assert(err, gc.IsNil) c.Assert(addresses, gc.Not(gc.HasLen), 0) insts, err = t.Env.Instances([]instance.Id{id0, ""}) c.Assert(err, gc.Equals, environs.ErrPartialInstances) c.Assert(insts, gc.HasLen, 2) c.Check(insts[0].Id(), gc.Equals, id0) c.Check(insts[1], gc.IsNil) err = t.Env.StopInstances(inst.Id()) c.Assert(err, gc.IsNil) // The machine may not be marked as shutting down // immediately. Repeat a few times to ensure we get the error. for a := t.Attempt.Start(); a.Next(); { insts, err = t.Env.Instances([]instance.Id{id0}) if err != nil { break } } c.Assert(err, gc.Equals, environs.ErrNoInstances) c.Assert(insts, gc.HasLen, 0) }
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") }