9
12
. "launchpad.net/gocheck"
10
"launchpad.net/juju-core/juju/testing"
13
"launchpad.net/juju-core/errors"
14
jujutesting "launchpad.net/juju-core/juju/testing"
11
15
"launchpad.net/juju-core/state"
16
"launchpad.net/juju-core/state/api/params"
12
17
coretesting "launchpad.net/juju-core/testing"
13
18
"launchpad.net/juju-core/worker/deployer"
34
39
s.JujuConnSuite.TearDownTest(c)
42
var _ = (*deployer.Deployer)(nil)
37
44
func (s *DeployerSuite) TestDeployRecallRemovePrincipals(c *C) {
38
45
// Create a machine, and a couple of units.
39
46
m, err := s.State.AddMachine("series", state.JobHostUnits)
40
47
c.Assert(err, IsNil)
41
err = m.SetProvisioned("i-exist", "fake_nonce")
48
err = m.SetProvisioned("i-exist", "fake_nonce", nil)
42
49
c.Assert(err, IsNil)
43
50
svc, err := s.State.AddService("wordpress", s.AddTestingCharm(c, "wordpress"))
44
51
c.Assert(err, IsNil)
48
55
c.Assert(err, IsNil)
50
57
// Create a deployer acting on behalf of the machine.
51
ctx := s.getContext(c, m.Tag())
52
dep := deployer.NewDeployer(s.State, ctx, m.WatchPrincipalUnits())
58
ctx := s.getContext(c)
59
dep := deployer.NewDeployer(s.State, ctx, m.Id())
55
62
// Assign one unit, and wait for it to be deployed.
63
70
s.waitFor(c, isDeployed(ctx, u0.Name(), u1.Name()))
65
72
// Cause a unit to become Dying, and check no change.
73
err = u1.SetStatus(params.StatusInstalled, "")
67
76
c.Assert(err, IsNil)
68
77
s.waitFor(c, isDeployed(ctx, u0.Name(), u1.Name()))
104
113
c.Assert(err, IsNil)
105
114
err = u1.AssignToMachine(m)
106
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 thing
118
// would happen if it were possible to have a dying unit in this situation.
119
err = u1.SetStatus(params.StatusInstalled, "")
107
121
err = u1.Destroy()
108
122
c.Assert(err, IsNil)
110
124
// When the deployer is started, in each case (1) no unit agent is deployed
111
125
// and (2) the non-Alive unit is been removed from state.
112
ctx := s.getContext(c, m.Tag())
113
dep := deployer.NewDeployer(s.State, ctx, m.WatchPrincipalUnits())
126
ctx := s.getContext(c)
127
dep := deployer.NewDeployer(s.State, ctx, m.Id())
114
128
defer stop(c, dep)
115
129
s.waitFor(c, isRemoved(s.State, u0.Name()))
116
130
s.waitFor(c, isRemoved(s.State, u1.Name()))
120
134
func (s *DeployerSuite) prepareSubordinates(c *C) (*state.Unit, []*state.RelationUnit) {
135
m, err := s.State.AddMachine("series", state.JobHostUnits)
121
137
svc, err := s.State.AddService("wordpress", s.AddTestingCharm(c, "wordpress"))
122
138
c.Assert(err, IsNil)
123
139
u, err := svc.AddUnit()
124
140
c.Assert(err, IsNil)
141
err = u.AssignToMachine(m)
125
143
rus := []*state.RelationUnit{}
126
144
logging := s.AddTestingCharm(c, "logging")
127
145
for _, name := range []string{"subsvc0", "subsvc1"} {
141
159
func (s *DeployerSuite) TestDeployRecallRemoveSubordinates(c *C) {
142
160
// Create a deployer acting on behalf of the principal.
143
161
u, rus := s.prepareSubordinates(c)
144
ctx := s.getContext(c, u.Tag())
145
dep := deployer.NewDeployer(s.State, ctx, u.WatchSubordinateUnits())
162
ctx := s.getContext(c)
163
machineId, err := u.AssignedMachineId()
165
dep := deployer.NewDeployer(s.State, ctx, machineId)
146
166
defer stop(c, dep)
148
168
// Add a subordinate, and wait for it to be deployed.
149
err := rus[0].EnterScope(nil)
169
err = rus[0].EnterScope(nil)
150
170
c.Assert(err, IsNil)
151
171
sub0, err := s.State.Unit("subsvc0/0")
152
172
c.Assert(err, IsNil)
153
s.waitFor(c, isDeployed(ctx, sub0.Name()))
173
// Make sure the principal is deployed first, then the subordinate
174
s.waitFor(c, isDeployed(ctx, u.Name(), sub0.Name()))
156
177
err = rus[1].EnterScope(nil)
157
178
c.Assert(err, IsNil)
158
179
sub1, err := s.State.Unit("subsvc1/0")
159
180
c.Assert(err, IsNil)
160
s.waitFor(c, isDeployed(ctx, sub0.Name(), sub1.Name()))
181
s.waitFor(c, isDeployed(ctx, u.Name(), sub0.Name(), sub1.Name()))
162
183
// Set one to Dying; check nothing happens.
163
184
err = sub1.Destroy()
164
185
c.Assert(err, IsNil)
165
186
s.State.StartSync()
166
187
c.Assert(isRemoved(s.State, sub1.Name())(c), Equals, false)
167
s.waitFor(c, isDeployed(ctx, sub0.Name(), sub1.Name()))
188
s.waitFor(c, isDeployed(ctx, u.Name(), sub0.Name(), sub1.Name()))
169
190
// Set the other to Dead; check it's recalled and removed.
170
191
err = sub0.EnsureDead()
171
192
c.Assert(err, IsNil)
172
s.waitFor(c, isDeployed(ctx, sub1.Name()))
193
s.waitFor(c, isDeployed(ctx, u.Name(), sub1.Name()))
173
194
s.waitFor(c, isRemoved(s.State, sub0.Name()))
192
213
// When we start a new deployer, neither unit will be deployed and
193
214
// both will be removed.
194
ctx := s.getContext(c, u.Tag())
195
dep := deployer.NewDeployer(s.State, ctx, u.WatchSubordinateUnits())
215
ctx := s.getContext(c)
216
machineId, err := u.AssignedMachineId()
218
dep := deployer.NewDeployer(s.State, ctx, machineId)
196
219
defer stop(c, dep)
197
220
s.waitFor(c, isRemoved(s.State, sub0.Name()))
198
221
s.waitFor(c, isRemoved(s.State, sub1.Name()))