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

Side by Side Diff: environs/ec2/live_test.go

Issue 9738043: cmd/jujud: do not change password
Patch Set: cmd/jujud: do not change password Created 11 years, 9 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:
View unified diff | Download patch
« no previous file with comments | « environs/ec2/image_test.go ('k') | environs/ec2/local_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "io/ioutil" 10 "io/ioutil"
11 amzec2 "launchpad.net/goamz/ec2" 11 amzec2 "launchpad.net/goamz/ec2"
12 . "launchpad.net/gocheck" 12 . "launchpad.net/gocheck"
13 "launchpad.net/juju-core/constraints" 13 "launchpad.net/juju-core/constraints"
14 "launchpad.net/juju-core/environs" 14 "launchpad.net/juju-core/environs"
15 "launchpad.net/juju-core/environs/config" 15 "launchpad.net/juju-core/environs/config"
16 "launchpad.net/juju-core/environs/ec2" 16 "launchpad.net/juju-core/environs/ec2"
17 "launchpad.net/juju-core/environs/jujutest" 17 "launchpad.net/juju-core/environs/jujutest"
18 envtesting "launchpad.net/juju-core/environs/testing" 18 envtesting "launchpad.net/juju-core/environs/testing"
19 "launchpad.net/juju-core/errors" 19 "launchpad.net/juju-core/errors"
20 "launchpad.net/juju-core/instance"
20 "launchpad.net/juju-core/juju/testing" 21 "launchpad.net/juju-core/juju/testing"
21 "launchpad.net/juju-core/state"
22 coretesting "launchpad.net/juju-core/testing" 22 coretesting "launchpad.net/juju-core/testing"
23 "strings" 23 "strings"
24 ) 24 )
25 25
26 // uniqueName is generated afresh for every test run, so that 26 // uniqueName is generated afresh for every test run, so that
27 // we are not polluted by previous test state. 27 // we are not polluted by previous test state.
28 var uniqueName = randomName() 28 var uniqueName = randomName()
29 29
30 func randomName() string { 30 func randomName() string {
31 buf := make([]byte, 8) 31 buf := make([]byte, 8)
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 106
107 func (t *LiveTests) TearDownTest(c *C) { 107 func (t *LiveTests) TearDownTest(c *C) {
108 t.LiveTests.TearDownTest(c) 108 t.LiveTests.TearDownTest(c)
109 t.LoggingSuite.TearDownTest(c) 109 t.LoggingSuite.TearDownTest(c)
110 } 110 }
111 111
112 // TODO(niemeyer): Looks like many of those tests should be moved to jujutest.Li veTests. 112 // TODO(niemeyer): Looks like many of those tests should be moved to jujutest.Li veTests.
113 113
114 func (t *LiveTests) TestInstanceAttributes(c *C) { 114 func (t *LiveTests) TestInstanceAttributes(c *C) {
115 inst := testing.StartInstance(c, t.Env, "30") 115 inst := testing.StartInstance(c, t.Env, "30")
116 » defer t.Env.StopInstances([]environs.Instance{inst}) 116 » defer t.Env.StopInstances([]instance.Instance{inst})
117 dns, err := inst.WaitDNSName() 117 dns, err := inst.WaitDNSName()
118 // TODO(niemeyer): This assert sometimes fails with "no instances found" 118 // TODO(niemeyer): This assert sometimes fails with "no instances found"
119 c.Assert(err, IsNil) 119 c.Assert(err, IsNil)
120 c.Assert(dns, Not(Equals), "") 120 c.Assert(dns, Not(Equals), "")
121 121
122 » insts, err := t.Env.Instances([]state.InstanceId{inst.Id()}) 122 » insts, err := t.Env.Instances([]instance.Id{inst.Id()})
123 c.Assert(err, IsNil) 123 c.Assert(err, IsNil)
124 c.Assert(len(insts), Equals, 1) 124 c.Assert(len(insts), Equals, 1)
125 125
126 ec2inst := ec2.InstanceEC2(insts[0]) 126 ec2inst := ec2.InstanceEC2(insts[0])
127 c.Assert(ec2inst.DNSName, Equals, dns) 127 c.Assert(ec2inst.DNSName, Equals, dns)
128 c.Assert(ec2inst.InstanceType, Equals, "m1.small") 128 c.Assert(ec2inst.InstanceType, Equals, "m1.small")
129 } 129 }
130 130
131 func (t *LiveTests) TestStartInstanceConstraints(c *C) { 131 func (t *LiveTests) TestStartInstanceConstraints(c *C) {
132 cons := constraints.MustParse("mem=2G") 132 cons := constraints.MustParse("mem=2G")
133 » inst, err := t.Env.StartInstance("31", "fake_nonce", config.DefaultSerie s, cons, testing.InvalidStateInfo("31"), testing.InvalidAPIInfo("31")) 133 » inst, err := t.Env.StartInstance("31", "fake_nonce", config.DefaultSerie s, cons, testing.FakeStateInfo("31"), testing.FakeAPIInfo("31"))
134 c.Assert(err, IsNil) 134 c.Assert(err, IsNil)
135 » defer t.Env.StopInstances([]environs.Instance{inst}) 135 » defer t.Env.StopInstances([]instance.Instance{inst})
136 ec2inst := ec2.InstanceEC2(inst) 136 ec2inst := ec2.InstanceEC2(inst)
137 c.Assert(ec2inst.InstanceType, Equals, "m1.medium") 137 c.Assert(ec2inst.InstanceType, Equals, "m1.medium")
138 } 138 }
139 139
140 func (t *LiveTests) TestInstanceGroups(c *C) { 140 func (t *LiveTests) TestInstanceGroups(c *C) {
141 ec2conn := ec2.EnvironEC2(t.Env) 141 ec2conn := ec2.EnvironEC2(t.Env)
142 142
143 groups := amzec2.SecurityGroupNames( 143 groups := amzec2.SecurityGroupNames(
144 ec2.JujuGroupName(t.Env), 144 ec2.JujuGroupName(t.Env),
145 ec2.MachineGroupName(t.Env, "98"), 145 ec2.MachineGroupName(t.Env, "98"),
(...skipping 20 matching lines...) Expand all
166 { 166 {
167 Protocol: "udp", 167 Protocol: "udp",
168 FromPort: 4321, 168 FromPort: 4321,
169 ToPort: 4322, 169 ToPort: 4322,
170 SourceIPs: []string{"3.4.5.6/32"}, 170 SourceIPs: []string{"3.4.5.6/32"},
171 }, 171 },
172 }) 172 })
173 c.Assert(err, IsNil) 173 c.Assert(err, IsNil)
174 174
175 inst0 := testing.StartInstance(c, t.Env, "98") 175 inst0 := testing.StartInstance(c, t.Env, "98")
176 » defer t.Env.StopInstances([]environs.Instance{inst0}) 176 » defer t.Env.StopInstances([]instance.Instance{inst0})
177 177
178 // Create a same-named group for the second instance 178 // Create a same-named group for the second instance
179 // before starting it, to check that it's reused correctly. 179 // before starting it, to check that it's reused correctly.
180 oldMachineGroup := createGroup(c, ec2conn, groups[2].Name, "old machine group") 180 oldMachineGroup := createGroup(c, ec2conn, groups[2].Name, "old machine group")
181 181
182 inst1 := testing.StartInstance(c, t.Env, "99") 182 inst1 := testing.StartInstance(c, t.Env, "99")
183 » defer t.Env.StopInstances([]environs.Instance{inst1}) 183 » defer t.Env.StopInstances([]instance.Instance{inst1})
184 184
185 groupsResp, err := ec2conn.SecurityGroups(groups, nil) 185 groupsResp, err := ec2conn.SecurityGroups(groups, nil)
186 c.Assert(err, IsNil) 186 c.Assert(err, IsNil)
187 c.Assert(groupsResp.Groups, HasLen, len(groups)) 187 c.Assert(groupsResp.Groups, HasLen, len(groups))
188 188
189 // For each group, check that it exists and record its id. 189 // For each group, check that it exists and record its id.
190 for i, group := range groups { 190 for i, group := range groups {
191 found := false 191 found := false
192 for _, g := range groupsResp.Groups { 192 for _, g := range groupsResp.Groups {
193 if g.Name == group.Name { 193 if g.Name == group.Name {
(...skipping 28 matching lines...) Expand all
222 // Check that each instance is part of the correct groups. 222 // Check that each instance is part of the correct groups.
223 resp, err := ec2conn.Instances([]string{string(inst0.Id()), string(inst1 .Id())}, nil) 223 resp, err := ec2conn.Instances([]string{string(inst0.Id()), string(inst1 .Id())}, nil)
224 c.Assert(err, IsNil) 224 c.Assert(err, IsNil)
225 c.Assert(resp.Reservations, HasLen, 2) 225 c.Assert(resp.Reservations, HasLen, 2)
226 for _, r := range resp.Reservations { 226 for _, r := range resp.Reservations {
227 c.Assert(r.Instances, HasLen, 1) 227 c.Assert(r.Instances, HasLen, 1)
228 // each instance must be part of the general juju group. 228 // each instance must be part of the general juju group.
229 msg := Commentf("reservation %#v", r) 229 msg := Commentf("reservation %#v", r)
230 c.Assert(hasSecurityGroup(r, groups[0]), Equals, true, msg) 230 c.Assert(hasSecurityGroup(r, groups[0]), Equals, true, msg)
231 inst := r.Instances[0] 231 inst := r.Instances[0]
232 » » switch state.InstanceId(inst.InstanceId) { 232 » » switch instance.Id(inst.InstanceId) {
233 case inst0.Id(): 233 case inst0.Id():
234 c.Assert(hasSecurityGroup(r, groups[1]), Equals, true, m sg) 234 c.Assert(hasSecurityGroup(r, groups[1]), Equals, true, m sg)
235 c.Assert(hasSecurityGroup(r, groups[2]), Equals, false, msg) 235 c.Assert(hasSecurityGroup(r, groups[2]), Equals, false, msg)
236 case inst1.Id(): 236 case inst1.Id():
237 c.Assert(hasSecurityGroup(r, groups[2]), Equals, true, m sg) 237 c.Assert(hasSecurityGroup(r, groups[2]), Equals, true, m sg)
238 c.Assert(hasSecurityGroup(r, groups[1]), Equals, false, msg) 238 c.Assert(hasSecurityGroup(r, groups[1]), Equals, false, msg)
239 default: 239 default:
240 c.Errorf("unknown instance found: %v", inst) 240 c.Errorf("unknown instance found: %v", inst)
241 } 241 }
242 } 242 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 } 307 }
308 308
309 func (t *LiveTests) TestStopInstances(c *C) { 309 func (t *LiveTests) TestStopInstances(c *C) {
310 // It would be nice if this test was in jujutest, but 310 // It would be nice if this test was in jujutest, but
311 // there's no way for jujutest to fabricate a valid-looking 311 // there's no way for jujutest to fabricate a valid-looking
312 // instance id. 312 // instance id.
313 inst0 := testing.StartInstance(c, t.Env, "40") 313 inst0 := testing.StartInstance(c, t.Env, "40")
314 inst1 := ec2.FabricateInstance(inst0, "i-aaaaaaaa") 314 inst1 := ec2.FabricateInstance(inst0, "i-aaaaaaaa")
315 inst2 := testing.StartInstance(c, t.Env, "41") 315 inst2 := testing.StartInstance(c, t.Env, "41")
316 316
317 » err := t.Env.StopInstances([]environs.Instance{inst0, inst1, inst2}) 317 » err := t.Env.StopInstances([]instance.Instance{inst0, inst1, inst2})
318 c.Check(err, IsNil) 318 c.Check(err, IsNil)
319 319
320 » var insts []environs.Instance 320 » var insts []instance.Instance
321 321
322 // We need the retry logic here because we are waiting 322 // We need the retry logic here because we are waiting
323 // for Instances to return an error, and it will not retry 323 // for Instances to return an error, and it will not retry
324 // if it succeeds. 324 // if it succeeds.
325 gone := false 325 gone := false
326 for a := ec2.ShortAttempt.Start(); a.Next(); { 326 for a := ec2.ShortAttempt.Start(); a.Next(); {
327 » » insts, err = t.Env.Instances([]state.InstanceId{inst0.Id(), inst 2.Id()}) 327 » » insts, err = t.Env.Instances([]instance.Id{inst0.Id(), inst2.Id( )})
328 if err == environs.ErrPartialInstances { 328 if err == environs.ErrPartialInstances {
329 // instances not gone yet. 329 // instances not gone yet.
330 continue 330 continue
331 } 331 }
332 if err == environs.ErrNoInstances { 332 if err == environs.ErrNoInstances {
333 gone = true 333 gone = true
334 break 334 break
335 } 335 }
336 c.Fatalf("error getting instances: %v", err) 336 c.Fatalf("error getting instances: %v", err)
337 } 337 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 } 409 }
410 410
411 func hasSecurityGroup(r amzec2.Reservation, g amzec2.SecurityGroup) bool { 411 func hasSecurityGroup(r amzec2.Reservation, g amzec2.SecurityGroup) bool {
412 for _, rg := range r.SecurityGroups { 412 for _, rg := range r.SecurityGroups {
413 if rg.Id == g.Id { 413 if rg.Id == g.Id {
414 return true 414 return true
415 } 415 }
416 } 416 }
417 return false 417 return false
418 } 418 }
OLDNEW
« no previous file with comments | « environs/ec2/image_test.go ('k') | environs/ec2/local_test.go » ('j') | no next file with comments »

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