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

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

Issue 6347044: environs/ec2: bootstrap (Closed)
Patch Set: environs/ec2: bootstrap Created 12 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
OLDNEW
1 package ec2_test 1 package ec2_test
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "launchpad.net/goamz/aws" 5 "launchpad.net/goamz/aws"
6 amzec2 "launchpad.net/goamz/ec2" 6 amzec2 "launchpad.net/goamz/ec2"
7 "launchpad.net/goamz/ec2/ec2test" 7 "launchpad.net/goamz/ec2/ec2test"
8 "launchpad.net/goamz/s3" 8 "launchpad.net/goamz/s3"
9 "launchpad.net/goamz/s3/s3test" 9 "launchpad.net/goamz/s3/s3test"
10 . "launchpad.net/gocheck" 10 . "launchpad.net/gocheck"
11 "launchpad.net/goyaml" 11 "launchpad.net/goyaml"
12 "launchpad.net/juju-core/environs" 12 "launchpad.net/juju-core/environs"
13 "launchpad.net/juju-core/environs/ec2" 13 "launchpad.net/juju-core/environs/ec2"
14 "launchpad.net/juju-core/environs/jujutest" 14 "launchpad.net/juju-core/environs/jujutest"
15 "launchpad.net/juju-core/state" 15 "launchpad.net/juju-core/state"
16 » "launchpad.net/juju-core/testing" 16 » "launchpad.net/juju-core/state/testing"
17 » coretesting "launchpad.net/juju-core/testing"
17 "launchpad.net/juju-core/version" 18 "launchpad.net/juju-core/version"
18 "strings" 19 "strings"
19 ) 20 )
20 21
21 // you need to make sure the region you use here 22 // you need to make sure the region you use here
22 // has entries in the images/query txt files. 23 // has entries in the images/query txt files.
23 var functionalConfig = []byte(` 24 var functionalConfig = []byte(`
24 environments: 25 environments:
25 sample: 26 sample:
26 type: ec2 27 type: ec2
(...skipping 16 matching lines...) Expand all
43 for _, name := range envs.Names() { 44 for _, name := range envs.Names() {
44 Suite(&localServerSuite{ 45 Suite(&localServerSuite{
45 Tests: jujutest.Tests{ 46 Tests: jujutest.Tests{
46 Environs: envs, 47 Environs: envs,
47 Name: name, 48 Name: name,
48 }, 49 },
49 }) 50 })
50 Suite(&localLiveSuite{ 51 Suite(&localLiveSuite{
51 LiveTests: LiveTests{ 52 LiveTests: LiveTests{
52 LiveTests: jujutest.LiveTests{ 53 LiveTests: jujutest.LiveTests{
53 » » » » » Environs: envs, 54 » » » » » Environs: envs,
54 » » » » » Name: name, 55 » » » » » Name: name,
56 » » » » » CanOpenState: false, // ec2test mock s erver returns an invalid dns address
57 » » » » » HasProvisioner: false,
niemeyer 2012/07/06 19:44:56 Please revert to original state.
dave_cheney.net 2012/07/09 00:52:58 Done.
55 }, 58 },
56 }, 59 },
57 }) 60 })
58 } 61 }
59 } 62 }
60 63
61 // localLiveSuite runs tests from LiveTests using a fake 64 // localLiveSuite runs tests from LiveTests using a fake
62 // EC2 server that runs within the test process itself. 65 // EC2 server that runs within the test process itself.
63 type localLiveSuite struct { 66 type localLiveSuite struct {
64 » testing.LoggingSuite 67 » coretesting.LoggingSuite
68 » testing.StateSuite
65 LiveTests 69 LiveTests
66 srv localServer 70 srv localServer
67 env environs.Environ 71 env environs.Environ
68 } 72 }
69 73
70 func (t *localLiveSuite) SetUpSuite(c *C) { 74 func (t *localLiveSuite) SetUpSuite(c *C) {
71 ec2.UseTestImageData(true) 75 ec2.UseTestImageData(true)
72 t.srv.startServer(c) 76 t.srv.startServer(c)
73 t.LiveTests.SetUpSuite(c) 77 t.LiveTests.SetUpSuite(c)
74 t.env = t.LiveTests.Env 78 t.env = t.LiveTests.Env
75 ec2.ShortTimeouts(true) 79 ec2.ShortTimeouts(true)
76 } 80 }
77 81
78 func (t *localLiveSuite) TearDownSuite(c *C) { 82 func (t *localLiveSuite) TearDownSuite(c *C) {
79 t.LiveTests.TearDownSuite(c) 83 t.LiveTests.TearDownSuite(c)
80 t.srv.stopServer(c) 84 t.srv.stopServer(c)
81 t.env = nil 85 t.env = nil
82 ec2.ShortTimeouts(false) 86 ec2.ShortTimeouts(false)
83 ec2.UseTestImageData(false) 87 ec2.UseTestImageData(false)
84 } 88 }
85 89
86 func (t *localLiveSuite) SetUpTest(c *C) { 90 func (t *localLiveSuite) SetUpTest(c *C) {
87 t.LoggingSuite.SetUpTest(c) 91 t.LoggingSuite.SetUpTest(c)
92 t.StateSuite.SetUpTest(c)
88 t.LiveTests.SetUpTest(c) 93 t.LiveTests.SetUpTest(c)
89 } 94 }
90 95
91 func (t *localLiveSuite) TearDownTest(c *C) { 96 func (t *localLiveSuite) TearDownTest(c *C) {
92 t.LiveTests.TearDownTest(c) 97 t.LiveTests.TearDownTest(c)
98 t.StateSuite.TearDownTest(c)
93 t.LoggingSuite.TearDownTest(c) 99 t.LoggingSuite.TearDownTest(c)
94 } 100 }
95 101
96 // localServer represents a fake EC2 server running within 102 // localServer represents a fake EC2 server running within
97 // the test process itself. 103 // the test process itself.
98 type localServer struct { 104 type localServer struct {
99 ec2srv *ec2test.Server 105 ec2srv *ec2test.Server
100 s3srv *s3test.Server 106 s3srv *s3test.Server
101 } 107 }
102 108
103 func (srv *localServer) startServer(c *C) { 109 func (srv *localServer) startServer(c *C) {
104 var err error 110 var err error
105 srv.ec2srv, err = ec2test.NewServer() 111 srv.ec2srv, err = ec2test.NewServer()
106 if err != nil { 112 if err != nil {
107 c.Fatalf("cannot start ec2 test server: %v", err) 113 c.Fatalf("cannot start ec2 test server: %v", err)
108 } 114 }
109 srv.s3srv, err = s3test.NewServer() 115 srv.s3srv, err = s3test.NewServer()
110 if err != nil { 116 if err != nil {
111 c.Fatalf("cannot start s3 test server: %v", err) 117 c.Fatalf("cannot start s3 test server: %v", err)
112 } 118 }
113 aws.Regions["test"] = aws.Region{ 119 aws.Regions["test"] = aws.Region{
114 » » Name: "test", 120 » » Name: "test",
115 » » EC2Endpoint: srv.ec2srv.URL(), 121 » » EC2Endpoint: srv.ec2srv.URL(),
116 » » S3Endpoint: srv.s3srv.URL(), 122 » » S3Endpoint: srv.s3srv.URL(),
117 S3LocationConstraint: true, 123 S3LocationConstraint: true,
118 } 124 }
119 s3inst := s3.New(aws.Auth{}, aws.Regions["test"]) 125 s3inst := s3.New(aws.Auth{}, aws.Regions["test"])
120 putFakeTools(c, ec2.BucketStorage(s3inst.Bucket("public-tools"))) 126 putFakeTools(c, ec2.BucketStorage(s3inst.Bucket("public-tools")))
121 srv.addSpice(c) 127 srv.addSpice(c)
122 } 128 }
123 129
124 // putFakeTools sets up a bucket containing something 130 // putFakeTools sets up a bucket containing something
125 // that looks like a tools archive so test methods 131 // that looks like a tools archive so test methods
126 // that start an instance can succeed even though they 132 // that start an instance can succeed even though they
127 // do not upload tools. 133 // do not upload tools.
128 func putFakeTools(c *C, s environs.StorageWriter) { 134 func putFakeTools(c *C, s environs.StorageWriter) {
129 path := environs.ToolsPath(version.Current, environs.CurrentSeries, envi rons.CurrentArch) 135 path := environs.ToolsPath(version.Current, environs.CurrentSeries, envi rons.CurrentArch)
130 c.Logf("putting fake tools at %v", path) 136 c.Logf("putting fake tools at %v", path)
131 toolsContents := "tools archive, honest guv" 137 toolsContents := "tools archive, honest guv"
132 err := s.Put(path, strings.NewReader(toolsContents), int64(len(toolsCont ents))) 138 err := s.Put(path, strings.NewReader(toolsContents), int64(len(toolsCont ents)))
133 » if err != nil { 139 » c.Assert(err, IsNil)
134 » » c.Fatal(err)
135 » }
136 } 140 }
137 141
138 // addSpice adds some "spice" to the local server 142 // addSpice adds some "spice" to the local server
139 // by adding state that may cause tests to fail. 143 // by adding state that may cause tests to fail.
140 func (srv *localServer) addSpice(c *C) { 144 func (srv *localServer) addSpice(c *C) {
141 states := []amzec2.InstanceState{ 145 states := []amzec2.InstanceState{
142 ec2test.ShuttingDown, 146 ec2test.ShuttingDown,
143 ec2test.Terminated, 147 ec2test.Terminated,
144 ec2test.Stopped, 148 ec2test.Stopped,
145 } 149 }
(...skipping 10 matching lines...) Expand all
156 delete(aws.Regions, "test") 160 delete(aws.Regions, "test")
157 } 161 }
158 162
159 // localServerSuite contains tests that run against a fake EC2 server 163 // localServerSuite contains tests that run against a fake EC2 server
160 // running within the test process itself. These tests can test things that 164 // running within the test process itself. These tests can test things that
161 // would be unreasonably slow or expensive to test on a live Amazon server. 165 // would be unreasonably slow or expensive to test on a live Amazon server.
162 // It starts a new local ec2test server for each test. The server is 166 // It starts a new local ec2test server for each test. The server is
163 // accessed by using the "test" region, which is changed to point to the 167 // accessed by using the "test" region, which is changed to point to the
164 // network address of the local server. 168 // network address of the local server.
165 type localServerSuite struct { 169 type localServerSuite struct {
166 » testing.LoggingSuite 170 » coretesting.LoggingSuite
171 » testing.StateSuite
167 jujutest.Tests 172 jujutest.Tests
168 srv localServer 173 srv localServer
169 env environs.Environ 174 env environs.Environ
170 } 175 }
171 176
172 func (t *localServerSuite) SetUpSuite(c *C) { 177 func (t *localServerSuite) SetUpSuite(c *C) {
173 ec2.UseTestImageData(true) 178 ec2.UseTestImageData(true)
174 t.Tests.SetUpSuite(c) 179 t.Tests.SetUpSuite(c)
175 ec2.ShortTimeouts(true) 180 ec2.ShortTimeouts(true)
176 } 181 }
177 182
178 func (t *localServerSuite) TearDownSuite(c *C) { 183 func (t *localServerSuite) TearDownSuite(c *C) {
179 t.Tests.TearDownSuite(c) 184 t.Tests.TearDownSuite(c)
180 ec2.ShortTimeouts(false) 185 ec2.ShortTimeouts(false)
181 ec2.UseTestImageData(false) 186 ec2.UseTestImageData(false)
182 } 187 }
183 188
184 func (t *localServerSuite) SetUpTest(c *C) { 189 func (t *localServerSuite) SetUpTest(c *C) {
185 t.LoggingSuite.SetUpTest(c) 190 t.LoggingSuite.SetUpTest(c)
191 t.StateSuite.SetUpTest(c)
186 t.srv.startServer(c) 192 t.srv.startServer(c)
187 t.Tests.SetUpTest(c) 193 t.Tests.SetUpTest(c)
188 t.env = t.Tests.Env 194 t.env = t.Tests.Env
189 } 195 }
190 196
191 func (t *localServerSuite) TearDownTest(c *C) { 197 func (t *localServerSuite) TearDownTest(c *C) {
192 t.Tests.TearDownTest(c) 198 t.Tests.TearDownTest(c)
193 t.srv.stopServer(c) 199 t.srv.stopServer(c)
200 t.StateSuite.TearDownTest(c)
194 t.LoggingSuite.TearDownTest(c) 201 t.LoggingSuite.TearDownTest(c)
195 } 202 }
196 203
197 func (t *localServerSuite) TestBootstrapInstanceUserDataAndState(c *C) { 204 func (t *localServerSuite) TestBootstrapInstanceUserDataAndState(c *C) {
198 policy := t.env.AssignmentPolicy() 205 policy := t.env.AssignmentPolicy()
199 c.Assert(policy, Equals, state.AssignUnused) 206 c.Assert(policy, Equals, state.AssignUnused)
200 207
201 err := t.env.Bootstrap(true) 208 err := t.env.Bootstrap(true)
202 c.Assert(err, IsNil) 209 c.Assert(err, IsNil)
203 210
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 // TODO check for machine agent 258 // TODO check for machine agent
252 ec2.CheckScripts(c, x, fmt.Sprintf("JUJU_ZOOKEEPER='%s%s'", bootstrapDNS , ec2.ZkPortSuffix), true) 259 ec2.CheckScripts(c, x, fmt.Sprintf("JUJU_ZOOKEEPER='%s%s'", bootstrapDNS , ec2.ZkPortSuffix), true)
253 ec2.CheckScripts(c, x, fmt.Sprintf("JUJU_MACHINE_ID=1"), true) 260 ec2.CheckScripts(c, x, fmt.Sprintf("JUJU_MACHINE_ID=1"), true)
254 261
255 err = t.env.Destroy(append(insts, inst1)) 262 err = t.env.Destroy(append(insts, inst1))
256 c.Assert(err, IsNil) 263 c.Assert(err, IsNil)
257 264
258 _, err = ec2.LoadState(t.env) 265 _, err = ec2.LoadState(t.env)
259 c.Assert(err, NotNil) 266 c.Assert(err, NotNil)
260 } 267 }
OLDNEW

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