LEFT | RIGHT |
1 // Copyright 2011, 2012, 2013 Canonical Ltd. | 1 // Copyright 2011, 2012, 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package ec2_test | 4 package ec2_test |
5 | 5 |
6 import ( | 6 import ( |
7 "crypto/rand" | 7 "crypto/rand" |
8 "fmt" | 8 "fmt" |
9 "io" | 9 "io" |
10 "strings" | 10 "strings" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 109 |
110 func (t *LiveTests) TearDownTest(c *gc.C) { | 110 func (t *LiveTests) TearDownTest(c *gc.C) { |
111 t.LiveTests.TearDownTest(c) | 111 t.LiveTests.TearDownTest(c) |
112 t.LoggingSuite.TearDownTest(c) | 112 t.LoggingSuite.TearDownTest(c) |
113 } | 113 } |
114 | 114 |
115 // TODO(niemeyer): Looks like many of those tests should be moved to jujutest.Li
veTests. | 115 // TODO(niemeyer): Looks like many of those tests should be moved to jujutest.Li
veTests. |
116 | 116 |
117 func (t *LiveTests) TestInstanceAttributes(c *gc.C) { | 117 func (t *LiveTests) TestInstanceAttributes(c *gc.C) { |
118 inst, hc := testing.AssertStartInstance(c, t.Env, "30") | 118 inst, hc := testing.AssertStartInstance(c, t.Env, "30") |
119 » defer t.Env.StopInstances([]instance.Id{inst.Id()}) | 119 » defer t.Env.StopInstances(inst.Id()) |
120 // Sanity check for hardware characteristics. | 120 // Sanity check for hardware characteristics. |
121 c.Assert(hc.Arch, gc.NotNil) | 121 c.Assert(hc.Arch, gc.NotNil) |
122 c.Assert(hc.Mem, gc.NotNil) | 122 c.Assert(hc.Mem, gc.NotNil) |
123 c.Assert(hc.RootDisk, gc.NotNil) | 123 c.Assert(hc.RootDisk, gc.NotNil) |
124 c.Assert(hc.CpuCores, gc.NotNil) | 124 c.Assert(hc.CpuCores, gc.NotNil) |
125 c.Assert(hc.CpuPower, gc.NotNil) | 125 c.Assert(hc.CpuPower, gc.NotNil) |
126 dns, err := inst.WaitDNSName() | 126 dns, err := inst.WaitDNSName() |
127 // TODO(niemeyer): This assert sometimes fails with "no instances found" | 127 // TODO(niemeyer): This assert sometimes fails with "no instances found" |
128 c.Assert(err, gc.IsNil) | 128 c.Assert(err, gc.IsNil) |
129 c.Assert(dns, gc.Not(gc.Equals), "") | 129 c.Assert(dns, gc.Not(gc.Equals), "") |
130 | 130 |
131 insts, err := t.Env.Instances([]instance.Id{inst.Id()}) | 131 insts, err := t.Env.Instances([]instance.Id{inst.Id()}) |
132 c.Assert(err, gc.IsNil) | 132 c.Assert(err, gc.IsNil) |
133 c.Assert(len(insts), gc.Equals, 1) | 133 c.Assert(len(insts), gc.Equals, 1) |
134 | 134 |
135 ec2inst := ec2.InstanceEC2(insts[0]) | 135 ec2inst := ec2.InstanceEC2(insts[0]) |
136 c.Assert(ec2inst.DNSName, gc.Equals, dns) | 136 c.Assert(ec2inst.DNSName, gc.Equals, dns) |
137 c.Assert(ec2inst.InstanceType, gc.Equals, "m1.small") | 137 c.Assert(ec2inst.InstanceType, gc.Equals, "m1.small") |
138 } | 138 } |
139 | 139 |
140 func (t *LiveTests) TestStartInstanceConstraints(c *gc.C) { | 140 func (t *LiveTests) TestStartInstanceConstraints(c *gc.C) { |
141 cons := constraints.MustParse("mem=2G") | 141 cons := constraints.MustParse("mem=2G") |
142 inst, hc := testing.AssertStartInstanceWithConstraints(c, t.Env, "30", c
ons) | 142 inst, hc := testing.AssertStartInstanceWithConstraints(c, t.Env, "30", c
ons) |
143 » defer t.Env.StopInstances([]instance.Id{inst.Id()}) | 143 » defer t.Env.StopInstances(inst.Id()) |
144 ec2inst := ec2.InstanceEC2(inst) | 144 ec2inst := ec2.InstanceEC2(inst) |
145 c.Assert(ec2inst.InstanceType, gc.Equals, "m1.medium") | 145 c.Assert(ec2inst.InstanceType, gc.Equals, "m1.medium") |
146 c.Assert(*hc.Arch, gc.Equals, "amd64") | 146 c.Assert(*hc.Arch, gc.Equals, "amd64") |
147 c.Assert(*hc.Mem, gc.Equals, uint64(3840)) | 147 c.Assert(*hc.Mem, gc.Equals, uint64(3840)) |
148 c.Assert(*hc.RootDisk, gc.Equals, uint64(8192)) | 148 c.Assert(*hc.RootDisk, gc.Equals, uint64(8192)) |
149 c.Assert(*hc.CpuCores, gc.Equals, uint64(1)) | 149 c.Assert(*hc.CpuCores, gc.Equals, uint64(1)) |
150 c.Assert(*hc.CpuPower, gc.Equals, uint64(200)) | 150 c.Assert(*hc.CpuPower, gc.Equals, uint64(200)) |
151 } | 151 } |
152 | 152 |
153 func (t *LiveTests) TestInstanceGroups(c *gc.C) { | 153 func (t *LiveTests) TestInstanceGroups(c *gc.C) { |
(...skipping 26 matching lines...) Expand all Loading... |
180 { | 180 { |
181 Protocol: "udp", | 181 Protocol: "udp", |
182 FromPort: 4321, | 182 FromPort: 4321, |
183 ToPort: 4322, | 183 ToPort: 4322, |
184 SourceIPs: []string{"3.4.5.6/32"}, | 184 SourceIPs: []string{"3.4.5.6/32"}, |
185 }, | 185 }, |
186 }) | 186 }) |
187 c.Assert(err, gc.IsNil) | 187 c.Assert(err, gc.IsNil) |
188 | 188 |
189 inst0, _ := testing.AssertStartInstance(c, t.Env, "98") | 189 inst0, _ := testing.AssertStartInstance(c, t.Env, "98") |
190 » defer t.Env.StopInstances([]instance.Id{inst0.Id()}) | 190 » defer t.Env.StopInstances(inst0.Id()) |
191 | 191 |
192 // Create a same-named group for the second instance | 192 // Create a same-named group for the second instance |
193 // before starting it, to check that it's reused correctly. | 193 // before starting it, to check that it's reused correctly. |
194 oldMachineGroup := createGroup(c, ec2conn, groups[2].Name, "old machine
group") | 194 oldMachineGroup := createGroup(c, ec2conn, groups[2].Name, "old machine
group") |
195 | 195 |
196 inst1, _ := testing.AssertStartInstance(c, t.Env, "99") | 196 inst1, _ := testing.AssertStartInstance(c, t.Env, "99") |
197 » defer t.Env.StopInstances([]instance.Id{inst1.Id()}) | 197 » defer t.Env.StopInstances(inst1.Id()) |
198 | 198 |
199 groupsResp, err := ec2conn.SecurityGroups(groups, nil) | 199 groupsResp, err := ec2conn.SecurityGroups(groups, nil) |
200 c.Assert(err, gc.IsNil) | 200 c.Assert(err, gc.IsNil) |
201 c.Assert(groupsResp.Groups, gc.HasLen, len(groups)) | 201 c.Assert(groupsResp.Groups, gc.HasLen, len(groups)) |
202 | 202 |
203 // For each group, check that it exists and record its id. | 203 // For each group, check that it exists and record its id. |
204 for i, group := range groups { | 204 for i, group := range groups { |
205 found := false | 205 found := false |
206 for _, g := range groupsResp.Groups { | 206 for _, g := range groupsResp.Groups { |
207 if g.Name == group.Name { | 207 if g.Name == group.Name { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 } | 336 } |
337 | 337 |
338 func (t *LiveTests) TestStopInstances(c *gc.C) { | 338 func (t *LiveTests) TestStopInstances(c *gc.C) { |
339 // It would be nice if this test was in jujutest, but | 339 // It would be nice if this test was in jujutest, but |
340 // there's no way for jujutest to fabricate a valid-looking | 340 // there's no way for jujutest to fabricate a valid-looking |
341 // instance id. | 341 // instance id. |
342 inst0, _ := testing.AssertStartInstance(c, t.Env, "40") | 342 inst0, _ := testing.AssertStartInstance(c, t.Env, "40") |
343 inst1 := ec2.FabricateInstance(inst0, "i-aaaaaaaa") | 343 inst1 := ec2.FabricateInstance(inst0, "i-aaaaaaaa") |
344 inst2, _ := testing.AssertStartInstance(c, t.Env, "41") | 344 inst2, _ := testing.AssertStartInstance(c, t.Env, "41") |
345 | 345 |
346 » err := t.Env.StopInstances([]instance.Id{inst0.Id(), inst1.Id(), inst2.I
d()}) | 346 » err := t.Env.StopInstances(inst0.Id(), inst1.Id(), inst2.Id()) |
347 c.Check(err, gc.IsNil) | 347 c.Check(err, gc.IsNil) |
348 | 348 |
349 var insts []instance.Instance | 349 var insts []instance.Instance |
350 | 350 |
351 // We need the retry logic here because we are waiting | 351 // We need the retry logic here because we are waiting |
352 // for Instances to return an error, and it will not retry | 352 // for Instances to return an error, and it will not retry |
353 // if it succeeds. | 353 // if it succeeds. |
354 gone := false | 354 gone := false |
355 for a := ec2.ShortAttempt.Start(); a.Next(); { | 355 for a := ec2.ShortAttempt.Start(); a.Next(); { |
356 insts, err = t.Env.Instances([]instance.Id{inst0.Id(), inst2.Id(
)}) | 356 insts, err = t.Env.Instances([]instance.Id{inst0.Id(), inst2.Id(
)}) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 } | 417 } |
418 | 418 |
419 func hasSecurityGroup(inst amzec2.Instance, group amzec2.SecurityGroup) bool { | 419 func hasSecurityGroup(inst amzec2.Instance, group amzec2.SecurityGroup) bool { |
420 for _, instGroup := range inst.SecurityGroups { | 420 for _, instGroup := range inst.SecurityGroups { |
421 if instGroup.Id == group.Id { | 421 if instGroup.Id == group.Id { |
422 return true | 422 return true |
423 } | 423 } |
424 } | 424 } |
425 return false | 425 return false |
426 } | 426 } |
LEFT | RIGHT |