Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(12)

Delta Between Two Patch Sets: environs/ec2/live_test.go

Issue 6851081: environs/ec2: respect default series (Closed)
Left Patch Set: environs/ec2: respect default series Created 12 years, 4 months ago
Right Patch Set: environs/ec2: respect default series Created 12 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
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 "launchpad.net/juju-core/state"
14 coretesting "launchpad.net/juju-core/testing" 15 coretesting "launchpad.net/juju-core/testing"
15 "strings" 16 "strings"
16 ) 17 )
17 18
18 // uniqueName is generated afresh for every test run, so that 19 // uniqueName is generated afresh for every test run, so that
19 // we are not polluted by previous test state. 20 // we are not polluted by previous test state.
20 var uniqueName = randomName() 21 var uniqueName = randomName()
21 22
22 func randomName() string { 23 func randomName() string {
23 buf := make([]byte, 8) 24 buf := make([]byte, 8)
24 _, err := io.ReadFull(rand.Reader, buf) 25 _, err := io.ReadFull(rand.Reader, buf)
25 if err != nil { 26 if err != nil {
26 panic(fmt.Sprintf("error from crypto rand: %v", err)) 27 panic(fmt.Sprintf("error from crypto rand: %v", err))
27 } 28 }
28 return fmt.Sprintf("%x", buf) 29 return fmt.Sprintf("%x", buf)
29 } 30 }
30 31
31 func registerAmazonTests() { 32 func registerAmazonTests() {
32 // The following attributes hold the environment configuration 33 // The following attributes hold the environment configuration
33 // for running the amazon EC2 integration tests. 34 // for running the amazon EC2 integration tests.
34 // 35 //
35 // This is missing keys for security reasons; set the following 36 // This is missing keys for security reasons; set the following
36 // environment variables to make the Amazon testing work: 37 // environment variables to make the Amazon testing work:
37 // access-key: $AWS_ACCESS_KEY_ID 38 // access-key: $AWS_ACCESS_KEY_ID
38 // secret-key: $AWS_SECRET_ACCESS_KEY 39 // secret-key: $AWS_SECRET_ACCESS_KEY
39 // 40 //
40 // default-series must not be specified, hence defaulting to the 41 // default-series must not be specified, hence defaulting to the
41 // series of the machine running the tests. This behavior is 42 // series of the machine running the tests. This behavior is
42 // required because --upload-tools will not create tools for 43 // required because --upload-tools will not create tools for
43 » // other series'. 44 » // other series.
rog 2012/11/21 10:27:05 s/'//
dave_cheney.net 2012/11/21 11:42:48 Done.
44 attrs := map[string]interface{}{ 45 attrs := map[string]interface{}{
45 "name": "sample-" + uniqueName, 46 "name": "sample-" + uniqueName,
46 "type": "ec2", 47 "type": "ec2",
47 "control-bucket": "juju-test-" + uniqueName, 48 "control-bucket": "juju-test-" + uniqueName,
48 "public-bucket": "juju-public-test-" + uniqueName, 49 "public-bucket": "juju-public-test-" + uniqueName,
49 "admin-secret": "for real", 50 "admin-secret": "for real",
51 "ca-cert": coretesting.CACert,
52 "ca-private-key": coretesting.CAKey,
50 } 53 }
51 Suite(&LiveTests{ 54 Suite(&LiveTests{
52 LiveTests: jujutest.LiveTests{ 55 LiveTests: jujutest.LiveTests{
53 Config: attrs, 56 Config: attrs,
54 Attempt: *ec2.ShortAttempt, 57 Attempt: *ec2.ShortAttempt,
55 CanOpenState: true, 58 CanOpenState: true,
56 HasProvisioner: true, 59 HasProvisioner: true,
57 }, 60 },
58 }) 61 })
59 } 62 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 96 }
94 97
95 func (t *LiveTests) TearDownTest(c *C) { 98 func (t *LiveTests) TearDownTest(c *C) {
96 t.LiveTests.TearDownTest(c) 99 t.LiveTests.TearDownTest(c)
97 t.LoggingSuite.TearDownTest(c) 100 t.LoggingSuite.TearDownTest(c)
98 } 101 }
99 102
100 // TODO(niemeyer): Looks like many of those tests should be moved to jujutest.Li veTests. 103 // TODO(niemeyer): Looks like many of those tests should be moved to jujutest.Li veTests.
101 104
102 func (t *LiveTests) TestInstanceDNSName(c *C) { 105 func (t *LiveTests) TestInstanceDNSName(c *C) {
103 » inst, err := t.Env.StartInstance(30, testing.InvalidStateInfo(30), nil) 106 » inst, err := t.Env.StartInstance("30", testing.InvalidStateInfo("30"), n il)
104 c.Assert(err, IsNil) 107 c.Assert(err, IsNil)
105 defer t.Env.StopInstances([]environs.Instance{inst}) 108 defer t.Env.StopInstances([]environs.Instance{inst})
106 dns, err := inst.WaitDNSName() 109 dns, err := inst.WaitDNSName()
107 // TODO(niemeyer): This assert sometimes fails with "no instances found" 110 // TODO(niemeyer): This assert sometimes fails with "no instances found"
108 c.Assert(err, IsNil) 111 c.Assert(err, IsNil)
109 c.Assert(dns, Not(Equals), "") 112 c.Assert(dns, Not(Equals), "")
110 113
111 » insts, err := t.Env.Instances([]string{inst.Id()}) 114 » insts, err := t.Env.Instances([]state.InstanceId{inst.Id()})
112 c.Assert(err, IsNil) 115 c.Assert(err, IsNil)
113 c.Assert(len(insts), Equals, 1) 116 c.Assert(len(insts), Equals, 1)
114 117
115 ec2inst := ec2.InstanceEC2(insts[0]) 118 ec2inst := ec2.InstanceEC2(insts[0])
116 c.Assert(ec2inst.DNSName, Equals, dns) 119 c.Assert(ec2inst.DNSName, Equals, dns)
117 } 120 }
118 121
119 func (t *LiveTests) TestInstanceGroups(c *C) { 122 func (t *LiveTests) TestInstanceGroups(c *C) {
120 ec2conn := ec2.EnvironEC2(t.Env) 123 ec2conn := ec2.EnvironEC2(t.Env)
121 124
122 groups := amzec2.SecurityGroupNames( 125 groups := amzec2.SecurityGroupNames(
123 ec2.JujuGroupName(t.Env), 126 ec2.JujuGroupName(t.Env),
124 » » ec2.MachineGroupName(t.Env, 98), 127 » » ec2.MachineGroupName(t.Env, "98"),
125 » » ec2.MachineGroupName(t.Env, 99), 128 » » ec2.MachineGroupName(t.Env, "99"),
126 ) 129 )
127 info := make([]amzec2.SecurityGroupInfo, len(groups)) 130 info := make([]amzec2.SecurityGroupInfo, len(groups))
128 131
129 // Create a group with the same name as the juju group 132 // Create a group with the same name as the juju group
130 // but with different permissions, to check that it's deleted 133 // but with different permissions, to check that it's deleted
131 // and recreated correctly. 134 // and recreated correctly.
132 oldJujuGroup := createGroup(c, ec2conn, groups[0].Name, "old juju group" ) 135 oldJujuGroup := createGroup(c, ec2conn, groups[0].Name, "old juju group" )
133 136
134 // Add two permissions: one is required and should be left alone; 137 // Add two permissions: one is required and should be left alone;
135 // the other is not and should be deleted. 138 // the other is not and should be deleted.
136 // N.B. this is unfortunately sensitive to the actual set of permissions used. 139 // N.B. this is unfortunately sensitive to the actual set of permissions used.
137 _, err := ec2conn.AuthorizeSecurityGroup(oldJujuGroup, 140 _, err := ec2conn.AuthorizeSecurityGroup(oldJujuGroup,
138 []amzec2.IPPerm{ 141 []amzec2.IPPerm{
139 { 142 {
140 Protocol: "tcp", 143 Protocol: "tcp",
141 FromPort: 22, 144 FromPort: 22,
142 ToPort: 22, 145 ToPort: 22,
143 SourceIPs: []string{"0.0.0.0/0"}, 146 SourceIPs: []string{"0.0.0.0/0"},
144 }, 147 },
145 { 148 {
146 Protocol: "udp", 149 Protocol: "udp",
147 FromPort: 4321, 150 FromPort: 4321,
148 ToPort: 4322, 151 ToPort: 4322,
149 SourceIPs: []string{"3.4.5.6/32"}, 152 SourceIPs: []string{"3.4.5.6/32"},
150 }, 153 },
151 }) 154 })
152 c.Assert(err, IsNil) 155 c.Assert(err, IsNil)
153 156
154 » inst0, err := t.Env.StartInstance(98, testing.InvalidStateInfo(98), nil) 157 » inst0, err := t.Env.StartInstance("98", testing.InvalidStateInfo("98"), nil)
155 c.Assert(err, IsNil) 158 c.Assert(err, IsNil)
156 defer t.Env.StopInstances([]environs.Instance{inst0}) 159 defer t.Env.StopInstances([]environs.Instance{inst0})
157 160
158 // Create a same-named group for the second instance 161 // Create a same-named group for the second instance
159 // before starting it, to check that it's reused correctly. 162 // before starting it, to check that it's reused correctly.
160 oldMachineGroup := createGroup(c, ec2conn, groups[2].Name, "old machine group") 163 oldMachineGroup := createGroup(c, ec2conn, groups[2].Name, "old machine group")
161 164
162 » inst1, err := t.Env.StartInstance(99, testing.InvalidStateInfo(99), nil) 165 » inst1, err := t.Env.StartInstance("99", testing.InvalidStateInfo("99"), nil)
163 c.Assert(err, IsNil) 166 c.Assert(err, IsNil)
164 defer t.Env.StopInstances([]environs.Instance{inst1}) 167 defer t.Env.StopInstances([]environs.Instance{inst1})
165 168
166 groupsResp, err := ec2conn.SecurityGroups(groups, nil) 169 groupsResp, err := ec2conn.SecurityGroups(groups, nil)
167 c.Assert(err, IsNil) 170 c.Assert(err, IsNil)
168 c.Assert(groupsResp.Groups, HasLen, len(groups)) 171 c.Assert(groupsResp.Groups, HasLen, len(groups))
169 172
170 // For each group, check that it exists and record its id. 173 // For each group, check that it exists and record its id.
171 for i, group := range groups { 174 for i, group := range groups {
172 found := false 175 found := false
(...skipping 11 matching lines...) Expand all
184 } 187 }
185 188
186 // The old juju group should have been reused. 189 // The old juju group should have been reused.
187 c.Check(groups[0].Id, Equals, oldJujuGroup.Id) 190 c.Check(groups[0].Id, Equals, oldJujuGroup.Id)
188 191
189 // Check that it authorizes the correct ports and there 192 // Check that it authorizes the correct ports and there
190 // are no extra permissions (in particular we are checking 193 // are no extra permissions (in particular we are checking
191 // that the unneeded permission that we added earlier 194 // that the unneeded permission that we added earlier
192 // has been deleted). 195 // has been deleted).
193 perms := info[0].IPPerms 196 perms := info[0].IPPerms
194 » c.Assert(perms, HasLen, 4) 197 » c.Assert(perms, HasLen, 5)
195 » checkPortAllowed(c, perms, 22) 198 » checkPortAllowed(c, perms, 22) // SSH
199 » checkPortAllowed(c, perms, 37017) // MongoDB
196 checkSecurityGroupAllowed(c, perms, groups[0]) 200 checkSecurityGroupAllowed(c, perms, groups[0])
197 201
198 // The old machine group should have been reused also. 202 // The old machine group should have been reused also.
199 c.Check(groups[2].Id, Equals, oldMachineGroup.Id) 203 c.Check(groups[2].Id, Equals, oldMachineGroup.Id)
200 204
201 // Check that each instance is part of the correct groups. 205 // Check that each instance is part of the correct groups.
202 » resp, err := ec2conn.Instances([]string{inst0.Id(), inst1.Id()}, nil) 206 » resp, err := ec2conn.Instances([]string{string(inst0.Id()), string(inst1 .Id())}, nil)
203 c.Assert(err, IsNil) 207 c.Assert(err, IsNil)
204 c.Assert(resp.Reservations, HasLen, 2) 208 c.Assert(resp.Reservations, HasLen, 2)
205 for _, r := range resp.Reservations { 209 for _, r := range resp.Reservations {
206 c.Assert(r.Instances, HasLen, 1) 210 c.Assert(r.Instances, HasLen, 1)
207 // each instance must be part of the general juju group. 211 // each instance must be part of the general juju group.
208 msg := Commentf("reservation %#v", r) 212 msg := Commentf("reservation %#v", r)
209 c.Assert(hasSecurityGroup(r, groups[0]), Equals, true, msg) 213 c.Assert(hasSecurityGroup(r, groups[0]), Equals, true, msg)
210 inst := r.Instances[0] 214 inst := r.Instances[0]
211 » » switch inst.InstanceId { 215 » » switch state.InstanceId(inst.InstanceId) {
212 case inst0.Id(): 216 case inst0.Id():
213 c.Assert(hasSecurityGroup(r, groups[1]), Equals, true, m sg) 217 c.Assert(hasSecurityGroup(r, groups[1]), Equals, true, m sg)
214 c.Assert(hasSecurityGroup(r, groups[2]), Equals, false, msg) 218 c.Assert(hasSecurityGroup(r, groups[2]), Equals, false, msg)
215 case inst1.Id(): 219 case inst1.Id():
216 c.Assert(hasSecurityGroup(r, groups[2]), Equals, true, m sg) 220 c.Assert(hasSecurityGroup(r, groups[2]), Equals, true, m sg)
217 c.Assert(hasSecurityGroup(r, groups[1]), Equals, false, msg) 221 c.Assert(hasSecurityGroup(r, groups[1]), Equals, false, msg)
218 default: 222 default:
219 c.Errorf("unknown instance found: %v", inst) 223 c.Errorf("unknown instance found: %v", inst)
220 } 224 }
221 } 225 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 } 286 }
283 if len(protos) > 0 { 287 if len(protos) > 0 {
284 c.Errorf("%d security group permission not found for %#v in %#v" , len(protos), g, perms) 288 c.Errorf("%d security group permission not found for %#v in %#v" , len(protos), g, perms)
285 } 289 }
286 } 290 }
287 291
288 func (t *LiveTests) TestStopInstances(c *C) { 292 func (t *LiveTests) TestStopInstances(c *C) {
289 // It would be nice if this test was in jujutest, but 293 // It would be nice if this test was in jujutest, but
290 // there's no way for jujutest to fabricate a valid-looking 294 // there's no way for jujutest to fabricate a valid-looking
291 // instance id. 295 // instance id.
292 » inst0, err := t.Env.StartInstance(40, testing.InvalidStateInfo(40), nil) 296 » inst0, err := t.Env.StartInstance("40", testing.InvalidStateInfo("40"), nil)
293 c.Assert(err, IsNil) 297 c.Assert(err, IsNil)
294 298
295 inst1 := ec2.FabricateInstance(inst0, "i-aaaaaaaa") 299 inst1 := ec2.FabricateInstance(inst0, "i-aaaaaaaa")
296 300
297 » inst2, err := t.Env.StartInstance(41, testing.InvalidStateInfo(41), nil) 301 » inst2, err := t.Env.StartInstance("41", testing.InvalidStateInfo("41"), nil)
298 c.Assert(err, IsNil) 302 c.Assert(err, IsNil)
299 303
300 err = t.Env.StopInstances([]environs.Instance{inst0, inst1, inst2}) 304 err = t.Env.StopInstances([]environs.Instance{inst0, inst1, inst2})
301 c.Check(err, IsNil) 305 c.Check(err, IsNil)
302 306
303 var insts []environs.Instance 307 var insts []environs.Instance
304 308
305 // We need the retry logic here because we are waiting 309 // We need the retry logic here because we are waiting
306 // for Instances to return an error, and it will not retry 310 // for Instances to return an error, and it will not retry
307 // if it succeeds. 311 // if it succeeds.
308 gone := false 312 gone := false
309 for a := ec2.ShortAttempt.Start(); a.Next(); { 313 for a := ec2.ShortAttempt.Start(); a.Next(); {
310 » » insts, err = t.Env.Instances([]string{inst0.Id(), inst2.Id()}) 314 » » insts, err = t.Env.Instances([]state.InstanceId{inst0.Id(), inst 2.Id()})
311 if err == environs.ErrPartialInstances { 315 if err == environs.ErrPartialInstances {
312 // instances not gone yet. 316 // instances not gone yet.
313 continue 317 continue
314 } 318 }
315 if err == environs.ErrNoInstances { 319 if err == environs.ErrNoInstances {
316 gone = true 320 gone = true
317 break 321 break
318 } 322 }
319 c.Fatalf("error getting instances: %v", err) 323 c.Fatalf("error getting instances: %v", err)
320 } 324 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 } 396 }
393 397
394 func hasSecurityGroup(r amzec2.Reservation, g amzec2.SecurityGroup) bool { 398 func hasSecurityGroup(r amzec2.Reservation, g amzec2.SecurityGroup) bool {
395 for _, rg := range r.SecurityGroups { 399 for _, rg := range r.SecurityGroups {
396 if rg.Id == g.Id { 400 if rg.Id == g.Id {
397 return true 401 return true
398 } 402 }
399 } 403 }
400 return false 404 return false
401 } 405 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b