LEFT | RIGHT |
(no file at all) | |
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 jujutest | 4 package jujutest |
5 | 5 |
6 import ( | 6 import ( |
7 "bytes" | 7 "bytes" |
8 "fmt" | 8 "fmt" |
9 "io" | 9 "io" |
| 10 "io/ioutil" |
10 . "launchpad.net/gocheck" | 11 . "launchpad.net/gocheck" |
11 "launchpad.net/juju-core/charm" | 12 "launchpad.net/juju-core/charm" |
12 "launchpad.net/juju-core/constraints" | 13 "launchpad.net/juju-core/constraints" |
13 "launchpad.net/juju-core/environs" | 14 "launchpad.net/juju-core/environs" |
14 "launchpad.net/juju-core/environs/config" | 15 "launchpad.net/juju-core/environs/config" |
15 "launchpad.net/juju-core/environs/tools" | 16 "launchpad.net/juju-core/environs/tools" |
16 "launchpad.net/juju-core/errors" | 17 "launchpad.net/juju-core/errors" |
| 18 "launchpad.net/juju-core/instance" |
17 "launchpad.net/juju-core/juju" | 19 "launchpad.net/juju-core/juju" |
18 "launchpad.net/juju-core/juju/testing" | 20 "launchpad.net/juju-core/juju/testing" |
19 "launchpad.net/juju-core/state" | 21 "launchpad.net/juju-core/state" |
20 » "launchpad.net/juju-core/state/api/params" | 22 » "launchpad.net/juju-core/state/api" |
21 coretesting "launchpad.net/juju-core/testing" | 23 coretesting "launchpad.net/juju-core/testing" |
22 "launchpad.net/juju-core/utils" | 24 "launchpad.net/juju-core/utils" |
23 "launchpad.net/juju-core/version" | 25 "launchpad.net/juju-core/version" |
24 "time" | 26 "time" |
25 ) | 27 ) |
26 | 28 |
27 // LiveTests contains tests that are designed to run against a live server | 29 // LiveTests contains tests that are designed to run against a live server |
28 // (e.g. Amazon EC2). The Environ is opened once only for all the tests | 30 // (e.g. Amazon EC2). The Environ is opened once only for all the tests |
29 // in the suite, stored in Env, and Destroyed after the suite has completed. | 31 // in the suite, stored in Env, and Destroyed after the suite has completed. |
30 type LiveTests struct { | 32 type LiveTests struct { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 t.bootstrapped = false | 106 t.bootstrapped = false |
105 } | 107 } |
106 | 108 |
107 // TestStartStop is similar to Tests.TestStartStop except | 109 // TestStartStop is similar to Tests.TestStartStop except |
108 // that it does not assume a pristine environment. | 110 // that it does not assume a pristine environment. |
109 func (t *LiveTests) TestStartStop(c *C) { | 111 func (t *LiveTests) TestStartStop(c *C) { |
110 inst := testing.StartInstance(c, t.Env, "0") | 112 inst := testing.StartInstance(c, t.Env, "0") |
111 c.Assert(inst, NotNil) | 113 c.Assert(inst, NotNil) |
112 id0 := inst.Id() | 114 id0 := inst.Id() |
113 | 115 |
114 » insts, err := t.Env.Instances([]state.InstanceId{id0, id0}) | 116 » insts, err := t.Env.Instances([]instance.Id{id0, id0}) |
115 c.Assert(err, IsNil) | 117 c.Assert(err, IsNil) |
116 c.Assert(insts, HasLen, 2) | 118 c.Assert(insts, HasLen, 2) |
117 c.Assert(insts[0].Id(), Equals, id0) | 119 c.Assert(insts[0].Id(), Equals, id0) |
118 c.Assert(insts[1].Id(), Equals, id0) | 120 c.Assert(insts[1].Id(), Equals, id0) |
119 | 121 |
120 // Asserting on the return of AllInstances makes the test fragile, | 122 // Asserting on the return of AllInstances makes the test fragile, |
121 // as even comparing the before and after start values can be thrown | 123 // as even comparing the before and after start values can be thrown |
122 // off if other instances have been created or destroyed in the same | 124 // off if other instances have been created or destroyed in the same |
123 // time frame. Instead, just check the instance we created exists. | 125 // time frame. Instead, just check the instance we created exists. |
124 insts, err = t.Env.AllInstances() | 126 insts, err = t.Env.AllInstances() |
125 c.Assert(err, IsNil) | 127 c.Assert(err, IsNil) |
126 found := false | 128 found := false |
127 for _, inst := range insts { | 129 for _, inst := range insts { |
128 if inst.Id() == id0 { | 130 if inst.Id() == id0 { |
129 c.Assert(found, Equals, false, Commentf("%v", insts)) | 131 c.Assert(found, Equals, false, Commentf("%v", insts)) |
130 found = true | 132 found = true |
131 } | 133 } |
132 } | 134 } |
133 c.Assert(found, Equals, true, Commentf("expected %v in %v", inst, insts)
) | 135 c.Assert(found, Equals, true, Commentf("expected %v in %v", inst, insts)
) |
134 | 136 |
135 dns, err := inst.WaitDNSName() | 137 dns, err := inst.WaitDNSName() |
136 c.Assert(err, IsNil) | 138 c.Assert(err, IsNil) |
137 c.Assert(dns, Not(Equals), "") | 139 c.Assert(dns, Not(Equals), "") |
138 | 140 |
139 » insts, err = t.Env.Instances([]state.InstanceId{id0, ""}) | 141 » insts, err = t.Env.Instances([]instance.Id{id0, ""}) |
140 c.Assert(err, Equals, environs.ErrPartialInstances) | 142 c.Assert(err, Equals, environs.ErrPartialInstances) |
141 c.Assert(insts, HasLen, 2) | 143 c.Assert(insts, HasLen, 2) |
142 c.Check(insts[0].Id(), Equals, id0) | 144 c.Check(insts[0].Id(), Equals, id0) |
143 c.Check(insts[1], IsNil) | 145 c.Check(insts[1], IsNil) |
144 | 146 |
145 » err = t.Env.StopInstances([]environs.Instance{inst}) | 147 » err = t.Env.StopInstances([]instance.Instance{inst}) |
146 c.Assert(err, IsNil) | 148 c.Assert(err, IsNil) |
147 | 149 |
148 // The machine may not be marked as shutting down | 150 // The machine may not be marked as shutting down |
149 // immediately. Repeat a few times to ensure we get the error. | 151 // immediately. Repeat a few times to ensure we get the error. |
150 for a := t.Attempt.Start(); a.Next(); { | 152 for a := t.Attempt.Start(); a.Next(); { |
151 » » insts, err = t.Env.Instances([]state.InstanceId{id0}) | 153 » » insts, err = t.Env.Instances([]instance.Id{id0}) |
152 if err != nil { | 154 if err != nil { |
153 break | 155 break |
154 } | 156 } |
155 } | 157 } |
156 c.Assert(err, Equals, environs.ErrNoInstances) | 158 c.Assert(err, Equals, environs.ErrNoInstances) |
157 c.Assert(insts, HasLen, 0) | 159 c.Assert(insts, HasLen, 0) |
158 } | 160 } |
159 | 161 |
160 func (t *LiveTests) TestPorts(c *C) { | 162 func (t *LiveTests) TestPorts(c *C) { |
161 inst1 := testing.StartInstance(c, t.Env, "1") | 163 inst1 := testing.StartInstance(c, t.Env, "1") |
162 c.Assert(inst1, NotNil) | 164 c.Assert(inst1, NotNil) |
163 » defer t.Env.StopInstances([]environs.Instance{inst1}) | 165 » defer t.Env.StopInstances([]instance.Instance{inst1}) |
164 ports, err := inst1.Ports("1") | 166 ports, err := inst1.Ports("1") |
165 c.Assert(err, IsNil) | 167 c.Assert(err, IsNil) |
166 c.Assert(ports, HasLen, 0) | 168 c.Assert(ports, HasLen, 0) |
167 | 169 |
168 inst2 := testing.StartInstance(c, t.Env, "2") | 170 inst2 := testing.StartInstance(c, t.Env, "2") |
169 c.Assert(inst2, NotNil) | 171 c.Assert(inst2, NotNil) |
170 ports, err = inst2.Ports("2") | 172 ports, err = inst2.Ports("2") |
171 c.Assert(err, IsNil) | 173 c.Assert(err, IsNil) |
172 c.Assert(ports, HasLen, 0) | 174 c.Assert(ports, HasLen, 0) |
173 » defer t.Env.StopInstances([]environs.Instance{inst2}) | 175 » defer t.Env.StopInstances([]instance.Instance{inst2}) |
174 | 176 |
175 // Open some ports and check they're there. | 177 // Open some ports and check they're there. |
176 » err = inst1.OpenPorts("1", []params.Port{{"udp", 67}, {"tcp", 45}}) | 178 » err = inst1.OpenPorts("1", []instance.Port{{"udp", 67}, {"tcp", 45}}) |
177 c.Assert(err, IsNil) | 179 c.Assert(err, IsNil) |
178 ports, err = inst1.Ports("1") | 180 ports, err = inst1.Ports("1") |
179 c.Assert(err, IsNil) | 181 c.Assert(err, IsNil) |
180 » c.Assert(ports, DeepEquals, []params.Port{{"tcp", 45}, {"udp", 67}}) | 182 » c.Assert(ports, DeepEquals, []instance.Port{{"tcp", 45}, {"udp", 67}}) |
181 ports, err = inst2.Ports("2") | 183 ports, err = inst2.Ports("2") |
182 c.Assert(err, IsNil) | 184 c.Assert(err, IsNil) |
183 c.Assert(ports, HasLen, 0) | 185 c.Assert(ports, HasLen, 0) |
184 | 186 |
185 » err = inst2.OpenPorts("2", []params.Port{{"tcp", 89}, {"tcp", 45}}) | 187 » err = inst2.OpenPorts("2", []instance.Port{{"tcp", 89}, {"tcp", 45}}) |
186 c.Assert(err, IsNil) | 188 c.Assert(err, IsNil) |
187 | 189 |
188 // Check there's no crosstalk to another machine | 190 // Check there's no crosstalk to another machine |
189 ports, err = inst2.Ports("2") | 191 ports, err = inst2.Ports("2") |
190 c.Assert(err, IsNil) | 192 c.Assert(err, IsNil) |
191 » c.Assert(ports, DeepEquals, []params.Port{{"tcp", 45}, {"tcp", 89}}) | 193 » c.Assert(ports, DeepEquals, []instance.Port{{"tcp", 45}, {"tcp", 89}}) |
192 ports, err = inst1.Ports("1") | 194 ports, err = inst1.Ports("1") |
193 c.Assert(err, IsNil) | 195 c.Assert(err, IsNil) |
194 » c.Assert(ports, DeepEquals, []params.Port{{"tcp", 45}, {"udp", 67}}) | 196 » c.Assert(ports, DeepEquals, []instance.Port{{"tcp", 45}, {"udp", 67}}) |
195 | 197 |
196 // Check that opening the same port again is ok. | 198 // Check that opening the same port again is ok. |
197 oldPorts, err := inst2.Ports("2") | 199 oldPorts, err := inst2.Ports("2") |
198 c.Assert(err, IsNil) | 200 c.Assert(err, IsNil) |
199 » err = inst2.OpenPorts("2", []params.Port{{"tcp", 45}}) | 201 » err = inst2.OpenPorts("2", []instance.Port{{"tcp", 45}}) |
200 c.Assert(err, IsNil) | 202 c.Assert(err, IsNil) |
201 ports, err = inst2.Ports("2") | 203 ports, err = inst2.Ports("2") |
202 c.Assert(err, IsNil) | 204 c.Assert(err, IsNil) |
203 c.Assert(ports, DeepEquals, oldPorts) | 205 c.Assert(ports, DeepEquals, oldPorts) |
204 | 206 |
205 // Check that opening the same port again and another port is ok. | 207 // Check that opening the same port again and another port is ok. |
206 » err = inst2.OpenPorts("2", []params.Port{{"tcp", 45}, {"tcp", 99}}) | 208 » err = inst2.OpenPorts("2", []instance.Port{{"tcp", 45}, {"tcp", 99}}) |
207 c.Assert(err, IsNil) | 209 c.Assert(err, IsNil) |
208 ports, err = inst2.Ports("2") | 210 ports, err = inst2.Ports("2") |
209 c.Assert(err, IsNil) | 211 c.Assert(err, IsNil) |
210 » c.Assert(ports, DeepEquals, []params.Port{{"tcp", 45}, {"tcp", 89}, {"tc
p", 99}}) | 212 » c.Assert(ports, DeepEquals, []instance.Port{{"tcp", 45}, {"tcp", 89}, {"
tcp", 99}}) |
211 | 213 |
212 » err = inst2.ClosePorts("2", []params.Port{{"tcp", 45}, {"tcp", 99}}) | 214 » err = inst2.ClosePorts("2", []instance.Port{{"tcp", 45}, {"tcp", 99}}) |
213 c.Assert(err, IsNil) | 215 c.Assert(err, IsNil) |
214 | 216 |
215 // Check that we can close ports and that there's no crosstalk. | 217 // Check that we can close ports and that there's no crosstalk. |
216 ports, err = inst2.Ports("2") | 218 ports, err = inst2.Ports("2") |
217 c.Assert(err, IsNil) | 219 c.Assert(err, IsNil) |
218 » c.Assert(ports, DeepEquals, []params.Port{{"tcp", 89}}) | 220 » c.Assert(ports, DeepEquals, []instance.Port{{"tcp", 89}}) |
219 ports, err = inst1.Ports("1") | 221 ports, err = inst1.Ports("1") |
220 c.Assert(err, IsNil) | 222 c.Assert(err, IsNil) |
221 » c.Assert(ports, DeepEquals, []params.Port{{"tcp", 45}, {"udp", 67}}) | 223 » c.Assert(ports, DeepEquals, []instance.Port{{"tcp", 45}, {"udp", 67}}) |
222 | 224 |
223 // Check that we can close multiple ports. | 225 // Check that we can close multiple ports. |
224 » err = inst1.ClosePorts("1", []params.Port{{"tcp", 45}, {"udp", 67}}) | 226 » err = inst1.ClosePorts("1", []instance.Port{{"tcp", 45}, {"udp", 67}}) |
225 c.Assert(err, IsNil) | 227 c.Assert(err, IsNil) |
226 ports, err = inst1.Ports("1") | 228 ports, err = inst1.Ports("1") |
227 c.Assert(ports, HasLen, 0) | 229 c.Assert(ports, HasLen, 0) |
228 | 230 |
229 // Check that we can close ports that aren't there. | 231 // Check that we can close ports that aren't there. |
230 » err = inst2.ClosePorts("2", []params.Port{{"tcp", 111}, {"udp", 222}}) | 232 » err = inst2.ClosePorts("2", []instance.Port{{"tcp", 111}, {"udp", 222}}) |
231 c.Assert(err, IsNil) | 233 c.Assert(err, IsNil) |
232 ports, err = inst2.Ports("2") | 234 ports, err = inst2.Ports("2") |
233 » c.Assert(ports, DeepEquals, []params.Port{{"tcp", 89}}) | 235 » c.Assert(ports, DeepEquals, []instance.Port{{"tcp", 89}}) |
234 | 236 |
235 // Check errors when acting on environment. | 237 // Check errors when acting on environment. |
236 » err = t.Env.OpenPorts([]params.Port{{"tcp", 80}}) | 238 » err = t.Env.OpenPorts([]instance.Port{{"tcp", 80}}) |
237 c.Assert(err, ErrorMatches, `invalid firewall mode for opening ports on
environment: "instance"`) | 239 c.Assert(err, ErrorMatches, `invalid firewall mode for opening ports on
environment: "instance"`) |
238 | 240 |
239 » err = t.Env.ClosePorts([]params.Port{{"tcp", 80}}) | 241 » err = t.Env.ClosePorts([]instance.Port{{"tcp", 80}}) |
240 c.Assert(err, ErrorMatches, `invalid firewall mode for closing ports on
environment: "instance"`) | 242 c.Assert(err, ErrorMatches, `invalid firewall mode for closing ports on
environment: "instance"`) |
241 | 243 |
242 _, err = t.Env.Ports() | 244 _, err = t.Env.Ports() |
243 c.Assert(err, ErrorMatches, `invalid firewall mode for retrieving ports
from environment: "instance"`) | 245 c.Assert(err, ErrorMatches, `invalid firewall mode for retrieving ports
from environment: "instance"`) |
244 } | 246 } |
245 | 247 |
246 func (t *LiveTests) TestGlobalPorts(c *C) { | 248 func (t *LiveTests) TestGlobalPorts(c *C) { |
247 // Change configuration. | 249 // Change configuration. |
248 oldConfig := t.Env.Config() | 250 oldConfig := t.Env.Config() |
249 defer func() { | 251 defer func() { |
250 err := t.Env.SetConfig(oldConfig) | 252 err := t.Env.SetConfig(oldConfig) |
251 c.Assert(err, IsNil) | 253 c.Assert(err, IsNil) |
252 }() | 254 }() |
253 | 255 |
254 attrs := t.Env.Config().AllAttrs() | 256 attrs := t.Env.Config().AllAttrs() |
255 attrs["firewall-mode"] = "global" | 257 attrs["firewall-mode"] = "global" |
256 newConfig, err := t.Env.Config().Apply(attrs) | 258 newConfig, err := t.Env.Config().Apply(attrs) |
257 c.Assert(err, IsNil) | 259 c.Assert(err, IsNil) |
258 err = t.Env.SetConfig(newConfig) | 260 err = t.Env.SetConfig(newConfig) |
259 c.Assert(err, IsNil) | 261 c.Assert(err, IsNil) |
260 | 262 |
261 // Create instances and check open ports on both instances. | 263 // Create instances and check open ports on both instances. |
262 inst1 := testing.StartInstance(c, t.Env, "1") | 264 inst1 := testing.StartInstance(c, t.Env, "1") |
263 » defer t.Env.StopInstances([]environs.Instance{inst1}) | 265 » defer t.Env.StopInstances([]instance.Instance{inst1}) |
264 ports, err := t.Env.Ports() | 266 ports, err := t.Env.Ports() |
265 c.Assert(err, IsNil) | 267 c.Assert(err, IsNil) |
266 c.Assert(ports, HasLen, 0) | 268 c.Assert(ports, HasLen, 0) |
267 | 269 |
268 inst2 := testing.StartInstance(c, t.Env, "2") | 270 inst2 := testing.StartInstance(c, t.Env, "2") |
269 ports, err = t.Env.Ports() | 271 ports, err = t.Env.Ports() |
270 c.Assert(err, IsNil) | 272 c.Assert(err, IsNil) |
271 c.Assert(ports, HasLen, 0) | 273 c.Assert(ports, HasLen, 0) |
272 » defer t.Env.StopInstances([]environs.Instance{inst2}) | 274 » defer t.Env.StopInstances([]instance.Instance{inst2}) |
273 | 275 |
274 » err = t.Env.OpenPorts([]params.Port{{"udp", 67}, {"tcp", 45}, {"tcp", 89
}, {"tcp", 99}}) | 276 » err = t.Env.OpenPorts([]instance.Port{{"udp", 67}, {"tcp", 45}, {"tcp",
89}, {"tcp", 99}}) |
275 c.Assert(err, IsNil) | 277 c.Assert(err, IsNil) |
276 | 278 |
277 ports, err = t.Env.Ports() | 279 ports, err = t.Env.Ports() |
278 c.Assert(err, IsNil) | 280 c.Assert(err, IsNil) |
279 » c.Assert(ports, DeepEquals, []params.Port{{"tcp", 45}, {"tcp", 89}, {"tc
p", 99}, {"udp", 67}}) | 281 » c.Assert(ports, DeepEquals, []instance.Port{{"tcp", 45}, {"tcp", 89}, {"
tcp", 99}, {"udp", 67}}) |
280 | 282 |
281 // Check closing some ports. | 283 // Check closing some ports. |
282 » err = t.Env.ClosePorts([]params.Port{{"tcp", 99}, {"udp", 67}}) | 284 » err = t.Env.ClosePorts([]instance.Port{{"tcp", 99}, {"udp", 67}}) |
283 c.Assert(err, IsNil) | 285 c.Assert(err, IsNil) |
284 | 286 |
285 ports, err = t.Env.Ports() | 287 ports, err = t.Env.Ports() |
286 c.Assert(err, IsNil) | 288 c.Assert(err, IsNil) |
287 » c.Assert(ports, DeepEquals, []params.Port{{"tcp", 45}, {"tcp", 89}}) | 289 » c.Assert(ports, DeepEquals, []instance.Port{{"tcp", 45}, {"tcp", 89}}) |
288 | 290 |
289 // Check that we can close ports that aren't there. | 291 // Check that we can close ports that aren't there. |
290 » err = t.Env.ClosePorts([]params.Port{{"tcp", 111}, {"udp", 222}}) | 292 » err = t.Env.ClosePorts([]instance.Port{{"tcp", 111}, {"udp", 222}}) |
291 c.Assert(err, IsNil) | 293 c.Assert(err, IsNil) |
292 | 294 |
293 ports, err = t.Env.Ports() | 295 ports, err = t.Env.Ports() |
294 c.Assert(err, IsNil) | 296 c.Assert(err, IsNil) |
295 » c.Assert(ports, DeepEquals, []params.Port{{"tcp", 45}, {"tcp", 89}}) | 297 » c.Assert(ports, DeepEquals, []instance.Port{{"tcp", 45}, {"tcp", 89}}) |
296 | 298 |
297 // Check errors when acting on instances. | 299 // Check errors when acting on instances. |
298 » err = inst1.OpenPorts("1", []params.Port{{"tcp", 80}}) | 300 » err = inst1.OpenPorts("1", []instance.Port{{"tcp", 80}}) |
299 c.Assert(err, ErrorMatches, `invalid firewall mode for opening ports on
instance: "global"`) | 301 c.Assert(err, ErrorMatches, `invalid firewall mode for opening ports on
instance: "global"`) |
300 | 302 |
301 » err = inst1.ClosePorts("1", []params.Port{{"tcp", 80}}) | 303 » err = inst1.ClosePorts("1", []instance.Port{{"tcp", 80}}) |
302 c.Assert(err, ErrorMatches, `invalid firewall mode for closing ports on
instance: "global"`) | 304 c.Assert(err, ErrorMatches, `invalid firewall mode for closing ports on
instance: "global"`) |
303 | 305 |
304 _, err = inst1.Ports("1") | 306 _, err = inst1.Ports("1") |
305 c.Assert(err, ErrorMatches, `invalid firewall mode for retrieving ports
from instance: "global"`) | 307 c.Assert(err, ErrorMatches, `invalid firewall mode for retrieving ports
from instance: "global"`) |
306 } | 308 } |
307 | 309 |
308 func (t *LiveTests) TestBootstrapMultiple(c *C) { | 310 func (t *LiveTests) TestBootstrapMultiple(c *C) { |
309 t.BootstrapOnce(c) | 311 t.BootstrapOnce(c) |
310 | 312 |
311 err := environs.Bootstrap(t.Env, constraints.Value{}) | 313 err := environs.Bootstrap(t.Env, constraints.Value{}) |
(...skipping 14 matching lines...) Expand all Loading... |
326 t.BootstrapOnce(c) | 328 t.BootstrapOnce(c) |
327 | 329 |
328 // TODO(niemeyer): Stop growing this kitchen sink test and split it into
proper parts. | 330 // TODO(niemeyer): Stop growing this kitchen sink test and split it into
proper parts. |
329 | 331 |
330 c.Logf("opening connection") | 332 c.Logf("opening connection") |
331 conn, err := juju.NewConn(t.Env) | 333 conn, err := juju.NewConn(t.Env) |
332 c.Assert(err, IsNil) | 334 c.Assert(err, IsNil) |
333 defer conn.Close() | 335 defer conn.Close() |
334 | 336 |
335 c.Logf("opening API connection") | 337 c.Logf("opening API connection") |
336 » apiConn, err := juju.NewAPIConn(t.Env) | 338 » apiConn, err := juju.NewAPIConn(t.Env, api.DefaultDialOpts()) |
337 c.Assert(err, IsNil) | 339 c.Assert(err, IsNil) |
338 defer conn.Close() | 340 defer conn.Close() |
339 | 341 |
340 // Check that the agent version has made it through the | 342 // Check that the agent version has made it through the |
341 // bootstrap process (it's optional in the config.Config) | 343 // bootstrap process (it's optional in the config.Config) |
342 cfg, err := conn.State.EnvironConfig() | 344 cfg, err := conn.State.EnvironConfig() |
343 c.Assert(err, IsNil) | 345 c.Assert(err, IsNil) |
344 agentVersion, ok := cfg.AgentVersion() | 346 agentVersion, ok := cfg.AgentVersion() |
345 c.Check(ok, Equals, true) | 347 c.Check(ok, Equals, true) |
346 c.Check(agentVersion, Equals, version.CurrentNumber()) | 348 c.Check(agentVersion, Equals, version.CurrentNumber()) |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 err = m1.Refresh() | 450 err = m1.Refresh() |
449 if errors.IsNotFoundError(err) { | 451 if errors.IsNotFoundError(err) { |
450 break | 452 break |
451 } | 453 } |
452 c.Assert(err, IsNil) | 454 c.Assert(err, IsNil) |
453 } | 455 } |
454 c.Logf("waiting for instance to be removed") | 456 c.Logf("waiting for instance to be removed") |
455 t.assertStopInstance(c, conn.Environ, instId1) | 457 t.assertStopInstance(c, conn.Environ, instId1) |
456 } | 458 } |
457 | 459 |
| 460 func (t *LiveTests) TestBootstrapVerifyStorage(c *C) { |
| 461 // Bootstrap automatically verifies that storage is writable. |
| 462 t.BootstrapOnce(c) |
| 463 environ := t.Env |
| 464 storage := environ.Storage() |
| 465 reader, err := storage.Get("bootstrap-verify") |
| 466 c.Assert(err, IsNil) |
| 467 defer reader.Close() |
| 468 contents, err := ioutil.ReadAll(reader) |
| 469 c.Assert(err, IsNil) |
| 470 c.Check(string(contents), Equals, |
| 471 "juju-core storage writing verified: ok\n") |
| 472 } |
| 473 |
458 type tooler interface { | 474 type tooler interface { |
459 Life() state.Life | 475 Life() state.Life |
460 AgentTools() (*state.Tools, error) | 476 AgentTools() (*state.Tools, error) |
461 Refresh() error | 477 Refresh() error |
462 String() string | 478 String() string |
463 } | 479 } |
464 | 480 |
465 type watcher interface { | 481 type watcher interface { |
466 Stop() error | 482 Stop() error |
467 Err() error | 483 Err() error |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 | 614 |
599 func (t *LiveTests) assertStartInstance(c *C, m *state.Machine) { | 615 func (t *LiveTests) assertStartInstance(c *C, m *state.Machine) { |
600 // Wait for machine to get an instance id. | 616 // Wait for machine to get an instance id. |
601 for a := waitAgent.Start(); a.Next(); { | 617 for a := waitAgent.Start(); a.Next(); { |
602 err := m.Refresh() | 618 err := m.Refresh() |
603 c.Assert(err, IsNil) | 619 c.Assert(err, IsNil) |
604 instId, ok := m.InstanceId() | 620 instId, ok := m.InstanceId() |
605 if !ok { | 621 if !ok { |
606 continue | 622 continue |
607 } | 623 } |
608 » » _, err = t.Env.Instances([]state.InstanceId{instId}) | 624 » » _, err = t.Env.Instances([]instance.Id{instId}) |
609 c.Assert(err, IsNil) | 625 c.Assert(err, IsNil) |
610 return | 626 return |
611 } | 627 } |
612 c.Fatalf("provisioner failed to start machine after %v", waitAgent.Total
) | 628 c.Fatalf("provisioner failed to start machine after %v", waitAgent.Total
) |
613 } | 629 } |
614 | 630 |
615 func (t *LiveTests) assertStopInstance(c *C, env environs.Environ, instId state.
InstanceId) { | 631 func (t *LiveTests) assertStopInstance(c *C, env environs.Environ, instId instan
ce.Id) { |
616 var err error | 632 var err error |
617 for a := waitAgent.Start(); a.Next(); { | 633 for a := waitAgent.Start(); a.Next(); { |
618 » » _, err = t.Env.Instances([]state.InstanceId{instId}) | 634 » » _, err = t.Env.Instances([]instance.Id{instId}) |
619 if err == nil { | 635 if err == nil { |
620 continue | 636 continue |
621 } | 637 } |
622 if err == environs.ErrNoInstances { | 638 if err == environs.ErrNoInstances { |
623 return | 639 return |
624 } | 640 } |
625 c.Logf("error from Instances: %v", err) | 641 c.Logf("error from Instances: %v", err) |
626 } | 642 } |
627 c.Fatalf("provisioner failed to stop machine after %v", waitAgent.Total) | 643 c.Fatalf("provisioner failed to stop machine after %v", waitAgent.Total) |
628 } | 644 } |
629 | 645 |
630 // assertInstanceId asserts that the machine has an instance id | 646 // assertInstanceId asserts that the machine has an instance id |
631 // that matches that of the given instance. If the instance is nil, | 647 // that matches that of the given instance. If the instance is nil, |
632 // It asserts that the instance id is unset. | 648 // It asserts that the instance id is unset. |
633 func assertInstanceId(c *C, m *state.Machine, inst environs.Instance) { | 649 func assertInstanceId(c *C, m *state.Machine, inst instance.Instance) { |
634 » var wantId, gotId state.InstanceId | 650 » var wantId, gotId instance.Id |
635 var err error | 651 var err error |
636 if inst != nil { | 652 if inst != nil { |
637 wantId = inst.Id() | 653 wantId = inst.Id() |
638 } | 654 } |
639 for a := waitAgent.Start(); a.Next(); { | 655 for a := waitAgent.Start(); a.Next(); { |
640 err := m.Refresh() | 656 err := m.Refresh() |
641 c.Assert(err, IsNil) | 657 c.Assert(err, IsNil) |
642 var ok bool | 658 var ok bool |
643 gotId, ok = m.InstanceId() | 659 gotId, ok = m.InstanceId() |
644 if !ok { | 660 if !ok { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 checkFileDoesNotExist(c, storage, name, t.Attempt) | 707 checkFileDoesNotExist(c, storage, name, t.Attempt) |
692 // removing a file that does not exist should not be an error. | 708 // removing a file that does not exist should not be an error. |
693 err = storage.Remove(name) | 709 err = storage.Remove(name) |
694 c.Check(err, IsNil) | 710 c.Check(err, IsNil) |
695 } | 711 } |
696 | 712 |
697 // Check that we can't start an instance running tools that correspond with no | 713 // Check that we can't start an instance running tools that correspond with no |
698 // available platform. The first thing start instance should do is find | 714 // available platform. The first thing start instance should do is find |
699 // appropriate tools. | 715 // appropriate tools. |
700 func (t *LiveTests) TestStartInstanceOnUnknownPlatform(c *C) { | 716 func (t *LiveTests) TestStartInstanceOnUnknownPlatform(c *C) { |
701 » inst, err := t.Env.StartInstance("4", "fake_nonce", "unknownseries", con
straints.Value{}, testing.InvalidStateInfo("4"), testing.InvalidAPIInfo("4")) | 717 » inst, err := t.Env.StartInstance("4", "fake_nonce", "unknownseries", con
straints.Value{}, testing.FakeStateInfo("4"), testing.FakeAPIInfo("4")) |
702 if inst != nil { | 718 if inst != nil { |
703 » » err := t.Env.StopInstances([]environs.Instance{inst}) | 719 » » err := t.Env.StopInstances([]instance.Instance{inst}) |
704 c.Check(err, IsNil) | 720 c.Check(err, IsNil) |
705 } | 721 } |
706 c.Assert(inst, IsNil) | 722 c.Assert(inst, IsNil) |
707 var notFoundError *errors.NotFoundError | 723 var notFoundError *errors.NotFoundError |
708 c.Assert(err, FitsTypeOf, notFoundError) | 724 c.Assert(err, FitsTypeOf, notFoundError) |
709 c.Assert(err, ErrorMatches, "no matching tools available") | 725 c.Assert(err, ErrorMatches, "no matching tools available") |
710 } | 726 } |
711 | 727 |
712 // Check that we can't start an instance with an empty nonce value. | 728 // Check that we can't start an instance with an empty nonce value. |
713 func (t *LiveTests) TestStartInstanceWithEmptyNonceFails(c *C) { | 729 func (t *LiveTests) TestStartInstanceWithEmptyNonceFails(c *C) { |
714 » inst, err := t.Env.StartInstance("4", "", config.DefaultSeries, constrai
nts.Value{}, testing.InvalidStateInfo("4"), testing.InvalidAPIInfo("4")) | 730 » inst, err := t.Env.StartInstance("4", "", config.DefaultSeries, constrai
nts.Value{}, testing.FakeStateInfo("4"), testing.FakeAPIInfo("4")) |
715 if inst != nil { | 731 if inst != nil { |
716 » » err := t.Env.StopInstances([]environs.Instance{inst}) | 732 » » err := t.Env.StopInstances([]instance.Instance{inst}) |
717 c.Check(err, IsNil) | 733 c.Check(err, IsNil) |
718 } | 734 } |
719 c.Assert(inst, IsNil) | 735 c.Assert(inst, IsNil) |
720 c.Assert(err, ErrorMatches, ".*missing machine nonce") | 736 c.Assert(err, ErrorMatches, ".*missing machine nonce") |
721 } | 737 } |
722 | 738 |
723 func (t *LiveTests) TestBootstrapWithDefaultSeries(c *C) { | 739 func (t *LiveTests) TestBootstrapWithDefaultSeries(c *C) { |
724 if !t.HasProvisioner { | 740 if !t.HasProvisioner { |
725 c.Skip("HasProvisioner is false; cannot test deployment") | 741 c.Skip("HasProvisioner is false; cannot test deployment") |
726 } | 742 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 return err | 812 return err |
797 } | 813 } |
798 var buf bytes.Buffer | 814 var buf bytes.Buffer |
799 _, err = io.Copy(&buf, rc) | 815 _, err = io.Copy(&buf, rc) |
800 rc.Close() | 816 rc.Close() |
801 if err != nil { | 817 if err != nil { |
802 return err | 818 return err |
803 } | 819 } |
804 return target.Put(targetPath, &buf, int64(buf.Len())) | 820 return target.Put(targetPath, &buf, int64(buf.Len())) |
805 } | 821 } |
LEFT | RIGHT |