OLD | NEW |
1 package ec2_test | 1 package ec2_test |
2 | 2 |
3 import ( | 3 import ( |
4 "crypto/rand" | 4 "crypto/rand" |
5 "fmt" | 5 "fmt" |
6 "io" | 6 "io" |
7 "io/ioutil" | 7 "io/ioutil" |
8 amzec2 "launchpad.net/goamz/ec2" | 8 amzec2 "launchpad.net/goamz/ec2" |
9 . "launchpad.net/gocheck" | 9 . "launchpad.net/gocheck" |
10 "launchpad.net/juju-core/environs" | 10 "launchpad.net/juju-core/environs" |
11 "launchpad.net/juju-core/environs/ec2" | 11 "launchpad.net/juju-core/environs/ec2" |
12 "launchpad.net/juju-core/environs/jujutest" | 12 "launchpad.net/juju-core/environs/jujutest" |
13 "launchpad.net/juju-core/juju/testing" | 13 "launchpad.net/juju-core/juju/testing" |
14 coretesting "launchpad.net/juju-core/testing" | 14 coretesting "launchpad.net/juju-core/testing" |
15 "strings" | 15 "strings" |
16 "time" | |
17 ) | 16 ) |
18 | 17 |
19 // amazonConfig holds the environments configuration | 18 // amazonConfig holds the environments configuration |
20 // for running the amazon EC2 integration tests. | 19 // for running the amazon EC2 integration tests. |
21 // | 20 // |
22 // This is missing keys for security reasons; set the following environment vari
ables | 21 // This is missing keys for security reasons; set the following environment vari
ables |
23 // to make the Amazon testing work: | 22 // to make the Amazon testing work: |
24 // access-key: $AWS_ACCESS_KEY_ID | 23 // access-key: $AWS_ACCESS_KEY_ID |
25 // secret-key: $AWS_SECRET_ACCESS_KEY | 24 // secret-key: $AWS_SECRET_ACCESS_KEY |
26 var amazonConfig = fmt.Sprintf(` | 25 var amazonConfig = fmt.Sprintf(` |
(...skipping 19 matching lines...) Expand all Loading... |
46 } | 45 } |
47 | 46 |
48 func registerAmazonTests() { | 47 func registerAmazonTests() { |
49 envs, err := environs.ReadEnvironsBytes([]byte(amazonConfig)) | 48 envs, err := environs.ReadEnvironsBytes([]byte(amazonConfig)) |
50 if err != nil { | 49 if err != nil { |
51 panic(fmt.Errorf("cannot parse amazon tests config data: %v", er
r)) | 50 panic(fmt.Errorf("cannot parse amazon tests config data: %v", er
r)) |
52 } | 51 } |
53 for _, name := range envs.Names() { | 52 for _, name := range envs.Names() { |
54 Suite(&LiveTests{ | 53 Suite(&LiveTests{ |
55 LiveTests: jujutest.LiveTests{ | 54 LiveTests: jujutest.LiveTests{ |
56 » » » » Environs: envs, | 55 » » » » Environs: envs, |
57 » » » » Name: name, | 56 » » » » Name: name, |
58 » » » » ConsistencyDelay: 5 * time.Second, | 57 » » » » Attempt: *ec2.ShortAttempt, |
59 » » » » CanOpenState: true, | 58 » » » » CanOpenState: true, |
60 » » » » HasProvisioner: true, | 59 » » » » HasProvisioner: true, |
61 }, | 60 }, |
62 }) | 61 }) |
63 } | 62 } |
64 } | 63 } |
65 | 64 |
66 // LiveTests contains tests that can be run against the Amazon servers. | 65 // LiveTests contains tests that can be run against the Amazon servers. |
67 // Each test runs using the same ec2 connection. | 66 // Each test runs using the same ec2 connection. |
68 type LiveTests struct { | 67 type LiveTests struct { |
69 coretesting.LoggingSuite | 68 coretesting.LoggingSuite |
70 jujutest.LiveTests | 69 jujutest.LiveTests |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 } | 225 } |
227 } | 226 } |
228 | 227 |
229 func (t *LiveTests) TestDestroy(c *C) { | 228 func (t *LiveTests) TestDestroy(c *C) { |
230 s := t.Env.Storage() | 229 s := t.Env.Storage() |
231 err := s.Put("foo", strings.NewReader("foo"), 3) | 230 err := s.Put("foo", strings.NewReader("foo"), 3) |
232 c.Assert(err, IsNil) | 231 c.Assert(err, IsNil) |
233 err = s.Put("bar", strings.NewReader("bar"), 3) | 232 err = s.Put("bar", strings.NewReader("bar"), 3) |
234 c.Assert(err, IsNil) | 233 c.Assert(err, IsNil) |
235 | 234 |
236 » // Check that bucket exists, so we can be sure | 235 » // Check that the bucket exists, so we can be sure |
237 // we have checked correctly that it's been destroyed. | 236 // we have checked correctly that it's been destroyed. |
238 names, err := s.List("") | 237 names, err := s.List("") |
239 c.Assert(err, IsNil) | 238 c.Assert(err, IsNil) |
240 c.Assert(len(names) >= 2, Equals, true) | 239 c.Assert(len(names) >= 2, Equals, true) |
241 | 240 |
242 t.Destroy(c) | 241 t.Destroy(c) |
243 » for i := 0; i < 30; i++ { | 242 » for a := ec2.ShortAttempt.Start(); a.Next(); { |
244 names, err = s.List("") | 243 names, err = s.List("") |
245 if len(names) == 0 { | 244 if len(names) == 0 { |
246 break | 245 break |
247 } | 246 } |
248 time.Sleep(100 * time.Millisecond) | |
249 } | 247 } |
250 c.Assert(names, HasLen, 0) | 248 c.Assert(names, HasLen, 0) |
251 } | 249 } |
252 | 250 |
253 func checkPortAllowed(c *C, perms []amzec2.IPPerm, port int) { | 251 func checkPortAllowed(c *C, perms []amzec2.IPPerm, port int) { |
254 for _, perm := range perms { | 252 for _, perm := range perms { |
255 if perm.FromPort == port { | 253 if perm.FromPort == port { |
256 c.Check(perm.Protocol, Equals, "tcp") | 254 c.Check(perm.Protocol, Equals, "tcp") |
257 c.Check(perm.ToPort, Equals, port) | 255 c.Check(perm.ToPort, Equals, port) |
258 c.Check(perm.SourceIPs, DeepEquals, []string{"0.0.0.0/0"
}) | 256 c.Check(perm.SourceIPs, DeepEquals, []string{"0.0.0.0/0"
}) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 | 303 |
306 err = t.Env.StopInstances([]environs.Instance{inst0, inst1, inst2}) | 304 err = t.Env.StopInstances([]environs.Instance{inst0, inst1, inst2}) |
307 c.Check(err, IsNil) | 305 c.Check(err, IsNil) |
308 | 306 |
309 var insts []environs.Instance | 307 var insts []environs.Instance |
310 | 308 |
311 // We need the retry logic here because we are waiting | 309 // We need the retry logic here because we are waiting |
312 // for Instances to return an error, and it will not retry | 310 // for Instances to return an error, and it will not retry |
313 // if it succeeds. | 311 // if it succeeds. |
314 gone := false | 312 gone := false |
315 » for i := 0; i < 30; i++ { | 313 » for a := ec2.ShortAttempt.Start(); a.Next(); { |
316 insts, err = t.Env.Instances([]string{inst0.Id(), inst2.Id()}) | 314 insts, err = t.Env.Instances([]string{inst0.Id(), inst2.Id()}) |
317 if err == environs.ErrPartialInstances { | 315 if err == environs.ErrPartialInstances { |
318 // instances not gone yet. | 316 // instances not gone yet. |
319 time.Sleep(100 * time.Millisecond) | |
320 continue | 317 continue |
321 } | 318 } |
322 if err == environs.ErrNoInstances { | 319 if err == environs.ErrNoInstances { |
323 gone = true | 320 gone = true |
324 break | 321 break |
325 } | 322 } |
326 c.Fatalf("error getting instances: %v", err) | 323 c.Fatalf("error getting instances: %v", err) |
327 } | 324 } |
328 if !gone { | 325 if !gone { |
329 c.Errorf("after termination, instances remaining: %v", insts) | 326 c.Errorf("after termination, instances remaining: %v", insts) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 } | 396 } |
400 | 397 |
401 func hasSecurityGroup(r amzec2.Reservation, g amzec2.SecurityGroup) bool { | 398 func hasSecurityGroup(r amzec2.Reservation, g amzec2.SecurityGroup) bool { |
402 for _, rg := range r.SecurityGroups { | 399 for _, rg := range r.SecurityGroups { |
403 if rg.Id == g.Id { | 400 if rg.Id == g.Id { |
404 return true | 401 return true |
405 } | 402 } |
406 } | 403 } |
407 return false | 404 return false |
408 } | 405 } |
OLD | NEW |