LEFT | RIGHT |
(no file at all) | |
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 deployer_test | 4 package deployer_test |
5 | 5 |
6 import ( | 6 import ( |
7 "sort" | 7 "sort" |
8 "strings" | 8 "strings" |
9 stdtesting "testing" | 9 stdtesting "testing" |
10 "time" | 10 "time" |
11 | 11 |
12 . "launchpad.net/gocheck" | 12 . "launchpad.net/gocheck" |
13 "launchpad.net/juju-core/errors" | 13 "launchpad.net/juju-core/errors" |
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 "launchpad.net/juju-core/state/api/params" |
16 coretesting "launchpad.net/juju-core/testing" | 17 coretesting "launchpad.net/juju-core/testing" |
17 "launchpad.net/juju-core/worker/deployer" | 18 "launchpad.net/juju-core/worker/deployer" |
18 ) | 19 ) |
19 | 20 |
20 func TestPackage(t *stdtesting.T) { | 21 func TestPackage(t *stdtesting.T) { |
21 coretesting.MgoTestPackage(t) | 22 coretesting.MgoTestPackage(t) |
22 } | 23 } |
23 | 24 |
24 type DeployerSuite struct { | 25 type DeployerSuite struct { |
25 testing.JujuConnSuite | 26 testing.JujuConnSuite |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 err = u0.AssignToMachine(m) | 63 err = u0.AssignToMachine(m) |
63 c.Assert(err, IsNil) | 64 c.Assert(err, IsNil) |
64 s.waitFor(c, isDeployed(ctx, u0.Name())) | 65 s.waitFor(c, isDeployed(ctx, u0.Name())) |
65 | 66 |
66 // Assign another unit, and wait for that to be deployed. | 67 // Assign another unit, and wait for that to be deployed. |
67 err = u1.AssignToMachine(m) | 68 err = u1.AssignToMachine(m) |
68 c.Assert(err, IsNil) | 69 c.Assert(err, IsNil) |
69 s.waitFor(c, isDeployed(ctx, u0.Name(), u1.Name())) | 70 s.waitFor(c, isDeployed(ctx, u0.Name(), u1.Name())) |
70 | 71 |
71 // Cause a unit to become Dying, and check no change. | 72 // Cause a unit to become Dying, and check no change. |
| 73 err = u1.SetStatus(params.StatusInstalled, "") |
| 74 c.Assert(err, IsNil) |
72 err = u1.Destroy() | 75 err = u1.Destroy() |
73 c.Assert(err, IsNil) | 76 c.Assert(err, IsNil) |
74 s.waitFor(c, isDeployed(ctx, u0.Name(), u1.Name())) | 77 s.waitFor(c, isDeployed(ctx, u0.Name(), u1.Name())) |
75 | 78 |
76 // Cause a unit to become Dead, and check that it is both recalled and | 79 // Cause a unit to become Dead, and check that it is both recalled and |
77 // removed from state. | 80 // removed from state. |
78 err = u0.EnsureDead() | 81 err = u0.EnsureDead() |
79 c.Assert(err, IsNil) | 82 c.Assert(err, IsNil) |
80 s.waitFor(c, isRemoved(s.State, u0.Name())) | 83 s.waitFor(c, isRemoved(s.State, u0.Name())) |
81 s.waitFor(c, isDeployed(ctx, u1.Name())) | 84 s.waitFor(c, isDeployed(ctx, u1.Name())) |
(...skipping 20 matching lines...) Expand all Loading... |
102 c.Assert(err, IsNil) | 105 c.Assert(err, IsNil) |
103 u1, err := svc.AddUnit() | 106 u1, err := svc.AddUnit() |
104 c.Assert(err, IsNil) | 107 c.Assert(err, IsNil) |
105 | 108 |
106 // Assign the units to the machine, and set them to Dying/Dead. | 109 // Assign the units to the machine, and set them to Dying/Dead. |
107 err = u0.AssignToMachine(m) | 110 err = u0.AssignToMachine(m) |
108 c.Assert(err, IsNil) | 111 c.Assert(err, IsNil) |
109 err = u0.EnsureDead() | 112 err = u0.EnsureDead() |
110 c.Assert(err, IsNil) | 113 c.Assert(err, IsNil) |
111 err = u1.AssignToMachine(m) | 114 err = u1.AssignToMachine(m) |
| 115 c.Assert(err, IsNil) |
| 116 // note: this is not a sane state; for the unit to have a status it must |
| 117 // have been deployed. But it's instructive to check that the right thin
g |
| 118 // would happen if it were possible to have a dying unit in this situati
on. |
| 119 err = u1.SetStatus(params.StatusInstalled, "") |
112 c.Assert(err, IsNil) | 120 c.Assert(err, IsNil) |
113 err = u1.Destroy() | 121 err = u1.Destroy() |
114 c.Assert(err, IsNil) | 122 c.Assert(err, IsNil) |
115 | 123 |
116 // When the deployer is started, in each case (1) no unit agent is deplo
yed | 124 // When the deployer is started, in each case (1) no unit agent is deplo
yed |
117 // and (2) the non-Alive unit is been removed from state. | 125 // and (2) the non-Alive unit is been removed from state. |
118 ctx := s.getContext(c, m.Tag()) | 126 ctx := s.getContext(c, m.Tag()) |
119 dep := deployer.NewDeployer(s.State, ctx, m.WatchPrincipalUnits()) | 127 dep := deployer.NewDeployer(s.State, ctx, m.WatchPrincipalUnits()) |
120 defer stop(c, dep) | 128 defer stop(c, dep) |
121 s.waitFor(c, isRemoved(s.State, u0.Name())) | 129 s.waitFor(c, isRemoved(s.State, u0.Name())) |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 } | 252 } |
245 } | 253 } |
246 | 254 |
247 type stopper interface { | 255 type stopper interface { |
248 Stop() error | 256 Stop() error |
249 } | 257 } |
250 | 258 |
251 func stop(c *C, stopper stopper) { | 259 func stop(c *C, stopper stopper) { |
252 c.Assert(stopper.Stop(), IsNil) | 260 c.Assert(stopper.Stop(), IsNil) |
253 } | 261 } |
LEFT | RIGHT |