~ubuntu-branches/ubuntu/saucy/juju-core/saucy-proposed

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/worker/deployer/deployer_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-07-11 17:18:27 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130711171827-vjqkg40r0dlf7ys2
Tags: 1.11.2-0ubuntu1
* New upstream release.
* Make juju-core the default juju (LP: #1190634):
  - d/control: Add virtual package juju -> juju-core.
  - d/juju-core.postinst.in: Bump priority of alternatives over that of
    python juju packages.
* Enable for all architectures (LP: #1172505):
  - d/control: Version BD on golang-go to >= 2:1.1.1 to ensure CGO
    support for non-x86 archs, make juju-core Arch: any.
  - d/README.source: Dropped - no longer required.
* d/watch: Updated for new upstream tarball naming.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2012, 2013 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
1
4
package deployer_test
2
5
 
3
6
import (
7
10
        "time"
8
11
 
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"
14
19
)
18
23
}
19
24
 
20
25
type DeployerSuite struct {
21
 
        testing.JujuConnSuite
 
26
        jujutesting.JujuConnSuite
22
27
        SimpleToolsFixture
23
28
}
24
29
 
34
39
        s.JujuConnSuite.TearDownTest(c)
35
40
}
36
41
 
 
42
var _ = (*deployer.Deployer)(nil)
 
43
 
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)
49
56
 
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())
53
60
        defer stop(c, dep)
54
61
 
55
62
        // Assign one unit, and wait for it to be deployed.
63
70
        s.waitFor(c, isDeployed(ctx, u0.Name(), u1.Name()))
64
71
 
65
72
        // Cause a unit to become Dying, and check no change.
 
73
        err = u1.SetStatus(params.StatusInstalled, "")
 
74
        c.Assert(err, IsNil)
66
75
        err = u1.Destroy()
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, "")
 
120
        c.Assert(err, IsNil)
107
121
        err = u1.Destroy()
108
122
        c.Assert(err, IsNil)
109
123
 
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()))
118
132
}
119
133
 
120
134
func (s *DeployerSuite) prepareSubordinates(c *C) (*state.Unit, []*state.RelationUnit) {
 
135
        m, err := s.State.AddMachine("series", state.JobHostUnits)
 
136
        c.Assert(err, IsNil)
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)
 
142
        c.Assert(err, IsNil)
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()
 
164
        c.Assert(err, IsNil)
 
165
        dep := deployer.NewDeployer(s.State, ctx, machineId)
146
166
        defer stop(c, dep)
147
167
 
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()))
154
175
 
155
176
        // And another.
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()))
161
182
 
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()))
168
189
 
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()))
174
195
}
175
196
 
191
212
 
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()
 
217
        c.Assert(err, IsNil)
 
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()))
230
253
func isRemoved(st *state.State, name string) func(*C) bool {
231
254
        return func(c *C) bool {
232
255
                _, err := st.Unit(name)
233
 
                if state.IsNotFound(err) {
 
256
                if errors.IsNotFoundError(err) {
234
257
                        return true
235
258
                }
236
259
                c.Assert(err, IsNil)