OLD | NEW |
1 // Copyright 2012, 2013 Canonical Ltd. | 1 // Copyright 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 firewaller_test | 4 package firewaller_test |
5 | 5 |
6 import ( | 6 import ( |
7 . "launchpad.net/gocheck" | 7 . "launchpad.net/gocheck" |
8 "launchpad.net/juju-core/environs" | |
9 "launchpad.net/juju-core/environs/config" | 8 "launchpad.net/juju-core/environs/config" |
10 "launchpad.net/juju-core/environs/dummy" | 9 "launchpad.net/juju-core/environs/dummy" |
| 10 "launchpad.net/juju-core/instance" |
11 "launchpad.net/juju-core/juju/testing" | 11 "launchpad.net/juju-core/juju/testing" |
12 "launchpad.net/juju-core/state" | 12 "launchpad.net/juju-core/state" |
13 "launchpad.net/juju-core/state/api/params" | |
14 coretesting "launchpad.net/juju-core/testing" | 13 coretesting "launchpad.net/juju-core/testing" |
15 "launchpad.net/juju-core/worker" | 14 "launchpad.net/juju-core/worker" |
16 "launchpad.net/juju-core/worker/firewaller" | 15 "launchpad.net/juju-core/worker/firewaller" |
17 "reflect" | 16 "reflect" |
18 stdtesting "testing" | 17 stdtesting "testing" |
19 "time" | 18 "time" |
20 ) | 19 ) |
21 | 20 |
22 func TestPackage(t *stdtesting.T) { | 21 func TestPackage(t *stdtesting.T) { |
23 coretesting.MgoTestPackage(t) | 22 coretesting.MgoTestPackage(t) |
24 } | 23 } |
25 | 24 |
26 type FirewallerSuite struct { | 25 type FirewallerSuite struct { |
27 testing.JujuConnSuite | 26 testing.JujuConnSuite |
28 op <-chan dummy.Operation | 27 op <-chan dummy.Operation |
29 charm *state.Charm | 28 charm *state.Charm |
30 } | 29 } |
31 | 30 |
32 var _ worker.Worker = (*firewaller.Firewaller)(nil) | 31 var _ worker.Worker = (*firewaller.Firewaller)(nil) |
33 | 32 |
34 // assertPorts retrieves the open ports of the instance and compares them | 33 // assertPorts retrieves the open ports of the instance and compares them |
35 // to the expected. | 34 // to the expected. |
36 func (s *FirewallerSuite) assertPorts(c *C, inst environs.Instance, machineId st
ring, expected []params.Port) { | 35 func (s *FirewallerSuite) assertPorts(c *C, inst instance.Instance, machineId st
ring, expected []instance.Port) { |
37 s.State.StartSync() | 36 s.State.StartSync() |
38 start := time.Now() | 37 start := time.Now() |
39 for { | 38 for { |
40 got, err := inst.Ports(machineId) | 39 got, err := inst.Ports(machineId) |
41 if err != nil { | 40 if err != nil { |
42 c.Fatal(err) | 41 c.Fatal(err) |
43 return | 42 return |
44 } | 43 } |
45 state.SortPorts(got) | 44 state.SortPorts(got) |
46 state.SortPorts(expected) | 45 state.SortPorts(expected) |
47 if reflect.DeepEqual(got, expected) { | 46 if reflect.DeepEqual(got, expected) { |
48 c.Succeed() | 47 c.Succeed() |
49 return | 48 return |
50 } | 49 } |
51 if time.Since(start) > 5*time.Second { | 50 if time.Since(start) > 5*time.Second { |
52 c.Fatalf("timed out: expected %q; got %q", expected, got
) | 51 c.Fatalf("timed out: expected %q; got %q", expected, got
) |
53 return | 52 return |
54 } | 53 } |
55 time.Sleep(50 * time.Millisecond) | 54 time.Sleep(50 * time.Millisecond) |
56 } | 55 } |
57 panic("unreachable") | 56 panic("unreachable") |
58 } | 57 } |
59 | 58 |
60 // assertEnvironPorts retrieves the open ports of environment and compares them | 59 // assertEnvironPorts retrieves the open ports of environment and compares them |
61 // to the expected. | 60 // to the expected. |
62 func (s *FirewallerSuite) assertEnvironPorts(c *C, expected []params.Port) { | 61 func (s *FirewallerSuite) assertEnvironPorts(c *C, expected []instance.Port) { |
63 s.State.StartSync() | 62 s.State.StartSync() |
64 start := time.Now() | 63 start := time.Now() |
65 for { | 64 for { |
66 got, err := s.Conn.Environ.Ports() | 65 got, err := s.Conn.Environ.Ports() |
67 if err != nil { | 66 if err != nil { |
68 c.Fatal(err) | 67 c.Fatal(err) |
69 return | 68 return |
70 } | 69 } |
71 state.SortPorts(got) | 70 state.SortPorts(got) |
72 state.SortPorts(expected) | 71 state.SortPorts(expected) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 c.Assert(err, IsNil) | 125 c.Assert(err, IsNil) |
127 err = s.Conn.Environ.SetConfig(newConfig) | 126 err = s.Conn.Environ.SetConfig(newConfig) |
128 c.Assert(err, IsNil) | 127 c.Assert(err, IsNil) |
129 err = s.State.SetEnvironConfig(newConfig) | 128 err = s.State.SetEnvironConfig(newConfig) |
130 c.Assert(err, IsNil) | 129 c.Assert(err, IsNil) |
131 | 130 |
132 return restore | 131 return restore |
133 } | 132 } |
134 | 133 |
135 // startInstance starts a new instance for the given machine. | 134 // startInstance starts a new instance for the given machine. |
136 func (s *FirewallerSuite) startInstance(c *C, m *state.Machine) environs.Instanc
e { | 135 func (s *FirewallerSuite) startInstance(c *C, m *state.Machine) instance.Instanc
e { |
137 inst := testing.StartInstance(c, s.Conn.Environ, m.Id()) | 136 inst := testing.StartInstance(c, s.Conn.Environ, m.Id()) |
138 err := m.SetProvisioned(inst.Id(), "fake_nonce") | 137 err := m.SetProvisioned(inst.Id(), "fake_nonce") |
139 c.Assert(err, IsNil) | 138 c.Assert(err, IsNil) |
140 return inst | 139 return inst |
141 } | 140 } |
142 | 141 |
143 func (s *FirewallerSuite) TestNotExposedService(c *C) { | 142 func (s *FirewallerSuite) TestNotExposedService(c *C) { |
144 fw := firewaller.NewFirewaller(s.State) | 143 fw := firewaller.NewFirewaller(s.State) |
145 defer func() { c.Assert(fw.Stop(), IsNil) }() | 144 defer func() { c.Assert(fw.Stop(), IsNil) }() |
146 | 145 |
(...skipping 25 matching lines...) Expand all Loading... |
172 err = svc.SetExposed() | 171 err = svc.SetExposed() |
173 c.Assert(err, IsNil) | 172 c.Assert(err, IsNil) |
174 u, m := s.addUnit(c, svc) | 173 u, m := s.addUnit(c, svc) |
175 inst := s.startInstance(c, m) | 174 inst := s.startInstance(c, m) |
176 | 175 |
177 err = u.OpenPort("tcp", 80) | 176 err = u.OpenPort("tcp", 80) |
178 c.Assert(err, IsNil) | 177 c.Assert(err, IsNil) |
179 err = u.OpenPort("tcp", 8080) | 178 err = u.OpenPort("tcp", 8080) |
180 c.Assert(err, IsNil) | 179 c.Assert(err, IsNil) |
181 | 180 |
182 » s.assertPorts(c, inst, m.Id(), []params.Port{{"tcp", 80}, {"tcp", 8080}}
) | 181 » s.assertPorts(c, inst, m.Id(), []instance.Port{{"tcp", 80}, {"tcp", 8080
}}) |
183 | 182 |
184 err = u.ClosePort("tcp", 80) | 183 err = u.ClosePort("tcp", 80) |
185 c.Assert(err, IsNil) | 184 c.Assert(err, IsNil) |
186 | 185 |
187 » s.assertPorts(c, inst, m.Id(), []params.Port{{"tcp", 8080}}) | 186 » s.assertPorts(c, inst, m.Id(), []instance.Port{{"tcp", 8080}}) |
188 } | 187 } |
189 | 188 |
190 func (s *FirewallerSuite) TestMultipleExposedServices(c *C) { | 189 func (s *FirewallerSuite) TestMultipleExposedServices(c *C) { |
191 fw := firewaller.NewFirewaller(s.State) | 190 fw := firewaller.NewFirewaller(s.State) |
192 defer func() { c.Assert(fw.Stop(), IsNil) }() | 191 defer func() { c.Assert(fw.Stop(), IsNil) }() |
193 | 192 |
194 svc1, err := s.State.AddService("wordpress", s.charm) | 193 svc1, err := s.State.AddService("wordpress", s.charm) |
195 c.Assert(err, IsNil) | 194 c.Assert(err, IsNil) |
196 err = svc1.SetExposed() | 195 err = svc1.SetExposed() |
197 c.Assert(err, IsNil) | 196 c.Assert(err, IsNil) |
198 | 197 |
199 u1, m1 := s.addUnit(c, svc1) | 198 u1, m1 := s.addUnit(c, svc1) |
200 inst1 := s.startInstance(c, m1) | 199 inst1 := s.startInstance(c, m1) |
201 err = u1.OpenPort("tcp", 80) | 200 err = u1.OpenPort("tcp", 80) |
202 c.Assert(err, IsNil) | 201 c.Assert(err, IsNil) |
203 err = u1.OpenPort("tcp", 8080) | 202 err = u1.OpenPort("tcp", 8080) |
204 c.Assert(err, IsNil) | 203 c.Assert(err, IsNil) |
205 | 204 |
206 svc2, err := s.State.AddService("mysql", s.charm) | 205 svc2, err := s.State.AddService("mysql", s.charm) |
207 c.Assert(err, IsNil) | 206 c.Assert(err, IsNil) |
208 err = svc2.SetExposed() | 207 err = svc2.SetExposed() |
209 c.Assert(err, IsNil) | 208 c.Assert(err, IsNil) |
210 | 209 |
211 u2, m2 := s.addUnit(c, svc2) | 210 u2, m2 := s.addUnit(c, svc2) |
212 inst2 := s.startInstance(c, m2) | 211 inst2 := s.startInstance(c, m2) |
213 err = u2.OpenPort("tcp", 3306) | 212 err = u2.OpenPort("tcp", 3306) |
214 c.Assert(err, IsNil) | 213 c.Assert(err, IsNil) |
215 | 214 |
216 » s.assertPorts(c, inst1, m1.Id(), []params.Port{{"tcp", 80}, {"tcp", 8080
}}) | 215 » s.assertPorts(c, inst1, m1.Id(), []instance.Port{{"tcp", 80}, {"tcp", 80
80}}) |
217 » s.assertPorts(c, inst2, m2.Id(), []params.Port{{"tcp", 3306}}) | 216 » s.assertPorts(c, inst2, m2.Id(), []instance.Port{{"tcp", 3306}}) |
218 | 217 |
219 err = u1.ClosePort("tcp", 80) | 218 err = u1.ClosePort("tcp", 80) |
220 c.Assert(err, IsNil) | 219 c.Assert(err, IsNil) |
221 err = u2.ClosePort("tcp", 3306) | 220 err = u2.ClosePort("tcp", 3306) |
222 c.Assert(err, IsNil) | 221 c.Assert(err, IsNil) |
223 | 222 |
224 » s.assertPorts(c, inst1, m1.Id(), []params.Port{{"tcp", 8080}}) | 223 » s.assertPorts(c, inst1, m1.Id(), []instance.Port{{"tcp", 8080}}) |
225 s.assertPorts(c, inst2, m2.Id(), nil) | 224 s.assertPorts(c, inst2, m2.Id(), nil) |
226 } | 225 } |
227 | 226 |
228 func (s *FirewallerSuite) TestMachineWithoutInstanceId(c *C) { | 227 func (s *FirewallerSuite) TestMachineWithoutInstanceId(c *C) { |
229 fw := firewaller.NewFirewaller(s.State) | 228 fw := firewaller.NewFirewaller(s.State) |
230 defer func() { c.Assert(fw.Stop(), IsNil) }() | 229 defer func() { c.Assert(fw.Stop(), IsNil) }() |
231 | 230 |
232 svc, err := s.State.AddService("wordpress", s.charm) | 231 svc, err := s.State.AddService("wordpress", s.charm) |
233 c.Assert(err, IsNil) | 232 c.Assert(err, IsNil) |
234 err = svc.SetExposed() | 233 err = svc.SetExposed() |
235 c.Assert(err, IsNil) | 234 c.Assert(err, IsNil) |
236 // add a unit but don't start its instance yet. | 235 // add a unit but don't start its instance yet. |
237 u1, m1 := s.addUnit(c, svc) | 236 u1, m1 := s.addUnit(c, svc) |
238 | 237 |
239 // add another unit and start its instance, so that | 238 // add another unit and start its instance, so that |
240 // we're sure the firewaller has seen the first instance. | 239 // we're sure the firewaller has seen the first instance. |
241 u2, m2 := s.addUnit(c, svc) | 240 u2, m2 := s.addUnit(c, svc) |
242 inst2 := s.startInstance(c, m2) | 241 inst2 := s.startInstance(c, m2) |
243 err = u2.OpenPort("tcp", 80) | 242 err = u2.OpenPort("tcp", 80) |
244 c.Assert(err, IsNil) | 243 c.Assert(err, IsNil) |
245 » s.assertPorts(c, inst2, m2.Id(), []params.Port{{"tcp", 80}}) | 244 » s.assertPorts(c, inst2, m2.Id(), []instance.Port{{"tcp", 80}}) |
246 | 245 |
247 inst1 := s.startInstance(c, m1) | 246 inst1 := s.startInstance(c, m1) |
248 err = u1.OpenPort("tcp", 8080) | 247 err = u1.OpenPort("tcp", 8080) |
249 c.Assert(err, IsNil) | 248 c.Assert(err, IsNil) |
250 » s.assertPorts(c, inst1, m1.Id(), []params.Port{{"tcp", 8080}}) | 249 » s.assertPorts(c, inst1, m1.Id(), []instance.Port{{"tcp", 8080}}) |
251 } | 250 } |
252 | 251 |
253 func (s *FirewallerSuite) TestMultipleUnits(c *C) { | 252 func (s *FirewallerSuite) TestMultipleUnits(c *C) { |
254 fw := firewaller.NewFirewaller(s.State) | 253 fw := firewaller.NewFirewaller(s.State) |
255 defer func() { c.Assert(fw.Stop(), IsNil) }() | 254 defer func() { c.Assert(fw.Stop(), IsNil) }() |
256 | 255 |
257 svc, err := s.State.AddService("wordpress", s.charm) | 256 svc, err := s.State.AddService("wordpress", s.charm) |
258 c.Assert(err, IsNil) | 257 c.Assert(err, IsNil) |
259 err = svc.SetExposed() | 258 err = svc.SetExposed() |
260 c.Assert(err, IsNil) | 259 c.Assert(err, IsNil) |
261 | 260 |
262 u1, m1 := s.addUnit(c, svc) | 261 u1, m1 := s.addUnit(c, svc) |
263 inst1 := s.startInstance(c, m1) | 262 inst1 := s.startInstance(c, m1) |
264 err = u1.OpenPort("tcp", 80) | 263 err = u1.OpenPort("tcp", 80) |
265 c.Assert(err, IsNil) | 264 c.Assert(err, IsNil) |
266 | 265 |
267 u2, m2 := s.addUnit(c, svc) | 266 u2, m2 := s.addUnit(c, svc) |
268 inst2 := s.startInstance(c, m2) | 267 inst2 := s.startInstance(c, m2) |
269 err = u2.OpenPort("tcp", 80) | 268 err = u2.OpenPort("tcp", 80) |
270 c.Assert(err, IsNil) | 269 c.Assert(err, IsNil) |
271 | 270 |
272 » s.assertPorts(c, inst1, m1.Id(), []params.Port{{"tcp", 80}}) | 271 » s.assertPorts(c, inst1, m1.Id(), []instance.Port{{"tcp", 80}}) |
273 » s.assertPorts(c, inst2, m2.Id(), []params.Port{{"tcp", 80}}) | 272 » s.assertPorts(c, inst2, m2.Id(), []instance.Port{{"tcp", 80}}) |
274 | 273 |
275 err = u1.ClosePort("tcp", 80) | 274 err = u1.ClosePort("tcp", 80) |
276 c.Assert(err, IsNil) | 275 c.Assert(err, IsNil) |
277 err = u2.ClosePort("tcp", 80) | 276 err = u2.ClosePort("tcp", 80) |
278 c.Assert(err, IsNil) | 277 c.Assert(err, IsNil) |
279 | 278 |
280 s.assertPorts(c, inst1, m1.Id(), nil) | 279 s.assertPorts(c, inst1, m1.Id(), nil) |
281 s.assertPorts(c, inst2, m2.Id(), nil) | 280 s.assertPorts(c, inst2, m2.Id(), nil) |
282 } | 281 } |
283 | 282 |
(...skipping 10 matching lines...) Expand all Loading... |
294 err = u.OpenPort("tcp", 8080) | 293 err = u.OpenPort("tcp", 8080) |
295 c.Assert(err, IsNil) | 294 c.Assert(err, IsNil) |
296 | 295 |
297 // Nothing open without firewaller. | 296 // Nothing open without firewaller. |
298 s.assertPorts(c, inst, m.Id(), nil) | 297 s.assertPorts(c, inst, m.Id(), nil) |
299 | 298 |
300 // Starting the firewaller opens the ports. | 299 // Starting the firewaller opens the ports. |
301 fw := firewaller.NewFirewaller(s.State) | 300 fw := firewaller.NewFirewaller(s.State) |
302 defer func() { c.Assert(fw.Stop(), IsNil) }() | 301 defer func() { c.Assert(fw.Stop(), IsNil) }() |
303 | 302 |
304 » s.assertPorts(c, inst, m.Id(), []params.Port{{"tcp", 80}, {"tcp", 8080}}
) | 303 » s.assertPorts(c, inst, m.Id(), []instance.Port{{"tcp", 80}, {"tcp", 8080
}}) |
305 | 304 |
306 err = svc.SetExposed() | 305 err = svc.SetExposed() |
307 c.Assert(err, IsNil) | 306 c.Assert(err, IsNil) |
308 } | 307 } |
309 | 308 |
310 func (s *FirewallerSuite) TestStartWithPartialState(c *C) { | 309 func (s *FirewallerSuite) TestStartWithPartialState(c *C) { |
311 m, err := s.State.AddMachine("series", state.JobHostUnits) | 310 m, err := s.State.AddMachine("series", state.JobHostUnits) |
312 c.Assert(err, IsNil) | 311 c.Assert(err, IsNil) |
313 inst := s.startInstance(c, m) | 312 inst := s.startInstance(c, m) |
314 | 313 |
315 svc, err := s.State.AddService("wordpress", s.charm) | 314 svc, err := s.State.AddService("wordpress", s.charm) |
316 c.Assert(err, IsNil) | 315 c.Assert(err, IsNil) |
317 err = svc.SetExposed() | 316 err = svc.SetExposed() |
318 c.Assert(err, IsNil) | 317 c.Assert(err, IsNil) |
319 | 318 |
320 // Starting the firewaller, no open ports. | 319 // Starting the firewaller, no open ports. |
321 fw := firewaller.NewFirewaller(s.State) | 320 fw := firewaller.NewFirewaller(s.State) |
322 defer func() { c.Assert(fw.Stop(), IsNil) }() | 321 defer func() { c.Assert(fw.Stop(), IsNil) }() |
323 | 322 |
324 s.assertPorts(c, inst, m.Id(), nil) | 323 s.assertPorts(c, inst, m.Id(), nil) |
325 | 324 |
326 // Complete steps to open port. | 325 // Complete steps to open port. |
327 u, err := svc.AddUnit() | 326 u, err := svc.AddUnit() |
328 c.Assert(err, IsNil) | 327 c.Assert(err, IsNil) |
329 err = u.AssignToMachine(m) | 328 err = u.AssignToMachine(m) |
330 c.Assert(err, IsNil) | 329 c.Assert(err, IsNil) |
331 err = u.OpenPort("tcp", 80) | 330 err = u.OpenPort("tcp", 80) |
332 c.Assert(err, IsNil) | 331 c.Assert(err, IsNil) |
333 | 332 |
334 » s.assertPorts(c, inst, m.Id(), []params.Port{{"tcp", 80}}) | 333 » s.assertPorts(c, inst, m.Id(), []instance.Port{{"tcp", 80}}) |
335 } | 334 } |
336 | 335 |
337 func (s *FirewallerSuite) TestStartWithUnexposedService(c *C) { | 336 func (s *FirewallerSuite) TestStartWithUnexposedService(c *C) { |
338 m, err := s.State.AddMachine("series", state.JobHostUnits) | 337 m, err := s.State.AddMachine("series", state.JobHostUnits) |
339 c.Assert(err, IsNil) | 338 c.Assert(err, IsNil) |
340 inst := s.startInstance(c, m) | 339 inst := s.startInstance(c, m) |
341 | 340 |
342 svc, err := s.State.AddService("wordpress", s.charm) | 341 svc, err := s.State.AddService("wordpress", s.charm) |
343 c.Assert(err, IsNil) | 342 c.Assert(err, IsNil) |
344 u, err := svc.AddUnit() | 343 u, err := svc.AddUnit() |
345 c.Assert(err, IsNil) | 344 c.Assert(err, IsNil) |
346 err = u.AssignToMachine(m) | 345 err = u.AssignToMachine(m) |
347 c.Assert(err, IsNil) | 346 c.Assert(err, IsNil) |
348 err = u.OpenPort("tcp", 80) | 347 err = u.OpenPort("tcp", 80) |
349 c.Assert(err, IsNil) | 348 c.Assert(err, IsNil) |
350 | 349 |
351 // Starting the firewaller, no open ports. | 350 // Starting the firewaller, no open ports. |
352 fw := firewaller.NewFirewaller(s.State) | 351 fw := firewaller.NewFirewaller(s.State) |
353 defer func() { c.Assert(fw.Stop(), IsNil) }() | 352 defer func() { c.Assert(fw.Stop(), IsNil) }() |
354 | 353 |
355 s.assertPorts(c, inst, m.Id(), nil) | 354 s.assertPorts(c, inst, m.Id(), nil) |
356 | 355 |
357 // Expose service. | 356 // Expose service. |
358 err = svc.SetExposed() | 357 err = svc.SetExposed() |
359 c.Assert(err, IsNil) | 358 c.Assert(err, IsNil) |
360 » s.assertPorts(c, inst, m.Id(), []params.Port{{"tcp", 80}}) | 359 » s.assertPorts(c, inst, m.Id(), []instance.Port{{"tcp", 80}}) |
361 } | 360 } |
362 | 361 |
363 func (s *FirewallerSuite) TestSetClearExposedService(c *C) { | 362 func (s *FirewallerSuite) TestSetClearExposedService(c *C) { |
364 fw := firewaller.NewFirewaller(s.State) | 363 fw := firewaller.NewFirewaller(s.State) |
365 defer func() { c.Assert(fw.Stop(), IsNil) }() | 364 defer func() { c.Assert(fw.Stop(), IsNil) }() |
366 | 365 |
367 svc, err := s.State.AddService("wordpress", s.charm) | 366 svc, err := s.State.AddService("wordpress", s.charm) |
368 c.Assert(err, IsNil) | 367 c.Assert(err, IsNil) |
369 | 368 |
370 u, m := s.addUnit(c, svc) | 369 u, m := s.addUnit(c, svc) |
371 inst := s.startInstance(c, m) | 370 inst := s.startInstance(c, m) |
372 err = u.OpenPort("tcp", 80) | 371 err = u.OpenPort("tcp", 80) |
373 c.Assert(err, IsNil) | 372 c.Assert(err, IsNil) |
374 err = u.OpenPort("tcp", 8080) | 373 err = u.OpenPort("tcp", 8080) |
375 c.Assert(err, IsNil) | 374 c.Assert(err, IsNil) |
376 | 375 |
377 // Not exposed service, so no open port. | 376 // Not exposed service, so no open port. |
378 s.assertPorts(c, inst, m.Id(), nil) | 377 s.assertPorts(c, inst, m.Id(), nil) |
379 | 378 |
380 // SeExposed opens the ports. | 379 // SeExposed opens the ports. |
381 err = svc.SetExposed() | 380 err = svc.SetExposed() |
382 c.Assert(err, IsNil) | 381 c.Assert(err, IsNil) |
383 | 382 |
384 » s.assertPorts(c, inst, m.Id(), []params.Port{{"tcp", 80}, {"tcp", 8080}}
) | 383 » s.assertPorts(c, inst, m.Id(), []instance.Port{{"tcp", 80}, {"tcp", 8080
}}) |
385 | 384 |
386 // ClearExposed closes the ports again. | 385 // ClearExposed closes the ports again. |
387 err = svc.ClearExposed() | 386 err = svc.ClearExposed() |
388 c.Assert(err, IsNil) | 387 c.Assert(err, IsNil) |
389 | 388 |
390 s.assertPorts(c, inst, m.Id(), nil) | 389 s.assertPorts(c, inst, m.Id(), nil) |
391 } | 390 } |
392 | 391 |
393 func (s *FirewallerSuite) TestRemoveUnit(c *C) { | 392 func (s *FirewallerSuite) TestRemoveUnit(c *C) { |
394 fw := firewaller.NewFirewaller(s.State) | 393 fw := firewaller.NewFirewaller(s.State) |
395 defer func() { c.Assert(fw.Stop(), IsNil) }() | 394 defer func() { c.Assert(fw.Stop(), IsNil) }() |
396 | 395 |
397 svc, err := s.State.AddService("wordpress", s.charm) | 396 svc, err := s.State.AddService("wordpress", s.charm) |
398 c.Assert(err, IsNil) | 397 c.Assert(err, IsNil) |
399 err = svc.SetExposed() | 398 err = svc.SetExposed() |
400 c.Assert(err, IsNil) | 399 c.Assert(err, IsNil) |
401 | 400 |
402 u1, m1 := s.addUnit(c, svc) | 401 u1, m1 := s.addUnit(c, svc) |
403 inst1 := s.startInstance(c, m1) | 402 inst1 := s.startInstance(c, m1) |
404 err = u1.OpenPort("tcp", 80) | 403 err = u1.OpenPort("tcp", 80) |
405 c.Assert(err, IsNil) | 404 c.Assert(err, IsNil) |
406 | 405 |
407 u2, m2 := s.addUnit(c, svc) | 406 u2, m2 := s.addUnit(c, svc) |
408 inst2 := s.startInstance(c, m2) | 407 inst2 := s.startInstance(c, m2) |
409 err = u2.OpenPort("tcp", 80) | 408 err = u2.OpenPort("tcp", 80) |
410 c.Assert(err, IsNil) | 409 c.Assert(err, IsNil) |
411 | 410 |
412 » s.assertPorts(c, inst1, m1.Id(), []params.Port{{"tcp", 80}}) | 411 » s.assertPorts(c, inst1, m1.Id(), []instance.Port{{"tcp", 80}}) |
413 » s.assertPorts(c, inst2, m2.Id(), []params.Port{{"tcp", 80}}) | 412 » s.assertPorts(c, inst2, m2.Id(), []instance.Port{{"tcp", 80}}) |
414 | 413 |
415 // Remove unit. | 414 // Remove unit. |
416 err = u1.EnsureDead() | 415 err = u1.EnsureDead() |
417 c.Assert(err, IsNil) | 416 c.Assert(err, IsNil) |
418 err = u1.Remove() | 417 err = u1.Remove() |
419 c.Assert(err, IsNil) | 418 c.Assert(err, IsNil) |
420 | 419 |
421 s.assertPorts(c, inst1, m1.Id(), nil) | 420 s.assertPorts(c, inst1, m1.Id(), nil) |
422 » s.assertPorts(c, inst2, m2.Id(), []params.Port{{"tcp", 80}}) | 421 » s.assertPorts(c, inst2, m2.Id(), []instance.Port{{"tcp", 80}}) |
423 } | 422 } |
424 | 423 |
425 func (s *FirewallerSuite) TestRemoveService(c *C) { | 424 func (s *FirewallerSuite) TestRemoveService(c *C) { |
426 fw := firewaller.NewFirewaller(s.State) | 425 fw := firewaller.NewFirewaller(s.State) |
427 defer func() { c.Assert(fw.Stop(), IsNil) }() | 426 defer func() { c.Assert(fw.Stop(), IsNil) }() |
428 | 427 |
429 svc, err := s.State.AddService("wordpress", s.charm) | 428 svc, err := s.State.AddService("wordpress", s.charm) |
430 c.Assert(err, IsNil) | 429 c.Assert(err, IsNil) |
431 err = svc.SetExposed() | 430 err = svc.SetExposed() |
432 c.Assert(err, IsNil) | 431 c.Assert(err, IsNil) |
433 | 432 |
434 u, m := s.addUnit(c, svc) | 433 u, m := s.addUnit(c, svc) |
435 inst := s.startInstance(c, m) | 434 inst := s.startInstance(c, m) |
436 err = u.OpenPort("tcp", 80) | 435 err = u.OpenPort("tcp", 80) |
437 c.Assert(err, IsNil) | 436 c.Assert(err, IsNil) |
438 | 437 |
439 » s.assertPorts(c, inst, m.Id(), []params.Port{{"tcp", 80}}) | 438 » s.assertPorts(c, inst, m.Id(), []instance.Port{{"tcp", 80}}) |
440 | 439 |
441 // Remove service. | 440 // Remove service. |
442 err = u.EnsureDead() | 441 err = u.EnsureDead() |
443 c.Assert(err, IsNil) | 442 c.Assert(err, IsNil) |
444 err = u.Remove() | 443 err = u.Remove() |
445 c.Assert(err, IsNil) | 444 c.Assert(err, IsNil) |
446 err = svc.Destroy() | 445 err = svc.Destroy() |
447 c.Assert(err, IsNil) | 446 c.Assert(err, IsNil) |
448 s.assertPorts(c, inst, m.Id(), nil) | 447 s.assertPorts(c, inst, m.Id(), nil) |
449 } | 448 } |
(...skipping 15 matching lines...) Expand all Loading... |
465 svc2, err := s.State.AddService("mysql", s.charm) | 464 svc2, err := s.State.AddService("mysql", s.charm) |
466 c.Assert(err, IsNil) | 465 c.Assert(err, IsNil) |
467 err = svc2.SetExposed() | 466 err = svc2.SetExposed() |
468 c.Assert(err, IsNil) | 467 c.Assert(err, IsNil) |
469 | 468 |
470 u2, m2 := s.addUnit(c, svc2) | 469 u2, m2 := s.addUnit(c, svc2) |
471 inst2 := s.startInstance(c, m2) | 470 inst2 := s.startInstance(c, m2) |
472 err = u2.OpenPort("tcp", 3306) | 471 err = u2.OpenPort("tcp", 3306) |
473 c.Assert(err, IsNil) | 472 c.Assert(err, IsNil) |
474 | 473 |
475 » s.assertPorts(c, inst1, m1.Id(), []params.Port{{"tcp", 80}}) | 474 » s.assertPorts(c, inst1, m1.Id(), []instance.Port{{"tcp", 80}}) |
476 » s.assertPorts(c, inst2, m2.Id(), []params.Port{{"tcp", 3306}}) | 475 » s.assertPorts(c, inst2, m2.Id(), []instance.Port{{"tcp", 3306}}) |
477 | 476 |
478 // Remove services. | 477 // Remove services. |
479 err = u2.EnsureDead() | 478 err = u2.EnsureDead() |
480 c.Assert(err, IsNil) | 479 c.Assert(err, IsNil) |
481 err = u2.Remove() | 480 err = u2.Remove() |
482 c.Assert(err, IsNil) | 481 c.Assert(err, IsNil) |
483 err = svc2.Destroy() | 482 err = svc2.Destroy() |
484 c.Assert(err, IsNil) | 483 c.Assert(err, IsNil) |
485 | 484 |
486 err = u1.EnsureDead() | 485 err = u1.EnsureDead() |
(...skipping 14 matching lines...) Expand all Loading... |
501 svc, err := s.State.AddService("wordpress", s.charm) | 500 svc, err := s.State.AddService("wordpress", s.charm) |
502 c.Assert(err, IsNil) | 501 c.Assert(err, IsNil) |
503 err = svc.SetExposed() | 502 err = svc.SetExposed() |
504 c.Assert(err, IsNil) | 503 c.Assert(err, IsNil) |
505 | 504 |
506 u, m := s.addUnit(c, svc) | 505 u, m := s.addUnit(c, svc) |
507 inst := s.startInstance(c, m) | 506 inst := s.startInstance(c, m) |
508 err = u.OpenPort("tcp", 80) | 507 err = u.OpenPort("tcp", 80) |
509 c.Assert(err, IsNil) | 508 c.Assert(err, IsNil) |
510 | 509 |
511 » s.assertPorts(c, inst, m.Id(), []params.Port{{"tcp", 80}}) | 510 » s.assertPorts(c, inst, m.Id(), []instance.Port{{"tcp", 80}}) |
512 | 511 |
513 // Remove unit and service, also tested without. Has no effect. | 512 // Remove unit and service, also tested without. Has no effect. |
514 err = u.EnsureDead() | 513 err = u.EnsureDead() |
515 c.Assert(err, IsNil) | 514 c.Assert(err, IsNil) |
516 err = u.Remove() | 515 err = u.Remove() |
517 c.Assert(err, IsNil) | 516 c.Assert(err, IsNil) |
518 err = svc.Destroy() | 517 err = svc.Destroy() |
519 c.Assert(err, IsNil) | 518 c.Assert(err, IsNil) |
520 | 519 |
521 // Kill machine. | 520 // Kill machine. |
(...skipping 12 matching lines...) Expand all Loading... |
534 svc, err := s.State.AddService("wordpress", s.charm) | 533 svc, err := s.State.AddService("wordpress", s.charm) |
535 c.Assert(err, IsNil) | 534 c.Assert(err, IsNil) |
536 err = svc.SetExposed() | 535 err = svc.SetExposed() |
537 c.Assert(err, IsNil) | 536 c.Assert(err, IsNil) |
538 | 537 |
539 u, m := s.addUnit(c, svc) | 538 u, m := s.addUnit(c, svc) |
540 inst := s.startInstance(c, m) | 539 inst := s.startInstance(c, m) |
541 err = u.OpenPort("tcp", 80) | 540 err = u.OpenPort("tcp", 80) |
542 c.Assert(err, IsNil) | 541 c.Assert(err, IsNil) |
543 | 542 |
544 » s.assertPorts(c, inst, m.Id(), []params.Port{{"tcp", 80}}) | 543 » s.assertPorts(c, inst, m.Id(), []instance.Port{{"tcp", 80}}) |
545 | 544 |
546 // Remove unit. | 545 // Remove unit. |
547 err = u.EnsureDead() | 546 err = u.EnsureDead() |
548 c.Assert(err, IsNil) | 547 c.Assert(err, IsNil) |
549 err = u.Remove() | 548 err = u.Remove() |
550 c.Assert(err, IsNil) | 549 c.Assert(err, IsNil) |
551 | 550 |
552 // Remove machine. Nothing bad should happen, but can't | 551 // Remove machine. Nothing bad should happen, but can't |
553 // assert port state since the machine must have been | 552 // assert port state since the machine must have been |
554 // destroyed and we lost its reference. | 553 // destroyed and we lost its reference. |
(...skipping 29 matching lines...) Expand all Loading... |
584 svc2, err := s.State.AddService("moinmoin", s.charm) | 583 svc2, err := s.State.AddService("moinmoin", s.charm) |
585 c.Assert(err, IsNil) | 584 c.Assert(err, IsNil) |
586 err = svc2.SetExposed() | 585 err = svc2.SetExposed() |
587 c.Assert(err, IsNil) | 586 c.Assert(err, IsNil) |
588 | 587 |
589 u2, m2 := s.addUnit(c, svc2) | 588 u2, m2 := s.addUnit(c, svc2) |
590 s.startInstance(c, m2) | 589 s.startInstance(c, m2) |
591 err = u2.OpenPort("tcp", 80) | 590 err = u2.OpenPort("tcp", 80) |
592 c.Assert(err, IsNil) | 591 c.Assert(err, IsNil) |
593 | 592 |
594 » s.assertEnvironPorts(c, []params.Port{{"tcp", 80}, {"tcp", 8080}}) | 593 » s.assertEnvironPorts(c, []instance.Port{{"tcp", 80}, {"tcp", 8080}}) |
595 | 594 |
596 // Closing a port opened by a different unit won't touch the environment
. | 595 // Closing a port opened by a different unit won't touch the environment
. |
597 err = u1.ClosePort("tcp", 80) | 596 err = u1.ClosePort("tcp", 80) |
598 c.Assert(err, IsNil) | 597 c.Assert(err, IsNil) |
599 » s.assertEnvironPorts(c, []params.Port{{"tcp", 80}, {"tcp", 8080}}) | 598 » s.assertEnvironPorts(c, []instance.Port{{"tcp", 80}, {"tcp", 8080}}) |
600 | 599 |
601 // Closing a port used just once changes the environment. | 600 // Closing a port used just once changes the environment. |
602 err = u1.ClosePort("tcp", 8080) | 601 err = u1.ClosePort("tcp", 8080) |
603 c.Assert(err, IsNil) | 602 c.Assert(err, IsNil) |
604 » s.assertEnvironPorts(c, []params.Port{{"tcp", 80}}) | 603 » s.assertEnvironPorts(c, []instance.Port{{"tcp", 80}}) |
605 | 604 |
606 // Closing the last port also modifies the environment. | 605 // Closing the last port also modifies the environment. |
607 err = u2.ClosePort("tcp", 80) | 606 err = u2.ClosePort("tcp", 80) |
608 c.Assert(err, IsNil) | 607 c.Assert(err, IsNil) |
609 s.assertEnvironPorts(c, nil) | 608 s.assertEnvironPorts(c, nil) |
610 } | 609 } |
611 | 610 |
612 func (s *FirewallerSuite) TestGlobalModeStartWithUnexposedService(c *C) { | 611 func (s *FirewallerSuite) TestGlobalModeStartWithUnexposedService(c *C) { |
613 // Change configuration. | 612 // Change configuration. |
614 restore := s.setGlobalMode(c) | 613 restore := s.setGlobalMode(c) |
(...skipping 14 matching lines...) Expand all Loading... |
629 | 628 |
630 // Starting the firewaller, no open ports. | 629 // Starting the firewaller, no open ports. |
631 fw := firewaller.NewFirewaller(s.State) | 630 fw := firewaller.NewFirewaller(s.State) |
632 defer func() { c.Assert(fw.Stop(), IsNil) }() | 631 defer func() { c.Assert(fw.Stop(), IsNil) }() |
633 | 632 |
634 s.assertEnvironPorts(c, nil) | 633 s.assertEnvironPorts(c, nil) |
635 | 634 |
636 // Expose service. | 635 // Expose service. |
637 err = svc.SetExposed() | 636 err = svc.SetExposed() |
638 c.Assert(err, IsNil) | 637 c.Assert(err, IsNil) |
639 » s.assertEnvironPorts(c, []params.Port{{"tcp", 80}}) | 638 » s.assertEnvironPorts(c, []instance.Port{{"tcp", 80}}) |
640 } | 639 } |
641 | 640 |
642 func (s *FirewallerSuite) TestGlobalModeRestart(c *C) { | 641 func (s *FirewallerSuite) TestGlobalModeRestart(c *C) { |
643 // Change configuration. | 642 // Change configuration. |
644 restore := s.setGlobalMode(c) | 643 restore := s.setGlobalMode(c) |
645 defer restore(c) | 644 defer restore(c) |
646 | 645 |
647 // Start firewall and open ports. | 646 // Start firewall and open ports. |
648 fw := firewaller.NewFirewaller(s.State) | 647 fw := firewaller.NewFirewaller(s.State) |
649 | 648 |
650 svc, err := s.State.AddService("wordpress", s.charm) | 649 svc, err := s.State.AddService("wordpress", s.charm) |
651 c.Assert(err, IsNil) | 650 c.Assert(err, IsNil) |
652 err = svc.SetExposed() | 651 err = svc.SetExposed() |
653 c.Assert(err, IsNil) | 652 c.Assert(err, IsNil) |
654 | 653 |
655 u, m := s.addUnit(c, svc) | 654 u, m := s.addUnit(c, svc) |
656 s.startInstance(c, m) | 655 s.startInstance(c, m) |
657 err = u.OpenPort("tcp", 80) | 656 err = u.OpenPort("tcp", 80) |
658 c.Assert(err, IsNil) | 657 c.Assert(err, IsNil) |
659 err = u.OpenPort("tcp", 8080) | 658 err = u.OpenPort("tcp", 8080) |
660 c.Assert(err, IsNil) | 659 c.Assert(err, IsNil) |
661 | 660 |
662 » s.assertEnvironPorts(c, []params.Port{{"tcp", 80}, {"tcp", 8080}}) | 661 » s.assertEnvironPorts(c, []instance.Port{{"tcp", 80}, {"tcp", 8080}}) |
663 | 662 |
664 // Stop firewall and close one and open a different port. | 663 // Stop firewall and close one and open a different port. |
665 err = fw.Stop() | 664 err = fw.Stop() |
666 c.Assert(err, IsNil) | 665 c.Assert(err, IsNil) |
667 | 666 |
668 err = u.ClosePort("tcp", 8080) | 667 err = u.ClosePort("tcp", 8080) |
669 c.Assert(err, IsNil) | 668 c.Assert(err, IsNil) |
670 err = u.OpenPort("tcp", 8888) | 669 err = u.OpenPort("tcp", 8888) |
671 c.Assert(err, IsNil) | 670 c.Assert(err, IsNil) |
672 | 671 |
673 // Start firewall and check port. | 672 // Start firewall and check port. |
674 fw = firewaller.NewFirewaller(s.State) | 673 fw = firewaller.NewFirewaller(s.State) |
675 defer func() { c.Assert(fw.Stop(), IsNil) }() | 674 defer func() { c.Assert(fw.Stop(), IsNil) }() |
676 | 675 |
677 » s.assertEnvironPorts(c, []params.Port{{"tcp", 80}, {"tcp", 8888}}) | 676 » s.assertEnvironPorts(c, []instance.Port{{"tcp", 80}, {"tcp", 8888}}) |
678 } | 677 } |
679 | 678 |
680 func (s *FirewallerSuite) TestGlobalModeRestartUnexposedService(c *C) { | 679 func (s *FirewallerSuite) TestGlobalModeRestartUnexposedService(c *C) { |
681 // Change configuration. | 680 // Change configuration. |
682 restore := s.setGlobalMode(c) | 681 restore := s.setGlobalMode(c) |
683 defer restore(c) | 682 defer restore(c) |
684 | 683 |
685 // Start firewall and open ports. | 684 // Start firewall and open ports. |
686 fw := firewaller.NewFirewaller(s.State) | 685 fw := firewaller.NewFirewaller(s.State) |
687 | 686 |
688 svc, err := s.State.AddService("wordpress", s.charm) | 687 svc, err := s.State.AddService("wordpress", s.charm) |
689 c.Assert(err, IsNil) | 688 c.Assert(err, IsNil) |
690 err = svc.SetExposed() | 689 err = svc.SetExposed() |
691 c.Assert(err, IsNil) | 690 c.Assert(err, IsNil) |
692 | 691 |
693 u, m := s.addUnit(c, svc) | 692 u, m := s.addUnit(c, svc) |
694 s.startInstance(c, m) | 693 s.startInstance(c, m) |
695 err = u.OpenPort("tcp", 80) | 694 err = u.OpenPort("tcp", 80) |
696 c.Assert(err, IsNil) | 695 c.Assert(err, IsNil) |
697 err = u.OpenPort("tcp", 8080) | 696 err = u.OpenPort("tcp", 8080) |
698 c.Assert(err, IsNil) | 697 c.Assert(err, IsNil) |
699 | 698 |
700 » s.assertEnvironPorts(c, []params.Port{{"tcp", 80}, {"tcp", 8080}}) | 699 » s.assertEnvironPorts(c, []instance.Port{{"tcp", 80}, {"tcp", 8080}}) |
701 | 700 |
702 // Stop firewall and clear exposed flag on service. | 701 // Stop firewall and clear exposed flag on service. |
703 err = fw.Stop() | 702 err = fw.Stop() |
704 c.Assert(err, IsNil) | 703 c.Assert(err, IsNil) |
705 | 704 |
706 err = svc.ClearExposed() | 705 err = svc.ClearExposed() |
707 c.Assert(err, IsNil) | 706 c.Assert(err, IsNil) |
708 | 707 |
709 // Start firewall and check port. | 708 // Start firewall and check port. |
710 fw = firewaller.NewFirewaller(s.State) | 709 fw = firewaller.NewFirewaller(s.State) |
(...skipping 15 matching lines...) Expand all Loading... |
726 err = svc1.SetExposed() | 725 err = svc1.SetExposed() |
727 c.Assert(err, IsNil) | 726 c.Assert(err, IsNil) |
728 | 727 |
729 u1, m1 := s.addUnit(c, svc1) | 728 u1, m1 := s.addUnit(c, svc1) |
730 s.startInstance(c, m1) | 729 s.startInstance(c, m1) |
731 err = u1.OpenPort("tcp", 80) | 730 err = u1.OpenPort("tcp", 80) |
732 c.Assert(err, IsNil) | 731 c.Assert(err, IsNil) |
733 err = u1.OpenPort("tcp", 8080) | 732 err = u1.OpenPort("tcp", 8080) |
734 c.Assert(err, IsNil) | 733 c.Assert(err, IsNil) |
735 | 734 |
736 » s.assertEnvironPorts(c, []params.Port{{"tcp", 80}, {"tcp", 8080}}) | 735 » s.assertEnvironPorts(c, []instance.Port{{"tcp", 80}, {"tcp", 8080}}) |
737 | 736 |
738 // Stop firewall and add another service using the port. | 737 // Stop firewall and add another service using the port. |
739 err = fw.Stop() | 738 err = fw.Stop() |
740 c.Assert(err, IsNil) | 739 c.Assert(err, IsNil) |
741 | 740 |
742 svc2, err := s.State.AddService("moinmoin", s.charm) | 741 svc2, err := s.State.AddService("moinmoin", s.charm) |
743 c.Assert(err, IsNil) | 742 c.Assert(err, IsNil) |
744 err = svc2.SetExposed() | 743 err = svc2.SetExposed() |
745 c.Assert(err, IsNil) | 744 c.Assert(err, IsNil) |
746 | 745 |
747 u2, m2 := s.addUnit(c, svc2) | 746 u2, m2 := s.addUnit(c, svc2) |
748 s.startInstance(c, m2) | 747 s.startInstance(c, m2) |
749 err = u2.OpenPort("tcp", 80) | 748 err = u2.OpenPort("tcp", 80) |
750 c.Assert(err, IsNil) | 749 c.Assert(err, IsNil) |
751 | 750 |
752 // Start firewall and check port. | 751 // Start firewall and check port. |
753 fw = firewaller.NewFirewaller(s.State) | 752 fw = firewaller.NewFirewaller(s.State) |
754 defer func() { c.Assert(fw.Stop(), IsNil) }() | 753 defer func() { c.Assert(fw.Stop(), IsNil) }() |
755 | 754 |
756 » s.assertEnvironPorts(c, []params.Port{{"tcp", 80}, {"tcp", 8080}}) | 755 » s.assertEnvironPorts(c, []instance.Port{{"tcp", 80}, {"tcp", 8080}}) |
757 | 756 |
758 // Closing a port opened by a different unit won't touch the environment
. | 757 // Closing a port opened by a different unit won't touch the environment
. |
759 err = u1.ClosePort("tcp", 80) | 758 err = u1.ClosePort("tcp", 80) |
760 c.Assert(err, IsNil) | 759 c.Assert(err, IsNil) |
761 » s.assertEnvironPorts(c, []params.Port{{"tcp", 80}, {"tcp", 8080}}) | 760 » s.assertEnvironPorts(c, []instance.Port{{"tcp", 80}, {"tcp", 8080}}) |
762 | 761 |
763 // Closing a port used just once changes the environment. | 762 // Closing a port used just once changes the environment. |
764 err = u1.ClosePort("tcp", 8080) | 763 err = u1.ClosePort("tcp", 8080) |
765 c.Assert(err, IsNil) | 764 c.Assert(err, IsNil) |
766 » s.assertEnvironPorts(c, []params.Port{{"tcp", 80}}) | 765 » s.assertEnvironPorts(c, []instance.Port{{"tcp", 80}}) |
767 | 766 |
768 // Closing the last port also modifies the environment. | 767 // Closing the last port also modifies the environment. |
769 err = u2.ClosePort("tcp", 80) | 768 err = u2.ClosePort("tcp", 80) |
770 c.Assert(err, IsNil) | 769 c.Assert(err, IsNil) |
771 s.assertEnvironPorts(c, nil) | 770 s.assertEnvironPorts(c, nil) |
772 } | 771 } |
OLD | NEW |