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

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

Issue 7950044: state/api/params: add CharmURL to ServiceInfo
Left Patch Set: Created 12 years ago
Right Patch Set: state/api/params: add CharmURL to ServiceInfo Created 12 years 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:
Right: Side by side diff | Download
« no previous file with change/comment | « environs/ec2/ec2.go ('k') | environs/ec2/local_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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/constraints" 10 "launchpad.net/juju-core/constraints"
11 "launchpad.net/juju-core/environs" 11 "launchpad.net/juju-core/environs"
12 "launchpad.net/juju-core/environs/ec2" 12 "launchpad.net/juju-core/environs/ec2"
13 "launchpad.net/juju-core/environs/jujutest" 13 "launchpad.net/juju-core/environs/jujutest"
14 "launchpad.net/juju-core/juju/testing" 14 "launchpad.net/juju-core/juju/testing"
15 "launchpad.net/juju-core/state" 15 "launchpad.net/juju-core/state"
16 coretesting "launchpad.net/juju-core/testing" 16 coretesting "launchpad.net/juju-core/testing"
17 "launchpad.net/juju-core/version"
17 "strings" 18 "strings"
18 ) 19 )
19 20
20 // uniqueName is generated afresh for every test run, so that 21 // uniqueName is generated afresh for every test run, so that
21 // we are not polluted by previous test state. 22 // we are not polluted by previous test state.
22 var uniqueName = randomName() 23 var uniqueName = randomName()
23 24
24 func randomName() string { 25 func randomName() string {
25 buf := make([]byte, 8) 26 buf := make([]byte, 8)
26 _, err := io.ReadFull(rand.Reader, buf) 27 _, err := io.ReadFull(rand.Reader, buf)
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 99 }
99 100
100 func (t *LiveTests) TearDownTest(c *C) { 101 func (t *LiveTests) TearDownTest(c *C) {
101 t.LiveTests.TearDownTest(c) 102 t.LiveTests.TearDownTest(c)
102 t.LoggingSuite.TearDownTest(c) 103 t.LoggingSuite.TearDownTest(c)
103 } 104 }
104 105
105 // TODO(niemeyer): Looks like many of those tests should be moved to jujutest.Li veTests. 106 // TODO(niemeyer): Looks like many of those tests should be moved to jujutest.Li veTests.
106 107
107 func (t *LiveTests) TestInstanceAttributes(c *C) { 108 func (t *LiveTests) TestInstanceAttributes(c *C) {
108 » inst, err := t.Env.StartInstance("30", constraints.Value{}, testing.Inva lidStateInfo("30"), testing.InvalidAPIInfo("30"), nil) 109 » inst := testing.StartInstance(c, t.Env, "30")
109 » c.Assert(err, IsNil)
110 defer t.Env.StopInstances([]environs.Instance{inst}) 110 defer t.Env.StopInstances([]environs.Instance{inst})
111 dns, err := inst.WaitDNSName() 111 dns, err := inst.WaitDNSName()
112 // TODO(niemeyer): This assert sometimes fails with "no instances found" 112 // TODO(niemeyer): This assert sometimes fails with "no instances found"
113 c.Assert(err, IsNil) 113 c.Assert(err, IsNil)
114 c.Assert(dns, Not(Equals), "") 114 c.Assert(dns, Not(Equals), "")
115 115
116 insts, err := t.Env.Instances([]state.InstanceId{inst.Id()}) 116 insts, err := t.Env.Instances([]state.InstanceId{inst.Id()})
117 c.Assert(err, IsNil) 117 c.Assert(err, IsNil)
118 c.Assert(len(insts), Equals, 1) 118 c.Assert(len(insts), Equals, 1)
119 119
120 ec2inst := ec2.InstanceEC2(insts[0]) 120 ec2inst := ec2.InstanceEC2(insts[0])
121 c.Assert(ec2inst.DNSName, Equals, dns) 121 c.Assert(ec2inst.DNSName, Equals, dns)
122 c.Assert(ec2inst.InstanceType, Equals, "m1.small") 122 c.Assert(ec2inst.InstanceType, Equals, "m1.small")
123 } 123 }
124 124
125 func (t *LiveTests) TestStartInstanceConstraints(c *C) { 125 func (t *LiveTests) TestStartInstanceConstraints(c *C) {
126 cons, err := constraints.Parse("mem=2G") 126 cons, err := constraints.Parse("mem=2G")
127 c.Assert(err, IsNil) 127 c.Assert(err, IsNil)
128 » inst, err := t.Env.StartInstance("31", cons, testing.InvalidStateInfo("3 1"), testing.InvalidAPIInfo("31"), nil) 128 » inst, err := t.Env.StartInstance("31", version.Current.Series, cons, tes ting.InvalidStateInfo("31"), testing.InvalidAPIInfo("31"))
129 c.Assert(err, IsNil) 129 c.Assert(err, IsNil)
130 defer t.Env.StopInstances([]environs.Instance{inst}) 130 defer t.Env.StopInstances([]environs.Instance{inst})
131 ec2inst := ec2.InstanceEC2(inst) 131 ec2inst := ec2.InstanceEC2(inst)
132 c.Assert(ec2inst.InstanceType, Equals, "m1.medium") 132 c.Assert(ec2inst.InstanceType, Equals, "m1.medium")
133 } 133 }
134 134
135 func (t *LiveTests) TestInstanceGroups(c *C) { 135 func (t *LiveTests) TestInstanceGroups(c *C) {
136 ec2conn := ec2.EnvironEC2(t.Env) 136 ec2conn := ec2.EnvironEC2(t.Env)
137 137
138 groups := amzec2.SecurityGroupNames( 138 groups := amzec2.SecurityGroupNames(
(...skipping 21 matching lines...) Expand all
160 }, 160 },
161 { 161 {
162 Protocol: "udp", 162 Protocol: "udp",
163 FromPort: 4321, 163 FromPort: 4321,
164 ToPort: 4322, 164 ToPort: 4322,
165 SourceIPs: []string{"3.4.5.6/32"}, 165 SourceIPs: []string{"3.4.5.6/32"},
166 }, 166 },
167 }) 167 })
168 c.Assert(err, IsNil) 168 c.Assert(err, IsNil)
169 169
170 » inst0, err := t.Env.StartInstance("98", constraints.Value{}, testing.Inv alidStateInfo("98"), testing.InvalidAPIInfo("98"), nil) 170 » inst0 := testing.StartInstance(c, t.Env, "98")
171 » c.Assert(err, IsNil)
172 defer t.Env.StopInstances([]environs.Instance{inst0}) 171 defer t.Env.StopInstances([]environs.Instance{inst0})
173 172
174 // Create a same-named group for the second instance 173 // Create a same-named group for the second instance
175 // before starting it, to check that it's reused correctly. 174 // before starting it, to check that it's reused correctly.
176 oldMachineGroup := createGroup(c, ec2conn, groups[2].Name, "old machine group") 175 oldMachineGroup := createGroup(c, ec2conn, groups[2].Name, "old machine group")
177 176
178 » inst1, err := t.Env.StartInstance("99", constraints.Value{}, testing.Inv alidStateInfo("99"), testing.InvalidAPIInfo("99"), nil) 177 » inst1 := testing.StartInstance(c, t.Env, "99")
179 » c.Assert(err, IsNil)
180 defer t.Env.StopInstances([]environs.Instance{inst1}) 178 defer t.Env.StopInstances([]environs.Instance{inst1})
181 179
182 groupsResp, err := ec2conn.SecurityGroups(groups, nil) 180 groupsResp, err := ec2conn.SecurityGroups(groups, nil)
183 c.Assert(err, IsNil) 181 c.Assert(err, IsNil)
184 c.Assert(groupsResp.Groups, HasLen, len(groups)) 182 c.Assert(groupsResp.Groups, HasLen, len(groups))
185 183
186 // For each group, check that it exists and record its id. 184 // For each group, check that it exists and record its id.
187 for i, group := range groups { 185 for i, group := range groups {
188 found := false 186 found := false
189 for _, g := range groupsResp.Groups { 187 for _, g := range groupsResp.Groups {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 } 298 }
301 if len(protos) > 0 { 299 if len(protos) > 0 {
302 c.Errorf("%d security group permission not found for %#v in %#v" , len(protos), g, perms) 300 c.Errorf("%d security group permission not found for %#v in %#v" , len(protos), g, perms)
303 } 301 }
304 } 302 }
305 303
306 func (t *LiveTests) TestStopInstances(c *C) { 304 func (t *LiveTests) TestStopInstances(c *C) {
307 // It would be nice if this test was in jujutest, but 305 // It would be nice if this test was in jujutest, but
308 // there's no way for jujutest to fabricate a valid-looking 306 // there's no way for jujutest to fabricate a valid-looking
309 // instance id. 307 // instance id.
310 » inst0, err := t.Env.StartInstance("40", constraints.Value{}, testing.Inv alidStateInfo("40"), testing.InvalidAPIInfo("40"), nil) 308 » inst0 := testing.StartInstance(c, t.Env, "40")
311 » c.Assert(err, IsNil)
312
313 inst1 := ec2.FabricateInstance(inst0, "i-aaaaaaaa") 309 inst1 := ec2.FabricateInstance(inst0, "i-aaaaaaaa")
314 310 » inst2 := testing.StartInstance(c, t.Env, "41")
315 » inst2, err := t.Env.StartInstance("41", constraints.Value{}, testing.Inv alidStateInfo("41"), testing.InvalidAPIInfo("41"), nil) 311
316 » c.Assert(err, IsNil) 312 » err := t.Env.StopInstances([]environs.Instance{inst0, inst1, inst2})
317
318 » err = t.Env.StopInstances([]environs.Instance{inst0, inst1, inst2})
319 c.Check(err, IsNil) 313 c.Check(err, IsNil)
320 314
321 var insts []environs.Instance 315 var insts []environs.Instance
322 316
323 // We need the retry logic here because we are waiting 317 // We need the retry logic here because we are waiting
324 // for Instances to return an error, and it will not retry 318 // for Instances to return an error, and it will not retry
325 // if it succeeds. 319 // if it succeeds.
326 gone := false 320 gone := false
327 for a := ec2.ShortAttempt.Start(); a.Next(); { 321 for a := ec2.ShortAttempt.Start(); a.Next(); {
328 insts, err = t.Env.Instances([]state.InstanceId{inst0.Id(), inst 2.Id()}) 322 insts, err = t.Env.Instances([]state.InstanceId{inst0.Id(), inst 2.Id()})
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 } 404 }
411 405
412 func hasSecurityGroup(r amzec2.Reservation, g amzec2.SecurityGroup) bool { 406 func hasSecurityGroup(r amzec2.Reservation, g amzec2.SecurityGroup) bool {
413 for _, rg := range r.SecurityGroups { 407 for _, rg := range r.SecurityGroups {
414 if rg.Id == g.Id { 408 if rg.Id == g.Id {
415 return true 409 return true
416 } 410 }
417 } 411 }
418 return false 412 return false
419 } 413 }
LEFTRIGHT

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