~rogpeppe/juju-core/azure

« back to all changes in this revision

Viewing changes to cmd/juju/deploy_test.go

[r=wallyworld] Add container support to force-machine

The deploy --force-machine option now supports containers,
either deploying to existing containers or creating new
ones on nominated machines.

Example syntax:

 juju deploy mysql --force-machine 23
 juju deploy mysql --force-machine 24/lxc/3
 juju deploy mysql --force-machine lxc:25

The last example creates a new lxc container on
machine 25.

The add-machine syntax has been tweaked to remove the
leading "/" from the container arg.

https://codereview.appspot.com/10777044/

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
        "launchpad.net/juju-core/charm"
9
9
        "launchpad.net/juju-core/constraints"
10
10
        "launchpad.net/juju-core/errors"
 
11
        "launchpad.net/juju-core/instance"
11
12
        "launchpad.net/juju-core/juju/testing"
12
13
        "launchpad.net/juju-core/state"
13
14
        coretesting "launchpad.net/juju-core/testing"
43
44
                err:  `--num-units must be a positive integer`,
44
45
        }, {
45
46
                args: []string{"craziness", "burble1", "--force-machine", "bigglesplop"},
46
 
                err:  `invalid machine id "bigglesplop"`,
 
47
                err:  `invalid --force-machine parameter "bigglesplop"`,
47
48
        }, {
48
49
                args: []string{"craziness", "burble1", "-n", "2", "--force-machine", "123"},
49
 
                err:  `cannot use --num-units with --force-machine`,
 
50
                err:  `cannot use --num-units > 1 with --force-machine`,
50
51
        }, {
51
52
                args: []string{"craziness", "burble1", "--constraints", "gibber=plop"},
52
53
                err:  `invalid value "gibber=plop" for flag --constraints: unknown constraint "gibber"`,
171
172
        c.Assert(err, ErrorMatches, `service "dummy" not found`)
172
173
}
173
174
 
174
 
func (s *DeploySuite) TestForceMachine(c *C) {
175
 
        coretesting.Charms.BundlePath(s.SeriesPath, "dummy")
176
 
        machine, err := s.State.AddMachine("precise", state.JobHostUnits)
177
 
        c.Assert(err, IsNil)
178
 
        err = runDeploy(c, "--force-machine", machine.Id(), "local:dummy", "portlandia")
179
 
        c.Assert(err, IsNil)
 
175
func (s *DeploySuite) assertForceMachine(c *C, machineId string) {
180
176
        svc, err := s.State.Service("portlandia")
181
177
        c.Assert(err, IsNil)
182
178
        units, err := svc.AllUnits()
184
180
        c.Assert(units, HasLen, 1)
185
181
        mid, err := units[0].AssignedMachineId()
186
182
        c.Assert(err, IsNil)
187
 
        c.Assert(mid, Equals, machine.Id())
 
183
        c.Assert(mid, Equals, machineId)
 
184
}
 
185
 
 
186
func (s *DeploySuite) TestForceMachine(c *C) {
 
187
        coretesting.Charms.BundlePath(s.SeriesPath, "dummy")
 
188
        machine, err := s.State.AddMachine("precise", state.JobHostUnits)
 
189
        c.Assert(err, IsNil)
 
190
        err = runDeploy(c, "--force-machine", machine.Id(), "local:dummy", "portlandia")
 
191
        c.Assert(err, IsNil)
 
192
        s.assertForceMachine(c, machine.Id())
 
193
}
 
194
 
 
195
func (s *DeploySuite) TestForceMachineExistingContainer(c *C) {
 
196
        coretesting.Charms.BundlePath(s.SeriesPath, "dummy")
 
197
        params := &state.AddMachineParams{
 
198
                Series:        "precise",
 
199
                ContainerType: instance.LXC,
 
200
                Jobs:          []state.MachineJob{state.JobHostUnits},
 
201
        }
 
202
        container, err := s.State.AddMachineWithConstraints(params)
 
203
        c.Assert(err, IsNil)
 
204
        err = runDeploy(c, "--force-machine", container.Id(), "local:dummy", "portlandia")
 
205
        c.Assert(err, IsNil)
 
206
        s.assertForceMachine(c, container.Id())
 
207
        machines, err := s.State.AllMachines()
 
208
        c.Assert(err, IsNil)
 
209
        c.Assert(machines, HasLen, 2)
 
210
}
 
211
 
 
212
func (s *DeploySuite) TestForceMachineNewContainer(c *C) {
 
213
        coretesting.Charms.BundlePath(s.SeriesPath, "dummy")
 
214
        machine, err := s.State.AddMachine("precise", state.JobHostUnits)
 
215
        c.Assert(err, IsNil)
 
216
        err = runDeploy(c, "--force-machine", "lxc:"+machine.Id(), "local:dummy", "portlandia")
 
217
        c.Assert(err, IsNil)
 
218
        s.assertForceMachine(c, machine.Id()+"/lxc/0")
 
219
        machines, err := s.State.AllMachines()
 
220
        c.Assert(err, IsNil)
 
221
        c.Assert(machines, HasLen, 2)
188
222
}
189
223
 
190
224
func (s *DeploySuite) TestForceMachineNotFound(c *C) {